KDEUI
KProxyItemSelectionModel Class Reference
Makes it possible to share a selection in multiple views which do not have the same source model. More...
#include <kproxyitemselectionmodel.h>

Public Member Functions | |
| KProxyItemSelectionModel (QAbstractItemModel *targetModel, QItemSelectionModel *proxySelector, QObject *parent=0) | |
| void | select (const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) |
| void | select (const QModelIndex &index, QItemSelectionModel::SelectionFlags command) |
| ~KProxyItemSelectionModel () | |
Protected Attributes | |
| KProxyItemSelectionModelPrivate *const | d_ptr |
Detailed Description
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.
Sharing a QItemSelectionModel between views on the same model is trivial
If a proxy model is used, it is no longer possible to share the QItemSelectionModel directly
A KProxyItemSelectionModel can be used to map the selection through the proxy model
QAbstractItemModel *model = getModel(); QSortFilterProxyModel *proxy = new QSortFilterProxyModel(); proxy->setSourceModel(model); QTreeView *view1 = new QTreeView(splitter); view1->setModel(model); KProxyItemSelectionModel *view2SelectionModel = new KProxyItemSelectionModel( proxy, view1->selectionModel()); QTreeView *view2 = new QTreeView(splitter); // Note that the QAbstractItemModel passed to KProxyItemSelectionModel must be the same as what is used in the view view2->setModel(proxy); view2->setSelectionModel( view2SelectionModel );
Arbitrarily complex proxy configurations on the same root model can be used
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); KProxyItemSelectionModel *view2SelectionModel = new KProxyItemSelectionModel( proxy5, view1->selectionModel()); QTreeView *view2 = new QTreeView(splitter); // Note that the QAbstractItemModel passed to KProxyItemSelectionModel must be the same as what is used in the view view2->setModel(proxy5); view2->setSelectionModel( view2SelectionModel );
See also kdelibs/kdeui/tests/proxymodeltestapp/proxyitemselectionwidget.cpp.
- Since:
- 4.5
Definition at line 96 of file kproxyitemselectionmodel.h.
Constructor & Destructor Documentation
| KProxyItemSelectionModel::KProxyItemSelectionModel | ( | QAbstractItemModel * | targetModel, | |
| QItemSelectionModel * | proxySelector, | |||
| QObject * | parent = 0 | |||
| ) |
| KProxyItemSelectionModel::~KProxyItemSelectionModel | ( | ) |
Definition at line 59 of file kproxyitemselectionmodel.cpp.
Member Function Documentation
| void KProxyItemSelectionModel::select | ( | const QItemSelection & | selection, | |
| QItemSelectionModel::SelectionFlags | command | |||
| ) |
Definition at line 80 of file kproxyitemselectionmodel.cpp.
| void KProxyItemSelectionModel::select | ( | const QModelIndex & | index, | |
| QItemSelectionModel::SelectionFlags | command | |||
| ) |
Definition at line 64 of file kproxyitemselectionmodel.cpp.
Member Data Documentation
KProxyItemSelectionModelPrivate* const KProxyItemSelectionModel::d_ptr [protected] |
Definition at line 112 of file kproxyitemselectionmodel.h.
The documentation for this class was generated from the following files:
KDE 4.5 API Reference