fix logsModel to allow filtering for multiple typeIds

This commit is contained in:
Michael Zanetti 2018-06-22 11:18:59 +02:00
parent e44d5c0fd8
commit 9bbfd9de19
8 changed files with 33 additions and 23 deletions

View File

@ -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) { if (m_typeIds != typeIds) {
m_typeId = typeId; m_typeIds = typeIds;
emit typeIdChanged(); emit typeIdsChanged();
} }
} }
@ -141,9 +141,11 @@ void LogsModel::update()
deviceIds.append(m_deviceId); deviceIds.append(m_deviceId);
params.insert("deviceIds", deviceIds); params.insert("deviceIds", deviceIds);
} }
if (!m_typeId.isEmpty()) { if (!m_typeIds.isEmpty()) {
QVariantList typeIds; QVariantList typeIds;
typeIds.append(m_typeId); foreach (const QString &typeId, m_typeIds) {
typeIds.append(typeId);
}
params.insert("typeIds", typeIds); params.insert("typeIds", typeIds);
} }
QVariantList timeFilters; QVariantList timeFilters;
@ -196,7 +198,7 @@ void LogsModel::newLogEntryReceived(const QVariantMap &data)
} }
QString typeId = entryMap.value("typeId").toString(); QString typeId = entryMap.value("typeId").toString();
if (!m_typeId.isNull() && typeId != m_typeId) { if (!m_typeIds.isEmpty() && !m_typeIds.contains(typeId)) {
return; return;
} }

View File

@ -12,7 +12,7 @@ class LogsModel : public QAbstractListModel
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged) Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
Q_PROPERTY(int count READ rowCount NOTIFY countChanged) Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged) 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 startTime READ startTime WRITE setStartTime NOTIFY startTimeChanged)
Q_PROPERTY(QDateTime endTime READ endTime WRITE setEndTime NOTIFY endTimeChanged) Q_PROPERTY(QDateTime endTime READ endTime WRITE setEndTime NOTIFY endTimeChanged)
@ -40,8 +40,8 @@ public:
QString deviceId() const; QString deviceId() const;
void setDeviceId(const QString &deviceId); void setDeviceId(const QString &deviceId);
QString typeId() const; QStringList typeIds() const;
void setTypeId(const QString &typeId); void setTypeIds(const QStringList &typeIds);
QDateTime startTime() const; QDateTime startTime() const;
void setStartTime(const QDateTime &startTime); void setStartTime(const QDateTime &startTime);
@ -58,7 +58,7 @@ signals:
void liveChanged(); void liveChanged();
void countChanged(); void countChanged();
void deviceIdChanged(); void deviceIdChanged();
void typeIdChanged(); void typeIdsChanged();
void startTimeChanged(); void startTimeChanged();
void endTimeChanged(); void endTimeChanged();
@ -72,7 +72,7 @@ private slots:
protected: protected:
QList<LogEntry*> m_list; QList<LogEntry*> m_list;
QString m_deviceId; QString m_deviceId;
QString m_typeId; QStringList m_typeIds;
QDateTime m_startTime = QDateTime::currentDateTime().addDays(-1); QDateTime m_startTime = QDateTime::currentDateTime().addDays(-1);
QDateTime m_endTime = QDateTime::currentDateTime(); QDateTime m_endTime = QDateTime::currentDateTime();

View File

@ -19,7 +19,7 @@ Item {
readonly property var device: root.model ? Engine.deviceManager.devices.getDevice(root.model.deviceId) : null 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 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 { Label {
anchors.centerIn: parent anchors.centerIn: parent
@ -93,7 +93,7 @@ Item {
} }
onPaint: { onPaint: {
print("painting graph") // print("painting graph")
var ctx = canvas.getContext('2d'); var ctx = canvas.getContext('2d');
ctx.save(); ctx.save();
@ -164,7 +164,6 @@ Item {
ctx.strokeStyle = Material.foreground ctx.strokeStyle = Material.foreground
ctx.fillStyle = Material.foreground ctx.fillStyle = Material.foreground
ctx.lineWidth = 0; ctx.lineWidth = 0;
print("blubb", root.stateType.unitString)
var label = root.stateType ? root.stateType.unitString : "" var label = root.stateType ? root.stateType.unitString : ""
var textSize = ctx.measureText(label) var textSize = ctx.measureText(label)
ctx.text(label, -textSize.width - app.margins, height + app.margins + app.smallFont) ctx.text(label, -textSize.width - app.margins, height + app.margins + app.smallFont)

View File

@ -43,6 +43,8 @@ Item {
id: logEntryDelegate id: logEntryDelegate
width: parent.width width: parent.width
implicitHeight: app.delegateHeight implicitHeight: app.delegateHeight
property var device: Engine.deviceManager.devices.getDevice(model.deviceId)
property var deviceClass: Engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId)
contentItem: RowLayout { contentItem: RowLayout {
ColorIcon { ColorIcon {
Layout.preferredHeight: app.iconSize Layout.preferredHeight: app.iconSize
@ -59,7 +61,7 @@ Item {
} }
Label { Label {
Layout.fillWidth: true 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 elide: Text.ElideRight
font.pixelSize: app.smallFont font.pixelSize: app.smallFont
} }

View File

@ -17,7 +17,7 @@ CustomViewBase {
ValueLogsProxyModel { ValueLogsProxyModel {
id: logsModel id: logsModel
deviceId: root.device.id deviceId: root.device.id
typeId: stateType.id typeIds: [stateType.id]
average: zoomTabBar.currentItem.avg average: zoomTabBar.currentItem.avg
startTime: zoomTabBar.currentItem.startTime startTime: zoomTabBar.currentItem.startTime
Component.onCompleted: updateTimer.start(); Component.onCompleted: updateTimer.start();

View File

@ -16,7 +16,14 @@ GenericDevicePage {
logsModel: LogsModel { logsModel: LogsModel {
deviceId: root.device.id deviceId: root.device.id
live: true 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() Component.onCompleted: update()
} }

View File

@ -16,7 +16,7 @@ GenericDevicePage {
deviceId: root.device.id deviceId: root.device.id
live: true live: true
Component.onCompleted: update() Component.onCompleted: update()
typeId: root.deviceClass.eventTypes.findByName("triggered").id; typeIds: [root.deviceClass.eventTypes.findByName("triggered").id];
} }
onAddRuleClicked: { onAddRuleClicked: {

View File

@ -31,7 +31,7 @@ Page {
deviceId: root.device.id deviceId: root.device.id
live: true live: true
Component.onCompleted: update() Component.onCompleted: update()
typeId: root.stateType.id typeIds: [root.stateType.id]
} }
// LogsModelNg { // LogsModelNg {
@ -151,7 +151,7 @@ Page {
model: ValueLogsProxyModel { model: ValueLogsProxyModel {
id: graphModel id: graphModel
deviceId: root.device.id deviceId: root.device.id
typeId: stateType.id typeIds: [stateType.id]
average: zoomTabBar.currentItem.avg average: zoomTabBar.currentItem.avg
startTime: zoomTabBar.currentItem.startTime startTime: zoomTabBar.currentItem.startTime
Component.onCompleted: updateTimer.start(); Component.onCompleted: updateTimer.start();