[Development] QConfig update.
Tomaz Canabrava
tcanabrava at kde.org
Tue Oct 14 18:22:51 CEST 2014
People, I'v read everything on the other two e-mails and I'v changed quite
a few things here and again I ask for some advice.
What I'v done:
QConfig / QConfigGroup / QConfigWatcher combo classes, to be used from the
user
QConfigIniBackend, to be used internally.
QConfig:
uses a 'global' QHash<QString, QConfigIniBackend> for different files in
a way that we don't destruct the info when the object is destroyed, but
reuses the JSON information stored, and parse it to the config object.
it has a QConfigGroup 'global' value that can be acced directly via
.setValue and .value
QConfig and QConfigGroup *does not* support setting a default value on the
getter, I know that this is used in a lot of places but this can cause
inconsistencies:
Main.cpp
QConfig c;
c.value("window-width", 800);
MainWindow.cpp
c.value("window-width", 1200);
so we must create a better way for that. for now, I simply removed the
possibility for that, we can only do
c.value("window-width");
I plan to set the defaults via a schema-based file ( could be the KConfigXt
based, but I dislike having to edit XML by hand, so something more similar
to QML would be best ).
Any tougths on that?
QConfigWatcher: created automatically via the .watcher() method on QConfig
and QConfigGroup
Removed the need for pointers and references, implemented via DPointer and
move-semantics.
Example usage:
QConfig config;
QConfigGroup window = config.group("window");
window.setValue("width", 800);
window.setValue("height", 600);
window.setValue("x", 100);
window.setValue("y",100);
window.setValue("opacity", 55);
QConfigGroup font = config.group("fonts");
font.setValue("family", "san-serif");
font.setValue("pointSize", 9);
font.setValue("bold", true);
font.setValue("italic", true);
QConfigGroup plasmoids = config.group("plasmoids");
for(int i = 0; i < 5; i++){
QConfigGroup plasmoid = plasmoids.group(QString::number(i));
plasmoid.setValue("name", "name_" + QString::number(i));
plasmoid.setValue("width", rand() % 100 + 100);
plasmoid.setValue("value", rand() % 100 + 100);
}
connect(plasmoids.watcher(), SIGNAL(changed(QConfigGroup)), this,
SLOT(plasmoidsChanged(QConfigGroup)));
config.sync();
TODO, but only after this part gets perfect, KconfigXT like automatic
creation of classes and structures based on a schema file.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20141014/7cf6bc9d/attachment.html>
More information about the Development
mailing list