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

0001 /*
0002     SPDX-FileCopyrightText: 2010 Stephen Kelly <steveire@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "matchcheckingwidget.h"
0008 
0009 #include <QLineEdit>
0010 #include <QRadioButton>
0011 #include <QSplitter>
0012 #include <QTreeView>
0013 #include <QVBoxLayout>
0014 
0015 #include "dynamictreemodel.h"
0016 #include "dynamictreewidget.h"
0017 #include <kselectionproxymodel.h>
0018 
0019 #include <QDebug>
0020 
0021 MatchCheckingWidget::MatchCheckingWidget(QWidget *parent, Qt::WindowFlags f)
0022     : QWidget(parent, f)
0023 {
0024     QVBoxLayout *layout = new QVBoxLayout(this);
0025 
0026     m_lineEdit = new QLineEdit();
0027 
0028     connect(m_lineEdit, SIGNAL(textChanged(QString)), SLOT(matchChanged(QString)));
0029 
0030     m_dynamicTreeRadioButton = new QRadioButton(QStringLiteral("Dynamic Tree Model"), this);
0031     m_selectionModelRadioButton = new QRadioButton(QStringLiteral("Selection Model"), this);
0032 
0033     layout->addWidget(m_lineEdit);
0034     layout->addWidget(m_dynamicTreeRadioButton);
0035     layout->addWidget(m_selectionModelRadioButton);
0036 
0037     QSplitter *splitter = new QSplitter(this);
0038     layout->addWidget(splitter);
0039     DynamicTreeModel *dynamicTreeModel = new DynamicTreeModel(this);
0040 
0041     m_dynamicTreeWidget = new DynamicTreeWidget(dynamicTreeModel, this);
0042 
0043     splitter->addWidget(m_dynamicTreeWidget);
0044 
0045     KSelectionProxyModel *selectionProxyModel = new KSelectionProxyModel(m_dynamicTreeWidget->treeView()->selectionModel(), this);
0046     selectionProxyModel->setSourceModel(dynamicTreeModel);
0047 
0048     m_selectionTreeView = new QTreeView(this);
0049     m_selectionTreeView->setModel(selectionProxyModel);
0050     splitter->addWidget(m_selectionTreeView);
0051 }
0052 
0053 void MatchCheckingWidget::matchChanged(const QString &matchData)
0054 {
0055     bool ok;
0056     int id = matchData.toInt(&ok);
0057     qDebug() << matchData << id << DynamicTreeModel::DynamicTreeModelId;
0058     if (!ok) {
0059         return;
0060     }
0061 
0062     QModelIndexList list;
0063     if (m_dynamicTreeRadioButton->isChecked()) {
0064         m_dynamicTreeWidget->treeView()->selectionModel()->clearSelection();
0065         list = m_dynamicTreeWidget->model()->match(m_dynamicTreeWidget->model()->index(0, 0), DynamicTreeModel::DynamicTreeModelId, id);
0066         qDebug() << list;
0067         for (const QModelIndex &idx : std::as_const(list)) {
0068             m_dynamicTreeWidget->treeView()->selectionModel()->select(idx, QItemSelectionModel::SelectCurrent);
0069         }
0070     } else if (m_selectionModelRadioButton->isChecked()) {
0071         m_selectionTreeView->selectionModel()->clearSelection();
0072         list = m_selectionTreeView->model()->match(m_selectionTreeView->model()->index(0, 0), DynamicTreeModel::DynamicTreeModelId, id);
0073         qDebug() << list;
0074         for (const QModelIndex &idx : std::as_const(list)) {
0075             m_selectionTreeView->selectionModel()->select(idx, QItemSelectionModel::SelectCurrent);
0076         }
0077     }
0078 }
0079 
0080 #include "moc_matchcheckingwidget.cpp"