From 05491442e68499d66199069b5d0967449e0e52eb Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Wed, 15 Apr 2015 13:00:23 +0200 Subject: [PATCH] Make it possible to fetch the device from the DevicesModel from QML Uses the row as the argument instead of the QModelIndex. Defines the Device type so it can be used from QML. REVIEW: 123361 --- interfaces/devicesmodel.cpp | 7 +------ interfaces/devicesmodel.h | 2 +- kcm/kcm.cpp | 2 +- plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp | 1 + 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/interfaces/devicesmodel.cpp b/interfaces/devicesmodel.cpp index 16b4d7703..35e44fc80 100644 --- a/interfaces/devicesmodel.cpp +++ b/interfaces/devicesmodel.cpp @@ -227,13 +227,8 @@ QVariant DevicesModel::data(const QModelIndex& index, int role) const } } -DeviceDbusInterface* DevicesModel::getDevice(const QModelIndex& index) const +DeviceDbusInterface* DevicesModel::getDevice(int row) const { - if (!index.isValid()) { - return NULL; - } - - int row = index.row(); if (row < 0 || row >= m_deviceList.size()) { return NULL; } diff --git a/interfaces/devicesmodel.h b/interfaces/devicesmodel.h index 1f157b252..e8c1d9e16 100644 --- a/interfaces/devicesmodel.h +++ b/interfaces/devicesmodel.h @@ -64,7 +64,7 @@ public: virtual QVariant data(const QModelIndex& index, int role) const; virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; - DeviceDbusInterface* getDevice(const QModelIndex& index) const; + Q_SCRIPTABLE DeviceDbusInterface* getDevice(int row) const; virtual QHash roleNames() const; public Q_SLOTS: diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp index 7a72f749e..cf422e3bc 100644 --- a/kcm/kcm.cpp +++ b/kcm/kcm.cpp @@ -157,7 +157,7 @@ void KdeConnectKcm::deviceSelected(const QModelIndex& current) } currentIndex = sortProxyModel->mapToSource(current); - currentDevice = devicesModel->getDevice(currentIndex); + currentDevice = devicesModel->getDevice(currentIndex.row()); bool valid = (currentDevice != NULL && currentDevice->isValid()); kcmUi->deviceInfo->setVisible(valid); diff --git a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp index 5b9716f09..c9c5f3d4e 100644 --- a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp +++ b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp @@ -61,6 +61,7 @@ void KdeConnectDeclarativePlugin::registerTypes(const char* uri) qmlRegisterType("org.kde.kdeconnect", 1, 0, "NotificationsModel"); qmlRegisterType("org.kde.kdeconnect", 1, 0, "DBusAsyncResponse"); qmlRegisterType(uri, 1, 0, "ProcessRunner"); + qmlRegisterUncreatableType("org.kde.kdeconnect", 1, 0, "DeviceDbusInterface", QStringLiteral("You're not supposed to instantiate interfacess")); } void KdeConnectDeclarativePlugin::initializeEngine(QQmlEngine* engine, const char* uri)