When the user selects a setting in a tool option widget, a dialog, a filter or for a brush preset, we currently either manually fill a configuration object or can use KisDialogStateSaver. Both approaches have problems.
We currently have the following classes:
- KisDialogStateSaver -- tries to identify all widgets with names that can contain values and creates a kconfiggroup with name-value pairs.
- KisSerializableConfiguration -- provides a base interface for to/fromXml
- KisPropertiesConfiguration : KisSerializableConfiguration -- a key-value map that is used by Filters, Operations, PaintOpSettings and KisWorkSpaceResource
Other approaches
- Adobe uses a xml based file format that defines both the ui for dialogs and settings panels, the mapping between widgets and configuration items and the type of widget and type of the item.
- Qt/QML provides a properties system that is queryable and can be used to automatically query getters/setters
Requirements
- Minimize manual setting/getting of values
- Can save to/from XML
- Need to explicitly list with widgets are mapped to which settings for each dialog/docker/gui element
- the mapping needs to be defined in json or xml in a declarative way (I prefer xml, since we use that in most places)
- one central class that uses the mapping to create the settings object/restore settings to the widget
- one place to store and retrieve the mapping for a certain dialog/options pane/etc.
- an easy way to generate a basic propertiesmap from a given dialog/options pane
First Attempt At a PropertiesMap example:
<?xml version="1.0" encoding="UTF-8"?> <PropertiesMap version="1" name="KritaShape_KisToolRectangle"> <Enumeration name="FillType"> <Enum>Not Filled</Enum> <Enum>Foreground Color</Enum> <Enum>Background Color</Enum> <Enum>Pattern</Enum> </Enumeration> <Enumeration name="OutlineType"> <Enum>No Outline</Enum> <Enum>Brush</Enum> <Enum>Brush (Background Color</Enum> </Enumeration> <Property name="Fill> <WidgetObjectName>cmbFill</WidgetObjectName> <Type>FillType</Type> <DefaultValue>0</DefaultValue> </Property> </Property name="Outline"> <WidgetObjectName>cmbOutline</WidgetObjectName> <Type>OutlineType</Type> <DefaultValue>0</DefaultValue> <Property name="Ratio" <WidgetObjectName>doubleRatio</WidgetObjectName> <Type>qreal</Type> <DefaultValue>0.0</DefaultValue> <MaxValue>10000.0</MaxValue> <MinValue>0.1</MinValue> </Property> <Property name = "Rotation"> <WidgetObjectName>sldRotation</WidgetObjectName> <Type>qreal</Type> <MinValue>0.0</MinValue> <MaxValue>360.0</MaxValue> <Decimals>2</Decimals> <Suffix>%</Suffix> <Singletep>1.0</SingleStep> </Property> </PropertiesMap>
(Interestingly, the cmbOutline combobox has three options, and the last one isn't in the StrokeStype enum that is used to set its value)