File indexing completed on 2024-07-14 03:54:51

0001 /*
0002     SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
0003     SPDX-FileContributor: Stephen Kelly <stephen@kdab.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "checkablewidget.h"
0009 
0010 #include <QHBoxLayout>
0011 #include <QSplitter>
0012 #include <QTreeView>
0013 
0014 #include "dynamictreemodel.h"
0015 #include <kcheckableproxymodel.h>
0016 #include <kselectionproxymodel.h>
0017 
0018 CheckableWidget::CheckableWidget(QWidget *parent, Qt::WindowFlags f)
0019     : QWidget(parent, f)
0020 {
0021     QHBoxLayout *layout = new QHBoxLayout(this);
0022     QSplitter *vSplitter = new QSplitter(this);
0023     layout->addWidget(vSplitter);
0024 
0025     DynamicTreeModel *rootModel = new DynamicTreeModel(this);
0026 
0027     ModelInsertCommand *insert = new ModelInsertCommand(rootModel, this);
0028     insert->setStartRow(0);
0029     insert->interpret(
0030         QLatin1String("- 1"
0031                       "- 1"
0032                       "- 1"
0033                       "- - 2"
0034                       "- - 2"
0035                       "- - 2"
0036                       "- - 2"
0037                       "- 1"
0038                       "- 1"
0039                       "- 1"
0040                       "- - 2"
0041                       "- - - 3"
0042                       "- - - - 4"
0043                       "- - - - 4"
0044                       "- - - 3"
0045                       "- - - 3"
0046                       "- - - 3"
0047                       "- - 2"
0048                       "- - 2"
0049                       "- - 2"
0050                       "- 1"
0051                       "- 1"));
0052     insert->doCommand();
0053 
0054     QItemSelectionModel *checkModel = new QItemSelectionModel(rootModel, this);
0055     KCheckableProxyModel *checkable = new KCheckableProxyModel(this);
0056     checkable->setSourceModel(rootModel);
0057     checkable->setSelectionModel(checkModel);
0058 
0059     QTreeView *tree1 = new QTreeView(vSplitter);
0060     tree1->setModel(checkable);
0061     tree1->expandAll();
0062 
0063     KSelectionProxyModel *selectionProxy = new KSelectionProxyModel(checkModel, this);
0064     selectionProxy->setFilterBehavior(KSelectionProxyModel::ExactSelection);
0065     selectionProxy->setSourceModel(rootModel);
0066 
0067     QTreeView *tree2 = new QTreeView(vSplitter);
0068     tree2->setModel(selectionProxy);
0069 }
0070 
0071 #include "moc_checkablewidget.cpp"