From 0159a145eca93abc24a21ee4f765bd780319a9a3 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Wed, 27 May 2020 11:12:08 +0200 Subject: [PATCH] Reduce some warnings from QML --- libnymea-app/types/states.cpp | 8 ++------ libnymea-app/types/states.h | 6 +++++- nymea-app/ui/delegates/ParamDelegate.qml | 10 ++++++++++ nymea-app/ui/devicepages/MediaDevicePage.qml | 6 ++++++ nymea-app/ui/mainviews/DevicesPageDelegate.qml | 6 +++--- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/libnymea-app/types/states.cpp b/libnymea-app/types/states.cpp index 440d0950..18ba010f 100644 --- a/libnymea-app/types/states.cpp +++ b/libnymea-app/types/states.cpp @@ -42,11 +42,6 @@ QList States::states() return m_states; } -int States::count() const -{ - return m_states.count(); -} - State *States::get(int index) const { return m_states.at(index); @@ -59,7 +54,7 @@ State *States::getState(const QUuid &stateTypeId) const return state; } } - return 0; + return nullptr; } int States::rowCount(const QModelIndex &parent) const @@ -94,6 +89,7 @@ void States::addState(State *state) emit dataChanged(index(idx), index(idx), {ValueRole}); }); endInsertRows(); + emit countChanged(); } QHash States::roleNames() const diff --git a/libnymea-app/types/states.h b/libnymea-app/types/states.h index d9898907..34c2d24d 100644 --- a/libnymea-app/types/states.h +++ b/libnymea-app/types/states.h @@ -39,6 +39,8 @@ class States : public QAbstractListModel { Q_OBJECT + Q_PROPERTY(int count READ rowCount NOTIFY countChanged) + public: enum StateRole { ValueRole = Qt::DisplayRole, @@ -49,7 +51,6 @@ public: QList states(); - Q_INVOKABLE int count() const; Q_INVOKABLE State *get(int index) const; Q_INVOKABLE State *getState(const QUuid &stateTypeId) const; @@ -58,6 +59,9 @@ public: void addState(State *state); +signals: + void countChanged(); + protected: QHash roleNames() const; diff --git a/nymea-app/ui/delegates/ParamDelegate.qml b/nymea-app/ui/delegates/ParamDelegate.qml index 4dc710c5..41eeda1f 100644 --- a/nymea-app/ui/delegates/ParamDelegate.qml +++ b/nymea-app/ui/delegates/ParamDelegate.qml @@ -158,6 +158,16 @@ ItemDelegate { from: root.paramType.minValue to: root.paramType.maxValue value: root.param.value + Component.onCompleted: { + if (root.param.value === undefined) { + if (root.paramType.defaultValue !== undefined) { + root.param.value = root.paramType.defaultValue + } else { + root.param.value = root.paramType.minValue + } + } + } + stepSize: { var ret = 1 for (var i = 0; i < decimals; i++) { diff --git a/nymea-app/ui/devicepages/MediaDevicePage.qml b/nymea-app/ui/devicepages/MediaDevicePage.qml index 2d77eca1..86f20a59 100644 --- a/nymea-app/ui/devicepages/MediaDevicePage.qml +++ b/nymea-app/ui/devicepages/MediaDevicePage.qml @@ -115,6 +115,12 @@ DevicePageBase { if (params["id"] === d.pendingVolumeId) { d.pendingVolumeId = -1 print("volume action finished") + if (params.params.deviceError !== "DeviceErrorNoError") { + print("Error setting volume", params.params.deviceError) + d.pendingVolumeValue = -1; + return; + } + if (d.pendingVolumeValue !== volumeState.value) { root.adjustVolume(d.pendingVolumeValue); } else { diff --git a/nymea-app/ui/mainviews/DevicesPageDelegate.qml b/nymea-app/ui/mainviews/DevicesPageDelegate.qml index b8b4c7b1..f3351869 100644 --- a/nymea-app/ui/mainviews/DevicesPageDelegate.qml +++ b/nymea-app/ui/mainviews/DevicesPageDelegate.qml @@ -523,7 +523,7 @@ MainPageTile { property int currentDevice: 0 property Device device: devicesProxy.get(currentDevice) - property DeviceClass deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null + property DeviceClass deviceClass: device ? device.deviceClass : null property var shownSensors: findSensors(deviceClass) property int currentSensor: 0 @@ -611,7 +611,7 @@ MainPageTile { Label { text: sensorsRoot.shownStateType - ? (Math.round(Types.toUiValue(sensorsRoot.device.states.getState(shownStateType.id).value, sensorsRoot.shownStateType.unit) * 100) / 100) + " " + Types.toUiUnit(sensorsRoot.shownStateType.unit) + ? (Math.round(Types.toUiValue(sensorsRoot.device.states.getState(sensorsRoot.shownStateType.id).value, sensorsRoot.shownStateType.unit) * 100) / 100) + " " + Types.toUiUnit(sensorsRoot.shownStateType.unit) : "" // font.pixelSize: app.smallFont Layout.fillWidth: true @@ -621,7 +621,7 @@ MainPageTile { Led { Layout.preferredHeight: app.iconSize * .5 Layout.preferredWidth: height - state: sensorsRoot.shownStateType && sensorsRoot.device.states.getState(sensorsRoot.shownStateType.id).value === true ? "on" : "off" + state: visible && sensorsRoot.device.states.getState(sensorsRoot.shownStateType.id).value === true ? "on" : "off" visible: sensorsRoot.shownStateType && sensorsRoot.shownStateType.type.toLowerCase() === "bool" } }