[Development] Settings API for QML
Hausmann Simon
Simon.Hausmann at digia.com
Fri Jun 21 18:58:33 CEST 2013
Hi,
I like this, but as a next step I think it would be good to get rid of the manual JS code for saving.
What about a general syntax of annotating properties? Then settings could be implemented on top by introspecting for properties annotated with settings tags and then save/restore then.
Inspired by IDL, how about square brackets with key and optional value pairs, comma separated?
[persistent] property into scale: 1.0
[persistent] width: 800
[Something, someKey=someValue] property string foo;
What do you think?
Simon
Nurmi J-P <jpnurmi at digia.com> wrote:
Hi,
Returning to the subject, here's a simplified proposal:
import QtQuick 2.0
import Qt.labs.settings 1.0
Item {
id: window
width: settings.width
height: settings.height
Settings {
id: settings
category: "Geometry"
property int width: 800
property int height: 600
}
Component.onDestruction: {
settings.width = window.width
settings.height = window.height
}
}
Implementation based on Joao's old prototype: https://codereview.qt-project.org/#change,59149
In short, the idea is to keep the API as minimal as possible, leaving the category/group as the only configurable property. I was delighted to find out that QCoreApplication::applicationName was already exposed to QML, but I would propose exposing organization name too (https://codereview.qt-project.org/#change,59524) in order to provide a bit better control over the settings location. The tricky thing is to get those initialized in pure QML applications before constructing a Settings object. Perhaps Component could have an attached onConstruction signal that would get triggered when construction begins?
--
J-P Nurmi
_______________________________________________
Development mailing list
Development at qt-project.org
http://lists.qt-project.org/mailman/listinfo/development
More information about the Development
mailing list