KSelectionProxyModel

Search for usage in LXR

#include <KSelectionProxyModel>

Inheritance diagram for KSelectionProxyModel:

Public Types

enum  FilterBehavior {
  SubTrees, SubTreeRoots, SubTreesWithoutRoots, ExactSelection,
  ChildrenOfExactSelection, InvalidBehavior
}
 
- Public Types inherited from QAbstractItemModel
enum  CheckIndexOption
 
enum  LayoutChangeHint
 

Properties

FilterBehavior filterBehavior
 
QItemSelectionModel selectionModel
 
- Properties inherited from QAbstractProxyModel
 sourceModel
 
- Properties inherited from QObject
 objectName
 

Signals

void filterBehaviorChanged (QPrivateSignal)
 
void rootIndexAboutToBeRemoved (const QModelIndex &removeRootIndex, QPrivateSignal)
 
void rootIndexAdded (const QModelIndex &newIndex, QPrivateSignal)
 
void rootSelectionAboutToBeRemoved (const QItemSelection &selection, QPrivateSignal)
 
void rootSelectionAdded (const QItemSelection &selection, QPrivateSignal)
 
void selectionModelChanged (QPrivateSignal)
 

Public Member Functions

 KSelectionProxyModel (QItemSelectionModel *selectionModel, QObject *parent=nullptr)
 
 KSelectionProxyModel ()
 
 ~KSelectionProxyModel () override
 
int columnCount (const QModelIndex &=QModelIndex()) const override
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
 
FilterBehavior filterBehavior () const
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 
bool hasChildren (const QModelIndex &parent=QModelIndex()) const override
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 
QModelIndex index (int, int, const QModelIndex &=QModelIndex()) const override
 
QModelIndex mapFromSource (const QModelIndex &sourceIndex) const override
 
QItemSelection mapSelectionFromSource (const QItemSelection &selection) const override
 
QItemSelection mapSelectionToSource (const QItemSelection &selection) const override
 
QModelIndex mapToSource (const QModelIndex &proxyIndex) const 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 override
 
QMimeDatamimeData (const QModelIndexList &indexes) const override
 
QStringList mimeTypes () const override
 
QModelIndex parent (const QModelIndex &) const override
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
QItemSelectionModelselectionModel () const
 
void setFilterBehavior (FilterBehavior behavior)
 
void setSelectionModel (QItemSelectionModel *selectionModel)
 
void setSourceModel (QAbstractItemModel *sourceModel) override
 
Qt::DropActions supportedDropActions () const override
 
- Public Member Functions inherited from QAbstractProxyModel
 QAbstractProxyModel (QObject *parent)
 
virtual QModelIndex buddy (const QModelIndex &index) const const override
 
virtual bool canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const const override
 
virtual bool canFetchMore (const QModelIndex &parent) const const override
 
virtual void fetchMore (const QModelIndex &parent) override
 
virtual QMap< int, QVariantitemData (const QModelIndex &proxyIndex) const const override
 
virtual void revert () override
 
virtual bool setData (const QModelIndex &index, const QVariant &value, int role) override
 
virtual bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role) override
 
virtual bool setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles) override
 
virtual QModelIndex sibling (int row, int column, const QModelIndex &idx) const const override
 
virtual void sort (int column, Qt::SortOrder order) override
 
QAbstractItemModelsourceModel () const const
 
void sourceModelChanged ()
 
virtual QSize span (const QModelIndex &index) const const override
 
virtual bool submit () override
 
virtual Qt::DropActions supportedDragActions () const const override
 
- Public Member Functions inherited from QAbstractItemModel
 QAbstractItemModel (QObject *parent)
 
bool checkIndex (const QModelIndex &index, QAbstractItemModel::CheckIndexOptions options) const const
 
void columnsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 
void columnsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
 
void columnsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 
void columnsInserted (const QModelIndex &parent, int first, int last)
 
void columnsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column)
 
void columnsRemoved (const QModelIndex &parent, int first, int last)
 
void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)
 
bool hasIndex (int row, int column, const QModelIndex &parent) const const
 
void headerDataChanged (Qt::Orientation orientation, int first, int last)
 
bool insertColumn (int column, const QModelIndex &parent)
 
virtual bool insertColumns (int column, int count, const QModelIndex &parent)
 
bool insertRow (int row, const QModelIndex &parent)
 
virtual bool insertRows (int row, int count, const QModelIndex &parent)
 
void layoutAboutToBeChanged (const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
 
void layoutChanged (const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
 
void modelAboutToBeReset ()
 
void modelReset ()
 
bool moveColumn (const QModelIndex &sourceParent, int sourceColumn, const QModelIndex &destinationParent, int destinationChild)
 
virtual bool moveColumns (const QModelIndex &sourceParent, int sourceColumn, int count, const QModelIndex &destinationParent, int destinationChild)
 
bool moveRow (const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild)
 
virtual bool moveRows (const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)
 
bool removeColumn (int column, const QModelIndex &parent)
 
virtual bool removeColumns (int column, int count, const QModelIndex &parent)
 
bool removeRow (int row, const QModelIndex &parent)
 
virtual bool removeRows (int row, int count, const QModelIndex &parent)
 
virtual QHash< int, QByteArrayroleNames () const const
 
void rowsAboutToBeInserted (const QModelIndex &parent, int start, int end)
 
void rowsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
 
void rowsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 
void rowsInserted (const QModelIndex &parent, int first, int last)
 
void rowsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
 
void rowsRemoved (const QModelIndex &parent, int first, int last)
 
void setSupportedDragActions (Qt::DropActions actions)
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
qobject_cast (QObject *object)
 
qobject_cast (const QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 

Protected Member Functions

QList< QPersistentModelIndexsourceRootIndexes () const
 
- Protected Member Functions inherited from QAbstractProxyModel
void resetInternalData ()
 
- Protected Member Functions inherited from QAbstractItemModel
void beginInsertColumns (const QModelIndex &parent, int first, int last)
 
void beginInsertRows (const QModelIndex &parent, int first, int last)
 
bool beginMoveColumns (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild)
 
bool beginMoveRows (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild)
 
void beginRemoveColumns (const QModelIndex &parent, int first, int last)
 
void beginRemoveRows (const QModelIndex &parent, int first, int last)
 
void beginResetModel ()
 
void changePersistentIndex (const QModelIndex &from, const QModelIndex &to)
 
void changePersistentIndexList (const QModelIndexList &from, const QModelIndexList &to)
 
QModelIndex createIndex (int row, int column, void *ptr) const const
 
QModelIndex createIndex (int row, int column, quintptr id) const const
 
void endInsertColumns ()
 
void endInsertRows ()
 
void endMoveColumns ()
 
void endMoveRows ()
 
void endRemoveColumns ()
 
void endRemoveRows ()
 
void endResetModel ()
 
QModelIndexList persistentIndexList () const const
 
void reset ()
 
void resetInternalData ()
 
void setRoleNames (const QHash< int, QByteArray > &roleNames)
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Additional Inherited Members

- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
- Public Attributes inherited from QAbstractItemModel
typedef CheckIndexOptions
 
 DoNotUseParent
 
 HorizontalSortHint
 
 IndexIsValid
 
 NoLayoutChangeHint
 
 NoOption
 
 ParentIsInvalid
 
 VerticalSortHint
 
- Public Attributes inherited from QObject
typedef QObjectList
 

Detailed Description

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.

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);
selectionproxymodelsimpleselection.png
A Selection in one view creating a model for use with another view.

The KSelectionProxyModel can handle complex selections.

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.

selectionproxymodelmultipleselection-withdescendant.png
Selecting an item and its descendant.

See the test application in tests/proxymodeltestapp to try out the valid configurations.

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 steve[email protected][email protected][email protected]gmail[email protected].com

Definition at line 76 of file kselectionproxymodel.h.

Constructor & Destructor Documentation

KSelectionProxyModel::KSelectionProxyModel ( QItemSelectionModel selectionModel,
QObject parent = nullptr 
)
explicit

ctor.

selectionModel The selection model used to filter what is presented by the proxy.

Definition at line 1994 of file kselectionproxymodel.cpp.

KSelectionProxyModel::KSelectionProxyModel ( )
explicit

Default constructor.

Allow the creation of a KSelectionProxyModel in QML code. QML will assign a parent after construction.

Definition at line 2001 of file kselectionproxymodel.cpp.

KSelectionProxyModel::~KSelectionProxyModel ( )
overridedefault

dtor

Member Function Documentation

void KSelectionProxyModel::rootIndexAboutToBeRemoved ( const QModelIndex removeRootIndex,
QPrivateSignal   
)
signal

Emitted before 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 KSelectionProxyModel::rootIndexAdded ( const QModelIndex newIndex,
QPrivateSignal   
)
signal

Emitted when 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 KSelectionProxyModel::rootSelectionAboutToBeRemoved ( const QItemSelection selection,
QPrivateSignal   
)
signal

Emitted before selection, a selection in the sourceModel, is removed from the root selection.

void KSelectionProxyModel::rootSelectionAdded ( const QItemSelection selection,
QPrivateSignal   
)
signal

Emitted after selection, a selection in the sourceModel, is added to the root selection.

void KSelectionProxyModel::setFilterBehavior ( FilterBehavior  behavior)

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:

(root)
  - A
  - B
    - C
    - D
      - E
        - F
      - G
  - H
  - I
    - J
    - K
    - L

And A, B, C and D are selected, the proxy will contain:

(root)
  - A
  - B
    - C
    - D
      - E
        - F
      - G

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:

(root)
  - A
  - C
  - D
    - E
      - F
    - G

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,

(root)
  - A
  - B

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:

(root)
  - C
  - D
    - E
      - F
    - G
  - J
  - K
  - L

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:

(root)
  - C
  - D
  - E
  - G
  - J
  - K
  - L

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:

(root)
  - A
  - B
  - D
  - I

This is the behavior used by the Favourite Folder View in KMail.

Definition at line 2009 of file kselectionproxymodel.cpp.

void KSelectionProxyModel::setSourceModel ( QAbstractItemModel sourceModel)
overridevirtual

reimp.

Reimplemented from QAbstractProxyModel.

Definition at line 2077 of file kselectionproxymodel.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Sep 18 2021 22:50:14 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.