Settings
October 10, 2020 ยท View on GitHub
This directory contains the header/sources related to the Settings window. Any code in this folder does not need to be under any namespace, It is because this directory is self sufficient and does not interacts with any outside code.
Useful Information
settings.json
It includes description of all settings, including those not in the Settings Interface.
Each item in the json array represents a configuration item, the structure is as follows:
{
"name": "", // Required, internal key/name of the option
"desc": "", // Optional, prompt text of the option in the setting interface. If not set, it'll be the internal name after replacing splash to space.
"type": "", // Required, data type of the option. Should be the type in the code.
"default": 0, // Optional, default value of the option.
"old": [], // Optional, previous key/name of the option for backward compatibility. It should be a list of all old keys.
"ui": "", // Optional, type of QtWidget to use in the settings interface.
"param": "" // Optional, parameters passed for control creation in the setting interface.
"onApply":"<function>" // Optional, invoked when user click apply button after changing this setting. Good to show warning messages or related information.
"depends":[ // If all dependency satisfied, this setting is enabled, otherwise it is disabled.
{
"name": // Name of key, this setting depends on. (Should be in same page as this setting)
"checks": // a function that return true or false by checking the keys variant.
}
...
]
"immediateApply": "" // a boolean when enabled, this setting is applied as soon as changed by user. It does not require pressing Apply button
}
ValueWrapper.hpp ValueWrapper.cpp
It includes codes for value and widget wrapping.
ValueWidget
The most basic wrapping. Currently it is not used. Use Wrapper<Type> instead.
-
Wrapper<Type>Wrapper for type
Type. It is specialized for typebool.It contains three pure virtual functon.
-
initIt's called when the Settings window is creating widgets for initialization.
-
getsetIt's called when the Setting window is ready to get or set the data.
-
-
XXXWrapperThe subclass of Wrapper for the widget XXX.
-
createXXXWrapperFunction to create the chosen XXXWrapper according to the type (specified in
uiinSetting.json).
genSettings.py
Script to generate SettingsInfo.hpp and SettingsHelper.hpp.
It includes the default value used when you don't specify it in Settings.json.
defs = { 'QString':'""', 'int': '0', 'bool': 'false', 'QRect': 'QRect()', 'QByteArray': 'QByteArray()' }
SettingsInfo.hpp
It is designed for PreferencesPageTemplate.
SettingsHelper.hpp
It includes the easy functions to set and get options.
Include <generated/SettingsHelper.hpp> to use them.
-
set:
SettingsHelper::setXXX -
get:
SettingsHelper::getXXXorSettingsHelper::isXXXaccording to type.
Current supported types
The first ui in the list is the default ui.
-
boolDefault value:
falseQCheckBox
-
QStringDefault value:
""-
QLineEdit -
QPlainTextEdit -
QComboBox-
param(
QStringList): The pre-defined choices. -
e.g.
"param": "QStringList {\"item1\", \"item2\"}
-
-
PathItemWidget for file choosing.
- param(
int): The index of title and filter strings in code.
- param(
-
ShortcutItemWidget for shortcut choosing.
-
-
intDefault value:
0param(
QVariantList): The range.e.g.
"param": "QVariantList {1, 100}"-
QSpinBox -
QScrollBarHorizontal only.
-
QSliderHorizontal only.
-
-
QFontDefault value: not defined yet
-
FontItemWidget for font choosing.
-
-
QVariantList-
StringListsItemWidget for several
QStringLists.Suppose the number of of
QStrings in a singleQStringListis<col>.value:
QVariantList, each the element ofvalueis aQStringListwith<col>QStrings.param: The param describes the header and
<col>. It's aQVariantListwith<col>elements, and each of the elements is aQStringListwith twoQStrings, the first one is the title and the second one is the tooltip.
-
Adding Settings
Refer to the existing code for more details.
Adding a new type or a new widget
- Add
XXXWrapperinValueWrapper(XXX represent the widget name) - Add
createXXXWrapperinValueWrapper(XXX represent the type name) - Add checking code for this type in
PreferebcesPageTemplate - Optionally, add fallback default valuein
genSettings.py
Adding a new setting
- Add a new option in settings.json with above mentioned syntax.
Adding a new page or a new option
- Add
addPage(path, options)in the constructor of preference window.pathis Path on Left of Preference window, andoptionsis set of internal names/keys. - Add a new Settings name to the existing
addPage()options
Using a new setting
Use the static members from SettingsHelper namespace. This is auto-generated from settings.json.