File indexing completed on 2024-10-06 03:40:27
0001 /* 0002 This file is part of the proxy model test suite. 0003 0004 SPDX-FileCopyrightText: 2015 Stephen Kelly <steveire@gmail.com> 0005 0006 SPDX-License-Identifier: LGPL-2.1-or-later 0007 */ 0008 0009 #include "selectioninqmlwidget.h" 0010 0011 #include <QHBoxLayout> 0012 #include <QLabel> 0013 #include <QQmlContext> 0014 #include <QQmlEngine> 0015 #include <QQuickWidget> 0016 #include <QSplitter> 0017 #include <QTreeView> 0018 0019 #include "dynamictreemodel.h" 0020 #include "dynamictreewidget.h" 0021 #include "kselectionproxymodel.h" 0022 0023 SelectionInQmlWidget::SelectionInQmlWidget(QWidget *parent) 0024 : QWidget(parent) 0025 { 0026 QHBoxLayout *layout = new QHBoxLayout(this); 0027 QSplitter *splitter = new QSplitter(this); 0028 layout->addWidget(splitter); 0029 0030 m_rootModel = new DynamicTreeModel(this); 0031 0032 new DynamicTreeWidget(m_rootModel, splitter); 0033 0034 QTreeView *selectionTree = new QTreeView(splitter); 0035 selectionTree->setSelectionMode(QAbstractItemView::ExtendedSelection); 0036 selectionTree->setModel(m_rootModel); 0037 selectionTree->expandAll(); 0038 0039 qmlRegisterType<KSelectionProxyModel>("KF5ItemModels", 1, 0, "SelectionProxyModel"); 0040 0041 QQuickWidget *quickView = new QQuickWidget(splitter); 0042 0043 quickView->engine()->rootContext()->setContextProperty(QStringLiteral("_model"), m_rootModel); 0044 quickView->engine()->rootContext()->setContextProperty(QStringLiteral("_selectionModel"), selectionTree->selectionModel()); 0045 0046 quickView->setSource(QUrl::fromLocalFile(QLatin1String(SRC_DIR "/selection.qml"))); 0047 }