Add KCoreConfigSkeleton::read() which doesn't call reparseConfiguration.

Call it from generated singletons, since the constructor creates
a KConfig from a filename, which already loads from disk.
This removes the need for using DelayedParsing.

REVIEW: 116845
wilder
David Faure 12 years ago
parent 41ccd7bcd6
commit c1980dbc51
  1. 2
      autotests/kconfig_compiler/test10.cpp.ref
  2. 13
      autotests/kconfig_compiler/test1main.cpp
  3. 2
      autotests/kconfig_compiler/test4.cpp.ref
  4. 16
      autotests/kconfig_compiler/test4main.cpp
  5. 2
      autotests/kconfig_compiler/test5.cpp.ref
  6. 2
      autotests/kconfig_compiler/test8b.cpp.ref
  7. 2
      autotests/kconfig_compiler/test_dpointer.cpp.ref
  8. 2
      autotests/kconfig_compiler/test_signal.cpp.ref
  9. 3
      autotests/kconfigskeletontest.cpp
  10. 7
      src/core/kcoreconfigskeleton.cpp
  11. 12
      src/core/kcoreconfigskeleton.h
  12. 4
      src/kconfig_compiler/kconfig_compiler.cpp

@ -18,7 +18,7 @@ Test10 *Test10::self()
{
if (!s_globalTest10()->q) {
new Test10;
s_globalTest10()->q->readConfig();
s_globalTest10()->q->read();
}
return s_globalTest10()->q;

@ -20,12 +20,23 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "test1.h"
#include <QGuiApplication>
#include <KConfig>
#include <KConfigGroup>
int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
Q_UNUSED(app);
{
KConfig initialConfig(QLatin1String("examplerc"));
KConfigGroup group = initialConfig.group(QLatin1String("MyOptions"));
group.writeEntry(QLatin1String("MyString"), QStringLiteral("The String"));
}
Test1 *t = new Test1(QString(), QString());
bool ok = t->myString() == QLatin1String("The String");
delete t;
return 0;
return ok ? 0 : 1;
}

@ -18,7 +18,7 @@ Test4 *Test4::self()
{
if (!s_globalTest4()->q) {
new Test4;
s_globalTest4()->q->readConfig();
s_globalTest4()->q->read();
}
return s_globalTest4()->q;

@ -21,12 +21,26 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "test4.h"
#include <QGuiApplication>
#include <QStandardPaths>
#include <QFile>
int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
Q_UNUSED(app);
{
KConfig initialConfig(QLatin1String("test4rc"));
KConfigGroup group = initialConfig.group(QLatin1String("Foo"));
group.writeEntry(QLatin1String("foo bar"), QStringLiteral("Value"));
}
Test4 *t = Test4::self();
bool ok = QFile::exists(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/test4rc");
if (!ok) {
qWarning() << "config file was not created!";
}
if (t->fooBar() != QStringLiteral("Value")) {
qWarning() << "wrong value for foo bar:" << t->fooBar();
}
delete t;
return 0;
return ok ? 0 : 1;
}

@ -18,7 +18,7 @@ Test5 *Test5::self()
{
if (!s_globalTest5()->q) {
new Test5;
s_globalTest5()->q->readConfig();
s_globalTest5()->q->read();
}
return s_globalTest5()->q;

@ -18,7 +18,7 @@ Test8b *Test8b::self()
{
if (!s_globalTest8b()->q) {
new Test8b;
s_globalTest8b()->q->readConfig();
s_globalTest8b()->q->read();
}
return s_globalTest8b()->q;

@ -57,7 +57,7 @@ TestDPointer *TestDPointer::self()
{
if (!s_globalTestDPointer()->q) {
new TestDPointer;
s_globalTestDPointer()->q->readConfig();
s_globalTestDPointer()->q->read();
}
return s_globalTestDPointer()->q;

@ -18,7 +18,7 @@ TestSignal *TestSignal::self()
{
if (!s_globalTestSignal()->q) {
new TestSignal;
s_globalTestSignal()->q->readConfig();
s_globalTestSignal()->q->read();
}
return s_globalTestSignal()->q;

@ -65,13 +65,12 @@ void KConfigSkeletonTest::testSimple()
mMyString.clear();
mMyFont = QFont();
readConfig();
read();
QCOMPARE(mMyBool, WRITE_SETTING1);
QCOMPARE(mMyColor, WRITE_SETTING2);
QCOMPARE(mMyFont, WRITE_SETTING3);
QCOMPARE(mMyString, WRITE_SETTING4);
}
void KConfigSkeletonTest::testRemoveItem()

@ -986,7 +986,7 @@ KCoreConfigSkeleton::KCoreConfigSkeleton(const QString &configname, QObject *par
{
//qDebug() << "Creating KCoreConfigSkeleton (" << (void *)this << ")";
d->mConfig = KSharedConfig::openConfig(configname, KConfig::FullConfig | KConfig::DelayedParsing);
d->mConfig = KSharedConfig::openConfig(configname, KConfig::FullConfig);
}
KCoreConfigSkeleton::KCoreConfigSkeleton(KSharedConfig::Ptr pConfig, QObject *parent)
@ -1065,6 +1065,11 @@ void KCoreConfigSkeleton::readConfig()
{
// qDebug();
d->mConfig->reparseConfiguration();
read();
}
void KCoreConfigSkeleton::read()
{
KConfigSkeletonItem::List::ConstIterator it;
for (it = d->mItems.constBegin(); it != d->mItems.constEnd(); ++it) {
(*it)->readConfig(d->mConfig.data());

@ -1040,6 +1040,18 @@ public:
*/
virtual void readConfig();
/**
* Read preferences from the KConfig object.
* This method assumes that the KConfig object was previously loaded,
* i.e. it uses the in-memory values from KConfig without reloading from disk.
*
* This method calls usrReadConfig() after reading the settings of the
* registered items from the KConfig. You can overridde usrReadConfig()
* in derived classes if you have special requirements.
* @since 5.0
*/
void read();
/**
* Set the config file group for subsequent addItem() calls. It is valid
* until setCurrentGroup() is called with a new argument. Call this before

@ -2249,7 +2249,7 @@ int main(int argc, char **argv)
} else {
cpp << " if (!s_global" << cfg.className << "()->q) {" << endl;
cpp << " new " << cfg.className << ';' << endl;
cpp << " s_global" << cfg.className << "()->q->readConfig();" << endl;
cpp << " s_global" << cfg.className << "()->q->read();" << endl;
cpp << " }" << endl << endl;
}
cpp << " return s_global" << cfg.className << "()->q;" << endl;
@ -2263,7 +2263,7 @@ int main(int argc, char **argv)
cpp << " return;" << endl;
cpp << " }" << endl;
cpp << " new " << cfg.className << "(cfgfilename);" << endl;
cpp << " s_global" << cfg.className << "()->q->readConfig();" << endl;
cpp << " s_global" << cfg.className << "()->q->read();" << endl;
cpp << "}" << endl << endl;
}
}

Loading…
Cancel
Save