File indexing completed on 2024-12-08 03:41:09
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 "proxyitemselectionwidget.h" 0009 0010 #include <QHBoxLayout> 0011 #include <QSortFilterProxyModel> 0012 #include <QSplitter> 0013 #include <QTreeView> 0014 0015 #include "dynamictreemodel.h" 0016 #include "dynamictreewidget.h" 0017 #include "klinkitemselectionmodel.h" 0018 0019 #define SON(object) object->setObjectName(QStringLiteral(#object)) 0020 0021 ProxyItemSelectionWidget::ProxyItemSelectionWidget(QWidget *parent, Qt::WindowFlags f) 0022 : QWidget(parent, f) 0023 { 0024 QSplitter *splitter = new QSplitter(this); 0025 QHBoxLayout *layout = new QHBoxLayout(this); 0026 layout->addWidget(splitter); 0027 0028 DynamicTreeModel *rootModel = new DynamicTreeModel(this); 0029 0030 DynamicTreeWidget *dynamicTreeWidget = new DynamicTreeWidget(rootModel, splitter); 0031 0032 dynamicTreeWidget->setInitialTree( 0033 QLatin1String("- 1" 0034 "- 2" 0035 "- - 3" 0036 "- - - 4" 0037 "- 5" 0038 "- 6" 0039 "- 7")); 0040 0041 QSplitter *vSplitter = new QSplitter(Qt::Vertical, splitter); 0042 QSplitter *hSplitter1 = new QSplitter(vSplitter); 0043 QSplitter *hSplitter2 = new QSplitter(vSplitter); 0044 0045 QSortFilterProxyModel *proxy1 = new QSortFilterProxyModel(this); 0046 SON(proxy1); 0047 QSortFilterProxyModel *proxy2 = new QSortFilterProxyModel(this); 0048 SON(proxy2); 0049 QSortFilterProxyModel *proxy3 = new QSortFilterProxyModel(this); 0050 SON(proxy3); 0051 QSortFilterProxyModel *proxy4 = new QSortFilterProxyModel(this); 0052 SON(proxy4); 0053 QSortFilterProxyModel *proxy5 = new QSortFilterProxyModel(this); 0054 SON(proxy5); 0055 0056 QTreeView *view1 = new QTreeView(hSplitter1); 0057 QTreeView *view2 = new QTreeView(hSplitter1); 0058 QTreeView *view3 = new QTreeView(hSplitter2); 0059 QTreeView *view4 = new QTreeView(hSplitter2); 0060 0061 proxy1->setSourceModel(rootModel); 0062 proxy2->setSourceModel(proxy1); 0063 proxy3->setSourceModel(proxy2); 0064 0065 proxy4->setSourceModel(rootModel); 0066 proxy5->setSourceModel(proxy4); 0067 0068 view1->setModel(proxy3); 0069 view2->setModel(proxy5); 0070 view3->setModel(proxy2); 0071 view4->setModel(proxy1); 0072 0073 QItemSelectionModel *rootSelectionModel = dynamicTreeWidget->treeView()->selectionModel(); 0074 0075 KLinkItemSelectionModel *view1SelectionModel = new KLinkItemSelectionModel(view1->model(), rootSelectionModel, this); 0076 view1->setSelectionModel(view1SelectionModel); 0077 0078 KLinkItemSelectionModel *view2SelectionModel = new KLinkItemSelectionModel(view2->model(), view1->selectionModel(), this); 0079 view2->setSelectionModel(view2SelectionModel); 0080 0081 KLinkItemSelectionModel *view3SelectionModel = new KLinkItemSelectionModel(view3->model(), view4->selectionModel(), this); 0082 view3->setSelectionModel(view3SelectionModel); 0083 0084 view1->expandAll(); 0085 view2->expandAll(); 0086 view3->expandAll(); 0087 view4->expandAll(); 0088 } 0089 0090 #include "moc_proxyitemselectionwidget.cpp"