File indexing completed on 2023-09-24 04:09:49
0001 /* 0002 This file is part of the proxy model test suite. 0003 0004 SPDX-FileCopyrightText: 2009 Stephen Kelly <steveire@gmail.com> 0005 0006 SPDX-License-Identifier: LGPL-2.1-or-later 0007 */ 0008 0009 #include "descendantpmwidget.h" 0010 0011 #include <QSplitter> 0012 #include <QTreeView> 0013 0014 #include "dynamictreemodel.h" 0015 #include "dynamictreewidget.h" 0016 #include "kdescendantsproxymodel.h" 0017 #include <QHBoxLayout> 0018 #include <QLineEdit> 0019 0020 #include "modeleventlogger.h" 0021 0022 DescendantProxyModelWidget::DescendantProxyModelWidget(QWidget *parent) 0023 : QWidget(parent) 0024 { 0025 QHBoxLayout *layout = new QHBoxLayout(this); 0026 QSplitter *vSplitter = new QSplitter(this); 0027 layout->addWidget(vSplitter); 0028 0029 m_rootModel = new DynamicTreeModel(this); 0030 0031 DynamicTreeWidget *dynTreeWidget = new DynamicTreeWidget(m_rootModel, vSplitter); 0032 0033 dynTreeWidget->setInitialTree( 0034 QLatin1String("- 1" 0035 "- 2" 0036 "- - 3" 0037 "- - 3" 0038 "- - - 4" 0039 "- - - 4" 0040 "- - - - 4" 0041 "- - 4" 0042 "- - 5" 0043 "- - - 4" 0044 "- - - - 4" 0045 "- - 5" 0046 "- 6" 0047 "- 7" 0048 "- - 8" 0049 "- - - 9" 0050 "- - - 10" 0051 "- - - - 9" 0052 "- - - - - 10" 0053 "- - - - - - 9" 0054 "- - - - - - 10" 0055 "- - - - - - - 9" 0056 "- - - - - - - - 10" 0057 "- - - - - - - - 9" 0058 "- - - - - - - 10" 0059 "- - - - - 9" 0060 "- - - - - 9" 0061 "- - - - - 9" 0062 "- - - - - 10" 0063 "- - - - - - 9" 0064 "- - - - - - 10" 0065 "- - - - - 9" 0066 "- - - - - 9" 0067 "- - - - - 9" 0068 "- - - - - 10" 0069 "- - - - - - 9" 0070 "- - - - - - 10" 0071 "- - - - 10" 0072 "- - 11" 0073 "- - 12" 0074 "- 13" 0075 "- 14" 0076 "- 15" 0077 "- - 16" 0078 "- - - 17" 0079 "- - - 18" 0080 "- 19" 0081 "- 20" 0082 "- 21")); 0083 0084 m_eventLogger = new ModelEventLogger(m_rootModel, this); 0085 0086 m_descProxyModel = new KDescendantsProxyModel(this); 0087 m_descProxyModel->setSourceModel(m_rootModel); 0088 0089 // KDescendantsProxyModel *descProxyModel2 = new KDescendantsProxyModel(this); 0090 // descProxyModel2->setSourceModel(m_rootModel); 0091 // descProxyModel2->setDisplayAncestorData(true); 0092 0093 // QTreeView *treeview = new QTreeView( vSplitter ); 0094 // treeview->setModel(m_rootModel); 0095 // treeview->setSelectionMode(QAbstractItemView::ExtendedSelection); 0096 0097 m_descView = new QTreeView(vSplitter); 0098 m_descView->setModel(m_descProxyModel); 0099 0100 // QTreeView *descView2 = new QTreeView( vSplitter ); 0101 // descView2->setModel(descProxyModel2); 0102 0103 // QWidget *w = new QWidget(vSplitter); 0104 // QVBoxLayout *vLayout = new QVBoxLayout(w); 0105 // QTreeView *matchView = new QTreeView(w); 0106 // matchView->setModel(m_selectionProxyModel); 0107 // m_lineEdit = new QLineEdit(w); 0108 // connect(m_lineEdit, SIGNAL(textChanged(QString)), SLOT(doMatch(QString))); 0109 // connect(m_descView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(refreshMatch())); 0110 0111 // vLayout->addWidget(m_lineEdit); 0112 // vLayout->addWidget(matchView); 0113 } 0114 0115 DescendantProxyModelWidget::~DescendantProxyModelWidget() 0116 { 0117 } 0118 0119 void DescendantProxyModelWidget::doMatch(const QString &matchData) 0120 { 0121 Q_UNUSED(matchData); 0122 #if 0 0123 m_itemSelectionModel->clearSelection(); 0124 0125 if (matchData.isEmpty()) { 0126 return; 0127 } 0128 0129 QModelIndex start = m_descView->currentIndex(); 0130 0131 if (!start.isValid()) { 0132 start = m_descProxyModel->index(0, 0); 0133 } 0134 0135 // TODO: get from user. 0136 int hits = -1; 0137 0138 QModelIndexList matches = m_descProxyModel->match(start, Qt::DisplayRole, matchData, hits, Qt::MatchContains); 0139 0140 Q_FOREACH (const QModelIndex &matchingIndex, matches) { 0141 m_itemSelectionModel->select(matchingIndex, QItemSelectionModel::Select | QItemSelectionModel::Rows); 0142 } 0143 #endif 0144 } 0145 0146 void DescendantProxyModelWidget::refreshMatch() 0147 { 0148 doMatch(m_lineEdit->text()); 0149 } 0150 0151 #include "moc_descendantpmwidget.cpp"