From 9bbfd9de192c681b59eaed82c3f6e15f598cf427 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 22 Jun 2018 11:18:59 +0200 Subject: [PATCH] fix logsModel to allow filtering for multiple typeIds --- libmea-core/models/logsmodel.cpp | 20 ++++++++++--------- libmea-core/models/logsmodel.h | 10 +++++----- mea/ui/components/Graph.qml | 5 ++--- mea/ui/customviews/GenericTypeLogView.qml | 4 +++- mea/ui/customviews/SensorView.qml | 2 +- mea/ui/devicepages/ButtonDevicePage.qml | 9 ++++++++- mea/ui/devicepages/InputTriggerDevicePage.qml | 2 +- mea/ui/devicepages/StateLogPage.qml | 4 ++-- 8 files changed, 33 insertions(+), 23 deletions(-) diff --git a/libmea-core/models/logsmodel.cpp b/libmea-core/models/logsmodel.cpp index cf8777bc..a67aa0fe 100644 --- a/libmea-core/models/logsmodel.cpp +++ b/libmea-core/models/logsmodel.cpp @@ -78,16 +78,16 @@ void LogsModel::setDeviceId(const QString &deviceId) } } -QString LogsModel::typeId() const +QStringList LogsModel::typeIds() const { - return m_typeId; + return m_typeIds; } -void LogsModel::setTypeId(const QString &typeId) +void LogsModel::setTypeIds(const QStringList &typeIds) { - if (m_typeId != typeId) { - m_typeId = typeId; - emit typeIdChanged(); + if (m_typeIds != typeIds) { + m_typeIds = typeIds; + emit typeIdsChanged(); } } @@ -141,9 +141,11 @@ void LogsModel::update() deviceIds.append(m_deviceId); params.insert("deviceIds", deviceIds); } - if (!m_typeId.isEmpty()) { + if (!m_typeIds.isEmpty()) { QVariantList typeIds; - typeIds.append(m_typeId); + foreach (const QString &typeId, m_typeIds) { + typeIds.append(typeId); + } params.insert("typeIds", typeIds); } QVariantList timeFilters; @@ -196,7 +198,7 @@ void LogsModel::newLogEntryReceived(const QVariantMap &data) } QString typeId = entryMap.value("typeId").toString(); - if (!m_typeId.isNull() && typeId != m_typeId) { + if (!m_typeIds.isEmpty() && !m_typeIds.contains(typeId)) { return; } diff --git a/libmea-core/models/logsmodel.h b/libmea-core/models/logsmodel.h index 3f4ed3ed..75691541 100644 --- a/libmea-core/models/logsmodel.h +++ b/libmea-core/models/logsmodel.h @@ -12,7 +12,7 @@ class LogsModel : public QAbstractListModel Q_PROPERTY(bool busy READ busy NOTIFY busyChanged) Q_PROPERTY(int count READ rowCount NOTIFY countChanged) Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged) - Q_PROPERTY(QString typeId READ typeId WRITE setTypeId NOTIFY typeIdChanged) + Q_PROPERTY(QStringList typeIds READ typeIds WRITE setTypeIds NOTIFY typeIdsChanged) Q_PROPERTY(QDateTime startTime READ startTime WRITE setStartTime NOTIFY startTimeChanged) Q_PROPERTY(QDateTime endTime READ endTime WRITE setEndTime NOTIFY endTimeChanged) @@ -40,8 +40,8 @@ public: QString deviceId() const; void setDeviceId(const QString &deviceId); - QString typeId() const; - void setTypeId(const QString &typeId); + QStringList typeIds() const; + void setTypeIds(const QStringList &typeIds); QDateTime startTime() const; void setStartTime(const QDateTime &startTime); @@ -58,7 +58,7 @@ signals: void liveChanged(); void countChanged(); void deviceIdChanged(); - void typeIdChanged(); + void typeIdsChanged(); void startTimeChanged(); void endTimeChanged(); @@ -72,7 +72,7 @@ private slots: protected: QList m_list; QString m_deviceId; - QString m_typeId; + QStringList m_typeIds; QDateTime m_startTime = QDateTime::currentDateTime().addDays(-1); QDateTime m_endTime = QDateTime::currentDateTime(); diff --git a/mea/ui/components/Graph.qml b/mea/ui/components/Graph.qml index 1e180e71..ee04e630 100644 --- a/mea/ui/components/Graph.qml +++ b/mea/ui/components/Graph.qml @@ -19,7 +19,7 @@ Item { readonly property var device: root.model ? Engine.deviceManager.devices.getDevice(root.model.deviceId) : null readonly property var deviceClass: device ? Engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null - readonly property var stateType: deviceClass ? deviceClass.stateTypes.getStateType(root.model.typeId) : null + readonly property var stateType: deviceClass ? deviceClass.stateTypes.getStateType(root.model.typeIds[0]) : null Label { anchors.centerIn: parent @@ -93,7 +93,7 @@ Item { } onPaint: { - print("painting graph") +// print("painting graph") var ctx = canvas.getContext('2d'); ctx.save(); @@ -164,7 +164,6 @@ Item { ctx.strokeStyle = Material.foreground ctx.fillStyle = Material.foreground ctx.lineWidth = 0; - print("blubb", root.stateType.unitString) var label = root.stateType ? root.stateType.unitString : "" var textSize = ctx.measureText(label) ctx.text(label, -textSize.width - app.margins, height + app.margins + app.smallFont) diff --git a/mea/ui/customviews/GenericTypeLogView.qml b/mea/ui/customviews/GenericTypeLogView.qml index 47dd1d7d..00d0e463 100644 --- a/mea/ui/customviews/GenericTypeLogView.qml +++ b/mea/ui/customviews/GenericTypeLogView.qml @@ -43,6 +43,8 @@ Item { id: logEntryDelegate width: parent.width implicitHeight: app.delegateHeight + property var device: Engine.deviceManager.devices.getDevice(model.deviceId) + property var deviceClass: Engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) contentItem: RowLayout { ColorIcon { Layout.preferredHeight: app.iconSize @@ -59,7 +61,7 @@ Item { } Label { Layout.fillWidth: true - text: qsTr("Data: %1").arg(model.value.trim()) + text: "%1: %2".arg(deviceClass.eventTypes.getEventType(model.typeId).displayName).arg(model.value.trim()) elide: Text.ElideRight font.pixelSize: app.smallFont } diff --git a/mea/ui/customviews/SensorView.qml b/mea/ui/customviews/SensorView.qml index 071add3c..262fe56e 100644 --- a/mea/ui/customviews/SensorView.qml +++ b/mea/ui/customviews/SensorView.qml @@ -17,7 +17,7 @@ CustomViewBase { ValueLogsProxyModel { id: logsModel deviceId: root.device.id - typeId: stateType.id + typeIds: [stateType.id] average: zoomTabBar.currentItem.avg startTime: zoomTabBar.currentItem.startTime Component.onCompleted: updateTimer.start(); diff --git a/mea/ui/devicepages/ButtonDevicePage.qml b/mea/ui/devicepages/ButtonDevicePage.qml index 2e1c2dd0..988769b2 100644 --- a/mea/ui/devicepages/ButtonDevicePage.qml +++ b/mea/ui/devicepages/ButtonDevicePage.qml @@ -16,7 +16,14 @@ GenericDevicePage { logsModel: LogsModel { deviceId: root.device.id live: true - typeId: root.deviceClass.eventTypes.findByName("pressed").id + typeIds: { + var ret = []; + ret.push(root.deviceClass.eventTypes.findByName("pressed").id) + if (root.deviceClass.eventTypes.findByName("longPressed")) { + ret.push(root.deviceClass.eventTypes.findByName("longPressed").id) + } + return ret; + } Component.onCompleted: update() } diff --git a/mea/ui/devicepages/InputTriggerDevicePage.qml b/mea/ui/devicepages/InputTriggerDevicePage.qml index 821c03a7..d6e5feb0 100644 --- a/mea/ui/devicepages/InputTriggerDevicePage.qml +++ b/mea/ui/devicepages/InputTriggerDevicePage.qml @@ -16,7 +16,7 @@ GenericDevicePage { deviceId: root.device.id live: true Component.onCompleted: update() - typeId: root.deviceClass.eventTypes.findByName("triggered").id; + typeIds: [root.deviceClass.eventTypes.findByName("triggered").id]; } onAddRuleClicked: { diff --git a/mea/ui/devicepages/StateLogPage.qml b/mea/ui/devicepages/StateLogPage.qml index 9c4ec3a3..a9251509 100644 --- a/mea/ui/devicepages/StateLogPage.qml +++ b/mea/ui/devicepages/StateLogPage.qml @@ -31,7 +31,7 @@ Page { deviceId: root.device.id live: true Component.onCompleted: update() - typeId: root.stateType.id + typeIds: [root.stateType.id] } // LogsModelNg { @@ -151,7 +151,7 @@ Page { model: ValueLogsProxyModel { id: graphModel deviceId: root.device.id - typeId: stateType.id + typeIds: [stateType.id] average: zoomTabBar.currentItem.avg startTime: zoomTabBar.currentItem.startTime Component.onCompleted: updateTimer.start();