move specifying custom properties for preferences dialog from C++ to QML (per Dante's request)

This commit is contained in:
Alexander Ivash 2018-06-22 03:00:19 +03:00
parent 68041dc93c
commit fb1a2037e3
5 changed files with 11 additions and 22 deletions

View file

@ -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" }
}
}
}
}
}

View file

@ -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}));
}
}

View file

@ -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];

View file

@ -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);
}

View file

@ -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 {