Warning, file /libraries/libqaccessibilityclient/examples/accessibleapps/clientcachedialog.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2012 Frederik Gladhorn <gladhorn@kde.org> 0003 SPDX-FileCopyrightText: 2012 Sebastian Sauer <sebastian.sauer@kdab.com> 0004 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "clientcachedialog.h" 0010 0011 #include "qaccessibilityclient/registrycache_p.h" 0012 0013 #include <QBoxLayout> 0014 #include <QComboBox> 0015 #include <QDialogButtonBox> 0016 #include <QLabel> 0017 #include <QPushButton> 0018 #include <QStandardItemModel> 0019 #include <QTreeView> 0020 0021 ClientCacheDialog::ClientCacheDialog(QAccessibleClient::Registry *registry, QWidget *parent) 0022 : QDialog(parent) 0023 , m_registry(registry) 0024 , m_cache(new QAccessibleClient::RegistryPrivateCacheApi(m_registry)) 0025 { 0026 setModal(true); 0027 QVBoxLayout *lay = new QVBoxLayout(this); 0028 setLayout(lay); 0029 0030 m_view = new QTreeView(this); 0031 m_view->setEditTriggers(QAbstractItemView::NoEditTriggers); 0032 m_view->setRootIsDecorated(false); 0033 m_view->setSortingEnabled(true); 0034 m_view->setItemsExpandable(false); 0035 //list->setHeaderHidden(true); 0036 m_model = new QStandardItemModel(m_view); 0037 m_model->setColumnCount(3); 0038 m_view->setModel(m_model); 0039 lay->addWidget(m_view); 0040 0041 QHBoxLayout *buttonsLay = new QHBoxLayout(this); 0042 buttonsLay->setContentsMargins(0, 0, 0, 0); 0043 buttonsLay->setSpacing(0); 0044 QPushButton *updateButton = new QPushButton(QStringLiteral("Refresh"), this); 0045 buttonsLay->addWidget(updateButton); 0046 connect(updateButton, SIGNAL(clicked(bool)), this, SLOT(updateView())); 0047 QPushButton *clearButton = new QPushButton(QStringLiteral("Clear"), this); 0048 buttonsLay->addWidget(clearButton); 0049 0050 QLabel *cacheLabel = new QLabel(QStringLiteral("Strategy:"), this); 0051 buttonsLay->addWidget(cacheLabel); 0052 m_cacheCombo = new QComboBox(this); 0053 cacheLabel->setBuddy(m_cacheCombo); 0054 m_cacheCombo->setEditable(false); 0055 m_cacheCombo->addItem(QStringLiteral("Disable"), int(QAccessibleClient::RegistryPrivateCacheApi::NoCache)); 0056 m_cacheCombo->addItem(QStringLiteral("Weak"), int(QAccessibleClient::RegistryPrivateCacheApi::WeakCache)); 0057 for(int i = 0; i < m_cacheCombo->count(); ++i) { 0058 if (m_cacheCombo->itemData(i).toInt() == m_cache->cacheType()) { 0059 m_cacheCombo->setCurrentIndex(i); 0060 break; 0061 } 0062 } 0063 connect(m_cacheCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(cacheStrategyChanged())); 0064 buttonsLay->addWidget(m_cacheCombo); 0065 buttonsLay->addWidget(new QLabel(QStringLiteral("Count:"), this)); 0066 m_countLabel = new QLabel(this); 0067 buttonsLay->addWidget(m_countLabel); 0068 buttonsLay->addStretch(1); 0069 0070 connect(clearButton, SIGNAL(clicked(bool)), this, SLOT(clearCache())); 0071 QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, this); 0072 buttonsLay->addWidget(buttons); 0073 QPushButton *closeButton = buttons->button(QDialogButtonBox::Close); 0074 connect(closeButton, SIGNAL(clicked(bool)), this, SLOT(accept())); 0075 lay->addLayout(buttonsLay); 0076 0077 resize(minimumSize().expandedTo(QSize(660,420))); 0078 0079 updateView(); 0080 m_view->sortByColumn(2, Qt::AscendingOrder); 0081 } 0082 0083 void ClientCacheDialog::clearCache() 0084 { 0085 m_cache->clearClientCache(); 0086 updateView(); 0087 } 0088 0089 void ClientCacheDialog::cacheStrategyChanged() 0090 { 0091 int c = m_cacheCombo->itemData(m_cacheCombo->currentIndex()).toInt(); 0092 m_cache->setCacheType(QAccessibleClient::RegistryPrivateCacheApi::CacheType(c)); 0093 updateView(); 0094 } 0095 0096 void ClientCacheDialog::updateView() 0097 { 0098 m_model->clear(); 0099 m_model->setHorizontalHeaderLabels( QStringList() << QStringLiteral("Name") << QStringLiteral("Role") << QStringLiteral("Identifier") ); 0100 const QStringList cache = m_cache->clientCacheObjects(); 0101 m_countLabel->setText(QString::number(cache.count())); 0102 for (const QString &c : cache) { 0103 QAccessibleClient::AccessibleObject obj = m_cache->clientCacheObject(c); 0104 if (obj.isValid()) 0105 m_model->appendRow( QList<QStandardItem*>() 0106 << new QStandardItem(obj.name()) 0107 << new QStandardItem(obj.roleName()) 0108 << new QStandardItem(obj.id()) ); 0109 } 0110 m_view->setColumnWidth(0, 180); 0111 m_view->resizeColumnToContents(1); 0112 m_view->resizeColumnToContents(2); 0113 } 0114 0115 #include "moc_clientcachedialog.cpp"