diff --git a/includes/CMakeLists.txt b/includes/CMakeLists.txt index be5fca01..d6be749a 100644 --- a/includes/CMakeLists.txt +++ b/includes/CMakeLists.txt @@ -28,7 +28,6 @@ install( KBookmarkManager KBookmarkMenu KBookmarkOwner - KBreadcrumbSelectionModel KBuildSycocaProgressDialog KButtonGroup KCapacityBar @@ -46,7 +45,6 @@ install( KCalendarSystem KCharMacroExpander KCharsets - KCheckableProxyModel KCmdLineArgs KCmdLineOptions KCodecAction @@ -158,7 +156,6 @@ install( KIconEffect KIconLoader KIconTheme - KIdentityProxyModel KImageFilePreview KImageIO KInputDialog diff --git a/includes/KBreadcrumbSelectionModel b/includes/KBreadcrumbSelectionModel deleted file mode 100644 index af5d6169..00000000 --- a/includes/KBreadcrumbSelectionModel +++ /dev/null @@ -1 +0,0 @@ -#include "../kbreadcrumbselectionmodel.h" diff --git a/includes/KCheckableProxyModel b/includes/KCheckableProxyModel deleted file mode 100644 index bda9cb5b..00000000 --- a/includes/KCheckableProxyModel +++ /dev/null @@ -1 +0,0 @@ -#include "../kcheckableproxymodel.h" diff --git a/includes/KIdentityProxyModel b/includes/KIdentityProxyModel deleted file mode 100644 index ed9612f1..00000000 --- a/includes/KIdentityProxyModel +++ /dev/null @@ -1 +0,0 @@ -#include "../kidentityproxymodel.h" diff --git a/kdeui/CMakeLists.txt b/kdeui/CMakeLists.txt index d407d4d8..fed2a998 100644 --- a/kdeui/CMakeLists.txt +++ b/kdeui/CMakeLists.txt @@ -125,10 +125,7 @@ set(kdeui_LIB_SRCS icons/kicon.cpp icons/kiconloader.cpp icons/kicontheme.cpp - itemviews/kbreadcrumbselectionmodel.cpp - itemviews/kcheckableproxymodel.cpp itemviews/klinkitemselectionmodel.cpp - itemviews/kidentityproxymodel.cpp itemviews/krecursivefilterproxymodel.cpp itemviews/klistwidget.cpp itemviews/klistwidgetsearchline.cpp @@ -449,12 +446,9 @@ install( icons/kicon.h icons/kiconloader.h icons/kicontheme.h - itemviews/kbreadcrumbselectionmodel.h - itemviews/kcheckableproxymodel.h itemviews/klinkitemselectionmodel.h itemviews/krecursivefilterproxymodel.h itemviews/klistwidget.h - itemviews/kidentityproxymodel.h itemviews/klistwidgetsearchline.h itemviews/ktreewidgetsearchline.h itemviews/kfilterproxysearchline.h diff --git a/kdeui/itemviews/dox/kbreadcrumbselectionmodel.png b/kdeui/itemviews/dox/kbreadcrumbselectionmodel.png deleted file mode 100644 index 28a96d28..00000000 Binary files a/kdeui/itemviews/dox/kbreadcrumbselectionmodel.png and /dev/null differ diff --git a/kdeui/itemviews/dox/kcheckableproxymodel.png b/kdeui/itemviews/dox/kcheckableproxymodel.png deleted file mode 100644 index 24a35d21..00000000 Binary files a/kdeui/itemviews/dox/kcheckableproxymodel.png and /dev/null differ diff --git a/kdeui/itemviews/kbreadcrumbselectionmodel.cpp b/kdeui/itemviews/kbreadcrumbselectionmodel.cpp deleted file mode 100644 index f5121a97..00000000 --- a/kdeui/itemviews/kbreadcrumbselectionmodel.cpp +++ /dev/null @@ -1,240 +0,0 @@ -/* - Copyright (C) 2010 Klarälvdalens Datakonsult AB, - a KDAB Group company, info@kdab.net, - author Stephen Kelly - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - - -#include "kbreadcrumbselectionmodel.h" - -#include "kdebug.h" - -class KBreadcrumbSelectionModelPrivate -{ - Q_DECLARE_PUBLIC(KBreadcrumbSelectionModel) - KBreadcrumbSelectionModel * const q_ptr; -public: - KBreadcrumbSelectionModelPrivate(KBreadcrumbSelectionModel *breadcrumbSelector, QItemSelectionModel *selectionModel, KBreadcrumbSelectionModel::BreadcrumbTarget direction) - : q_ptr(breadcrumbSelector), - m_includeActualSelection(true), - m_selectionDepth(-1), - m_showHiddenAscendantData(false), - m_selectionModel(selectionModel), - m_direction(direction), - m_ignoreCurrentChanged(false) - { - - } - - /** - Returns a selection containing the breadcrumbs for @p index - */ - QItemSelection getBreadcrumbSelection(const QModelIndex &index); - - /** - Returns a selection containing the breadcrumbs for @p selection - */ - QItemSelection getBreadcrumbSelection(const QItemSelection &selection); - - void sourceSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected); - - void init(); - void syncBreadcrumbs(); - - bool m_includeActualSelection; - int m_selectionDepth; - bool m_showHiddenAscendantData; - QItemSelectionModel *m_selectionModel; - KBreadcrumbSelectionModel::BreadcrumbTarget m_direction; - bool m_ignoreCurrentChanged; -}; - -KBreadcrumbSelectionModel::KBreadcrumbSelectionModel(QItemSelectionModel *selectionModel, QObject* parent) - : QItemSelectionModel(const_cast(selectionModel->model()), parent), - d_ptr(new KBreadcrumbSelectionModelPrivate(this, selectionModel, MakeBreadcrumbSelectionInSelf)) -{ - d_ptr->init(); -} - -KBreadcrumbSelectionModel::KBreadcrumbSelectionModel(QItemSelectionModel *selectionModel, BreadcrumbTarget direction, QObject* parent) - : QItemSelectionModel(const_cast(selectionModel->model()), parent), - d_ptr(new KBreadcrumbSelectionModelPrivate(this, selectionModel, direction)) -{ - if ( direction != MakeBreadcrumbSelectionInSelf) - connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), - this, SLOT(sourceSelectionChanged(QItemSelection,QItemSelection))); - - d_ptr->init(); -} - -KBreadcrumbSelectionModel::~KBreadcrumbSelectionModel() -{ - delete d_ptr; -} - -bool KBreadcrumbSelectionModel::isActualSelectionIncluded() const -{ - Q_D(const KBreadcrumbSelectionModel); - return d->m_includeActualSelection; -} - -void KBreadcrumbSelectionModel::setActualSelectionIncluded(bool includeActualSelection) -{ - Q_D(KBreadcrumbSelectionModel); - d->m_includeActualSelection = includeActualSelection; -} - -int KBreadcrumbSelectionModel::breadcrumbLength() const -{ - Q_D(const KBreadcrumbSelectionModel); - return d->m_selectionDepth; -} - -void KBreadcrumbSelectionModel::setBreadcrumbLength(int breadcrumbLength) -{ - Q_D(KBreadcrumbSelectionModel); - d->m_selectionDepth = breadcrumbLength; -} - -QItemSelection KBreadcrumbSelectionModelPrivate::getBreadcrumbSelection(const QModelIndex& index) -{ - QItemSelection breadcrumbSelection; - - if (m_includeActualSelection) - breadcrumbSelection.append(QItemSelectionRange(index)); - - QModelIndex parent = index.parent(); - int sumBreadcrumbs = 0; - bool includeAll = m_selectionDepth < 0; - while (parent.isValid() && (includeAll || sumBreadcrumbs < m_selectionDepth)) { - breadcrumbSelection.append(QItemSelectionRange(parent)); - parent = parent.parent(); - } - return breadcrumbSelection; -} - -QItemSelection KBreadcrumbSelectionModelPrivate::getBreadcrumbSelection(const QItemSelection& selection) -{ - QItemSelection breadcrumbSelection; - - if (m_includeActualSelection) - breadcrumbSelection = selection; - - foreach (const QItemSelectionRange it, selection) - { - QModelIndex parent = it.parent(); - - if (breadcrumbSelection.contains(parent)) - continue; - - int sumBreadcrumbs = 0; - bool includeAll = m_selectionDepth < 0; - - while (parent.isValid() && (includeAll || sumBreadcrumbs < m_selectionDepth)) - { - breadcrumbSelection.append(QItemSelectionRange(parent)); - parent = parent.parent(); - - if (breadcrumbSelection.contains(parent)) - break; - - ++sumBreadcrumbs; - } - } - return breadcrumbSelection; -} - -void KBreadcrumbSelectionModelPrivate::sourceSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected) -{ - Q_Q(KBreadcrumbSelectionModel); - QItemSelection deselectedCrumbs = getBreadcrumbSelection(deselected); - QItemSelection selectedCrumbs = getBreadcrumbSelection(selected); - - QItemSelection removed = deselectedCrumbs; - foreach(const QItemSelectionRange &range, selectedCrumbs) - { - removed.removeAll(range); - } - - QItemSelection added = selectedCrumbs; - foreach(const QItemSelectionRange &range, deselectedCrumbs) - { - added.removeAll(range); - } - - if (!removed.isEmpty()) - { - q->QItemSelectionModel::select(removed, QItemSelectionModel::Deselect); - } - if (!added.isEmpty()) - { - q->QItemSelectionModel::select(added, QItemSelectionModel::Select); - } -} - -void KBreadcrumbSelectionModel::select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) -{ - Q_D(KBreadcrumbSelectionModel); - // When an item is removed, the current index is set to the top index in the model. - // That causes a selectionChanged signal with a selection which we do not want. - if ( d->m_ignoreCurrentChanged ) - { - d->m_ignoreCurrentChanged = false; - return; - } - if ( d->m_direction == MakeBreadcrumbSelectionInOther ) - { - d->m_selectionModel->select(d->getBreadcrumbSelection(index), command); - QItemSelectionModel::select(index, command); - } else { - d->m_selectionModel->select(index, command); - QItemSelectionModel::select(d->getBreadcrumbSelection(index), command); - } -} - -void KBreadcrumbSelectionModel::select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) -{ - Q_D(KBreadcrumbSelectionModel); - QItemSelection bcc = d->getBreadcrumbSelection(selection); - if ( d->m_direction == MakeBreadcrumbSelectionInOther ) - { - d->m_selectionModel->select(selection, command); - QItemSelectionModel::select(bcc, command); - } else { - d->m_selectionModel->select(bcc, command); - QItemSelectionModel::select(selection, command); - } -} - -void KBreadcrumbSelectionModelPrivate::init() -{ - Q_Q(KBreadcrumbSelectionModel); - q->connect(m_selectionModel->model(), SIGNAL(layoutChanged()), SLOT(syncBreadcrumbs())); - q->connect(m_selectionModel->model(), SIGNAL(modelReset()), SLOT(syncBreadcrumbs())); - q->connect(m_selectionModel->model(), SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), SLOT(syncBreadcrumbs())); - // Don't need to handle insert & remove because they can't change the breadcrumbs on their own. -} - -void KBreadcrumbSelectionModelPrivate::syncBreadcrumbs() -{ - Q_Q(KBreadcrumbSelectionModel); - q->select(m_selectionModel->selection(), QItemSelectionModel::ClearAndSelect); -} - - -#include "moc_kbreadcrumbselectionmodel.cpp" diff --git a/kdeui/itemviews/kbreadcrumbselectionmodel.h b/kdeui/itemviews/kbreadcrumbselectionmodel.h deleted file mode 100644 index 678d205f..00000000 --- a/kdeui/itemviews/kbreadcrumbselectionmodel.h +++ /dev/null @@ -1,163 +0,0 @@ -/* - Copyright (C) 2010 Klarälvdalens Datakonsult AB, - a KDAB Group company, info@kdab.net, - author Stephen Kelly - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef KBREADCRUMBSPROXYMODEL_H -#define KBREADCRUMBSPROXYMODEL_H - -#include -#include - -#include "kdeui_export.h" - -class KBreadcrumbSelectionModelPrivate; - -/** - @class KBreadcrumbSelectionModel kbreadcrumbselectionmodel.h - - @brief Selects the parents of selected items to create breadcrumbs - - For example, if the tree is - @verbatim - - A - - B - - - C - - - D - - - - E - - - - - F - @endverbatim - - and E is selected, the selection can contain - - @verbatim - - B - - D - @endverbatim - - or - - @verbatim - - B - - D - - E - @endverbatim - - if isActualSelectionIncluded is true. - - The depth of the selection may also be set. For example if the breadcrumbLength is 1: - - @verbatim - - D - - E - @endverbatim - - And if breadcrumbLength is 2: - - @verbatim - - B - - D - - E - @endverbatim - - A KBreadcrumbsProxyModel with a breadcrumbLength of 0 and including the actual selection is - the same as a KSelectionProxyModel in the KSelectionProxyModel::ExactSelection configuration. - - @code - view1->setModel(rootModel); - - QItemSelectionModel *breadcrumbSelectionModel = new QItemSelectionModel(rootModel, this); - - KBreadcrumbSelectionModel *breadcrumbProxySelector = new KBreadcrumbSelectionModel(breadcrumbSelectionModel, rootModel, this); - - view1->setSelectionModel(breadcrumbProxySelector); - - KSelectionProxyModel *breadcrumbSelectionProxyModel = new KSelectionProxyModel( breadcrumbSelectionModel, this); - breadcrumbSelectionProxyModel->setSourceModel( rootModel ); - breadcrumbSelectionProxyModel->setFilterBehavior( KSelectionProxyModel::ExactSelection ); - - view2->setModel(breadcrumbSelectionProxyModel); - @endcode - - @image html kbreadcrumbselectionmodel.png "KBreadcrumbSelectionModel in several configurations" - - This can work in two directions. One option is for a single selection in the KBreadcrumbSelectionModel to invoke - the breadcrumb selection in its constructor argument. - - The other is for a selection in the itemselectionmodel in the constructor argument to cause a breadcrumb selection - in @p this. - - @since 4.5 - -*/ -class KDEUI_EXPORT KBreadcrumbSelectionModel : public QItemSelectionModel -{ - Q_OBJECT -public: - enum BreadcrumbTarget - { - MakeBreadcrumbSelectionInOther, - MakeBreadcrumbSelectionInSelf - }; - - explicit KBreadcrumbSelectionModel(QItemSelectionModel *selectionModel, QObject* parent = 0); - KBreadcrumbSelectionModel(QItemSelectionModel *selectionModel, BreadcrumbTarget target, QObject* parent = 0); - virtual ~KBreadcrumbSelectionModel(); - - /** - Returns whether the actual selection in included in the proxy. - - The default is true. - */ - bool isActualSelectionIncluded() const; - - /** - Set whether the actual selection in included in the proxy to @p isActualSelectionIncluded. - */ - void setActualSelectionIncluded(bool isActualSelectionIncluded); - - /** - Returns the depth that the breadcrumb selection should go to. - */ - int breadcrumbLength() const; - - /** - Sets the depth that the breadcrumb selection should go to. - - If the @p breadcrumbLength is -1, all breadcrumbs are selected. - The default is -1 - */ - void setBreadcrumbLength(int breadcrumbLength); - - /* reimp */ void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command); - - /* reimp */ void select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command); - -protected: - KBreadcrumbSelectionModelPrivate * const d_ptr; -private: - //@cond PRIVATE - Q_DECLARE_PRIVATE(KBreadcrumbSelectionModel) - Q_PRIVATE_SLOT( d_func(),void sourceSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)) - Q_PRIVATE_SLOT( d_func(),void syncBreadcrumbs()) - //@cond PRIVATE -}; - - -#endif diff --git a/kdeui/itemviews/kcheckableproxymodel.cpp b/kdeui/itemviews/kcheckableproxymodel.cpp deleted file mode 100644 index 71e6b082..00000000 --- a/kdeui/itemviews/kcheckableproxymodel.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* - This file is part of KDE. - - Copyright (c) 2010 Stephen Kelly - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. -*/ - - -#include "kcheckableproxymodel.h" - -#include - -class KCheckableProxyModelPrivate -{ - Q_DECLARE_PUBLIC(KCheckableProxyModel) - KCheckableProxyModel *q_ptr; - - KCheckableProxyModelPrivate(KCheckableProxyModel *checkableModel) - : q_ptr(checkableModel), - m_itemSelectionModel(0) - { - - } - - QItemSelectionModel *m_itemSelectionModel; - - void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); - -}; - -KCheckableProxyModel::KCheckableProxyModel(QObject* parent) - : KIdentityProxyModel(parent), d_ptr(new KCheckableProxyModelPrivate(this)) -{ - -} - -KCheckableProxyModel::~KCheckableProxyModel() -{ - delete d_ptr; -} - -void KCheckableProxyModel::setSelectionModel(QItemSelectionModel* itemSelectionModel) -{ - Q_D(KCheckableProxyModel); - d->m_itemSelectionModel = itemSelectionModel; - Q_ASSERT(sourceModel() ? d->m_itemSelectionModel->model() == sourceModel() : true); - connect(itemSelectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(selectionChanged(QItemSelection,QItemSelection))); -} - -QItemSelectionModel *KCheckableProxyModel::selectionModel() const -{ - Q_D(const KCheckableProxyModel); - return d->m_itemSelectionModel; -} - -Qt::ItemFlags KCheckableProxyModel::flags(const QModelIndex& index) const -{ - if (!index.isValid() || index.column() != 0) - return KIdentityProxyModel::flags(index); - return KIdentityProxyModel::flags(index) | Qt::ItemIsUserCheckable; -} - -QVariant KCheckableProxyModel::data(const QModelIndex& index, int role) const -{ - Q_D(const KCheckableProxyModel); - - if (role == Qt::CheckStateRole) - { - if (index.column() != 0) - return QVariant(); - if (!d->m_itemSelectionModel) - return Qt::Unchecked; - - return d->m_itemSelectionModel->selection().contains(mapToSource(index)) ? Qt::Checked : Qt::Unchecked; - } - return KIdentityProxyModel::data(index, role); -} - -bool KCheckableProxyModel::setData(const QModelIndex& index, const QVariant& value, int role) -{ - Q_D(KCheckableProxyModel); - if (role == Qt::CheckStateRole) - { - if (index.column() != 0) - return false; - if (!d->m_itemSelectionModel) - return false; - - Qt::CheckState state = static_cast(value.toInt()); - const QModelIndex srcIndex = mapToSource(index); - bool result = select(QItemSelection(srcIndex, srcIndex), state == Qt::Checked ? QItemSelectionModel::Select : QItemSelectionModel::Deselect); - emit dataChanged(index, index); - return result; - } - return KIdentityProxyModel::setData(index, value, role); -} - -void KCheckableProxyModel::setSourceModel(QAbstractItemModel* sourceModel) -{ - KIdentityProxyModel::setSourceModel(sourceModel); - Q_ASSERT(d_ptr->m_itemSelectionModel ? d_ptr->m_itemSelectionModel->model() == sourceModel : true); -} - -void KCheckableProxyModelPrivate::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) -{ - Q_Q(KCheckableProxyModel); - foreach (const QItemSelectionRange &range, q->mapSelectionFromSource(selected)) - q->dataChanged(range.topLeft(), range.bottomRight()); - foreach (const QItemSelectionRange &range, q->mapSelectionFromSource(deselected)) - q->dataChanged(range.topLeft(), range.bottomRight()); -} - -bool KCheckableProxyModel::select(const QItemSelection& selection, QItemSelectionModel::SelectionFlags command) -{ - Q_D(KCheckableProxyModel); - d->m_itemSelectionModel->select(selection, command); - return true; -} - - -#include "moc_kcheckableproxymodel.cpp" - diff --git a/kdeui/itemviews/kcheckableproxymodel.h b/kdeui/itemviews/kcheckableproxymodel.h deleted file mode 100644 index 15027b43..00000000 --- a/kdeui/itemviews/kcheckableproxymodel.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - This file is part of Akonadi. - - Copyright (c) 2010 Stephen Kelly - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. -*/ - -#ifndef KCHECKABLEPROXYMODEL_H -#define KCHECKABLEPROXYMODEL_H - -#include "kidentityproxymodel.h" - -#include "kdeui_export.h" - -#include - -class KCheckableProxyModelPrivate; - -/** - * @brief Adds a checkable capability to a source model - * - * Items is standard Qt views such as QTreeView and QListView can have a - * checkable capability and draw checkboxes. Adding such a capability - * requires specific implementations of the data() and flags() virtual methods. - * This class implements those methods generically so that it is not necessary to - * implement them in your model. - * - * This can be combined with a KSelectionProxyModel showing the items currently selected - * - * @code - * - * QItemSelectionModel *checkModel = new QItemSelectionModel(rootModel, this); - * KCheckableProxyModel *checkable = new KCheckableProxyModel(this); - * checkable->setSourceModel(rootModel); - * checkable->setSelectionModel(checkModel); - * - * QTreeView *tree1 = new QTreeView(vSplitter); - * tree1->setModel(checkable); - * tree1->expandAll(); - * - * KSelectionProxyModel *selectionProxy = new KSelectionProxyModel(checkModel, this); - * selectionProxy->setFilterBehavior(KSelectionProxyModel::ExactSelection); - * selectionProxy->setSourceModel(rootModel); - * - * QTreeView *tree2 = new QTreeView(vSplitter); - * tree2->setModel(selectionProxy); - * @endcode - * - * @image html kcheckableproxymodel.png "A KCheckableProxyModel and KSelectionProxyModel showing checked items" - * - * @since 4.6 - * @author Stephen Kelly - */ -class KDEUI_EXPORT KCheckableProxyModel : public KIdentityProxyModel -{ - Q_OBJECT -public: - KCheckableProxyModel(QObject* parent = 0); - ~KCheckableProxyModel(); - - void setSelectionModel(QItemSelectionModel *itemSelectionModel); - QItemSelectionModel *selectionModel() const; - - /* reimp */ Qt::ItemFlags flags(const QModelIndex& index) const; - - /* reimp */ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; - - /* reimp */ bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); - - /* reimp */ void setSourceModel(QAbstractItemModel* sourceModel); - -protected: - virtual bool select( const QItemSelection &selection, QItemSelectionModel::SelectionFlags command ); - -private: - Q_DECLARE_PRIVATE(KCheckableProxyModel ) - KCheckableProxyModelPrivate * const d_ptr; - - Q_PRIVATE_SLOT(d_func(), void selectionChanged(const QItemSelection &, const QItemSelection &) ) -}; - -#endif - diff --git a/kdeui/itemviews/kidentityproxymodel.cpp b/kdeui/itemviews/kidentityproxymodel.cpp deleted file mode 100644 index d16cf997..00000000 --- a/kdeui/itemviews/kidentityproxymodel.cpp +++ /dev/null @@ -1,757 +0,0 @@ -/* - Copyright (C) 2010 Klarälvdalens Datakonsult AB, - a KDAB Group company, info@kdab.net, - author Stephen Kelly - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "kidentityproxymodel.h" - -#include -#include -#include - -class KIdentityProxyModelPrivate -{ - KIdentityProxyModelPrivate(KIdentityProxyModel *qq) - : q_ptr(qq) -// ignoreNextLayoutAboutToBeChanged(false), -// ignoreNextLayoutChanged(false) - { - - } - - Q_DECLARE_PUBLIC(KIdentityProxyModel) - KIdentityProxyModel * const q_ptr; - -// bool ignoreNextLayoutAboutToBeChanged; -// bool ignoreNextLayoutChanged; - QList layoutChangePersistentIndexes; - QModelIndexList proxyIndexes; - - void _k_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end); - void _k_sourceRowsInserted(const QModelIndex &parent, int start, int end); - void _k_sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end); - void _k_sourceRowsRemoved(const QModelIndex &parent, int start, int end); - void _k_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest); - void _k_sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest); - - void _k_sourceColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end); - void _k_sourceColumnsInserted(const QModelIndex &parent, int start, int end); - void _k_sourceColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end); - void _k_sourceColumnsRemoved(const QModelIndex &parent, int start, int end); - void _k_sourceColumnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest); - void _k_sourceColumnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest); - - void _k_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); - void _k_sourceHeaderDataChanged(Qt::Orientation orientation, int first, int last); - - void _k_sourceLayoutAboutToBeChanged(); - void _k_sourceLayoutChanged(); -// void _k_sourceChildrenLayoutsAboutToBeChanged(const QModelIndex &parent1, const QModelIndex &parent2); -// void _k_sourceChildrenLayoutsChanged(const QModelIndex &parent1, const QModelIndex &parent2); - void _k_sourceModelAboutToBeReset(); - void _k_sourceModelReset(); - void _k_sourceModelDestroyed(); - -}; - -/*! - \since 4.6 - \class KIdentityProxyModel - \brief The KIdentityProxyModel class proxies its source model unmodified - - \ingroup model-view - - KIdentityProxyModel can be used to forward the structure of a source model exactly, with no sorting, filtering or other transformation. - This is similar in concept to an identity matrix where A.I = A. - - Because it does no sorting or filtering, this class is most suitable to proxy models which transform the data() of the source model. - For example, a proxy model could be created to define the font used, or the background colour, or the tooltip etc. This removes the - need to implement all data handling in the same class that creates the structure of the model, and can also be used to create - re-usable components. - - This also provides a way to change the data in the case where a source model is supplied by a third party which can not be modified. - - \code - class DateFormatProxyModel : public KIdentityProxyModel - { - // ... - - void setDateFormatString(const QString &formatString) - { - m_formatString = formatString; - } - - QVariant data(const QModelIndex &index, int role) - { - if (role != Qt::DisplayRole) - return KIdentityProxyModel::data(index, role); - - const QDateTime dateTime = sourceModel()->data(SourceClass::DateRole).toDateTime(); - - return dateTime.toString(m_formatString); - } - - private: - QString m_formatString; - }; - \endcode - - \since 4.6 - \author Stephen Kelly - -*/ - -/*! - Constructs an identity model with the given \a parent. -*/ -KIdentityProxyModel::KIdentityProxyModel(QObject* parent) - : QAbstractProxyModel(parent), d_ptr(new KIdentityProxyModelPrivate(this)) -{ - -} - -/*! \internal - */ -KIdentityProxyModel::KIdentityProxyModel(KIdentityProxyModelPrivate* privateClass, QObject* parent) - : QAbstractProxyModel(parent), d_ptr(privateClass) -{ - -} - -/*! - Destroys this identity model. -*/ -KIdentityProxyModel::~KIdentityProxyModel() -{ - delete d_ptr; -} - -/*! - \reimp - */ -bool KIdentityProxyModel::canFetchMore(const QModelIndex& parent) const -{ - if (!sourceModel()) - return 0; - Q_ASSERT(parent.isValid() ? parent.model() == this : true); - return sourceModel()->canFetchMore(mapToSource(parent)); -} - -/*! - \\reimp - */ -int KIdentityProxyModel::columnCount(const QModelIndex& parent) const -{ - if (!sourceModel()) - return 0; - Q_ASSERT(parent.isValid() ? parent.model() == this : true); - return sourceModel()->columnCount(mapToSource(parent)); -} - -/*! - \reimp - */ -void KIdentityProxyModel::fetchMore(const QModelIndex& parent) -{ - if (!sourceModel()) - return; - Q_ASSERT(parent.isValid() ? parent.model() == this : true); - sourceModel()->fetchMore(mapToSource(parent)); -} - -/*! - \\reimp - */ -bool KIdentityProxyModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) -{ - if (!sourceModel()) - return false; - Q_ASSERT(parent.isValid() ? parent.model() == this : true); - return sourceModel()->dropMimeData(data, action, row, column, mapToSource(parent)); -} - -/*! - \reimp - */ -QModelIndex KIdentityProxyModel::index(int row, int column, const QModelIndex& parent) const -{ - if (!sourceModel()) - return QModelIndex(); - Q_ASSERT(parent.isValid() ? parent.model() == this : true); - const QModelIndex sourceParent = mapToSource(parent); - const QModelIndex sourceIndex = sourceModel()->index(row, column, sourceParent); - return mapFromSource(sourceIndex); -} - -/*! - \reimp - */ -bool KIdentityProxyModel::insertColumns(int column, int count, const QModelIndex& parent) -{ - if (!sourceModel()) - return false; - Q_ASSERT(parent.isValid() ? parent.model() == this : true); - return sourceModel()->insertColumns(column, count, mapToSource(parent)); -} - -/*! - \reimp - */ -bool KIdentityProxyModel::insertRows(int row, int count, const QModelIndex& parent) -{ - if (!sourceModel()) - return false; - Q_ASSERT(parent.isValid() ? parent.model() == this : true); - return sourceModel()->insertRows(row, count, mapToSource(parent)); -} - -/*! - \reimp - */ -QModelIndex KIdentityProxyModel::mapFromSource(const QModelIndex& sourceIndex) const -{ - if (!sourceModel() || !sourceIndex.isValid()) - return QModelIndex(); - - Q_ASSERT(sourceIndex.model() == sourceModel()); - return createIndex(sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer()); -} - -/*! - \reimp - */ -QItemSelection KIdentityProxyModel::mapSelectionFromSource(const QItemSelection& selection) const -{ - QItemSelection proxySelection; - - if (!sourceModel()) - return proxySelection; - - QItemSelection::const_iterator it = selection.constBegin(); - const QItemSelection::const_iterator end = selection.constEnd(); - for ( ; it != end; ++it) { - Q_ASSERT(it->model() == sourceModel()); - const QItemSelectionRange range(mapFromSource(it->topLeft()), mapFromSource(it->bottomRight())); - proxySelection.append(range); - } - - return proxySelection; -} - -/*! - \reimp - */ -QItemSelection KIdentityProxyModel::mapSelectionToSource(const QItemSelection& selection) const -{ - QItemSelection sourceSelection; - - if (!sourceModel()) - return sourceSelection; - - QItemSelection::const_iterator it = selection.constBegin(); - const QItemSelection::const_iterator end = selection.constEnd(); - for ( ; it != end; ++it) { - Q_ASSERT(it->model() == this); - const QItemSelectionRange range(mapToSource(it->topLeft()), mapToSource(it->bottomRight())); - sourceSelection.append(range); - } - - return sourceSelection; -} - -struct SourceModelIndex -{ - SourceModelIndex(int _r, int _c, void *_p, QAbstractItemModel *_m) - : r(_r), c(_c), p(_p), m(_m) - { - - } - - operator QModelIndex() { return reinterpret_cast(*this); } - - int r, c; - void *p; - const QAbstractItemModel *m; -}; - -/*! - \reimp - */ -QModelIndex KIdentityProxyModel::mapToSource(const QModelIndex& proxyIndex) const -{ - if (!sourceModel() || !proxyIndex.isValid()) - return QModelIndex(); - Q_ASSERT(proxyIndex.model() == this); - return SourceModelIndex(proxyIndex.row(), proxyIndex.column(), proxyIndex.internalPointer(), sourceModel()); -} - -/*! - \reimp - */ -QModelIndexList KIdentityProxyModel::match(const QModelIndex& start, int role, const QVariant& value, int hits, Qt::MatchFlags flags) const -{ - Q_ASSERT(start.isValid() ? start.model() == this : true); - if (!sourceModel()) - return QModelIndexList(); - - const QModelIndexList sourceList = sourceModel()->match(mapToSource(start), role, value, hits, flags); - QModelIndexList::const_iterator it = sourceList.constBegin(); - const QModelIndexList::const_iterator end = sourceList.constEnd(); - QModelIndexList proxyList; - for ( ; it != end; ++it) - proxyList.append(mapFromSource(*it)); - return proxyList; -} - -/*! - \reimp - */ -QStringList KIdentityProxyModel::mimeTypes() const -{ - if (sourceModel()) - return sourceModel()->mimeTypes(); - else - return QAbstractProxyModel::mimeTypes(); -} - -QMimeData* KIdentityProxyModel::mimeData(const QModelIndexList& indexes) const -{ - if (!sourceModel()) - return QAbstractProxyModel::mimeData(indexes); - - QModelIndexList proxyIndexes; - foreach(const QModelIndex &index, indexes) - proxyIndexes.append(mapToSource(index)); - - return sourceModel()->mimeData(proxyIndexes); -} - - -/*! - \\reimp - */ -QModelIndex KIdentityProxyModel::parent(const QModelIndex& child) const -{ - if (!sourceModel()) - return QModelIndex(); - - Q_ASSERT(child.isValid() ? child.model() == this : true); - const QModelIndex sourceIndex = mapToSource(child); - const QModelIndex sourceParent = sourceIndex.parent(); - return mapFromSource(sourceParent); -} - -/*! - \reimp - */ -bool KIdentityProxyModel::removeColumns(int column, int count, const QModelIndex& parent) -{ - if (!sourceModel()) - return false; - - Q_ASSERT(parent.isValid() ? parent.model() == this : true); - return sourceModel()->removeColumns(column, count, mapToSource(parent)); -} - -/*! - \reimp - */ -bool KIdentityProxyModel::removeRows(int row, int count, const QModelIndex& parent) -{ - if (!sourceModel()) - return false; - - Q_ASSERT(parent.isValid() ? parent.model() == this : true); - return sourceModel()->removeRows(row, count, mapToSource(parent)); -} - -/*! - \reimp - */ -int KIdentityProxyModel::rowCount(const QModelIndex& parent) const -{ - if (!sourceModel()) - return 0; - Q_ASSERT(parent.isValid() ? parent.model() == this : true); - return sourceModel()->rowCount(mapToSource(parent)); -} - -/*! - \reimp - */ -void KIdentityProxyModel::setSourceModel(QAbstractItemModel* sourceModel) -{ - beginResetModel(); - - if (sourceModel) { - disconnect(sourceModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), - this, SLOT(_k_sourceRowsAboutToBeInserted(QModelIndex,int,int))); - disconnect(sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)), - this, SLOT(_k_sourceRowsInserted(QModelIndex,int,int))); - disconnect(sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), - this, SLOT(_k_sourceRowsAboutToBeRemoved(QModelIndex,int,int))); - disconnect(sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), - this, SLOT(_k_sourceRowsRemoved(QModelIndex,int,int))); - disconnect(sourceModel, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), - this, SLOT(_k_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int))); - disconnect(sourceModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), - this, SLOT(_k_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int))); - disconnect(sourceModel, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), - this, SLOT(_k_sourceColumnsAboutToBeInserted(QModelIndex,int,int))); - disconnect(sourceModel, SIGNAL(columnsInserted(QModelIndex,int,int)), - this, SLOT(_k_sourceColumnsInserted(QModelIndex,int,int))); - disconnect(sourceModel, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), - this, SLOT(_k_sourceColumnsAboutToBeRemoved(QModelIndex,int,int))); - disconnect(sourceModel, SIGNAL(columnsRemoved(QModelIndex,int,int)), - this, SLOT(_k_sourceColumnsRemoved(QModelIndex,int,int))); - disconnect(sourceModel, SIGNAL(columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), - this, SLOT(_k_sourceColumnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int))); - disconnect(sourceModel, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)), - this, SLOT(_k_sourceColumnsMoved(QModelIndex,int,int,QModelIndex,int))); - disconnect(sourceModel, SIGNAL(modelAboutToBeReset()), - this, SLOT(_k_sourceModelAboutToBeReset())); -// disconnect(sourceModel, SIGNAL(internalDataReset()), -// this, SLOT(resetInternalData())); - disconnect(sourceModel, SIGNAL(modelReset()), - this, SLOT(_k_sourceModelReset())); - disconnect(sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), - this, SLOT(_k_sourceDataChanged(QModelIndex,QModelIndex))); - disconnect(sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), - this, SLOT(_k_sourceHeaderDataChanged(Qt::Orientation,int,int))); - disconnect(sourceModel, SIGNAL(layoutAboutToBeChanged()), - this, SLOT(_k_sourceLayoutAboutToBeChanged())); - disconnect(sourceModel, SIGNAL(layoutChanged()), - this, SLOT(_k_sourceLayoutChanged())); -// disconnect(sourceModel, SIGNAL(childrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)), -// this, SLOT(_k_sourceChildrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex))); -// disconnect(sourceModel, SIGNAL(childrenLayoutsChanged(QModelIndex,QModelIndex)), -// this, SLOT(_k_sourceChildrenLayoutsChanged(QModelIndex,QModelIndex))); - disconnect(sourceModel, SIGNAL(destroyed()), - this, SLOT(_k_sourceModelDestroyed())); - } - - QAbstractProxyModel::setSourceModel(sourceModel); - - if (sourceModel) { - connect(sourceModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), - SLOT(_k_sourceRowsAboutToBeInserted(QModelIndex,int,int))); - connect(sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)), - SLOT(_k_sourceRowsInserted(QModelIndex,int,int))); - connect(sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), - SLOT(_k_sourceRowsAboutToBeRemoved(QModelIndex,int,int))); - connect(sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), - SLOT(_k_sourceRowsRemoved(QModelIndex,int,int))); - connect(sourceModel, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), - SLOT(_k_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int))); - connect(sourceModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), - SLOT(_k_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int))); - connect(sourceModel, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), - SLOT(_k_sourceColumnsAboutToBeInserted(QModelIndex,int,int))); - connect(sourceModel, SIGNAL(columnsInserted(QModelIndex,int,int)), - SLOT(_k_sourceColumnsInserted(QModelIndex,int,int))); - connect(sourceModel, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), - SLOT(_k_sourceColumnsAboutToBeRemoved(QModelIndex,int,int))); - connect(sourceModel, SIGNAL(columnsRemoved(QModelIndex,int,int)), - SLOT(_k_sourceColumnsRemoved(QModelIndex,int,int))); - connect(sourceModel, SIGNAL(columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), - SLOT(_k_sourceColumnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int))); - connect(sourceModel, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)), - SLOT(_k_sourceColumnsMoved(QModelIndex,int,int,QModelIndex,int))); - connect(sourceModel, SIGNAL(modelAboutToBeReset()), - SLOT(_k_sourceModelAboutToBeReset())); -// connect(sourceModel, SIGNAL(internalDataReset()), -// SLOT(resetInternalData())); - connect(sourceModel, SIGNAL(modelReset()), - SLOT(_k_sourceModelReset())); - connect(sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), - SLOT(_k_sourceDataChanged(QModelIndex,QModelIndex))); - connect(sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), - SLOT(_k_sourceHeaderDataChanged(Qt::Orientation,int,int))); - connect(sourceModel, SIGNAL(layoutAboutToBeChanged()), - SLOT(_k_sourceLayoutAboutToBeChanged())); - connect(sourceModel, SIGNAL(layoutChanged()), - SLOT(_k_sourceLayoutChanged())); - // Hopefully this will be in Qt4.8 -// connect(sourceModel, SIGNAL(childrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex)), -// SLOT(_k_sourceChildrenLayoutsAboutToBeChanged(QModelIndex,QModelIndex))); -// connect(sourceModel, SIGNAL(childrenLayoutsChanged(QModelIndex,QModelIndex)), -// SLOT(_k_sourceChildrenLayoutsChanged(QModelIndex,QModelIndex))); - connect(sourceModel, SIGNAL(destroyed()), - SLOT(_k_sourceModelDestroyed())); - } - - endResetModel(); -} - -Qt::DropActions KIdentityProxyModel::supportedDropActions() const -{ - if (sourceModel()) - return sourceModel()->supportedDropActions(); - else - return QAbstractProxyModel::supportedDropActions(); -} - -void KIdentityProxyModelPrivate::_k_sourceColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end) -{ - Q_Q(KIdentityProxyModel); - Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true); - q->beginInsertColumns(q->mapFromSource(parent), start, end); -} - -void KIdentityProxyModelPrivate::_k_sourceColumnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest) -{ - Q_Q(KIdentityProxyModel); - Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true); - Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true); - q->beginMoveColumns(q->mapFromSource(sourceParent), sourceStart, sourceEnd, q->mapFromSource(destParent), dest); -} - -void KIdentityProxyModelPrivate::_k_sourceColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end) -{ - Q_Q(KIdentityProxyModel); - Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true); - q->beginRemoveColumns(q->mapFromSource(parent), start, end); -} - -void KIdentityProxyModelPrivate::_k_sourceColumnsInserted(const QModelIndex &parent, int start, int end) -{ - Q_Q(KIdentityProxyModel); - Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true); - Q_UNUSED(parent) - Q_UNUSED(start) - Q_UNUSED(end) - q->endInsertColumns(); -} - -void KIdentityProxyModelPrivate::_k_sourceColumnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest) -{ - Q_Q(KIdentityProxyModel); - Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true); - Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true); - Q_UNUSED(sourceParent) - Q_UNUSED(sourceStart) - Q_UNUSED(sourceEnd) - Q_UNUSED(destParent) - Q_UNUSED(dest) - q->endMoveColumns(); -} - -void KIdentityProxyModelPrivate::_k_sourceColumnsRemoved(const QModelIndex &parent, int start, int end) -{ - Q_Q(KIdentityProxyModel); - Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true); - Q_UNUSED(parent) - Q_UNUSED(start) - Q_UNUSED(end) - q->endRemoveColumns(); -} - -void KIdentityProxyModelPrivate::_k_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) -{ - Q_Q(KIdentityProxyModel); - Q_ASSERT(topLeft.model() == q->sourceModel()); - Q_ASSERT(bottomRight.model() == q->sourceModel()); - q->dataChanged(q->mapFromSource(topLeft), q->mapFromSource(bottomRight)); -} - -void KIdentityProxyModelPrivate::_k_sourceHeaderDataChanged(Qt::Orientation orientation, int first, int last) -{ - Q_Q(KIdentityProxyModel); - q->headerDataChanged(orientation, first, last); -} - -void KIdentityProxyModelPrivate::_k_sourceLayoutAboutToBeChanged() -{ - //if (ignoreNextLayoutAboutToBeChanged) - // return; - - Q_Q(KIdentityProxyModel); - - q->layoutAboutToBeChanged(); - - Q_FOREACH(const QModelIndex &proxyPersistentIndex, q->persistentIndexList()) { - Q_ASSERT(proxyPersistentIndex.isValid()); - const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex); - if (!srcPersistentIndex.isValid()) // can happen with extra columns, e.g. KPIM::StatisticsProxyModel - continue; - proxyIndexes << proxyPersistentIndex; - layoutChangePersistentIndexes << srcPersistentIndex; - } -} - -void KIdentityProxyModelPrivate::_k_sourceLayoutChanged() -{ - //if (ignoreNextLayoutChanged) - // return; - - Q_Q(KIdentityProxyModel); - - for (int i = 0; i < proxyIndexes.size(); ++i) { - const QModelIndex oldProxyIndex = proxyIndexes.at(i); - const QModelIndex newProxyIndex = q->mapFromSource(layoutChangePersistentIndexes.at(i)); - if (oldProxyIndex != newProxyIndex) - q->changePersistentIndex(oldProxyIndex, newProxyIndex); - } - - layoutChangePersistentIndexes.clear(); - proxyIndexes.clear(); - - q->layoutChanged(); -} - -#if 0 // this code was for the stuff that never went into Qt-4.8. We are keeping it for the Qt5 QIPM sourceLayoutChanged(QModelIndex) future code. -void KIdentityProxyModelPrivate::_k_sourceChildrenLayoutsAboutToBeChanged(const QModelIndex &parent1, const QModelIndex &parent2) -{ - Q_Q(KIdentityProxyModel); - Q_ASSERT(parent1.isValid() ? parent1.model() == q->sourceModel() : true); - Q_ASSERT(parent2.isValid() ? parent2.model() == q->sourceModel() : true); - - - ignoreNextLayoutAboutToBeChanged = true; - - const QModelIndex proxyParent1 = q->mapFromSource(parent1); - const QModelIndex proxyParent2 = q->mapFromSource(parent2); - //emit q->childrenLayoutsAboutToBeChanged(proxyParent1, proxyParent2); - emit q->layoutAboutToBeChanged(); - - if (q->persistentIndexList().isEmpty()) - return; - - Q_FOREACH(const QModelIndex &proxyPersistentIndex, q->persistentIndexList()) { - const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex); - Q_ASSERT(proxyPersistentIndex.isValid()); - Q_ASSERT(srcPersistentIndex.isValid()); - const QModelIndex idxParent = srcPersistentIndex.parent(); - if (idxParent != parent1 && idxParent != parent2) - continue; - proxyIndexes << proxyPersistentIndex; - layoutChangePersistentIndexes << srcPersistentIndex; - } -} - -void KIdentityProxyModelPrivate::_k_sourceChildrenLayoutsChanged(const QModelIndex &parent1, const QModelIndex &parent2) -{ - Q_Q(KIdentityProxyModel); - Q_ASSERT(parent1.isValid() ? parent1.model() == q->sourceModel() : true); - Q_ASSERT(parent2.isValid() ? parent2.model() == q->sourceModel() : true); - - ignoreNextLayoutChanged = true; - - QModelIndexList oldList, newList; - for( int i = 0; i < layoutChangePersistentIndexes.size(); ++i) { - const QModelIndex srcIdx = layoutChangePersistentIndexes.at(i); - const QModelIndex oldProxyIdx = proxyIndexes.at(i); - oldList << oldProxyIdx; - newList << q->mapFromSource(srcIdx); - } - q->changePersistentIndexList(oldList, newList); - layoutChangePersistentIndexes.clear(); - proxyIndexes.clear(); - - const QModelIndex proxyParent1 = q->mapFromSource(parent1); - const QModelIndex proxyParent2 = q->mapFromSource(parent2); -// emit q->childrenLayoutsChanged(proxyParent1, proxyParent2); - emit q->layoutChanged(); -} -#endif - -void KIdentityProxyModelPrivate::_k_sourceModelAboutToBeReset() -{ - Q_Q(KIdentityProxyModel); - q->beginResetModel(); -} - -void KIdentityProxyModelPrivate::_k_sourceModelReset() -{ - Q_Q(KIdentityProxyModel); - q->endResetModel(); -} - -void KIdentityProxyModelPrivate::_k_sourceModelDestroyed() -{ -// Q_Q(KIdentityProxyModel); -// q->endResetModel(); -} - -void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end) -{ - Q_Q(KIdentityProxyModel); - Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true); - q->beginInsertRows(q->mapFromSource(parent), start, end); -} - -void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest) -{ - Q_Q(KIdentityProxyModel); - Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true); - Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true); - q->beginMoveRows(q->mapFromSource(sourceParent), sourceStart, sourceEnd, q->mapFromSource(destParent), dest); -} - -void KIdentityProxyModelPrivate::_k_sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) -{ - Q_Q(KIdentityProxyModel); - Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true); - q->beginRemoveRows(q->mapFromSource(parent), start, end); -} - -void KIdentityProxyModelPrivate::_k_sourceRowsInserted(const QModelIndex &parent, int start, int end) -{ - Q_Q(KIdentityProxyModel); - Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true); - Q_UNUSED(parent) - Q_UNUSED(start) - Q_UNUSED(end) - q->endInsertRows(); -} - -void KIdentityProxyModelPrivate::_k_sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest) -{ - Q_Q(KIdentityProxyModel); - Q_ASSERT(sourceParent.isValid() ? sourceParent.model() == q->sourceModel() : true); - Q_ASSERT(destParent.isValid() ? destParent.model() == q->sourceModel() : true); - Q_UNUSED(sourceParent) - Q_UNUSED(sourceStart) - Q_UNUSED(sourceEnd) - Q_UNUSED(destParent) - Q_UNUSED(dest) - q->endMoveRows(); -} - -void KIdentityProxyModelPrivate::_k_sourceRowsRemoved(const QModelIndex &parent, int start, int end) -{ - Q_Q(KIdentityProxyModel); - Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true); - Q_UNUSED(parent) - Q_UNUSED(start) - Q_UNUSED(end) - q->endRemoveRows(); -} - -/*! - This slot is automatically invoked when the model is reset. It can be used to clear any data internal to the proxy at the appropriate time. - - \sa QAbstractItemModel::internalDataReset() - */ -void KIdentityProxyModel::resetInternalData() -{ - -} - -#include "moc_kidentityproxymodel.cpp" diff --git a/kdeui/itemviews/kidentityproxymodel.h b/kdeui/itemviews/kidentityproxymodel.h deleted file mode 100644 index d2810b30..00000000 --- a/kdeui/itemviews/kidentityproxymodel.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - Copyright (C) 2010 Klarälvdalens Datakonsult AB, - a KDAB Group company, info@kdab.net, - author Stephen Kelly - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef KIDENTITYPROXYMODEL_H -#define KIDENTITYPROXYMODEL_H - -#include - -#include "kdeui_export.h" - -class KIdentityProxyModelPrivate; - -class KDEUI_EXPORT KIdentityProxyModel : public QAbstractProxyModel -{ - Q_OBJECT -public: - explicit KIdentityProxyModel(QObject* parent = 0); - virtual ~KIdentityProxyModel(); - - int columnCount(const QModelIndex& parent = QModelIndex()) const; - QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const; - QModelIndex mapFromSource(const QModelIndex& sourceIndex) const; - QModelIndex mapToSource(const QModelIndex& proxyIndex) const; - QModelIndex parent(const QModelIndex& child) const; - int rowCount(const QModelIndex& parent = QModelIndex()) const; - bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent); - - QItemSelection mapSelectionFromSource(const QItemSelection& selection) const; - QItemSelection mapSelectionToSource(const QItemSelection& selection) const; - QModelIndexList match(const QModelIndex& start, int role, const QVariant& value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const; - void setSourceModel(QAbstractItemModel* sourceModel); - - bool insertColumns(int column, int count, const QModelIndex& parent = QModelIndex()); - bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()); - bool removeColumns(int column, int count, const QModelIndex& parent = QModelIndex()); - bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()); - - virtual bool canFetchMore(const QModelIndex& parent) const; - virtual void fetchMore(const QModelIndex& parent); - virtual QStringList mimeTypes() const; - virtual QMimeData* mimeData(const QModelIndexList& indexes) const; - virtual Qt::DropActions supportedDropActions() const; - -protected: - KIdentityProxyModel(KIdentityProxyModelPrivate *privateClass, QObject* parent); - KIdentityProxyModelPrivate * const d_ptr; - -protected Q_SLOTS: - virtual void resetInternalData(); - -private: - Q_DECLARE_PRIVATE(KIdentityProxyModel) - Q_DISABLE_COPY(KIdentityProxyModel) - - Q_PRIVATE_SLOT(d_func(), void _k_sourceRowsAboutToBeInserted(QModelIndex,int,int)) - Q_PRIVATE_SLOT(d_func(), void _k_sourceRowsInserted(QModelIndex,int,int)) - Q_PRIVATE_SLOT(d_func(), void _k_sourceRowsAboutToBeRemoved(QModelIndex,int,int)) - Q_PRIVATE_SLOT(d_func(), void _k_sourceRowsRemoved(QModelIndex,int,int)) - Q_PRIVATE_SLOT(d_func(), void _k_sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)) - Q_PRIVATE_SLOT(d_func(), void _k_sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)) - - Q_PRIVATE_SLOT(d_func(), void _k_sourceColumnsAboutToBeInserted(QModelIndex,int,int)) - Q_PRIVATE_SLOT(d_func(), void _k_sourceColumnsInserted(QModelIndex,int,int)) - Q_PRIVATE_SLOT(d_func(), void _k_sourceColumnsAboutToBeRemoved(QModelIndex,int,int)) - Q_PRIVATE_SLOT(d_func(), void _k_sourceColumnsRemoved(QModelIndex,int,int)) - Q_PRIVATE_SLOT(d_func(), void _k_sourceColumnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)) - Q_PRIVATE_SLOT(d_func(), void _k_sourceColumnsMoved(QModelIndex,int,int,QModelIndex,int)) - - Q_PRIVATE_SLOT(d_func(), void _k_sourceDataChanged(QModelIndex,QModelIndex)) - Q_PRIVATE_SLOT(d_func(), void _k_sourceHeaderDataChanged(Qt::Orientation orientation, int first, int last)) - - Q_PRIVATE_SLOT(d_func(), void _k_sourceLayoutAboutToBeChanged()) - Q_PRIVATE_SLOT(d_func(), void _k_sourceLayoutChanged()) - // Q_PRIVATE_SLOT(d_func(), void _k_sourceChildrenLayoutsAboutToBeChanged(const QModelIndex &parent1, const QModelIndex &parent2)) - // Q_PRIVATE_SLOT(d_func(), void _k_sourceChildrenLayoutsChanged(const QModelIndex &parent1, const QModelIndex &parent2)) - Q_PRIVATE_SLOT(d_func(), void _k_sourceModelAboutToBeReset()) - Q_PRIVATE_SLOT(d_func(), void _k_sourceModelReset()) - Q_PRIVATE_SLOT(d_func(), void _k_sourceModelDestroyed()) -}; - -#endif // KIDENTITYPROXYMODEL_H