From 5a4ada75282caf38e0f500b71042685b65963f58 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sun, 1 Dec 2019 23:46:39 +0100 Subject: [PATCH] Fix browserItemActionTypes with nymea:core on Qt >= 5.10 --- libnymea-app-core/devicemanager.cpp | 2 +- libnymea-app-core/models/devicemodel.h | 2 +- libnymea-common/types/actiontype.cpp | 4 ++-- libnymea-common/types/actiontype.h | 8 ++++---- libnymea-common/types/actiontypes.cpp | 2 +- libnymea-common/types/actiontypes.h | 4 ++-- libnymea-common/types/eventtype.cpp | 4 ++-- libnymea-common/types/eventtype.h | 10 +++++----- libnymea-common/types/eventtypes.cpp | 2 +- libnymea-common/types/eventtypes.h | 2 +- libnymea-common/types/statetype.cpp | 4 ++-- libnymea-common/types/statetype.h | 8 ++++---- libnymea-common/types/statetypes.cpp | 2 +- libnymea-common/types/statetypes.h | 2 +- nymea-app/ui/components/BrowserContextMenu.qml | 6 +++++- nymea-app/ui/delegates/BrowserItemDelegate.qml | 8 +++++++- 16 files changed, 40 insertions(+), 30 deletions(-) diff --git a/libnymea-app-core/devicemanager.cpp b/libnymea-app-core/devicemanager.cpp index 289fde2b..a24230d1 100644 --- a/libnymea-app-core/devicemanager.cpp +++ b/libnymea-app-core/devicemanager.cpp @@ -188,7 +188,7 @@ void DeviceManager::getVendorsResponse(const QVariantMap ¶ms) void DeviceManager::getSupportedDevicesResponse(const QVariantMap ¶ms) { -// qDebug() << "DeviceClass received:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson(QJsonDocument::Indented)); + qDebug() << "DeviceClass received:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson(QJsonDocument::Indented)); if (params.value("params").toMap().keys().contains("deviceClasses")) { QVariantList deviceClassList = params.value("params").toMap().value("deviceClasses").toList(); foreach (QVariant deviceClassVariant, deviceClassList) { diff --git a/libnymea-app-core/models/devicemodel.h b/libnymea-app-core/models/devicemodel.h index e7029f5a..828c7b0a 100644 --- a/libnymea-app-core/models/devicemodel.h +++ b/libnymea-app-core/models/devicemodel.h @@ -71,7 +71,7 @@ private: bool m_showActions = true; bool m_showEvents = true; - QList m_list; + QList m_list; }; #endif // DEVICEMODEL_H diff --git a/libnymea-common/types/actiontype.cpp b/libnymea-common/types/actiontype.cpp index ca1229d8..a65298ad 100644 --- a/libnymea-common/types/actiontype.cpp +++ b/libnymea-common/types/actiontype.cpp @@ -27,12 +27,12 @@ ActionType::ActionType(QObject *parent) : { } -QString ActionType::id() const +QUuid ActionType::id() const { return m_id; } -void ActionType::setId(const QString &id) +void ActionType::setId(const QUuid &id) { m_id = id; } diff --git a/libnymea-common/types/actiontype.h b/libnymea-common/types/actiontype.h index 9db3fc51..5894d2d5 100644 --- a/libnymea-common/types/actiontype.h +++ b/libnymea-common/types/actiontype.h @@ -31,7 +31,7 @@ class ActionType : public QObject { Q_OBJECT - Q_PROPERTY(QString id READ id CONSTANT) + Q_PROPERTY(QUuid id READ id CONSTANT) Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(QString displayName READ displayName CONSTANT) Q_PROPERTY(int index READ index CONSTANT) @@ -40,8 +40,8 @@ class ActionType : public QObject public: explicit ActionType(QObject *parent = nullptr); - QString id() const; - void setId(const QString &id); + QUuid id() const; + void setId(const QUuid &id); QString name() const; void setName(const QString &name); @@ -56,7 +56,7 @@ public: void setParamTypes(ParamTypes *paramTypes); private: - QString m_id; + QUuid m_id; QString m_name; QString m_displayName; int m_index; diff --git a/libnymea-common/types/actiontypes.cpp b/libnymea-common/types/actiontypes.cpp index ecac57b5..3898c6fc 100644 --- a/libnymea-common/types/actiontypes.cpp +++ b/libnymea-common/types/actiontypes.cpp @@ -38,7 +38,7 @@ ActionType *ActionTypes::get(int index) const return m_actionTypes.at(index); } -ActionType *ActionTypes::getActionType(const QString &actionTypeId) const +ActionType *ActionTypes::getActionType(const QUuid &actionTypeId) const { foreach (ActionType *actionType, m_actionTypes) { if (actionType->id() == actionTypeId) { diff --git a/libnymea-common/types/actiontypes.h b/libnymea-common/types/actiontypes.h index 081ab1bd..a63d1008 100644 --- a/libnymea-common/types/actiontypes.h +++ b/libnymea-common/types/actiontypes.h @@ -39,12 +39,12 @@ public: RoleDisplayName }; - ActionTypes(QObject *parent = 0); + ActionTypes(QObject *parent = nullptr); QList actionTypes(); Q_INVOKABLE ActionType *get(int index) const; - Q_INVOKABLE ActionType *getActionType(const QString &actionTypeId) const; + Q_INVOKABLE ActionType *getActionType(const QUuid &actionTypeId) const; int rowCount(const QModelIndex & parent = QModelIndex()) const; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; diff --git a/libnymea-common/types/eventtype.cpp b/libnymea-common/types/eventtype.cpp index 11e6241a..eefd30fa 100644 --- a/libnymea-common/types/eventtype.cpp +++ b/libnymea-common/types/eventtype.cpp @@ -27,12 +27,12 @@ EventType::EventType(QObject *parent) : { } -QString EventType::id() const +QUuid EventType::id() const { return m_id; } -void EventType::setId(const QString &id) +void EventType::setId(const QUuid &id) { m_id = id; } diff --git a/libnymea-common/types/eventtype.h b/libnymea-common/types/eventtype.h index 498e0ffa..1cee63e0 100644 --- a/libnymea-common/types/eventtype.h +++ b/libnymea-common/types/eventtype.h @@ -31,17 +31,17 @@ class EventType : public QObject { Q_OBJECT - Q_PROPERTY(QString id READ id CONSTANT) + Q_PROPERTY(QUuid id READ id CONSTANT) Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(QString displayName READ displayName CONSTANT) Q_PROPERTY(int index READ index CONSTANT) Q_PROPERTY(ParamTypes* paramTypes READ paramTypes CONSTANT) public: - explicit EventType(QObject *parent = 0); + explicit EventType(QObject *parent = nullptr); - QString id() const; - void setId(const QString &id); + QUuid id() const; + void setId(const QUuid &id); QString name() const; void setName(const QString &name); @@ -56,7 +56,7 @@ public: void setParamTypes(ParamTypes *paramTypes); private: - QString m_id; + QUuid m_id; QString m_name; QString m_displayName; int m_index; diff --git a/libnymea-common/types/eventtypes.cpp b/libnymea-common/types/eventtypes.cpp index 368d6e04..b3e316e8 100644 --- a/libnymea-common/types/eventtypes.cpp +++ b/libnymea-common/types/eventtypes.cpp @@ -39,7 +39,7 @@ EventType *EventTypes::get(int index) const return m_eventTypes.at(index); } -EventType *EventTypes::getEventType(const QString &eventTypeId) const +EventType *EventTypes::getEventType(const QUuid &eventTypeId) const { foreach (EventType *eventType, m_eventTypes) { if (eventType->id() == eventTypeId) { diff --git a/libnymea-common/types/eventtypes.h b/libnymea-common/types/eventtypes.h index 4fadf2c1..042dfbec 100644 --- a/libnymea-common/types/eventtypes.h +++ b/libnymea-common/types/eventtypes.h @@ -45,7 +45,7 @@ public: QList eventTypes(); Q_INVOKABLE EventType *get(int index) const; - Q_INVOKABLE EventType *getEventType(const QString &eventTypeId) const; + Q_INVOKABLE EventType *getEventType(const QUuid &eventTypeId) const; int rowCount(const QModelIndex & parent = QModelIndex()) const; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; diff --git a/libnymea-common/types/statetype.cpp b/libnymea-common/types/statetype.cpp index 1bbb98fa..7374c8a3 100644 --- a/libnymea-common/types/statetype.cpp +++ b/libnymea-common/types/statetype.cpp @@ -27,12 +27,12 @@ StateType::StateType(QObject *parent) : { } -QString StateType::id() const +QUuid StateType::id() const { return m_id; } -void StateType::setId(const QString &id) +void StateType::setId(const QUuid &id) { m_id = id; } diff --git a/libnymea-common/types/statetype.h b/libnymea-common/types/statetype.h index 5a1e7114..9c2ebdd4 100644 --- a/libnymea-common/types/statetype.h +++ b/libnymea-common/types/statetype.h @@ -32,7 +32,7 @@ class StateType : public QObject { Q_OBJECT - Q_PROPERTY(QString id READ id CONSTANT) + Q_PROPERTY(QUuid id READ id CONSTANT) Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(QString displayName READ displayName CONSTANT) Q_PROPERTY(QString type READ type CONSTANT) @@ -47,8 +47,8 @@ class StateType : public QObject public: StateType(QObject *parent = nullptr); - QString id() const; - void setId(const QString &id); + QUuid id() const; + void setId(const QUuid &id); QString name() const; void setName(const QString &name); @@ -82,7 +82,7 @@ public: void setMaxValue(const QVariant &maxValue); private: - QString m_id; + QUuid m_id; QString m_name; QString m_displayName; QString m_type; diff --git a/libnymea-common/types/statetypes.cpp b/libnymea-common/types/statetypes.cpp index 7bf0c274..10bad681 100644 --- a/libnymea-common/types/statetypes.cpp +++ b/libnymea-common/types/statetypes.cpp @@ -42,7 +42,7 @@ StateType *StateTypes::get(int index) const return m_stateTypes.at(index); } -StateType *StateTypes::getStateType(const QString &stateTypeId) const +StateType *StateTypes::getStateType(const QUuid &stateTypeId) const { foreach (StateType *stateType, m_stateTypes) { if (stateType->id() == stateTypeId) { diff --git a/libnymea-common/types/statetypes.h b/libnymea-common/types/statetypes.h index f77aa8ed..4a78bcb8 100644 --- a/libnymea-common/types/statetypes.h +++ b/libnymea-common/types/statetypes.h @@ -49,7 +49,7 @@ public: QList stateTypes(); Q_INVOKABLE StateType *get(int index) const; - Q_INVOKABLE StateType *getStateType(const QString &stateTypeId) const; + Q_INVOKABLE StateType *getStateType(const QUuid &stateTypeId) const; int rowCount(const QModelIndex & parent = QModelIndex()) const; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; diff --git a/nymea-app/ui/components/BrowserContextMenu.qml b/nymea-app/ui/components/BrowserContextMenu.qml index 96db7d8a..72aaf115 100644 --- a/nymea-app/ui/components/BrowserContextMenu.qml +++ b/nymea-app/ui/components/BrowserContextMenu.qml @@ -6,6 +6,8 @@ import "../delegates" MeaDialog { id: root + x: (parent.width - width) / 2 + y: (parent.height - height / 2) property Device device property string itemId @@ -18,7 +20,7 @@ MeaDialog { StackView { id: stackView Layout.fillWidth: true - Layout.minimumHeight: actionListView.implicitHeight + Layout.preferredHeight: actionListView.implicitHeight property var actionTypeId @@ -64,9 +66,11 @@ MeaDialog { } RowLayout { + id: buttonRow Layout.fillWidth: true Button { + id: cancelButton text: qsTr("Cancel") onClicked: root.reject() } diff --git a/nymea-app/ui/delegates/BrowserItemDelegate.qml b/nymea-app/ui/delegates/BrowserItemDelegate.qml index 1df27724..d392aa51 100644 --- a/nymea-app/ui/delegates/BrowserItemDelegate.qml +++ b/nymea-app/ui/delegates/BrowserItemDelegate.qml @@ -31,7 +31,13 @@ NymeaListItemDelegate { } var actionDialogComponent = Qt.createComponent(Qt.resolvedUrl("../components/BrowserContextMenu.qml")); - var popup = actionDialogComponent.createObject(root, {device: root.device, title: model.displayName, itemId: model.id, actionTypeIds: model.actionTypeIds}); + var popup = actionDialogComponent.createObject(root.parent, + { + device: root.device, + title: model.displayName, + itemId: model.id, + actionTypeIds: model.actionTypeIds + }); popup.activated.connect(function(actionTypeId, params) { root.contextMenuActionTriggered(actionTypeId, params) })