From af71bb25c504b39d7573c65625c4038c482d60b5 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 31 Aug 2018 20:48:34 +0200 Subject: [PATCH] drop EventDescriptorParamsProxyModel as it didn't do what it was supposed and was useless --- libnymea-app-core/libnymea-app-core.h | 2 - libnymea-app-core/libnymea-app-core.pro | 2 - .../eventdescriptorparamsfiltermodel.cpp | 86 ------------------- .../models/eventdescriptorparamsfiltermodel.h | 44 ---------- .../ui/magic/SelectRuleActionParamsPage.qml | 26 +++--- 5 files changed, 13 insertions(+), 147 deletions(-) delete mode 100644 libnymea-app-core/models/eventdescriptorparamsfiltermodel.cpp delete mode 100644 libnymea-app-core/models/eventdescriptorparamsfiltermodel.h diff --git a/libnymea-app-core/libnymea-app-core.h b/libnymea-app-core/libnymea-app-core.h index 85a56e6a..939016d4 100644 --- a/libnymea-app-core/libnymea-app-core.h +++ b/libnymea-app-core/libnymea-app-core.h @@ -34,7 +34,6 @@ #include "models/logsmodel.h" #include "models/logsmodelng.h" #include "models/valuelogsproxymodel.h" -#include "models/eventdescriptorparamsfiltermodel.h" #include "models/interfacesproxy.h" #include "basicconfiguration.h" #include "wifisetup/networkmanagercontroler.h" @@ -152,7 +151,6 @@ void registerQmlTypes() { qmlRegisterUncreatableType(uri, 1, 0, "DiscoveryDevice", "Get it from DiscoveryModel"); qmlRegisterUncreatableType(uri, 1, 0, "Connection", "Get it from DiscoveryDevice"); - qmlRegisterType(uri, 1, 0, "EventDescriptorParamsFilterModel"); qmlRegisterType(uri, 1, 0, "LogsModel"); qmlRegisterType(uri, 1, 0, "LogsModelNg"); diff --git a/libnymea-app-core/libnymea-app-core.pro b/libnymea-app-core/libnymea-app-core.pro index 6b85a26f..22d40baa 100644 --- a/libnymea-app-core/libnymea-app-core.pro +++ b/libnymea-app-core/libnymea-app-core.pro @@ -56,7 +56,6 @@ SOURCES += \ discovery/nymeadiscovery.cpp \ logmanager.cpp \ basicconfiguration.cpp \ - models/eventdescriptorparamsfiltermodel.cpp \ wifisetup/bluetoothdevice.cpp \ wifisetup/bluetoothdeviceinfo.cpp \ wifisetup/bluetoothdeviceinfos.cpp \ @@ -114,7 +113,6 @@ HEADERS += \ discovery/nymeadiscovery.h \ logmanager.h \ basicconfiguration.h \ - models/eventdescriptorparamsfiltermodel.h \ wifisetup/bluetoothdevice.h \ wifisetup/bluetoothdeviceinfo.h \ wifisetup/bluetoothdeviceinfos.h \ diff --git a/libnymea-app-core/models/eventdescriptorparamsfiltermodel.cpp b/libnymea-app-core/models/eventdescriptorparamsfiltermodel.cpp deleted file mode 100644 index b6d472e4..00000000 --- a/libnymea-app-core/models/eventdescriptorparamsfiltermodel.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include "eventdescriptorparamsfiltermodel.h" - -#include "types/eventdescriptor.h" -#include "engine.h" - -EventDescriptorParamsFilterModel::EventDescriptorParamsFilterModel(QObject *parent) : QSortFilterProxyModel(parent) -{ - -} - -//int EventDescriptorParamsFilterModel::rowCount(const QModelIndex &parent) const -//{ -// Q_UNUSED(parent) -// if (!m_eventDescriptor) { -// return 0; -// } -// foreach (const Param ¶m, m_eventDescriptor->paramDescriptors()->rowCount()) -//} - -EventDescriptor *EventDescriptorParamsFilterModel::eventDescriptor() const -{ - return m_eventDescriptor; -} - -void EventDescriptorParamsFilterModel::setEventDescriptor(EventDescriptor *eventDescriptor) -{ - if (m_eventDescriptor != eventDescriptor) { - m_eventDescriptor = eventDescriptor; - emit eventDescriptorChanged(); - Device *d = Engine::instance()->deviceManager()->devices()->getDevice(eventDescriptor->deviceId()); - if (!d) { - qDebug() << "Can't find a device for this descriptor..."; - return; - } - DeviceClass* dc = Engine::instance()->deviceManager()->deviceClasses()->getDeviceClass(d->deviceClassId()); - if (!dc) { - qDebug() << "Uh oh... No deviceClass for a device!?!11"; - return; - } - EventType* et = dc->eventTypes()->getEventType(eventDescriptor->eventTypeId()); - if (!et) { - qDebug() << "Couldn't find eventtype"; - return; - } - setSourceModel(et->paramTypes()); - qDebug() << "have set source model" << et->paramTypes()->rowCount(); - } -} - -QVariant::Type EventDescriptorParamsFilterModel::type() const -{ - return m_type; -} - -void EventDescriptorParamsFilterModel::setType(QVariant::Type type) -{ - if (type != m_type) { - m_type = type; - emit typeChanged(); - invalidateFilter(); - } -} - -ParamDescriptor *EventDescriptorParamsFilterModel::get(int idx) const -{ -// qDebug() << "...." << m_eventDescriptor->paramDescriptors()->get(mapToSource(index(idx, 0)).row())->paramTypeId() - return m_eventDescriptor->paramDescriptors()->get(mapToSource(index(idx, 0)).row()); -} - -bool EventDescriptorParamsFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const -{ - Q_UNUSED(source_parent) - ParamType *pd = dynamic_cast(sourceModel())->get(source_row); - - Device *device = Engine::instance()->deviceManager()->devices()->getDevice(m_eventDescriptor->deviceId()); - if (!device) { - qDebug() << "rejecting entry" << pd->id(); - return false; - } - qDebug() << "accepting entty:" << pd->id(); -// DeviceClass dc = Engine::instance()->deviceManager()->deviceClasses()->getDeviceClass(device->deviceClassId()); -// if (dc.paramTypes()->getParamType(pd->paramTypeId())->type() == m_type) { - return true; -// } -// return false; -} diff --git a/libnymea-app-core/models/eventdescriptorparamsfiltermodel.h b/libnymea-app-core/models/eventdescriptorparamsfiltermodel.h deleted file mode 100644 index 7867683d..00000000 --- a/libnymea-app-core/models/eventdescriptorparamsfiltermodel.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef EVENTDESCRIPTORPARAMSFILTERMODEL_H -#define EVENTDESCRIPTORPARAMSFILTERMODEL_H - -#include - -class EventDescriptor; -class ParamDescriptor; - -class EventDescriptorParamsFilterModel : public QSortFilterProxyModel -{ - Q_OBJECT -// Q_PROPERTY(int count READ rowCount NOTIFY countChanged) - Q_PROPERTY(EventDescriptor* eventDescriptor READ eventDescriptor WRITE setEventDescriptor NOTIFY eventDescriptorChanged) - Q_PROPERTY(QVariant::Type type READ type WRITE setType NOTIFY typeChanged) - -public: - explicit EventDescriptorParamsFilterModel(QObject *parent = nullptr); - -// int rowCount(const QModelIndex &parent = QModelIndex()) const override; -// QVariant data(const QModelIndex &index, int role) const override; - - EventDescriptor* eventDescriptor() const; - void setEventDescriptor(EventDescriptor* eventDescriptor); - - QVariant::Type type() const; - void setType(QVariant::Type type); - - Q_INVOKABLE ParamDescriptor* get(int idx) const; - -protected: - bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; - -signals: - void eventDescriptorChanged(); - void typeChanged(); - -public slots: - -private: - EventDescriptor* m_eventDescriptor = nullptr; - QVariant::Type m_type; -}; - -#endif // EVENTDESCRIPTORPARAMSFILTERMODEL_H diff --git a/nymea-app/ui/magic/SelectRuleActionParamsPage.qml b/nymea-app/ui/magic/SelectRuleActionParamsPage.qml index e5556a47..a3e0ea8f 100644 --- a/nymea-app/ui/magic/SelectRuleActionParamsPage.qml +++ b/nymea-app/ui/magic/SelectRuleActionParamsPage.qml @@ -51,8 +51,8 @@ Page { property alias paramType: paramDelegate.paramType property alias value: paramDelegate.value - property alias eventType: eventDescriptorParamsFilterModel.eventType - property alias eventParamTypeId: eventDescriptorParamsFilterModel.paramTypeId + property alias eventType: eventParamsComboBox.eventType + property alias eventParamTypeId: eventParamsComboBox.currentParamTypeId RadioButton { id: staticParamRadioButton @@ -78,24 +78,24 @@ Page { enabled: eventParamRadioButton.checked visible: count > 0 Component.onCompleted: currentIndex = 0; - model: EventDescriptorParamsFilterModel { - id: eventDescriptorParamsFilterModel - eventDescriptor: root.rule.eventDescriptors.count === 1 ? root.rule.eventDescriptors.get(0) : null - property var device: eventDescriptor ? Engine.deviceManager.devices.getDevice(eventDescriptor.deviceId) : null - property var deviceClass: device ? Engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null - property var eventType: deviceClass ? deviceClass.eventTypes.getEventType(eventDescriptor.eventTypeId) : null - property var paramDescriptor: eventDescriptorParamsFilterModel.eventType.paramTypes.get(eventParamsComboBox.currentIndex) - property var paramTypeId: paramDescriptor.id - } + property var eventDescriptor: root.rule.eventDescriptors.count === 1 ? root.rule.eventDescriptors.get(0) : null + property var device: eventDescriptor ? Engine.deviceManager.devices.getDevice(eventDescriptor.deviceId) : null + property var deviceClass: device ? Engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null + property var eventType: deviceClass ? deviceClass.eventTypes.getEventType(eventDescriptor.eventTypeId) : null + + property var currentParamDescriptor: eventType.paramTypes.get(eventParamsComboBox.currentIndex) + property var currentParamTypeId: currentParamDescriptor.id + + model: eventType.paramTypes delegate: ItemDelegate { width: parent.width - text: eventDescriptorParamsFilterModel.device.name + " - " + eventDescriptorParamsFilterModel.eventType.displayName + " - " + eventDescriptorParamsFilterModel.eventType.paramTypes.getParamType(model.id).displayName + text: eventParamsComboBox.device.name + " - " + eventParamsComboBox.eventType.displayName + " - " + eventParamsComboBox.eventType.paramTypes.getParamType(model.id).displayName } contentItem: Label { id: eventParamsComboBoxContentItem anchors.fill: parent anchors.margins: app.margins - text: eventDescriptorParamsFilterModel.device.name + " - " + eventDescriptorParamsFilterModel.eventType.displayName + " - " + eventDescriptorParamsFilterModel.paramDescriptor.displayName + text: eventParamsComboBox.device.name + " - " + eventParamsComboBox.eventType.displayName + " - " + eventParamsComboBox.currentParamDescriptor.displayName elide: Text.ElideRight } }