From cd4e6504dfbdface00037625f0cedda511e6d839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 16 Nov 2016 14:59:28 +0100 Subject: Generate an instance with KSharedConfig::Ptr for singleton and arg Summary: In case a kcfg with arg="true" was used and singleton the static instance method only accepted a QString config name. This made it impossible to combine a singleton config with an already existing and open KSharedConfig::Ptr. With this change an overloaded instance method is added which takes a KSharedConfig::Ptr as argument. The private ctor, though, only takes a KSharedConfig::Ptr and the instance method taking a QString argument uses KSharedConfig::openConfig on the config file name. This provides full API compatibility and at the same time allows to use KSharedConfig in addition to the arg name based variant. Test Plan: kconfigcompiler tests still pass and a config with singleton and arg="true" generates the code as I need it Reviewers: #frameworks Differential Revision: https://phabricator.kde.org/D3386 --- autotests/kconfig_compiler/test8c.cpp.ref | 65 +++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 autotests/kconfig_compiler/test8c.cpp.ref (limited to 'autotests/kconfig_compiler/test8c.cpp.ref') diff --git a/autotests/kconfig_compiler/test8c.cpp.ref b/autotests/kconfig_compiler/test8c.cpp.ref new file mode 100644 index 00000000..7c7799bc --- /dev/null +++ b/autotests/kconfig_compiler/test8c.cpp.ref @@ -0,0 +1,65 @@ +// This file is generated by kconfig_compiler_kf5 from test8a.kcfg. +// All changes you do to this file will be lost. + +#include "test8c.h" + +#include +#include + +#include + +class Test8cHelper +{ + public: + Test8cHelper() : q(0) {} + ~Test8cHelper() { delete q; } + Test8c *q; +}; +Q_GLOBAL_STATIC(Test8cHelper, s_globalTest8c) +Test8c *Test8c::self() +{ + if (!s_globalTest8c()->q) + qFatal("you need to call Test8c::instance before using"); + return s_globalTest8c()->q; +} + +void Test8c::instance(const QString& cfgfilename) +{ + if (s_globalTest8c()->q) { + qDebug() << "Test8c::instance called after the first use - ignoring"; + return; + } + new Test8c(KSharedConfig::openConfig(cfgfilename)); + s_globalTest8c()->q->read(); +} + +void Test8c::instance(KSharedConfig::Ptr config) +{ + if (s_globalTest8c()->q) { + qDebug() << "Test8c::instance called after the first use - ignoring"; + return; + } + new Test8c(config); + s_globalTest8c()->q->read(); +} + +Test8c::Test8c( KSharedConfig::Ptr config ) + : KConfigSkeleton( config ) +{ + Q_ASSERT(!s_globalTest8c()->q); + s_globalTest8c()->q = this; + setCurrentGroup( QStringLiteral( "Group" ) ); + + KConfigSkeleton::ItemFont *itemFont; + itemFont = new KConfigSkeleton::ItemFont( currentGroup(), QStringLiteral( "Font" ), mFont, QFont() ); + addItem( itemFont, QStringLiteral( "Font" ) ); + KConfigSkeleton::ItemFont *itemTitleFont; + itemTitleFont = new KConfigSkeleton::ItemFont( currentGroup(), QStringLiteral( "TitleFont" ), mTitleFont, QFont() ); + addItem( itemTitleFont, QStringLiteral( "TitleFont" ) ); +} + +Test8c::~Test8c() +{ + s_globalTest8c()->q = 0; +} + -- cgit v1.2.1