StateSaver
Attached propertyes to save component property states. More...
Properties
- enabled : bool
- properties : string
Detailed Description
StateSaver attached object provides the ability to serialize property values between application starts. The properties subject of serialization must be given in the properties as a string, separated with commas. The serialization will happen automatically on component's completion and destruction time, as well as when the application is deactivated. Automatic serialization can be turned off by simply setting false to enabled property.
Example:
import QtQuick 2.0 import Ubuntu.Components 0.1 TextField { id: input StateSaver.properties: "text" StateSaver.enabled: input.enabled }
In this example the state saver is synchronized with the attachee's one.
Group properties can also be serialized by specifying the path to their individual properties.
Rectangle { id: rect color: "gray" border { color: "blue" width: units.gu(1) } StateSaver.properties: "color, border.color, border.width" }
StateSaver computes a unique identifier for the attachee using the component's and all its parents' id. Therefore attachee component as well as all its parents must have a valid ID set.
The following example will give error for the input, as the root component has no id specified:
Item { //[...] Item { id: parent //[...] TextField { id: input StateSaver.properties: "text" } } }
but the following example will successfully save the text field content
Item { id: root //[...] Item { id: parent //[...] TextField { id: input StateSaver.properties: "text" } } }
The StateSaver can save all QML base types, Objects, list of objects or variants containing any of these cannot be saved.
Property Documentation
The property drives the automatic state saving. When disabled, state saving will not happen on properties.
The default value is true.
List of properties to be serialized, separated with commas. Properties must be writable and can only be QML base types.
A custom singl eline input which saves the text, polaceholderText, font and color would look as follows:
TextField { id: input StateSaver.properties: "text, placeholderText, font, color" }