summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Schlarb <alexander-qt@xmine128.tk>2015-10-09 22:30:13 +0200
committerAlexander Schlarb <alexander-qt@xmine128.tk>2015-10-26 16:09:43 +0000
commitf55f4acfd8167650fe931ab532ec7b086642b224 (patch)
tree84f04663140a5ad427e908a55d230596efc7951c
parente15ca59111fe05f5ecc0f7fb48c34b5b22115a12 (diff)
Sort items in QDBusViewer
Before this commit QDBusViewer does not sort the list of service names it shows in the service list. This makes it pretty hard to find to desired service in the service list. By sorting all services using a custom SortFilterProxy the usability of QDBusViewer is greatly improved. Change-Id: I464addf0988ee020e4efbb4486ec6a4a11c36b6d Task-number: QTBUG-5403 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
-rw-r--r--src/qdbus/qdbusviewer/qdbusviewer.cpp5
-rw-r--r--src/qdbus/qdbusviewer/qdbusviewer.h5
-rw-r--r--src/qdbus/qdbusviewer/qdbusviewer.pro2
-rw-r--r--src/qdbus/qdbusviewer/servicesproxymodel.cpp60
-rw-r--r--src/qdbus/qdbusviewer/servicesproxymodel.h50
5 files changed, 118 insertions, 4 deletions
diff --git a/src/qdbus/qdbusviewer/qdbusviewer.cpp b/src/qdbus/qdbusviewer/qdbusviewer.cpp
index 7f8c35675..438442685 100644
--- a/src/qdbus/qdbusviewer/qdbusviewer.cpp
+++ b/src/qdbus/qdbusviewer/qdbusviewer.cpp
@@ -33,12 +33,12 @@
#include "qdbusviewer.h"
#include "qdbusmodel.h"
+#include "servicesproxymodel.h"
#include "propertydialog.h"
#include "logviewer.h"
#include <QtWidgets/QTreeWidget>
#include <QtCore/QStringListModel>
-#include <QtCore/QSortFilterProxyModel>
#include <QtCore/QMetaProperty>
#include <QtCore/QSettings>
#include <QtWidgets/QLineEdit>
@@ -80,9 +80,10 @@ QDBusViewer::QDBusViewer(const QDBusConnection &connection, QWidget *parent) :
objectPathRegExp(QLatin1String("\\[ObjectPath: (.*)\\]"))
{
servicesModel = new QStringListModel(this);
- servicesFilterModel = new QSortFilterProxyModel(this);
+ servicesFilterModel = new ServicesProxyModel(this);
servicesFilterModel->setSourceModel(servicesModel);
servicesFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
+ servicesFilterModel->sort(0, Qt::AscendingOrder);
serviceFilterLine = new QLineEdit(this);
serviceFilterLine->setPlaceholderText(tr("Search..."));
servicesView = new QListView(this);
diff --git a/src/qdbus/qdbusviewer/qdbusviewer.h b/src/qdbus/qdbusviewer/qdbusviewer.h
index cd6b5a347..3d54b0e7e 100644
--- a/src/qdbus/qdbusviewer/qdbusviewer.h
+++ b/src/qdbus/qdbusviewer/qdbusviewer.h
@@ -37,10 +37,11 @@
#include <QtWidgets/QWidget>
#include <QtDBus/QDBusConnection>
+class ServicesProxyModel;
+
QT_FORWARD_DECLARE_CLASS(QTreeView)
QT_FORWARD_DECLARE_CLASS(QTreeWidget)
QT_FORWARD_DECLARE_CLASS(QStringListModel)
-QT_FORWARD_DECLARE_CLASS(QSortFilterProxyModel)
QT_FORWARD_DECLARE_CLASS(QLineEdit)
QT_FORWARD_DECLARE_CLASS(QListView)
QT_FORWARD_DECLARE_CLASS(QTextBrowser)
@@ -95,7 +96,7 @@ private:
QAction *refreshAction;
QTreeWidget *services;
QStringListModel *servicesModel;
- QSortFilterProxyModel *servicesFilterModel;
+ ServicesProxyModel *servicesFilterModel;
QLineEdit *serviceFilterLine;
QListView *servicesView;
QTextBrowser *log;
diff --git a/src/qdbus/qdbusviewer/qdbusviewer.pro b/src/qdbus/qdbusviewer/qdbusviewer.pro
index a653f9f46..02ec7a2d2 100644
--- a/src/qdbus/qdbusviewer/qdbusviewer.pro
+++ b/src/qdbus/qdbusviewer/qdbusviewer.pro
@@ -1,11 +1,13 @@
HEADERS = qdbusviewer.h \
qdbusmodel.h \
+ servicesproxymodel.h \
propertydialog.h \
logviewer.h \
mainwindow.h
SOURCES = qdbusviewer.cpp \
qdbusmodel.cpp \
+ servicesproxymodel.cpp \
propertydialog.cpp \
logviewer.cpp \
mainwindow.cpp \
diff --git a/src/qdbus/qdbusviewer/servicesproxymodel.cpp b/src/qdbus/qdbusviewer/servicesproxymodel.cpp
new file mode 100644
index 000000000..74a4b8d5d
--- /dev/null
+++ b/src/qdbus/qdbusviewer/servicesproxymodel.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the tools applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "servicesproxymodel.h"
+
+ServicesProxyModel::ServicesProxyModel(QObject *parent)
+ : QSortFilterProxyModel(parent)
+{
+}
+
+bool ServicesProxyModel::lessThan(const QModelIndex &left,
+ const QModelIndex &right) const
+{
+ QString s1 = sourceModel()->data(left).toString();
+ QString s2 = sourceModel()->data(right).toString();
+
+ const bool isNumber1 = s1.startsWith(QLatin1String(":1."));
+ const bool isNumber2 = s2.startsWith(QLatin1String(":1."));
+ if (isNumber1 == isNumber2) {
+ if (isNumber1) {
+ int number1 = s1.midRef(3).toInt();
+ int number2 = s2.midRef(3).toInt();
+ return number1 < number2;
+ } else {
+ return s1.compare(s2, Qt::CaseInsensitive) < 0;
+ }
+ } else {
+ return isNumber2;
+ }
+}
diff --git a/src/qdbus/qdbusviewer/servicesproxymodel.h b/src/qdbus/qdbusviewer/servicesproxymodel.h
new file mode 100644
index 000000000..da2bb1565
--- /dev/null
+++ b/src/qdbus/qdbusviewer/servicesproxymodel.h
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the tools applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SERVICESFILTERPROXYMODEL_H
+#define SERVICESFILTERPROXYMODEL_H
+
+#include <QSortFilterProxyModel>
+
+class ServicesProxyModel : public QSortFilterProxyModel
+{
+ Q_OBJECT
+
+public:
+ ServicesProxyModel(QObject *parent = Q_NULLPTR);
+
+protected:
+ bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE;
+};
+
+#endif // SERVICESFILTERPROXYMODEL_H