From fb1a2037e377fe35833d5506dc1824f4d5660419 Mon Sep 17 00:00:00 2001 From: Alexander Ivash Date: Fri, 22 Jun 2018 03:00:19 +0300 Subject: [PATCH] move specifying custom properties for preferences dialog from C++ to QML (per Dante's request) --- .../resources/qml/hifi/tablet/ControllerSettings.qml | 6 ++++++ .../tablet/tabletWindows/TabletPreferencesDialog.qml | 4 +++- .../hifi/tablet/tabletWindows/preferences/Section.qml | 3 ++- interface/src/ui/PreferencesDialog.cpp | 9 --------- libraries/shared/src/Preferences.h | 11 ----------- 5 files changed, 11 insertions(+), 22 deletions(-) diff --git a/interface/resources/qml/hifi/tablet/ControllerSettings.qml b/interface/resources/qml/hifi/tablet/ControllerSettings.qml index 92b750fa7a..135c1379e2 100644 --- a/interface/resources/qml/hifi/tablet/ControllerSettings.qml +++ b/interface/resources/qml/hifi/tablet/ControllerSettings.qml @@ -300,6 +300,12 @@ Item { id: controllerPrefereneces objectName: "TabletControllerPreferences" showCategories: ["VR Movement", "Game Controller", "Sixense Controllers", "Perception Neuron", "Leap Motion"] + categoryProperties: { + "VR Movement" : { + "User real-world height (meters)" : { "anchors.right" : "undefined" }, + "RESET SENSORS" : { "width" : "180", "anchors.left" : "undefined" } + } + } } } } diff --git a/interface/resources/qml/hifi/tablet/tabletWindows/TabletPreferencesDialog.qml b/interface/resources/qml/hifi/tablet/tabletWindows/TabletPreferencesDialog.qml index 646a0d2c77..05f45dc61e 100644 --- a/interface/resources/qml/hifi/tablet/tabletWindows/TabletPreferencesDialog.qml +++ b/interface/resources/qml/hifi/tablet/tabletWindows/TabletPreferencesDialog.qml @@ -24,6 +24,7 @@ Item { HifiConstants { id: hifi } property var sections: [] property var showCategories: [] + property var categoryProperties: ({}) property bool keyboardEnabled: false property bool keyboardRaised: false @@ -100,7 +101,8 @@ Item { // NOTE: the sort order of items in the showCategories array is the same order in the dialog. for (i = 0; i < showCategories.length; i++) { if (categoryMap[showCategories[i]]) { - sections.push(sectionBuilder.createObject(prefControls, {name: showCategories[i]})); + var properties = categoryProperties.hasOwnProperty(showCategories[i]) ? categoryProperties[showCategories[i]] : {}; + sections.push(sectionBuilder.createObject(prefControls, {name: showCategories[i], sectionProperties: properties})); } } diff --git a/interface/resources/qml/hifi/tablet/tabletWindows/preferences/Section.qml b/interface/resources/qml/hifi/tablet/tabletWindows/preferences/Section.qml index cf32b21c67..833175f311 100644 --- a/interface/resources/qml/hifi/tablet/tabletWindows/preferences/Section.qml +++ b/interface/resources/qml/hifi/tablet/tabletWindows/preferences/Section.qml @@ -24,6 +24,7 @@ Preference { property bool isLast: false property string name: "Header" property real spacing: 8 + property var sectionProperties: ({}) default property alias preferences: contentContainer.children HifiConstants { id: hifi } @@ -165,7 +166,7 @@ Preference { preferences.push(builder.createObject(contentContainer, { preference: preference, isFirstCheckBox: (checkBoxCount === 1) , z: zpos})); var preferenceObject = preferences[preferences.length - 1]; - var props = preference.properties; + var props = sectionProperties.hasOwnProperty(preference.name) ? sectionProperties[preference.name] : {}; for(var prop in props) { var value = props[prop]; diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 4943a4be65..d0fe92ea00 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -298,21 +298,12 @@ void setupPreferences() { preference->setMax(2.2f); preference->setDecimals(3); preference->setStep(0.001f); - - QVariantMap properties; - properties["anchors.right"] = "undefined"; - preference->setProperties(properties); - preferences->addPreference(preference); } { auto preference = new ButtonPreference(MOVEMENT, "RESET SENSORS", [] { qApp->resetSensors(); }); - QVariantMap properties; - properties["width"] = "180"; - properties["anchors.left"] = "undefined"; - preference->setProperties(properties); preferences->addPreference(preference); } diff --git a/libraries/shared/src/Preferences.h b/libraries/shared/src/Preferences.h index 5352d0e726..27bcf7a71b 100644 --- a/libraries/shared/src/Preferences.h +++ b/libraries/shared/src/Preferences.h @@ -44,7 +44,6 @@ class Preference : public QObject { Q_PROPERTY(QString name READ getName CONSTANT) Q_PROPERTY(Type type READ getType CONSTANT) Q_PROPERTY(bool enabled READ isEnabled NOTIFY enabledChanged) - Q_PROPERTY(QVariantMap properties READ getProperties); Q_ENUMS(Type) public: @@ -82,15 +81,6 @@ public: } void setEnabler(BoolPreference* enabler, bool inverse = false); - - const QVariantMap& getProperties() { - return _properties; - } - - void setProperties(const QVariantMap& properties) { - _properties = properties; - } - virtual Type getType() { return Invalid; }; Q_INVOKABLE virtual void load() {}; @@ -110,7 +100,6 @@ protected: const QString _name; bool _enabled { true }; bool _enablerInverted { false }; - QVariantMap _properties; }; class ButtonPreference : public Preference {