Browse Source

fixed settings code and added settings core sample

pull/2/head
Skycoder42 7 years ago
parent
commit
46c4d81dfa
  1. 3
      examples/mvvmcore/SampleCore/SampleCore.pro
  2. 5
      examples/mvvmcore/SampleCore/sample_core.qrc
  3. 2
      examples/mvvmcore/SampleCore/samplecoreapp.cpp
  4. 89
      examples/mvvmcore/SampleCore/settings.xml
  5. 2
      src/mvvmquick/DoubleSpinBox.qml
  6. 30
      src/mvvmquick/ListEdit.qml
  7. 2
      src/mvvmquick/SpinBox.qml
  8. 108
      src/mvvmsettingscore/settings.xsd
  9. 4
      src/mvvmsettingscore/settingssetup.h
  10. 7
      src/mvvmsettingscore/settingssetuploader.cpp
  11. 3
      src/mvvmsettingscore/settingsviewmodel.cpp
  12. 2
      src/mvvmsettingscore/settingsviewmodel.h
  13. 2
      src/mvvmwidgets/selectcombobox.cpp
  14. 59
      tests/auto/settings.xml

3
examples/mvvmcore/SampleCore/SampleCore.pro

@ -24,3 +24,6 @@ SOURCES += \
target.path = $$[QT_INSTALL_EXAMPLES]/mvvmcore/$$TARGET
INSTALLS += target
RESOURCES += \
sample_core.qrc

5
examples/mvvmcore/SampleCore/sample_core.qrc

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/etc">
<file>settings.xml</file>
</qresource>
</RCC>

2
examples/mvvmcore/SampleCore/samplecoreapp.cpp

@ -13,6 +13,8 @@ SampleCoreApp::SampleCoreApp(QObject *parent) :
void SampleCoreApp::performRegistrations()
{
Q_INIT_RESOURCE(sample_core);
QtMvvm::registerInterfaceConverter<IEventService>();
}

89
examples/mvvmcore/SampleCore/settings.xml

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<SettingsConfig allowSearch="true" allowRestore="true">
<!--Include optional="true">/absolute/include/path.xml</Include-->
<Category>
<Section>
<Group>
<Entry key="prop1"
type="bool"
title="&amp;Check me"
tooltip="I am a checkbox!"
default="false">
<SearchKey>property</SearchKey>
<SearchKey>bool</SearchKey>
<Property key="text" type="string">Please do check me</Property>
</Entry>
<Entry key="prop2"
type="string"
title="Enter a &amp;name"/>
</Group>
<Group title="Sub-Group" tooltip="This is a tooltip">
<Entry key="prop3"
type="action"
title="Open &amp;system settings">
<Property key="name" type="string">baum</Property>
<Property key="value" type="double">4.2</Property>
</Entry>
<Entry key="prop4"
type="selection"
title="Select a &amp;mode"
default="Variant B">
<Property key="listElements" type="list">
<Element type="string">Variant A</Element>
<Element type="string">Variant B</Element>
<Element type="string">Variant C</Element>
</Property>
</Entry>
</Group>
</Section>
<Section title="Another Section" icon="" tooltip="This is another section">
<Entry key="prop5"
type="double"
title="Enter a &amp;value"
tooltip="The value must be between 0 and 1">
<Property key="minimum" type="double">0.0</Property>
<Property key="maximum" type="double">1.0</Property>
</Entry>
<Entry key="prop6"
type="selection"
title="Select a &amp;mode"
default="10">
<Property key="listElements" type="list">
<Element type="object">
<Property key="name" type="string">Value A</Property>
<Property key="value" type="int">1</property>
</Element>
<Element type="object">
<Property key="name" type="string">Value B</Property>
<Property key="value" type="int">2</property>
</Element>
<Element type="object">
<Property key="name" type="string">Value C</Property>
<Property key="value" type="int">4</property>
</Element>
<Element type="object">
<Property key="name" type="string">Value A+B</Property>
<Property key="value" type="int">3</property>
</Element>
<Element type="object">
<Property key="name" type="string">Value A+C</Property>
<Property key="value" type="int">5</property>
</Element>
<Element type="object">
<Property key="name" type="string">Value B+C</Property>
<Property key="value" type="int">6</property>
</Element>
<Element type="object">
<Property key="name" type="string">Value A+B+C</Property>
<Property key="value" type="int">7</property>
</Element>
</Property>
</Entry>
</Section>
</Category>
<Category title="Another main category">
<Entry key="prop7"
type="int"
title="Enter a &amp;number"/>
</Category>
</SettingsConfig>

2
src/mvvmquick/DoubleSpinBox.qml

@ -4,6 +4,8 @@ import QtQuick.Controls 2.3
SpinBox {
id: _edit
property alias inputValue: _edit.dValue
property alias minimum: _edit.dFrom
property alias maximum: _edit.dTo
editable: true
//double spinbox code

30
src/mvvmquick/ListEdit.qml

@ -4,16 +4,32 @@ import QtQuick.Controls 2.3
ComboBox {
id: _edit
property alias inputValue: _edit.currentValue
property var currentValue: getCurrentValue()
property alias listElements: _edit.model
property alias currentValue: _valueHelper.value
textRole: "name"
property var _valueHelper: { return {}; }
function getCurrentValue() {
var value = _edit.model[_edit.currentIndex].value;
if(typeof value !== "undefined")
return value;
else
return _edit.displayText;
Component.onCompleted: {
Object.defineProperty(
_valueHelper,
"value",
{
get: function () {
var value = _edit.model[_edit.currentIndex].value;
if(typeof value !== "undefined")
return value;
else
return _edit.displayText;
},
set: function (value) {
var index = find(value);
if(index !== -1)
currentIndex = index;
else if(editable)
editText = value;
}
}
);
}
}

2
src/mvvmquick/SpinBox.qml

@ -4,5 +4,7 @@ import QtQuick.Controls 2.3
SpinBox {
id: _edit
property alias inputValue: _edit.value
property alias minimum: _edit.from
property alias maximum: _edit.to
editable: true
}

108
src/mvvmsettingscore/settings.xsd

@ -0,0 +1,108 @@
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="SettingsConfig" type="SettingsConfigType"/>
<xs:complexType name="IncludeType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:boolean" name="optional" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="PropertyType" mixed="true">
<xs:all>
<xs:element type="PropertyType" name="Property" maxOccurs="unbounded" minOccurs="0"/>
<xs:element type="ElementType" name="Element" maxOccurs="unbounded" minOccurs="0"/>
</xs:all>
<xs:attribute type="xs:string" name="key" use="required"/>
<xs:attribute type="xs:string" name="type" use="required"/>
</xs:complexType>
<xs:complexType name="ElementType" mixed="true">
<xs:all>
<xs:element type="ElementType" name="Element" maxOccurs="unbounded" minOccurs="0"/>
<xs:element type="PropertyType" name="Property" maxOccurs="unbounded" minOccurs="0"/>
</xs:all>
<xs:attribute type="xs:string" name="type" use="required"/>
</xs:complexType>
<xs:complexType name="EntryType" mixed="true">
<xs:all>
<xs:element type="xs:string" name="SearchKey" maxOccurs="unbounded" minOccurs="0"/>
<xs:element type="PropertyType" name="Property" maxOccurs="unbounded" minOccurs="0"/>
</xs:all>
<xs:attribute type="xs:string" name="key" use="required"/>
<xs:attribute type="xs:string" name="type" use="required"/>
<xs:attribute type="xs:string" name="title" use="required"/>
<xs:attribute type="xs:string" name="tooltip" use="optional"/>
<xs:attribute type="xs:string" name="default" use="optional"/>
<xs:attribute type="xs:string" name="frontends" use="optional"/>
<xs:attribute type="xs:string" name="selectors" use="optional"/>
</xs:complexType>
<xs:complexType name="GroupType" mixed="true">
<xs:all>
<xs:element type="IncludeType" name="Include" maxOccurs="unbounded" minOccurs="0"/>
<xs:element type="EntryType" name="Entry" maxOccurs="unbounded" minOccurs="0"/>
</xs:all>
<xs:attribute type="xs:string" name="title" use="required"/>
<xs:attribute type="xs:string" name="tooltip" use="optional"/>
<xs:attribute type="xs:string" name="frontends" use="optional"/>
<xs:attribute type="xs:string" name="selectors" use="optional"/>
</xs:complexType>
<xs:complexType name="SectionType" mixed="true">
<xs:choice>
<xs:choice maxOccurs="unbounded">
<xs:element type="IncludeType" name="Include" maxOccurs="unbounded" minOccurs="0"/>
<xs:element type="GroupType" name="Group" maxOccurs="unbounded" minOccurs="0"/>
</xs:choice>
<xs:choice maxOccurs="unbounded">
<xs:element type="IncludeType" name="Include" maxOccurs="unbounded" minOccurs="0"/>
<xs:element type="EntryType" name="Entry" maxOccurs="unbounded" minOccurs="0"/>
</xs:choice>
</xs:choice>
<xs:attribute type="xs:string" name="title" use="required"/>
<xs:attribute type="xs:string" name="icon" use="optional"/>
<xs:attribute type="xs:string" name="tooltip" use="optional"/>
<xs:attribute type="xs:string" name="frontends" use="optional"/>
<xs:attribute type="xs:string" name="selectors" use="optional"/>
</xs:complexType>
<xs:complexType name="CategoryType" mixed="true">
<xs:choice>
<xs:choice maxOccurs="unbounded">
<xs:element type="IncludeType" name="Include" maxOccurs="unbounded" minOccurs="0"/>
<xs:element type="SectionType" name="Section" maxOccurs="unbounded" minOccurs="0"/>
</xs:choice>
<xs:choice maxOccurs="unbounded">
<xs:element type="IncludeType" name="Include" maxOccurs="unbounded" minOccurs="0"/>
<xs:element type="GroupType" name="Group" maxOccurs="unbounded" minOccurs="0"/>
</xs:choice>
<xs:choice maxOccurs="unbounded">
<xs:element type="IncludeType" name="Include" maxOccurs="unbounded" minOccurs="0"/>
<xs:element type="EntryType" name="Entry" maxOccurs="unbounded" minOccurs="0"/>
</xs:choice>
</xs:choice>
<xs:attribute type="xs:string" name="title" use="required"/>
<xs:attribute type="xs:string" name="icon" use="optional"/>
<xs:attribute type="xs:string" name="tooltip" use="optional"/>
<xs:attribute type="xs:string" name="frontends" use="optional"/>
<xs:attribute type="xs:string" name="selectors" use="optional"/>
</xs:complexType>
<xs:complexType name="SettingsConfigType">
<xs:choice>
<xs:choice maxOccurs="unbounded">
<xs:element type="IncludeType" name="Include" maxOccurs="unbounded" minOccurs="0"/>
<xs:element type="CategoryType" name="Category" maxOccurs="unbounded" minOccurs="0"/>
</xs:choice>
<xs:choice maxOccurs="unbounded">
<xs:element type="IncludeType" name="Include" maxOccurs="unbounded" minOccurs="0"/>
<xs:element type="SectionType" name="Section" maxOccurs="unbounded" minOccurs="0"/>
</xs:choice>
<xs:choice maxOccurs="unbounded">
<xs:element type="IncludeType" name="Include" maxOccurs="unbounded" minOccurs="0"/>
<xs:element type="GroupType" name="Group" maxOccurs="unbounded" minOccurs="0"/>
</xs:choice>
<xs:choice maxOccurs="unbounded">
<xs:element type="IncludeType" name="Include" maxOccurs="unbounded" minOccurs="0"/>
<xs:element type="EntryType" name="Entry" maxOccurs="unbounded" minOccurs="0"/>
</xs:choice>
</xs:choice>
<xs:attribute type="xs:boolean" name="allowSearch" use="optional"/>
<xs:attribute type="xs:boolean" name="allowRestore" use="optional"/>
</xs:complexType>
</xs:schema>

4
src/mvvmsettingscore/settingssetup.h

@ -65,8 +65,8 @@ struct SettingsCategory
struct SettingsSetup
{
bool allowSearch = false;
bool allowRestore = false;
bool allowSearch = true;
bool allowRestore = true;
QList<SettingsCategory> categories;
};

7
src/mvvmsettingscore/settingssetuploader.cpp

@ -39,8 +39,11 @@ SettingsSetup SettingsSetupLoader::loadSetup(const QString &filePath, const QStr
if(!reader.readNextStartElement() || reader.name() != QStringLiteral("SettingsConfig"))
throwElement(reader, "SettingsConfig");
setup.allowSearch = reader.boolValue("allowSearch");
setup.allowRestore = reader.boolValue("allowRestore");
if(reader.hasValue("allowSearch"))
setup.allowSearch = reader.boolValue("allowSearch");
if(reader.hasValue("allowRestore"))
setup.allowRestore = reader.boolValue("allowRestore");
if(reader.readNextStartElement()) {
if(reader.name() == QStringLiteral("Category") ||

3
src/mvvmsettingscore/settingsviewmodel.cpp

@ -77,8 +77,9 @@ void SettingsViewModel::resetValue(const QString &key)
d->settings->remove(key);
}
void SettingsViewModel::callAction(const QString &entryId)
void SettingsViewModel::callAction(const QString &entryId, const QVariantMap &parameters)
{
Q_UNUSED(parameters)
logWarning() << "Unknown action requested with entry id:" << entryId;
}

2
src/mvvmsettingscore/settingsviewmodel.h

@ -45,7 +45,7 @@ public:
Q_INVOKABLE virtual void resetValue(const QString &key);
public Q_SLOTS:
virtual void callAction(const QString &entryId);
virtual void callAction(const QString &entryId, const QVariantMap &parameters);
void setSettingsSetupLoader(QtMvvm::ISettingsSetupLoader* settingsSetupLoader);

2
src/mvvmwidgets/selectcombobox.cpp

@ -41,7 +41,7 @@ void SelectComboBox::setCurrentValue(const QVariant &data)
auto index = findData(data);
if(index != -1)
setCurrentIndex(index);
else
else if(isEditable())
setCurrentText(data.toString());
}

59
tests/auto/settings.xml

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<SettingsConfig allowSearch="true" allowRestore="true">
<Include optional="true">/absolute/include/path.xml</Include>
<Include optional="false">../relative/include/path.xml</Include>
<Category title="title"
icon="file:///icon/path.svg"
tooltip="useful tip"
frontends="widgets|quick"
selectors="ios|android&amp;xhdpi">
<Include optional="true">/absolute/include/path.xml</Include>
<Include>../relative/include/path.xml</Include>
<Section title="another title"
icon="https://example.org/icon/path.svg"
tooltip="another tip"
frontends="widgets"
selectors="android&amp;xhdpi">
<Include optional="true">/absolute/include/path.xml</Include>
<Include>../relative/include/path.xml</Include>
<Group title="group title"
tooltip="hovering tool tip"
frontends="quick"
selectors="ios|android">
<Include optional="true">/absolute/include/path.xml</Include>
<Include>../relative/include/path.xml</Include>
<Entry key="property"
type="bool"
title="&amp;Check me"
tooltip="I am a checkbox!"
default="false"
frontends="widgets|quick"
selectors="ios|android&amp;xhdpi">
<SearchKey>prop</SearchKey>
<SearchKey>attrib</SearchKey>
<SearchKey>sample</SearchKey>
<Property key="text" type="string">Please do check me</Property>
<Property key="size" type="object">
<Property key="width" type="int">42</Property>
<Property key="height" type="int">42</Property>
</Property>
<Property key="things" type="list">
<Element type="int">42</Element>
<Element type="list">
<Element type="string">elem 1</Element>
<Element type="string">elem 2</Element>
</Element>
<Element type="object">
<Property key="name" type="string">baum</Property>
<Property key="number" type="int">42</Property>
</Element>
</Property>
</Entry>
<Entry key="req" type="req" title="req" />
</Group>
<Group/>
</Section>
<Section/>
</Category>
<Category/>
</SettingsConfig>
Loading…
Cancel
Save