1
/****************************************************************************
3
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
5
** Contact: Nokia Corporation (qt-info@nokia.com)
7
** This file is part of the examples of the Qt Toolkit.
9
** You may use this file under the terms of the BSD license as follows:
11
** "Redistribution and use in source and binary forms, with or without
12
** modification, are permitted provided that the following conditions are
14
** * Redistributions of source code must retain the above copyright
15
** notice, this list of conditions and the following disclaimer.
16
** * Redistributions in binary form must reproduce the above copyright
17
** notice, this list of conditions and the following disclaimer in
18
** the documentation and/or other materials provided with the
20
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
21
** the names of its contributors may be used to endorse or promote
22
** products derived from this software without specific prior written
25
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
38
****************************************************************************/
42
Settings::Settings(QObject *parent)
44
, initialPropertyCount(metaObject()->propertyCount())
55
void Settings::componentComplete()
63
const QMetaObject *mo = metaObject();
64
int propertyCount = mo->propertyCount();
65
for (int i = initialPropertyCount; i < propertyCount; ++i) {
66
const QMetaProperty &property = mo->property(i);
67
const QString name(property.name());
69
QVariant previousValue = property.read(this);
70
QVariant currentValue = settings.value(name, previousValue);
72
if (!currentValue.isNull()
73
&& currentValue.canConvert(previousValue.type())
74
&& previousValue != currentValue)
75
property.write(this, currentValue);
77
// Setup change notifications on first load
78
if (!isComplete && property.hasNotifySignal()) {
79
static int pcSlot = metaObject()->indexOfSlot("propertyChanged()");
80
Q_ASSERT(pcSlot != -1);
82
bool ok = QMetaObject::connect(this, property.notifySignalIndex(), this, pcSlot);
83
Q_UNUSED(ok) Q_ASSERT(ok);
88
void Settings::store()
90
const QMetaObject *mo = metaObject();
91
int propertyCount = mo->propertyCount();
92
for (int i = initialPropertyCount; i < propertyCount; ++i) {
93
const QMetaProperty &property = mo->property(i);
94
settings.setValue(property.name(), property.read(this));
100
void Settings::propertyChanged()
104
timerId = startTimer(500);
107
void Settings::timerEvent(QTimerEvent *)
109
if (propertyChanges == 0) {
118
QString Settings::group() const
120
return settings.group();
123
void Settings::setGroup(const QString &name)
127
if (!settings.group().isEmpty())
131
settings.beginGroup(name);