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
This commit is contained in:
Aleix Pol 2015-04-15 13:00:23 +02:00
parent 2e58f34e1d
commit 05491442e6
4 changed files with 4 additions and 8 deletions

View file

@ -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()) { if (row < 0 || row >= m_deviceList.size()) {
return NULL; return NULL;
} }

View file

@ -64,7 +64,7 @@ public:
virtual QVariant data(const QModelIndex& index, int role) const; virtual QVariant data(const QModelIndex& index, int role) const;
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
DeviceDbusInterface* getDevice(const QModelIndex& index) const; Q_SCRIPTABLE DeviceDbusInterface* getDevice(int row) const;
virtual QHash<int, QByteArray> roleNames() const; virtual QHash<int, QByteArray> roleNames() const;
public Q_SLOTS: public Q_SLOTS:

View file

@ -157,7 +157,7 @@ void KdeConnectKcm::deviceSelected(const QModelIndex& current)
} }
currentIndex = sortProxyModel->mapToSource(current); currentIndex = sortProxyModel->mapToSource(current);
currentDevice = devicesModel->getDevice(currentIndex); currentDevice = devicesModel->getDevice(currentIndex.row());
bool valid = (currentDevice != NULL && currentDevice->isValid()); bool valid = (currentDevice != NULL && currentDevice->isValid());
kcmUi->deviceInfo->setVisible(valid); kcmUi->deviceInfo->setVisible(valid);

View file

@ -61,6 +61,7 @@ void KdeConnectDeclarativePlugin::registerTypes(const char* uri)
qmlRegisterType<NotificationsModel>("org.kde.kdeconnect", 1, 0, "NotificationsModel"); qmlRegisterType<NotificationsModel>("org.kde.kdeconnect", 1, 0, "NotificationsModel");
qmlRegisterType<DBusAsyncResponse>("org.kde.kdeconnect", 1, 0, "DBusAsyncResponse"); qmlRegisterType<DBusAsyncResponse>("org.kde.kdeconnect", 1, 0, "DBusAsyncResponse");
qmlRegisterType<ProcessRunner>(uri, 1, 0, "ProcessRunner"); qmlRegisterType<ProcessRunner>(uri, 1, 0, "ProcessRunner");
qmlRegisterUncreatableType<DeviceDbusInterface>("org.kde.kdeconnect", 1, 0, "DeviceDbusInterface", QStringLiteral("You're not supposed to instantiate interfacess"));
} }
void KdeConnectDeclarativePlugin::initializeEngine(QQmlEngine* engine, const char* uri) void KdeConnectDeclarativePlugin::initializeEngine(QQmlEngine* engine, const char* uri)