diff options
-rw-r--r-- | tools/qdbus/qdbusviewer/qdbusviewer.cpp | 80 | ||||
-rw-r--r-- | tools/qdbus/qdbusviewer/qdbusviewer.h | 6 |
2 files changed, 54 insertions, 32 deletions
diff --git a/tools/qdbus/qdbusviewer/qdbusviewer.cpp b/tools/qdbus/qdbusviewer/qdbusviewer.cpp index 8952241..9820b87 100644 --- a/tools/qdbus/qdbusviewer/qdbusviewer.cpp +++ b/tools/qdbus/qdbusviewer/qdbusviewer.cpp @@ -69,9 +69,15 @@ QDBusViewer::QDBusViewer(const QDBusConnection &connection, QWidget *parent) : c(connection), objectPathRegExp(QLatin1String("\\[ObjectPath: (.*)\\]")) { - services = new QTreeWidget; - services->setRootIsDecorated(false); - services->setHeaderLabels(QStringList(QLatin1String("Services"))); + servicesModel = new QStringListModel(this); + servicesFilterModel = new QSortFilterProxyModel(this); + servicesFilterModel->setSourceModel(servicesModel); + servicesFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); + serviceFilterLine = new QLineEdit(this); + servicesView = new QListView(this); + servicesView->setModel(servicesFilterModel); + + connect(serviceFilterLine, SIGNAL(textChanged(QString)), servicesFilterModel, SLOT(setFilterFixedString(QString))); tree = new QTreeView; tree->setContextMenuPolicy(Qt::CustomContextMenu); @@ -86,19 +92,28 @@ QDBusViewer::QDBusViewer(const QDBusConnection &connection, QWidget *parent) : QShortcut *refreshShortcut = new QShortcut(QKeySequence::Refresh, tree); connect(refreshShortcut, SIGNAL(activated()), this, SLOT(refreshChildren())); - QVBoxLayout *topLayout = new QVBoxLayout(this); + QVBoxLayout *layout = new QVBoxLayout(this); + QSplitter *topSplitter = new QSplitter(Qt::Vertical, this); + layout->addWidget(topSplitter); + log = new QTextBrowser; connect(log, SIGNAL(anchorClicked(QUrl)), this, SLOT(anchorClicked(QUrl))); - QHBoxLayout *layout = new QHBoxLayout; - layout->addWidget(services, 1); - layout->addWidget(tree, 2); + QSplitter *splitter = new QSplitter(topSplitter); + splitter->addWidget(servicesView); + + QWidget *servicesWidget = new QWidget; + QVBoxLayout *servicesLayout = new QVBoxLayout(servicesWidget); + servicesLayout->addWidget(serviceFilterLine); + servicesLayout->addWidget(servicesView); + splitter->addWidget(servicesWidget); + splitter->addWidget(tree); - topLayout->addLayout(layout); - topLayout->addWidget(log); + topSplitter->addWidget(splitter); + topSplitter->addWidget(log); - connect(services, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), - this, SLOT(serviceChanged(QTreeWidgetItem*))); + connect(servicesView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), + this, SLOT(serviceChanged(QModelIndex))); connect(tree, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint))); @@ -133,12 +148,11 @@ void QDBusViewer::logError(const QString &msg) void QDBusViewer::refresh() { - services->clear(); + servicesModel->removeRows(0, servicesModel->rowCount()); if (c.isConnected()) { const QStringList serviceNames = c.interface()->registeredServiceNames(); - foreach (QString service, serviceNames) - new QTreeWidgetItem(services, QStringList(service)); + servicesModel->setStringList(serviceNames); } } @@ -393,14 +407,14 @@ void QDBusViewer::dumpMessage(const QDBusMessage &message) log->append(out); } -void QDBusViewer::serviceChanged(QTreeWidgetItem *item) +void QDBusViewer::serviceChanged(const QModelIndex &index) { delete tree->model(); currentService.clear(); - if (!item) + if (!index.isValid()) return; - currentService = item->text(0); + currentService = index.data().toString(); tree->setModel(new QDBusViewModel(currentService, c)); connect(tree->model(), SIGNAL(busError(QString)), this, SLOT(logError(QString))); @@ -411,34 +425,38 @@ void QDBusViewer::serviceRegistered(const QString &service) if (service == c.baseService()) return; - new QTreeWidgetItem(services, QStringList(service)); + servicesModel->insertRows(0, 1); + servicesModel->setData(servicesModel->index(0, 0), service); } -static QTreeWidgetItem *findItem(const QTreeWidget *services, const QString &name) +static QModelIndex findItem(QStringListModel *servicesModel, const QString &name) { - for (int i = 0; i < services->topLevelItemCount(); ++i) { - if (services->topLevelItem(i)->text(0) == name) - return services->topLevelItem(i); - } - return 0; + QModelIndexList hits = servicesModel->match(servicesModel->index(0, 0), Qt::DisplayRole, name); + if (hits.isEmpty()) + return QModelIndex(); + + return hits.first(); } void QDBusViewer::serviceUnregistered(const QString &name) { - delete findItem(services, name); + QModelIndex hit = findItem(servicesModel, name); + if (!hit.isValid()) + return; + servicesModel->removeRows(hit.row(), 1); } void QDBusViewer::serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner) { - QTreeWidgetItem *item = findItem(services, name); + QModelIndex hit = findItem(servicesModel, name); - if (!item && oldOwner.isEmpty() && !newOwner.isEmpty()) + if (!hit.isValid() && oldOwner.isEmpty() && !newOwner.isEmpty()) serviceRegistered(name); - else if (item && !oldOwner.isEmpty() && newOwner.isEmpty()) - delete item; - else if (item && !oldOwner.isEmpty() && !newOwner.isEmpty()) { - delete item; + else if (hit.isValid() && !oldOwner.isEmpty() && newOwner.isEmpty()) + servicesModel->removeRows(hit.row(), 1); + else if (hit.isValid() && !oldOwner.isEmpty() && !newOwner.isEmpty()) { + servicesModel->removeRows(hit.row(), 1); serviceRegistered(name); } } diff --git a/tools/qdbus/qdbusviewer/qdbusviewer.h b/tools/qdbus/qdbusviewer/qdbusviewer.h index c9faab9..d5d1a69 100644 --- a/tools/qdbus/qdbusviewer/qdbusviewer.h +++ b/tools/qdbus/qdbusviewer/qdbusviewer.h @@ -66,7 +66,7 @@ public slots: void about(); private slots: - void serviceChanged(QTreeWidgetItem *item); + void serviceChanged(const QModelIndex &index); void showContextMenu(const QPoint &); void connectionRequested(const BusSignature &sig); void callMethod(const BusSignature &sig); @@ -92,6 +92,10 @@ private: QTreeView *tree; QAction *refreshAction; QTreeWidget *services; + QStringListModel *servicesModel; + QSortFilterProxyModel *servicesFilterModel; + QLineEdit *serviceFilterLine; + QListView *servicesView; QTextBrowser *log; QRegExp objectPathRegExp; }; |