From a83bf73a4dbf646b1946431bad99fbcbb6bef250 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Thu, 11 Jun 2015 16:09:27 +0200 Subject: [PATCH] Move the DevicesSortProxyModel to interfaces/ This way it can be used by other parts of the project. It belongs with the DevicesModel. REVIEW: 124067 --- interfaces/CMakeLists.txt | 1 + {kcm => interfaces}/devicessortproxymodel.cpp | 12 +++++++++--- {kcm => interfaces}/devicessortproxymodel.h | 6 ++++-- kcm/CMakeLists.txt | 1 - .../kdeconnectdeclarativeplugin.cpp | 2 ++ 5 files changed, 16 insertions(+), 6 deletions(-) rename {kcm => interfaces}/devicessortproxymodel.cpp (86%) rename {kcm => interfaces}/devicessortproxymodel.h (83%) diff --git a/interfaces/CMakeLists.txt b/interfaces/CMakeLists.txt index eb72363ff..7879b357d 100644 --- a/interfaces/CMakeLists.txt +++ b/interfaces/CMakeLists.txt @@ -11,6 +11,7 @@ set(libkdeconnect_SRC dbusinterfaces.cpp devicesmodel.cpp notificationsmodel.cpp + devicessortproxymodel.cpp # modeltest.cpp ) diff --git a/kcm/devicessortproxymodel.cpp b/interfaces/devicessortproxymodel.cpp similarity index 86% rename from kcm/devicessortproxymodel.cpp rename to interfaces/devicessortproxymodel.cpp index 02d02a616..4588dd687 100644 --- a/kcm/devicessortproxymodel.cpp +++ b/interfaces/devicessortproxymodel.cpp @@ -27,9 +27,15 @@ DevicesSortProxyModel::DevicesSortProxyModel(DevicesModel* devicesModel) : QSortFilterProxyModel(devicesModel) { setSourceModel(devicesModel); - setSortRole(DevicesModel::StatusModelRole); - connect(devicesModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), - this, SLOT(sourceDataChanged(QModelIndex,QModelIndex))); +} + +void DevicesSortProxyModel::setSourceModel(QAbstractItemModel *devicesModel) +{ + QSortFilterProxyModel::setSourceModel(devicesModel); + if (devicesModel) { + setSortRole(DevicesModel::StatusModelRole); + connect(devicesModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(sourceDataChanged(QModelIndex,QModelIndex))); + } sort(0); } diff --git a/kcm/devicessortproxymodel.h b/interfaces/devicessortproxymodel.h similarity index 83% rename from kcm/devicessortproxymodel.h rename to interfaces/devicessortproxymodel.h index 1b6249b3a..54b7a0bf7 100644 --- a/kcm/devicessortproxymodel.h +++ b/interfaces/devicessortproxymodel.h @@ -22,16 +22,18 @@ #define DEVICESSORTPROXYMODEL_H #include +#include "interfaces/kdeconnectinterfaces_export.h" class DevicesModel; -class DevicesSortProxyModel : public QSortFilterProxyModel +class KDECONNECTINTERFACES_EXPORT DevicesSortProxyModel : public QSortFilterProxyModel { Q_OBJECT public: - DevicesSortProxyModel(DevicesModel* devicesModel); + DevicesSortProxyModel(DevicesModel* devicesModel = Q_NULLPTR); virtual bool lessThan(const QModelIndex& left, const QModelIndex& right) const; virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const; + virtual void setSourceModel(QAbstractItemModel *sourceModel); public Q_SLOTS: void sourceDataChanged(QModelIndex,QModelIndex); diff --git a/kcm/CMakeLists.txt b/kcm/CMakeLists.txt index 568972bb5..b596e7695 100644 --- a/kcm/CMakeLists.txt +++ b/kcm/CMakeLists.txt @@ -9,7 +9,6 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR} set(kcm_SRCS kcm.cpp - devicessortproxymodel.cpp ) ki18n_wrap_ui(kcm_SRCS kcm.ui) diff --git a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp index 28892f95f..76a76015c 100644 --- a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp +++ b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp @@ -30,6 +30,7 @@ #include "responsewaiter.h" #include "processrunner.h" +#include "interfaces/devicessortproxymodel.h" #include "interfaces/devicesmodel.h" #include "interfaces/notificationsmodel.h" @@ -59,6 +60,7 @@ void KdeConnectDeclarativePlugin::registerTypes(const char* uri) qmlRegisterType(uri, 1, 0, "NotificationsModel"); qmlRegisterType(uri, 1, 0, "DBusAsyncResponse"); qmlRegisterType(uri, 1, 0, "ProcessRunner"); + qmlRegisterType(uri, 1, 0, "DevicesSortProxyModel"); qmlRegisterUncreatableType(uri, 1, 0, "DeviceDbusInterface", QStringLiteral("You're not supposed to instantiate interfacess")); }