• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KDEUI

Public Member Functions | Protected Attributes

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>

Inheritance diagram for KLinkItemSelectionModel:
Inheritance graph
[legend]

List of all members.

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.

kproxyitemselectionmodel-simple.png

Sharing a QItemSelectionModel between views on the same model is trivial

kproxyitemselectionmodel-error.png

If a proxy model is used, it is no longer possible to share the QItemSelectionModel directly

kproxyitemselectionmodel-solution.png

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 );
kproxyitemselectionmodel-complex.png

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
Author:
Stephen Kelly <steveire@gmail.com>

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:
  • klinkitemselectionmodel.h
  • klinkitemselectionmodel.cpp

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal