diff --git a/src/kbreadcrumbselectionmodel.h b/src/kbreadcrumbselectionmodel.h index 0680a83..10109dc 100644 --- a/src/kbreadcrumbselectionmodel.h +++ b/src/kbreadcrumbselectionmodel.h @@ -1,161 +1,161 @@ /* 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 "kitemmodels_export.h" class KBreadcrumbSelectionModelPrivate; /** - @class KBreadcrumbSelectionModel kbreadcrumbselectionmodel.h + @class KBreadcrumbSelectionModel kbreadcrumbselectionmodel.h KBreadcrumbSelectionModel @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 KBreadcrumbsSelectionModel 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 KITEMMODELS_EXPORT KBreadcrumbSelectionModel : public QItemSelectionModel { Q_OBJECT public: enum BreadcrumbTarget { MakeBreadcrumbSelectionInOther, MakeBreadcrumbSelectionInSelf }; explicit KBreadcrumbSelectionModel(QItemSelectionModel *selectionModel, QObject *parent = nullptr); KBreadcrumbSelectionModel(QItemSelectionModel *selectionModel, BreadcrumbTarget target, QObject *parent = nullptr); 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) Q_DECL_OVERRIDE; /* reimp */ void select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) Q_DECL_OVERRIDE; 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/src/kcheckableproxymodel.h b/src/kcheckableproxymodel.h index 334b6b8..d524a90 100644 --- a/src/kcheckableproxymodel.h +++ b/src/kcheckableproxymodel.h @@ -1,93 +1,95 @@ /* Copyright (c) 2010 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 KCHECKABLEPROXYMODEL_H #define KCHECKABLEPROXYMODEL_H #include "kitemmodels_export.h" #include #include class KCheckableProxyModelPrivate; /** + * @class KCheckableProxyModel kcheckableproxymodel.h KCheckableProxyModel + * * @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 KITEMMODELS_EXPORT KCheckableProxyModel : public QIdentityProxyModel { Q_OBJECT public: KCheckableProxyModel(QObject *parent = nullptr); ~KCheckableProxyModel(); void setSelectionModel(QItemSelectionModel *itemSelectionModel); QItemSelectionModel *selectionModel() const; /* reimp */ Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; /* reimp */ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; /* reimp */ bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE; /* reimp */ void setSourceModel(QAbstractItemModel *sourceModel) Q_DECL_OVERRIDE; 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/src/kconcatenaterowsproxymodel.h b/src/kconcatenaterowsproxymodel.h index ab2112c..e5e5d37 100644 --- a/src/kconcatenaterowsproxymodel.h +++ b/src/kconcatenaterowsproxymodel.h @@ -1,151 +1,153 @@ /* Copyright (c) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Authors: David Faure 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 KCONCATENATEROWSPROXYMODEL_H #define KCONCATENATEROWSPROXYMODEL_H #include #include #include "kitemmodels_export.h" class KConcatenateRowsProxyModelPrivate; /** + * @class KConcatenateRowsProxyModel kconcatenaterowsproxymodel.h KConcatenateRowsProxyModel + * * This proxy takes multiple source models and concatenates their rows. * * In other words, the proxy will have all rows of the first source model, * followed by all rows of the second source model, etc. * * Only flat models (lists and tables) are supported, no trees. * * All models are assumed to have the same number of columns. * More precisely, the number of columns of the first source model is used, * so all source models should have at least as many columns as the first source model, * and additional columns in other source models will simply be ignored. * * Source models can be added and removed at runtime, including the first source * model (but it should keep the same number of columns). * * Dynamic insertion and removal of rows and columns in any source model is supported. * dataChanged, layoutChanged and reset coming from the source models are supported. * * At the moment this model doesn't support editing, drag-n-drop. * It could be added though, nothing prevents it. * * This proxy does not inherit from QAbstractProxyModel because it uses multiple source * models, rather than a single one. * * Author: David Faure, KDAB * @since 5.14 */ class KITEMMODELS_EXPORT KConcatenateRowsProxyModel : public QAbstractItemModel { Q_OBJECT public: /** * Creates a KConcatenateRowsProxyModel. * @param parent optional parent */ KConcatenateRowsProxyModel(QObject *parent = nullptr); /** * Destructor. */ virtual ~KConcatenateRowsProxyModel(); /** * Adds a source model @p sourceModel, after all existing source models. * @param sourceModel the source model * * The ownership of @p sourceModel is not affected by this. * The same source model cannot be added more than once. */ Q_SCRIPTABLE void addSourceModel(QAbstractItemModel *sourceModel); /** * Removes the source model @p sourceModel. * @param sourceModel a source model previously added to this proxy * * The ownership of @sourceModel is not affected by this. */ Q_SCRIPTABLE void removeSourceModel(QAbstractItemModel *sourceModel); /** * Returns the proxy index for a given source index * @param sourceIndex an index coming from any of the source models * @return a proxy index * Calling this method with an index not from a source model is undefined behavior. */ QModelIndex mapFromSource(const QModelIndex &sourceIndex) const; /** * Returns the source index for a given proxy index. * @param proxyIndex an index for this proxy model * @return a source index */ QModelIndex mapToSource(const QModelIndex &proxyIndex) const; /// @reimp QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; /// @reimp bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole) Q_DECL_OVERRIDE; /// @reimp QMap itemData(const QModelIndex &proxyIndex) const Q_DECL_OVERRIDE; /// @reimp Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; /// @reimp QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; /// @reimp QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE; /// @reimp int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; /** * The horizontal header data for the first source model is returned here. * @reimp */ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; /** * The column count for the first source model is returned here. * @reimp */ int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; private: Q_PRIVATE_SLOT(d, void slotRowsAboutToBeInserted(const QModelIndex &, int start, int end)) Q_PRIVATE_SLOT(d, void slotRowsInserted(const QModelIndex &, int start, int end)) Q_PRIVATE_SLOT(d, void slotRowsAboutToBeRemoved(const QModelIndex &, int start, int end)) Q_PRIVATE_SLOT(d, void slotRowsRemoved(const QModelIndex &, int start, int end)) Q_PRIVATE_SLOT(d, void slotColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end)) Q_PRIVATE_SLOT(d, void slotColumnsInserted(const QModelIndex &parent, int, int)) Q_PRIVATE_SLOT(d, void slotColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)) Q_PRIVATE_SLOT(d, void slotColumnsRemoved(const QModelIndex &parent, int, int)) Q_PRIVATE_SLOT(d, void slotDataChanged(const QModelIndex &from, const QModelIndex &to, const QVector &roles)) Q_PRIVATE_SLOT(d, void slotSourceLayoutAboutToBeChanged(QList, QAbstractItemModel::LayoutChangeHint)) Q_PRIVATE_SLOT(d, void slotSourceLayoutChanged(const QList &, QAbstractItemModel::LayoutChangeHint)) Q_PRIVATE_SLOT(d, void slotModelAboutToBeReset()) Q_PRIVATE_SLOT(d, void slotModelReset()) private: friend class KConcatenateRowsProxyModelPrivate; const QScopedPointer d; }; #endif diff --git a/src/kdescendantsproxymodel.h b/src/kdescendantsproxymodel.h index ec4cd1f..136a120 100644 --- a/src/kdescendantsproxymodel.h +++ b/src/kdescendantsproxymodel.h @@ -1,206 +1,208 @@ /* Copyright (c) 2009 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 KDESCENDANTSPROXYMODEL_P_H #define KDESCENDANTSPROXYMODEL_P_H #include class KDescendantsProxyModelPrivate; #include "kitemmodels_export.h" /** +@class KDescendantsProxyModel kdescendantsproxymodel.h KDescendantsProxyModel + @brief Proxy Model for restructuring a Tree into a list. A KDescendantsProxyModel may be used to alter how the items in the tree are presented. Given a model which is represented as a tree: \image html entitytreemodel.png "A plain EntityTreeModel in a view" The KDescendantsProxyModel restructures the sourceModel to represent it as a flat list. @code // ... Create an entityTreeModel KDescendantsProxyModel *descProxy = new KDescendantsProxyModel(this); descProxy->setSourceModel(entityTree); view->setModel(descProxy); @endcode \image html descendantentitiesproxymodel.png "A KDescendantsProxyModel." KDescendantEntitiesProxyModel can also display the ancestors of the index in the source model as part of its display. @code // ... Create an entityTreeModel KDescendantsProxyModel *descProxy = new KDescendantsProxyModel(this); descProxy->setSourceModel(entityTree); // #### This is new descProxy->setDisplayAncestorData(true); descProxy->setAncestorSeparator(QString(" / ")); view->setModel(descProxy); @endcode \image html descendantentitiesproxymodel-withansecnames.png "A KDescendantsProxyModel with ancestor names." @since 4.6 @author Stephen Kelly */ class KITEMMODELS_EXPORT KDescendantsProxyModel : public QAbstractProxyModel { Q_OBJECT public: /** * Creates a new descendant entities proxy model. * * @param parent The parent object. */ explicit KDescendantsProxyModel(QObject *parent = nullptr); /** * Destroys the descendant entities proxy model. */ virtual ~KDescendantsProxyModel(); /** * Sets the source @p model of the proxy. */ void setSourceModel(QAbstractItemModel *model) Q_DECL_OVERRIDE; /** * @deprecated * * This method does nothing. */ void setRootIndex(const QModelIndex &index); /** * Set whether to show ancestor data in the model. If @p display is true, then * a source model which is displayed as * * @code * -> "Item 0-0" (this is row-depth) * -> -> "Item 0-1" * -> -> "Item 1-1" * -> -> -> "Item 0-2" * -> -> -> "Item 1-2" * -> "Item 1-0" * @endcode * * will be displayed as * * @code * -> *Item 0-0" * -> "Item 0-0 / Item 0-1" * -> "Item 0-0 / Item 1-1" * -> "Item 0-0 / Item 1-1 / Item 0-2" * -> "Item 0-0 / Item 1-1 / Item 1-2" * -> "Item 1-0" * @endcode * * If @p display is false, the proxy will show * * @code * -> *Item 0-0" * -> "Item 0-1" * -> "Item 1-1" * -> "Item 0-2" * -> "Item 1-2" * -> "Item 1-0" * @endcode * * Default is false. */ void setDisplayAncestorData(bool display); /** * Whether ancestor data will be displayed. */ bool displayAncestorData() const; /** * Sets the ancestor @p separator used between data of ancestors. */ void setAncestorSeparator(const QString &separator); /** * Separator used between data of ancestors. */ QString ancestorSeparator() const; QModelIndex mapFromSource(const QModelIndex &sourceIndex) const Q_DECL_OVERRIDE; QModelIndex mapToSource(const QModelIndex &proxyIndex) const Q_DECL_OVERRIDE; Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; QVariant headerData(int section, Qt::Orientation orientation, int role) const Q_DECL_OVERRIDE; QMimeData *mimeData(const QModelIndexList &indexes) const Q_DECL_OVERRIDE; QStringList mimeTypes() const Q_DECL_OVERRIDE; bool hasChildren(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; QModelIndex index(int, int, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; QModelIndex parent(const QModelIndex &) const Q_DECL_OVERRIDE; int columnCount(const QModelIndex &index = QModelIndex()) const Q_DECL_OVERRIDE; Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE; /** Reimplemented to match all descendants. */ virtual QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const Q_DECL_OVERRIDE; private: Q_DECLARE_PRIVATE(KDescendantsProxyModel) //@cond PRIVATE KDescendantsProxyModelPrivate *d_ptr; Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeInserted(const QModelIndex &, int, int)) Q_PRIVATE_SLOT(d_func(), void sourceRowsInserted(const QModelIndex &, int, int)) Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeRemoved(const QModelIndex &, int, int)) Q_PRIVATE_SLOT(d_func(), void sourceRowsRemoved(const QModelIndex &, int, int)) Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)) Q_PRIVATE_SLOT(d_func(), void sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)) Q_PRIVATE_SLOT(d_func(), void sourceModelAboutToBeReset()) Q_PRIVATE_SLOT(d_func(), void sourceModelReset()) Q_PRIVATE_SLOT(d_func(), void sourceLayoutAboutToBeChanged()) Q_PRIVATE_SLOT(d_func(), void sourceLayoutChanged()) Q_PRIVATE_SLOT(d_func(), void sourceDataChanged(const QModelIndex &, const QModelIndex &)) Q_PRIVATE_SLOT(d_func(), void sourceModelDestroyed()) Q_PRIVATE_SLOT(d_func(), void processPendingParents()) // Make these private, they shouldn't be called by applications // virtual bool insertRows(int , int, const QModelIndex & = QModelIndex()); // virtual bool insertColumns(int, int, const QModelIndex & = QModelIndex()); // virtual bool removeRows(int, int, const QModelIndex & = QModelIndex()); // virtual bool removeColumns(int, int, const QModelIndex & = QModelIndex()); //@endcond }; #endif diff --git a/src/kextracolumnsproxymodel.h b/src/kextracolumnsproxymodel.h index 0f49dff..a4a34cc 100644 --- a/src/kextracolumnsproxymodel.h +++ b/src/kextracolumnsproxymodel.h @@ -1,157 +1,159 @@ /* Copyright (c) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Authors: David Faure 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 KEXTRACOLUMNSPROXYMODEL_H #define KEXTRACOLUMNSPROXYMODEL_H #include #include #include "kitemmodels_export.h" class KExtraColumnsProxyModelPrivate; /** + * @class KExtraColumnsProxyModel kextracolumnsproxymodel.h KExtraColumnsProxyModel + * * This proxy appends extra columns (after all existing columns). * * The proxy supports source models that have a tree structure. * It also supports editing, and propagating changes from the source model. * Row insertion/removal, column insertion/removal in the source model are supported. * * Not supported: adding/removing extra columns at runtime; having a different number of columns in subtrees; * drag-n-drop support in the extra columns; moving columns. * * Derive from KExtraColumnsProxyModel, call appendColumn (typically in the constructor) for each extra column, * and reimplement extraColumnData() to allow KExtraColumnsProxyModel to retrieve the data to show in the extra columns. * * If you want your new column(s) to be somewhere else than at the right of the existing columns, you can * use a KRearrangeColumnsProxyModel on top. * * Author: David Faure, KDAB * @since 5.13 */ class KITEMMODELS_EXPORT KExtraColumnsProxyModel : public QIdentityProxyModel { Q_OBJECT public: /** * Base class constructor. * Remember to call setSourceModel afterwards, and appendColumn. */ explicit KExtraColumnsProxyModel(QObject *parent = nullptr); /** * Destructor. */ ~KExtraColumnsProxyModel(); // API /** * Appends an extra column. * @param header an optional text for the horizontal header * This does not emit any signals - do it in the initial setup phase */ void appendColumn(const QString &header = QString()); /** * Removes an extra column. * @param idx index of the extra column (starting from 0). * This does not emit any signals - do it in the initial setup phase * @since 5.24 */ void removeExtraColumn(int idx); /** * This method is called by data() for extra columns. * Reimplement this method to return the data for the extra columns. * * @param parent the parent model index in the proxy model (only useful in tree models) * @param row the row number for which the proxy model is querying for data (child of @p parent, if set) * @param extraColumn the number of the extra column, starting at 0 (this doesn't require knowing how many columns the source model has) * @param role the role being queried * @return the data at @p row and @p extraColumn */ virtual QVariant extraColumnData(const QModelIndex &parent, int row, int extraColumn, int role = Qt::DisplayRole) const = 0; // KF6 TODO: add extraColumnFlags() virtual method /** * This method is called by setData() for extra columns. * Reimplement this method to set the data for the extra columns, if editing is supported. * Remember to call extraColumnDataChanged() after changing the data storage. * The default implementation returns false. */ virtual bool setExtraColumnData(const QModelIndex &parent, int row, int extraColumn, const QVariant &data, int role = Qt::EditRole); /** * This method can be called by your derived class when the data in an extra column has changed. * The use case is data that changes "by itself", unrelated to setData. */ void extraColumnDataChanged(const QModelIndex &parent, int row, int extraColumn, const QVector &roles); /** * Returns the extra column number (0, 1, ...) for a given column number of the proxymodel. * This basically means subtracting the amount of columns in the source model. */ int extraColumnForProxyColumn(int proxyColumn) const; /** * Returns the proxy column number for a given extra column number (starting at 0). * This basically means adding the amount of columns in the source model. */ int proxyColumnForExtraColumn(int extraColumn) const; // Implementation /// @reimp void setSourceModel(QAbstractItemModel *model) Q_DECL_OVERRIDE; /// @reimp QModelIndex mapToSource(const QModelIndex &proxyIndex) const Q_DECL_OVERRIDE; /// @reimp QItemSelection mapSelectionToSource(const QItemSelection &selection) const Q_DECL_OVERRIDE; /// @reimp int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; /// @reimp QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; /// @reimp bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE; /// @reimp QModelIndex sibling(int row, int column, const QModelIndex &idx) const Q_DECL_OVERRIDE; /// @reimp QModelIndex buddy(const QModelIndex &index) const Q_DECL_OVERRIDE; /// @reimp Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; /// @reimp bool hasChildren(const QModelIndex &index) const Q_DECL_OVERRIDE; /// @reimp QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; /// @reimp QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; /// @reimp QModelIndex parent(const QModelIndex &child) const Q_DECL_OVERRIDE; private: Q_DECLARE_PRIVATE(KExtraColumnsProxyModel) Q_PRIVATE_SLOT(d_func(), void _ec_sourceLayoutAboutToBeChanged(const QList &, QAbstractItemModel::LayoutChangeHint)) Q_PRIVATE_SLOT(d_func(), void _ec_sourceLayoutChanged(const QList &, QAbstractItemModel::LayoutChangeHint)) const QScopedPointer d_ptr; }; #endif diff --git a/src/klinkitemselectionmodel.h b/src/klinkitemselectionmodel.h index aecb217..98a822e 100644 --- a/src/klinkitemselectionmodel.h +++ b/src/klinkitemselectionmodel.h @@ -1,131 +1,133 @@ /* Copyright (C) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net, author Stephen Kelly Copyright (c) 2016 Ableton AG 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 KLINKITEMSELECTIONMODEL_H #define KLINKITEMSELECTIONMODEL_H #include #include #include "kitemmodels_export.h" class KLinkItemSelectionModelPrivate; /** + @class KLinkItemSelectionModel klinkitemselectionmodel.h KLinkItemSelectionModel + @brief Makes it possible to share a selection in multiple views which do not have the same source model Although multiple views can share the same QItemSelectionModel, the views then need to have the same source model. If there is a proxy model between the model and one of the views, or different proxy models in each, this class makes it possible to share the selection between the views. @image html kproxyitemselectionmodel-simple.png "Sharing a QItemSelectionModel between views on the same model is trivial" @image html kproxyitemselectionmodel-error.png "If a proxy model is used, it is no longer possible to share the QItemSelectionModel directly" @image html kproxyitemselectionmodel-solution.png "A KLinkItemSelectionModel can be used to map the selection through the proxy model" @code QAbstractItemModel *model = getModel(); QSortFilterProxyModel *proxy = new QSortFilterProxyModel(); proxy->setSourceModel(model); QTreeView *view1 = new QTreeView(splitter); view1->setModel(model); KLinkItemSelectionModel *view2SelectionModel = new KLinkItemSelectionModel( proxy, view1->selectionModel()); QTreeView *view2 = new QTreeView(splitter); // Note that the QAbstractItemModel passed to KLinkItemSelectionModel must be the same as what is used in the view view2->setModel(proxy); view2->setSelectionModel( view2SelectionModel ); @endcode @image html kproxyitemselectionmodel-complex.png "Arbitrarily complex proxy configurations on the same root model can be used" @code QAbstractItemModel *model = getModel(); QSortFilterProxyModel *proxy1 = new QSortFilterProxyModel(); proxy1->setSourceModel(model); QSortFilterProxyModel *proxy2 = new QSortFilterProxyModel(); proxy2->setSourceModel(proxy1); QSortFilterProxyModel *proxy3 = new QSortFilterProxyModel(); proxy3->setSourceModel(proxy2); QTreeView *view1 = new QTreeView(splitter); view1->setModel(proxy3); QSortFilterProxyModel *proxy4 = new QSortFilterProxyModel(); proxy4->setSourceModel(model); QSortFilterProxyModel *proxy5 = new QSortFilterProxyModel(); proxy5->setSourceModel(proxy4); KLinkItemSelectionModel *view2SelectionModel = new KLinkItemSelectionModel( proxy5, view1->selectionModel()); QTreeView *view2 = new QTreeView(splitter); // Note that the QAbstractItemModel passed to KLinkItemSelectionModel must be the same as what is used in the view view2->setModel(proxy5); view2->setSelectionModel( view2SelectionModel ); @endcode See also kdelibs/kdeui/tests/proxymodeltestapp/proxyitemselectionwidget.cpp. @since 4.5 @author Stephen Kelly */ class KITEMMODELS_EXPORT KLinkItemSelectionModel : public QItemSelectionModel { Q_OBJECT Q_PROPERTY(QItemSelectionModel *linkedItemSelectionModel READ linkedItemSelectionModel WRITE setLinkedItemSelectionModel NOTIFY linkedItemSelectionModelChanged) public: /** Constructor. */ KLinkItemSelectionModel(QAbstractItemModel *targetModel, QItemSelectionModel *linkedItemSelectionModel, QObject *parent = nullptr); explicit KLinkItemSelectionModel(QObject *parent = nullptr); ~KLinkItemSelectionModel(); QItemSelectionModel *linkedItemSelectionModel() const; void setLinkedItemSelectionModel(QItemSelectionModel *selectionModel); void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) Q_DECL_OVERRIDE; void select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) Q_DECL_OVERRIDE; Q_SIGNALS: void linkedItemSelectionModelChanged(); protected: KLinkItemSelectionModelPrivate *const d_ptr; private: Q_DECLARE_PRIVATE(KLinkItemSelectionModel) Q_PRIVATE_SLOT(d_func(), void sourceSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)) Q_PRIVATE_SLOT(d_func(), void sourceCurrentChanged(const QModelIndex ¤t)) Q_PRIVATE_SLOT(d_func(), void slotCurrentChanged(const QModelIndex ¤t)) }; #endif diff --git a/src/kmodelindexproxymapper.h b/src/kmodelindexproxymapper.h index 0caed89..3090d78 100644 --- a/src/kmodelindexproxymapper.h +++ b/src/kmodelindexproxymapper.h @@ -1,134 +1,136 @@ /* Copyright (C) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net, author Stephen Kelly Copyright (c) 2016 Ableton AG 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 KMODELINDEXPROXYMAPPER_H #define KMODELINDEXPROXYMAPPER_H #include #include "kitemmodels_export.h" class QAbstractItemModel; class QModelIndex; class QItemSelection; class KModelIndexProxyMapperPrivate; /** + * @class KModelIndexProxyMapper kmodelindexproxymapper.h KModelIndexProxyMapper + * * @brief This class facilitates easy mapping of indexes and selections through proxy models. * * In a complex system of proxy models there can be a need to map indexes and selections between them, * and sometimes to do so without knowledge of the path from one model to another. * * For example, * * @verbatim * Root model * | * / \ * Proxy 1 Proxy 3 * | | * Proxy 2 Proxy 4 * @endverbatim * * If there is a need to map indexes between proxy 2 and proxy 4, a KModelIndexProxyMapper can be created * to facilitate mapping of indexes between them. * * @code * m_indexMapper = new KModelIndexProxyMapper(proxy2, proxy4, this); * * ... * * const QModelIndex proxy4Index = m_mapLeftToRight(proxy2->index(0, 0)); * Q_ASSERT(proxy4Index.model() == proxy4); * @endcode * * Note that the aim is to achieve black box connections so that there is no need for application code to * know the structure of proxy models in the path between left and right and attempt to manually map them. * * @verbatim * Root model * | * --------------- * | Black Box | * --------------- * | | * Proxy 2 Proxy 4 * @endverbatim * * The isConnected property indicates whether there is a * path from the left side to the right side. * * @author Stephen Kelly * */ class KITEMMODELS_EXPORT KModelIndexProxyMapper : public QObject { Q_OBJECT /** * Indicates whether there is a chain that can be followed from leftModel to rightModel. * * This value can change if the sourceModel of an intermediate proxy is changed. */ Q_PROPERTY(bool isConnected READ isConnected NOTIFY isConnectedChanged) public: /** * Constructor */ KModelIndexProxyMapper(const QAbstractItemModel *leftModel, const QAbstractItemModel *rightModel, QObject *parent = nullptr); ~KModelIndexProxyMapper(); /** * Maps the @p index from the left model to the right model. */ QModelIndex mapLeftToRight(const QModelIndex &index) const; /** * Maps the @p index from the right model to the left model. */ QModelIndex mapRightToLeft(const QModelIndex &index) const; /** * Maps the @p selection from the left model to the right model. */ QItemSelection mapSelectionLeftToRight(const QItemSelection &selection) const; /** * Maps the @p selection from the right model to the left model. */ QItemSelection mapSelectionRightToLeft(const QItemSelection &selection) const; bool isConnected() const; Q_SIGNALS: void isConnectedChanged(); private: //@cond PRIVATE Q_DECLARE_PRIVATE(KModelIndexProxyMapper) KModelIndexProxyMapperPrivate *const d_ptr; //@endcond }; #endif diff --git a/src/krearrangecolumnsproxymodel.h b/src/krearrangecolumnsproxymodel.h index bd955c6..c2ac8eb 100644 --- a/src/krearrangecolumnsproxymodel.h +++ b/src/krearrangecolumnsproxymodel.h @@ -1,96 +1,98 @@ /* Copyright (c) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Authors: David Faure 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 REARRANGECOLUMNSPROXYMODEL_H #define REARRANGECOLUMNSPROXYMODEL_H #include #include #include "kitemmodels_export.h" class KRearrangeColumnsProxyModelPrivate; /** + * @class KRearrangeColumnsProxyModel krearrangecolumnsproxymodel.h KRearrangeColumnsProxyModel + * * This proxy shows specific columns from the source model, in any order. * This allows to reorder columns, as well as not showing all of them. * * The proxy supports source models that have a tree structure. * It also supports editing, and propagating changes from the source model. * * Showing the same source column more than once is not supported. * * Author: David Faure, KDAB * @since 5.12 */ class KITEMMODELS_EXPORT KRearrangeColumnsProxyModel : public QIdentityProxyModel { Q_OBJECT public: /** * Creates a KRearrangeColumnsProxyModel proxy. * Remember to call setSourceModel afterwards. */ explicit KRearrangeColumnsProxyModel(QObject *parent = nullptr); /** * Destructor. */ ~KRearrangeColumnsProxyModel(); // API /** * Set the chosen source columns, in the desired order for the proxy columns * columns[proxyColumn=0] is the source column to show in the first proxy column, etc. * * Example: QVector() << 2 << 1; * This examples configures the proxy to hide column 0, show column 2 from the source model, * then show column 1 from the source model. */ void setSourceColumns(const QVector &columns); // Implementation /// @reimp int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; /// @reimp int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; /// @reimp QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; /// @reimp QModelIndex parent(const QModelIndex &child) const Q_DECL_OVERRIDE; /// @reimp QModelIndex mapFromSource(const QModelIndex &sourceIndex) const Q_DECL_OVERRIDE; /// @reimp QModelIndex mapToSource(const QModelIndex &proxyIndex) const Q_DECL_OVERRIDE; /// @reimp QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; private: int proxyColumnForSourceColumn(int sourceColumn) const; int sourceColumnForProxyColumn(int proxyColumn) const; private: const QScopedPointer d_ptr; }; #endif diff --git a/src/krecursivefilterproxymodel.h b/src/krecursivefilterproxymodel.h index 5f9e415..5b57884 100644 --- a/src/krecursivefilterproxymodel.h +++ b/src/krecursivefilterproxymodel.h @@ -1,136 +1,138 @@ /* Copyright (c) 2009 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 KRECURSIVEFILTERPROXYMODEL_H #define KRECURSIVEFILTERPROXYMODEL_H #include #include "kitemmodels_export.h" class KRecursiveFilterProxyModelPrivate; /** + @class KRecursiveFilterProxyModel krecursivefilterproxymodel.h KRecursiveFilterProxyModel + @brief Implements recursive filtering of models Until Qt 5.10, QSortFilterProxyModel did not recurse when invoking a filtering stage, so that if a particular row is filtered out, its children are not even checked to see if they match the filter. If you can depend on Qt >= 5.10, then just use QSortFilterProxyModel::setRecursiveFiltering(true), and you don't need to use KRecursiveFilterProxyModel. For example, given a source model: @verbatim - A - B - - C - - - D - - - - E - - - F - - G - - H - I @endverbatim If a QSortFilterProxyModel is used with a filter matching A, D, G and I, the QSortFilterProxyModel will contain @verbatim - A - I @endverbatim That is, even though D and E match the filter, they are not represented in the proxy model because B does not match the filter and is filtered out. The KRecursiveFilterProxyModel checks child indexes for filter matching and ensures that all matching indexes are represented in the model. In the above example, the KRecursiveFilterProxyModel will contain @verbatim - A - B - - C - - - D - - G - I @endverbatim That is, the leaves in the model match the filter, but not necessarily the inner branches. QSortFilterProxyModel provides the virtual method filterAcceptsRow to allow custom filter implementations. Custom filter implementations can be written for KRecuriveFilterProxyModel using the acceptRow virtual method. Note that using this proxy model is additional overhead compared to QSortFilterProxyModel as every index in the model must be visited and queried. @author Stephen Kelly @since 4.5 */ class KITEMMODELS_EXPORT KRecursiveFilterProxyModel : public QSortFilterProxyModel { Q_OBJECT public: /** Constructor */ explicit KRecursiveFilterProxyModel(QObject *parent = nullptr); /** Destructor */ virtual ~KRecursiveFilterProxyModel(); /** @reimp */ void setSourceModel(QAbstractItemModel *model) Q_DECL_OVERRIDE; /** * @reimplemented */ QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const Q_DECL_OVERRIDE; protected: /** Reimplement this method for custom filtering strategies. */ virtual bool acceptRow(int sourceRow, const QModelIndex &sourceParent) const; /** @reimp */ bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_OVERRIDE; KRecursiveFilterProxyModelPrivate *const d_ptr; private: //@cond PRIVATE Q_DECLARE_PRIVATE(KRecursiveFilterProxyModel) Q_PRIVATE_SLOT(d_func(), void sourceDataChanged(const QModelIndex &source_top_left, const QModelIndex &source_bottom_right, const QVector &roles = QVector())) Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeInserted(const QModelIndex &source_parent, int start, int end)) Q_PRIVATE_SLOT(d_func(), void sourceRowsInserted(const QModelIndex &source_parent, int start, int end)) Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeRemoved(const QModelIndex &source_parent, int start, int end)) Q_PRIVATE_SLOT(d_func(), void sourceRowsRemoved(const QModelIndex &source_parent, int start, int end)) //@endcond }; #endif diff --git a/src/kselectionproxymodel.h b/src/kselectionproxymodel.h index 0b1d627..a505a57 100644 --- a/src/kselectionproxymodel.h +++ b/src/kselectionproxymodel.h @@ -1,336 +1,338 @@ /* Copyright (c) 2009 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 KSELECTIONPROXYMODEL_H #define KSELECTIONPROXYMODEL_H #include #include #include "kitemmodels_export.h" class KSelectionProxyModelPrivate; /** + @class KSelectionProxyModel kselectionproxymodel.h KSelectionProxyModel + @brief A Proxy Model which presents a subset of its source model to observers. The KSelectionProxyModel is most useful as a convenience for displaying the selection in one view in another view. The selectionModel of the initial view is used to create a proxied model which is filtered based on the configuration of this class. For example, when a user clicks a mail folder in one view in an email application, the contained emails should be displayed in another view. This takes away the need for the developer to handle the selection between the views, including all the mapToSource, mapFromSource and setRootIndex calls. @code MyModel *sourceModel = new MyModel(this); QTreeView *leftView = new QTreeView(this); leftView->setModel(sourceModel); KSelectionProxyModel *selectionProxy = new KSelectionProxyModel(leftView->selectionModel(), this); selectionProxy->setSourceModel(sourceModel); QTreeView *rightView = new QTreeView(this); rightView->setModel(selectionProxy); @endcode \image html selectionproxymodelsimpleselection.png "A Selection in one view creating a model for use with another view." The KSelectionProxyModel can handle complex selections. \image html selectionproxymodelmultipleselection.png "Non-contiguous selection creating a new simple model in a second view." The contents of the secondary view depends on the selection in the primary view, and the configuration of the proxy model. See KSelectionProxyModel::setFilterBehavior for the different possible configurations. For example, if the filterBehavior is SubTrees, selecting another item in an already selected subtree has no effect. \image html selectionproxymodelmultipleselection-withdescendant.png "Selecting an item and its descendant." See the test application in tests/proxymodeltestapp to try out the valid configurations. \image html kselectionproxymodel-testapp.png "KSelectionProxyModel test application" Obviously, the KSelectionProxyModel may be used in a view, or further processed with other proxy models. See KAddressBook and AkonadiConsole in kdepim for examples which use a further KDescendantsProxyModel and QSortFilterProxyModel on top of a KSelectionProxyModel. Additionally, this class can be used to programmatically choose some items from the source model to display in the view. For example, this is how the Favourite Folder View in KMail works, and is also used in unit testing. See also: https://doc.qt.io/qt-5/model-view-programming.html#proxy-models @since 4.4 @author Stephen Kelly */ class KITEMMODELS_EXPORT KSelectionProxyModel : public QAbstractProxyModel { Q_OBJECT Q_PROPERTY(FilterBehavior filterBehavior READ filterBehavior WRITE setFilterBehavior NOTIFY filterBehaviorChanged) Q_PROPERTY(QItemSelectionModel *selectionModel READ selectionModel WRITE setSelectionModel NOTIFY selectionModelChanged) public: /** ctor. @p selectionModel The selection model used to filter what is presented by the proxy. */ // KF6: Remove the selectionModel from the constructor here. explicit KSelectionProxyModel(QItemSelectionModel *selectionModel, QObject *parent = nullptr); /** Default constructor. Allow the creation of a KSelectionProxyModel in QML code. QML will assign a parent after construction. */ // KF6: Remove in favor of the constructor above. explicit KSelectionProxyModel(); /** dtor */ virtual ~KSelectionProxyModel(); /** reimp. */ void setSourceModel(QAbstractItemModel *sourceModel) Q_DECL_OVERRIDE; QItemSelectionModel *selectionModel() const; void setSelectionModel(QItemSelectionModel *selectionModel); enum FilterBehavior { SubTrees, SubTreeRoots, SubTreesWithoutRoots, ExactSelection, ChildrenOfExactSelection, InvalidBehavior }; Q_ENUM(FilterBehavior) /** Set the filter behaviors of this model. The filter behaviors of the model govern the content of the model based on the selection of the contained QItemSelectionModel. See kdeui/proxymodeltestapp to try out the different proxy model behaviors. The most useful behaviors are SubTrees, ExactSelection and ChildrenOfExactSelection. The default behavior is SubTrees. This means that this proxy model will contain the roots of the items in the source model. Any descendants which are also selected have no additional effect. For example if the source model is like: @verbatim (root) - A - B - C - D - E - F - G - H - I - J - K - L @endverbatim And A, B, C and D are selected, the proxy will contain: @verbatim (root) - A - B - C - D - E - F - G @endverbatim That is, selecting 'D' or 'C' if 'B' is also selected has no effect. If 'B' is de-selected, then 'C' amd 'D' become top-level items: @verbatim (root) - A - C - D - E - F - G @endverbatim This is the behavior used by KJots when rendering books. If the behavior is set to SubTreeRoots, then the children of selected indexes are not part of the model. If 'A', 'B' and 'D' are selected, @verbatim (root) - A - B @endverbatim Note that although 'D' is selected, it is not part of the proxy model, because its parent 'B' is already selected. SubTreesWithoutRoots has the effect of not making the selected items part of the model, but making their children part of the model instead. If 'A', 'B' and 'I' are selected: @verbatim (root) - C - D - E - F - G - J - K - L @endverbatim Note that 'A' has no children, so selecting it has no outward effect on the model. ChildrenOfExactSelection causes the proxy model to contain the children of the selected indexes,but further descendants are omitted. Additionally, if descendants of an already selected index are selected, their children are part of the proxy model. For example, if 'A', 'B', 'D' and 'I' are selected: @verbatim (root) - C - D - E - G - J - K - L @endverbatim This would be useful for example if showing containers (for example maildirs) in one view and their items in another. Sub-maildirs would still appear in the proxy, but could be filtered out using a QSortfilterProxyModel. The ExactSelection behavior causes the selected items to be part of the proxy model, even if their ancestors are already selected, but children of selected items are not included. Again, if 'A', 'B', 'D' and 'I' are selected: @verbatim (root) - A - B - D - I @endverbatim This is the behavior used by the Favourite Folder View in KMail. */ void setFilterBehavior(FilterBehavior behavior); FilterBehavior filterBehavior() const; QModelIndex mapFromSource(const QModelIndex &sourceIndex) const Q_DECL_OVERRIDE; QModelIndex mapToSource(const QModelIndex &proxyIndex) const Q_DECL_OVERRIDE; QItemSelection mapSelectionFromSource(const QItemSelection &selection) const Q_DECL_OVERRIDE; QItemSelection mapSelectionToSource(const QItemSelection &selection) const Q_DECL_OVERRIDE; Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; QMimeData *mimeData(const QModelIndexList &indexes) const Q_DECL_OVERRIDE; QStringList mimeTypes() const Q_DECL_OVERRIDE; Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE; bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) Q_DECL_OVERRIDE; bool hasChildren(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; QModelIndex index(int, int, const QModelIndex & = QModelIndex()) const Q_DECL_OVERRIDE; QModelIndex parent(const QModelIndex &) const Q_DECL_OVERRIDE; int columnCount(const QModelIndex & = QModelIndex()) const Q_DECL_OVERRIDE; virtual QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const Q_DECL_OVERRIDE; Q_SIGNALS: #if !defined(Q_MOC_RUN) && !defined(DOXYGEN_SHOULD_SKIP_THIS) && !defined(IN_IDE_PARSER) private: // Don't allow subclasses to emit these Q_SIGNALS. #endif /** @internal Emitted before @p removeRootIndex, an index in the sourceModel is removed from the root selected indexes. This may be unrelated to rows removed from the model, depending on configuration. */ void rootIndexAboutToBeRemoved(const QModelIndex &removeRootIndex); /** @internal Emitted when @p newIndex, an index in the sourceModel is added to the root selected indexes. This may be unrelated to rows inserted to the model, depending on configuration. */ void rootIndexAdded(const QModelIndex &newIndex); /** @internal Emitted before @p selection, a selection in the sourceModel, is removed from the root selection. */ void rootSelectionAboutToBeRemoved(const QItemSelection &selection); /** @internal Emitted after @p selection, a selection in the sourceModel, is added to the root selection. */ void rootSelectionAdded(const QItemSelection &selection); void selectionModelChanged(); void filterBehaviorChanged(); protected: QList sourceRootIndexes() const; private: Q_DECLARE_PRIVATE(KSelectionProxyModel) //@cond PRIVATE KSelectionProxyModelPrivate *d_ptr; Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeInserted(const QModelIndex &, int, int)) Q_PRIVATE_SLOT(d_func(), void sourceRowsInserted(const QModelIndex &, int, int)) Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeRemoved(const QModelIndex &, int, int)) Q_PRIVATE_SLOT(d_func(), void sourceRowsRemoved(const QModelIndex &, int, int)) Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)) Q_PRIVATE_SLOT(d_func(), void sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)) Q_PRIVATE_SLOT(d_func(), void sourceModelAboutToBeReset()) Q_PRIVATE_SLOT(d_func(), void sourceModelReset()) Q_PRIVATE_SLOT(d_func(), void sourceLayoutAboutToBeChanged()) Q_PRIVATE_SLOT(d_func(), void sourceLayoutChanged()) Q_PRIVATE_SLOT(d_func(), void sourceDataChanged(const QModelIndex &, const QModelIndex &)) Q_PRIVATE_SLOT(d_func(), void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)) Q_PRIVATE_SLOT(d_func(), void sourceModelDestroyed()) //@endcond }; #endif