diff options
-rw-r--r-- | src/qdbus/qdbusviewer/qdbusviewer.cpp | 5 | ||||
-rw-r--r-- | src/qdbus/qdbusviewer/qdbusviewer.h | 5 | ||||
-rw-r--r-- | src/qdbus/qdbusviewer/qdbusviewer.pro | 2 | ||||
-rw-r--r-- | src/qdbus/qdbusviewer/servicesproxymodel.cpp | 60 | ||||
-rw-r--r-- | src/qdbus/qdbusviewer/servicesproxymodel.h | 50 |
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 |