KCheckableProxyModel Class

Adds a checkable capability to a source model. More...

Header: #include <KCheckableProxyModel>
CMake: find_package(KF6 REQUIRED COMPONENTS ItemModels)
target_link_libraries(mytarget PRIVATE KF6::ItemModels)
Since: KDE Frameworks 4.6

Detailed Description

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

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);

"A KCheckableProxyModel and KSelectionProxyModel showing checked items"

@author Stephen Kelly <steveire@gmail.com>