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

Public Member Functions | |
| KLinkItemSelectionModel (QAbstractItemModel *targetModel, QItemSelectionModel *linkedItemSelectionModel, QObject *parent=0) | |
| ~KLinkItemSelectionModel () | |
| void | select (const QModelIndex &index, QItemSelectionModel::SelectionFlags command) |
| void | select (const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) |
Protected Attributes | |
| KLinkItemSelectionModelPrivate *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 95 of file klinkitemselectionmodel.h.
Constructor & Destructor Documentation
| KLinkItemSelectionModel::KLinkItemSelectionModel | ( | QAbstractItemModel * | targetModel, |
| QItemSelectionModel * | linkedItemSelectionModel, | ||
| QObject * | parent = 0 |
||
| ) |
Constructor.
Definition at line 66 of file klinkitemselectionmodel.cpp.
| KLinkItemSelectionModel::~KLinkItemSelectionModel | ( | ) |
Definition at line 73 of file klinkitemselectionmodel.cpp.
Member Function Documentation
| void KLinkItemSelectionModel::select | ( | const QModelIndex & | index, |
| QItemSelectionModel::SelectionFlags | command | ||
| ) |
Definition at line 78 of file klinkitemselectionmodel.cpp.
| void KLinkItemSelectionModel::select | ( | const QItemSelection & | selection, |
| QItemSelectionModel::SelectionFlags | command | ||
| ) |
Definition at line 116 of file klinkitemselectionmodel.cpp.
Member Data Documentation
KLinkItemSelectionModelPrivate* const KLinkItemSelectionModel::d_ptr [protected] |
Definition at line 108 of file klinkitemselectionmodel.h.
The documentation for this class was generated from the following files:
KDE 4.6 API Reference