Documentation of the XML format used to create settings uis
This format is used to create settings.xml files to be read by the default XML QtMvvm::ISettingsSetupLoader. The files are read via that service and mapped to QtMvvm::SettingsElements::Setup.
All the settings files you have can be easily translated via a standard ts/qm file. The following explains how exactly.
The mvvm core module comes with a special make taget, called lupdate
that will automatically run lupdate when your sources change to update the TRANSLATIONS files. To not run this automatically, call qmake with qmake CONFIG+=no_auto_lupdate ...
. In both cases, you can always run make lupdate
to explicitly update the dependencies.
With this step enabled, the only thing left to do is to add the settings xml file to the translation targets so it gets included as a source when running the lupdate target. To do so, simply add it to the SETTINGS_TRANSLATIONS
qmake variable:
This will internally generate a cpp file that is parsed and included in lupdate when running it via the builtin lupdate target.
The possible elements of such a file
The whole settings setup.
The <SettingsConfig>
element must be the root Element of the XML document and is mapped to the QtMvvm::SettingsElements::Setup.
Name | Type | Default | Translated | Description |
---|---|---|---|---|
allowSearch | bool | true | no | Specifies if the user is allowed to search in the settings. |
allowRestore | bool | true | no | Specifies if the user is allowed to restore the factory defaults. |
Can be an arbitrary number of Elements from the following list. However, only one type of element is allowed. If you for example use <Entry>
as first child, all other children must be of the same type as well:
A top level category to organize sections in.
The <Category>
element is mapped to the QtMvvm::SettingsElements::Category.
Name | Type | Default | Translated | Description |
---|---|---|---|---|
title | string | "General Settings" | yes | The categories title. |
icon | url | "qrc:/de/skycoder42/qtmvvm/icons/settings.svg" | no | An icon for the category. |
tooltip | string | Empty | yes | A tooltip to describe what the category is about. |
frontends | descriptor | Empty | no | [Internal] A logical string describing the allowed frontends |
selectors | descriptor | Empty | no | [Internal] A logical string describing the allowed selectors |
Can be an arbitrary number of Elements from the following list. However, only one type of element is allowed. If you for example use <Entry>
as first child, all other children must be of the same type as well:
A bigger section for different entries and groups.
The <Section>
element is mapped to the QtMvvm::SettingsElements::Section.
Name | Type | Default | Translated | Description |
---|---|---|---|---|
title | string | "General" | yes | The sections title. |
icon | url | Empty | no | An icon for the section. |
tooltip | string | Empty | yes | A tooltip to describe what the section is about. |
frontends | descriptor | Empty | no | [Internal] A logical string describing the allowed frontends |
selectors | descriptor | Empty | no | [Internal] A logical string describing the allowed selectors |
Can be an arbitrary number of Elements from the following list. However, only one type of element is allowed. If you for example use <Entry>
as first child, all other children must be of the same type as well:
A logical group of settings entries.
The <Group>
element is mapped to the QtMvvm::SettingsElements::Group. A special property of the group is, that when the title
is not set, the group becomes hidden and instead all entries that are part of the group are simply shown as normal elements in the section, instead of organizing them into subgroups. If the title is empty, the tooltip is ignored, even if set. The descriptors however still apply.
Name | Type | Default | Translated | Description |
---|---|---|---|---|
title | string | Empty | yes | The groups title. |
tooltip | string | Empty | yes | A tooltip to describe what the group is about. |
frontends | descriptor | Empty | no | [Internal] A logical string describing the allowed frontends |
selectors | descriptor | Empty | no | [Internal] A logical string describing the allowed selectors |
Can be an arbitrary number of Elements from the following list. However, only one type of element is allowed. If you for example use <Entry>
as first child, all other children must be of the same type as well:
An entry in the settings to display and edit a value.
The <Entry>
element is mapped to the QtMvvm::SettingsElements::Entry.
Name | Type | Default | Translated | Description |
---|---|---|---|---|
key | string | Empty | no | The QSettings key this entry should handle. |
type | type | "QString" | no | The input view type (typically the actual data type) to show. |
title | string | Empty | yes | A short title/label of the entry to give it a name. |
tooltip | string | Empty | yes | A tooltip with more detailed information about the entry. |
default | variant | Invalid | trdefault | A default value to display in case no value is in the settings yet. |
trdefault | bool | false | no | If set to true, default will be translated. If not set or set to false, it will not be |
frontends | descriptor | Empty | no | [Internal] A logical string describing the allowed frontends |
selectors | descriptor | Empty | no | [Internal] A logical string describing the allowed selectors |
Can be an arbitrary number of Elements from the following list. They can be mixed and in any order
The <SearchKey>
Element is converted to a string added to the QtMvvm::SettingsElements::Entry::searchKeys property. A searchkey can only be a child of an Entry, and all the keys are merged to a list. It's a leaf element and must contain the string that becomes the search key. The contens of the search key will be translated.
The <Property>
Element is an XML description of a generic QVariant property. Each property gets converted to a QString key and a QVariant value that then becomes a property of the parent element. Properties can be children of entries, as well as properties and elements, as long as for the last two their type is object
Name | Type | Default | Translated | Description |
---|---|---|---|---|
key | string | Required | no | The key of the property |
type | type | Required | no | The type of the properties value |
tr | bool | false | no | Specify whether the properties value (content) should be translated. Does not apply to list or object types |
ztr | bool | false | no | Like tr, but does not translate the text, only generate the translation in the ts file |
The content depend on the type
attribute. The following tables shows which type leads to which kind of child element:
Type | Child Element |
---|---|
list | An arbitrary number of Element elements |
object | An arbitrary number of Property elements |
Others | Has text content. The text content is interpreted as a value of the given type |
The <Element>
Element is an XML description of a generic QVariant list value. A property of type list
will have a number of elements as children that are converted to a list of QVariant values. Each element can be of a different type, but typically they all are of the same.
Name | Type | Default | Translated | Description |
---|---|---|---|---|
type | type | Required | no | The type of the list element |
tr | bool | false | no | Specify whether the element value (content) should be translated. Does not apply to list or object types |
ztr | bool | false | no | Like tr, but does not translate the text, only generate the translation in the ts file |
The content depend on the type
attribute. The following tables shows which type leads to which kind of child element:
Type | Child Element |
---|---|
list | An arbitrary number of Element elements |
object | An arbitrary number of Property elements |
Others | Has text content. The text content is interpreted as a value of the given type |
An <Include>
element is a reference to a different file to be included at that point. When the parser reaches an include, it continues to read the included file as if it was a part of the original XML document. Because of that the root element of an included settings file must not be <SettingsConfig>
, but instead the expected primary child of the current parent element. For example, if the include element is a child of a <Section>
, then the root element must be a <Group>
element (Each element that support includes as one child type marked as primary). It is possible to specify an include element in another included document.
Name | Type | Default | Translated | Description |
---|---|---|---|---|
optional | bool | false | no | An optional include. If the file cannot be found it is skipped instead of aborting with an error |
frontends | descriptor | Empty | no | [Internal] A logical string describing the allowed frontends |
selectors | descriptor | Empty | no | [Internal] A logical string describing the allowed selectors |
The content of the include element must be a path to an XML file to be read as include. If the path is relative, it is resolved relative to the directory of the current file (the one that contains the include directive). It is possible to use a path with file selectors. If the file could not be found, the parser will fail, unless the include is marked as optional.
In the above element descriptions a number of types are specified. Most are very basic types, but some need some more explanation to them.
The following table lists all basic types that don't need much explanation:
Type | Description |
---|---|
string | A simple string |
bool | A boolean value. Allowed values are true and false |
url | A standard XML encoded URL |
variant | A string that is read by C++ as string and then stored as QVariant. It thus must be a string convertible to the desired type via QVariant |
The type
type must be a simple string that corresponds to a C++ type name (or special ui type, for entry elements). It defines the actual type of for example the default of the <Entry>
element or the contents of a <Property>
element. Typical values would be:
The type you need depends on what kind of data you want to represent via the XML elements. But remember that all types you use must be convertible from a simple string.
A descripter is a simplified string of a boolean logic statement. It us used for the frontend
and selectors
attributes of various elements. The general idea is that these descriptors serve as "filters". This allows you to create one xml file for all platforms and frontends, by excluding specific elements for specific configurations. See QtMvvm::ISettingsSetupLoader::loadSetup.
The allowed symbols and syntax depend on the attribute the descriptor is used for:
The frontend is the name of the GUI implementation beeing used (For example widgest
for the QWidgets based gui, and quick
for the Qt Quick Controls 2 gui). Must be a string of the following format:
With <frontend>
beeing the name of the frontend the element should be visible for. It's basically a list of allowed frontend as simple string. If the attribute is not specified, the element is visible on all frontends.
The selectors are active file selectors (of the QFileSelector class). By specifiying this attribute you can set selectors that must be active for the element to be visible. This can for example be used to show a specific element on one platform only. Must be a string of the following format:
With <selector>
beeing the names of the selectors that must be set. It's basically a bunch of or condiditions around and conditions. This is a very reduced boolean logic, but it should be enough to create the desired filters. For example, you may want to show an element only on windows or on android when the material design is used. The resulting string would be: windows|android&material
.
The action type is meant as a placeholder for a pressable button. An action edit will simply display a button or similar, and instead of representing a value in the settings, pressing it will trigger QtMvvm::SettingsViewModel::callAction. The Entries key
attribute is passed as the first parameter to the method. The parameters can be specified by adding a <Property>
to the entry with the key args
and the type object
. The property of this object are the elements of the map passed as the second parameter.
The following code block is a sample settings XML file. It is the same that is beeing used in the example application.
The following file is the XSD the parser operates on. You can use it to verify your settings xml files.