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:
parent
2e58f34e1d
commit
05491442e6
4 changed files with 4 additions and 8 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<int, QByteArray> roleNames() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -61,6 +61,7 @@ void KdeConnectDeclarativePlugin::registerTypes(const char* uri)
|
|||
qmlRegisterType<NotificationsModel>("org.kde.kdeconnect", 1, 0, "NotificationsModel");
|
||||
qmlRegisterType<DBusAsyncResponse>("org.kde.kdeconnect", 1, 0, "DBusAsyncResponse");
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue