diff --git a/autotests/kconfig_compiler/test1.h.ref b/autotests/kconfig_compiler/test1.h.ref --- a/autotests/kconfig_compiler/test1.h.ref +++ b/autotests/kconfig_compiler/test1.h.ref @@ -17,7 +17,7 @@ enum type { One, Two, Three, COUNT }; }; - Test1( const QString & transport, const QString & folder ); + Test1( const QString & transport, const QString & folder, QObject *parent = nullptr ); ~Test1(); /** diff --git a/autotests/kconfig_compiler/test1.cpp.ref b/autotests/kconfig_compiler/test1.cpp.ref --- a/autotests/kconfig_compiler/test1.cpp.ref +++ b/autotests/kconfig_compiler/test1.cpp.ref @@ -3,11 +3,12 @@ #include "test1.h" -Test1::Test1( const QString & transport, const QString & folder ) +Test1::Test1( const QString & transport, const QString & folder, QObject *parent ) : KConfigSkeleton( QStringLiteral( "examplerc" ) ) , mParamtransport(transport) , mParamfolder(folder) { + setParent(parent); setCurrentGroup( QStringLiteral( "General-%1" ).arg( mParamfolder ) ); KConfigSkeleton::ItemBool *itemOneOption; diff --git a/autotests/kconfig_compiler/test1.kcfgc b/autotests/kconfig_compiler/test1.kcfgc --- a/autotests/kconfig_compiler/test1.kcfgc +++ b/autotests/kconfig_compiler/test1.kcfgc @@ -1,6 +1,7 @@ # Code generation options for kconfig_compiler_kf5 ClassName=Test1 File=test1.kcfg +ParentInConstructor=true # # Singleton=false # diff --git a/autotests/kconfig_compiler/test10.cpp.ref b/autotests/kconfig_compiler/test10.cpp.ref --- a/autotests/kconfig_compiler/test10.cpp.ref +++ b/autotests/kconfig_compiler/test10.cpp.ref @@ -26,7 +26,7 @@ return s_globalTest10()->q; } -Test10::Test10( ) +Test10::Test10( ) : KConfigSkeleton( QStringLiteral( "test10rc" ) ) { Q_ASSERT(!s_globalTest10()->q); diff --git a/autotests/kconfig_compiler/test11.h.ref b/autotests/kconfig_compiler/test11.h.ref --- a/autotests/kconfig_compiler/test11.h.ref +++ b/autotests/kconfig_compiler/test11.h.ref @@ -21,7 +21,7 @@ }; enum MailClient { sendmail, kmail }; - Test11( ); + Test11( QObject *parent = nullptr ); ~Test11(); /** diff --git a/autotests/kconfig_compiler/test11.cpp.ref b/autotests/kconfig_compiler/test11.cpp.ref --- a/autotests/kconfig_compiler/test11.cpp.ref +++ b/autotests/kconfig_compiler/test11.cpp.ref @@ -3,9 +3,10 @@ #include "test11.h" -Test11::Test11( ) +Test11::Test11( QObject *parent ) : MyPrefs( QStringLiteral( "korganizerrc" ) ) { + setParent(parent); setCurrentGroup( QStringLiteral( "General" ) ); mAutoSaveItem = new MyPrefs::ItemBool( currentGroup(), QStringLiteral( "Auto Save" ), mAutoSave, false ); diff --git a/autotests/kconfig_compiler/test11.kcfgc b/autotests/kconfig_compiler/test11.kcfgc --- a/autotests/kconfig_compiler/test11.kcfgc +++ b/autotests/kconfig_compiler/test11.kcfgc @@ -1,6 +1,7 @@ # Code generation options for kconfig_compiler_kf5 File=test11.kcfg ClassName=Test11 +ParentInConstructor=true Singleton=false Mutators=true Inherits=MyPrefs diff --git a/autotests/kconfig_compiler/test11a.cpp.ref b/autotests/kconfig_compiler/test11a.cpp.ref --- a/autotests/kconfig_compiler/test11a.cpp.ref +++ b/autotests/kconfig_compiler/test11a.cpp.ref @@ -3,7 +3,7 @@ #include "test11a.h" -Test11a::Test11a( ) +Test11a::Test11a( ) : MyPrefs( QStringLiteral( "korganizerrc" ) ) { setCurrentGroup( QStringLiteral( "General" ) ); diff --git a/autotests/kconfig_compiler/test12.cpp.ref b/autotests/kconfig_compiler/test12.cpp.ref --- a/autotests/kconfig_compiler/test12.cpp.ref +++ b/autotests/kconfig_compiler/test12.cpp.ref @@ -3,7 +3,7 @@ #include "test12.h" -Test12::Test12( ) +Test12::Test12( ) : KConfigSkeleton( QStringLiteral( "muondatasourcesrc" ) ) { setCurrentGroup( QStringLiteral( "muon" ) ); diff --git a/autotests/kconfig_compiler/test13.cpp.ref b/autotests/kconfig_compiler/test13.cpp.ref --- a/autotests/kconfig_compiler/test13.cpp.ref +++ b/autotests/kconfig_compiler/test13.cpp.ref @@ -3,7 +3,7 @@ #include "test13.h" -Test13::Test13( ) +Test13::Test13( ) : KConfigSkeleton( QStringLiteral( "muondatasourcesrc" ) ) { KConfigCompilerSignallingItem::NotifyFunction notifyFunction = static_cast(&Test13::itemChanged); diff --git a/autotests/kconfig_compiler/test2.cpp.ref b/autotests/kconfig_compiler/test2.cpp.ref --- a/autotests/kconfig_compiler/test2.cpp.ref +++ b/autotests/kconfig_compiler/test2.cpp.ref @@ -3,7 +3,7 @@ #include "test2.h" -Test2::Test2( ) +Test2::Test2( ) : MyPrefs( QStringLiteral( "korganizerrc" ) ) { setCurrentGroup( QStringLiteral( "General" ) ); diff --git a/autotests/kconfig_compiler/test3.cpp.ref b/autotests/kconfig_compiler/test3.cpp.ref --- a/autotests/kconfig_compiler/test3.cpp.ref +++ b/autotests/kconfig_compiler/test3.cpp.ref @@ -5,7 +5,7 @@ using namespace TestNameSpace; -Test3::Test3( ) +Test3::Test3( ) : KConfigSkeleton( QStringLiteral( "test3rc" ) ) { setCurrentGroup( QStringLiteral( "General" ) ); diff --git a/autotests/kconfig_compiler/test3a.cpp.ref b/autotests/kconfig_compiler/test3a.cpp.ref --- a/autotests/kconfig_compiler/test3a.cpp.ref +++ b/autotests/kconfig_compiler/test3a.cpp.ref @@ -5,7 +5,7 @@ using namespace TestNameSpace::InnerNameSpace; -Test3a::Test3a( ) +Test3a::Test3a( ) : KConfigSkeleton( QStringLiteral( "test3arc" ) ) { setCurrentGroup( QStringLiteral( "General" ) ); diff --git a/autotests/kconfig_compiler/test4.cpp.ref b/autotests/kconfig_compiler/test4.cpp.ref --- a/autotests/kconfig_compiler/test4.cpp.ref +++ b/autotests/kconfig_compiler/test4.cpp.ref @@ -28,7 +28,7 @@ const char* const Test4::EnumButton::enumToString[] = { "right", "mid", "left" }; -Test4::Test4( ) +Test4::Test4( ) : KConfigSkeleton( QStringLiteral( "test4rc" ) ) { Q_ASSERT(!s_globalTest4()->q); diff --git a/autotests/kconfig_compiler/test5.h.ref b/autotests/kconfig_compiler/test5.h.ref --- a/autotests/kconfig_compiler/test5.h.ref +++ b/autotests/kconfig_compiler/test5.h.ref @@ -106,7 +106,7 @@ } protected: - Test5(); + Test5(QObject *parent = nullptr); friend class Test5Helper; diff --git a/autotests/kconfig_compiler/test5.cpp.ref b/autotests/kconfig_compiler/test5.cpp.ref --- a/autotests/kconfig_compiler/test5.cpp.ref +++ b/autotests/kconfig_compiler/test5.cpp.ref @@ -28,9 +28,10 @@ const char* const Test5::EnumButtonToString[] = { "right", "mid", "left" }; -Test5::Test5( ) +Test5::Test5( QObject *parent ) : KConfigSkeleton( QStringLiteral( "test4rc" ) ) { + setParent(parent); Q_ASSERT(!s_globalTest5()->q); s_globalTest5()->q = this; setCurrentGroup( QStringLiteral( "Foo" ) ); diff --git a/autotests/kconfig_compiler/test5.kcfgc b/autotests/kconfig_compiler/test5.kcfgc --- a/autotests/kconfig_compiler/test5.kcfgc +++ b/autotests/kconfig_compiler/test5.kcfgc @@ -1,6 +1,7 @@ # Code generation options for kconfig_compiler_kf5 File=test5.kcfg ClassName=Test5 +ParentInConstructor=true Singleton=true Mutators=true #Inherits=MyPrefs diff --git a/autotests/kconfig_compiler/test6.cpp.ref b/autotests/kconfig_compiler/test6.cpp.ref --- a/autotests/kconfig_compiler/test6.cpp.ref +++ b/autotests/kconfig_compiler/test6.cpp.ref @@ -3,7 +3,7 @@ #include "test6.h" -Test6::Test6( const QString & Number ) +Test6::Test6( const QString & Number ) : KConfigSkeleton( QStringLiteral( "test4rc" ) ) , mParamNumber(Number) { diff --git a/autotests/kconfig_compiler/test7.cpp.ref b/autotests/kconfig_compiler/test7.cpp.ref --- a/autotests/kconfig_compiler/test7.cpp.ref +++ b/autotests/kconfig_compiler/test7.cpp.ref @@ -3,7 +3,7 @@ #include "test7.h" -Test7::Test7( int Number ) +Test7::Test7( int Number ) : KConfigSkeleton( QStringLiteral( "test7rc" ) ) , mParamNumber(Number) { diff --git a/autotests/kconfig_compiler/test8a.h.ref b/autotests/kconfig_compiler/test8a.h.ref --- a/autotests/kconfig_compiler/test8a.h.ref +++ b/autotests/kconfig_compiler/test8a.h.ref @@ -12,7 +12,7 @@ { public: - Test8a( KSharedConfig::Ptr config = KSharedConfig::openConfig() ); + Test8a( KSharedConfig::Ptr config = KSharedConfig::openConfig(), QObject *parent = nullptr ); ~Test8a(); /** diff --git a/autotests/kconfig_compiler/test8a.cpp.ref b/autotests/kconfig_compiler/test8a.cpp.ref --- a/autotests/kconfig_compiler/test8a.cpp.ref +++ b/autotests/kconfig_compiler/test8a.cpp.ref @@ -3,9 +3,10 @@ #include "test8a.h" -Test8a::Test8a( KSharedConfig::Ptr config ) +Test8a::Test8a( KSharedConfig::Ptr config, QObject *parent ) : KConfigSkeleton( config ) { + setParent(parent); setCurrentGroup( QStringLiteral( "Group" ) ); KConfigSkeleton::ItemFont *itemFont; diff --git a/autotests/kconfig_compiler/test8a.kcfgc b/autotests/kconfig_compiler/test8a.kcfgc --- a/autotests/kconfig_compiler/test8a.kcfgc +++ b/autotests/kconfig_compiler/test8a.kcfgc @@ -1,3 +1,4 @@ File=test8a.kcfg ClassName=Test8a +ParentInConstructor=true Mutators=true diff --git a/autotests/kconfig_compiler/test8b.cpp.ref b/autotests/kconfig_compiler/test8b.cpp.ref --- a/autotests/kconfig_compiler/test8b.cpp.ref +++ b/autotests/kconfig_compiler/test8b.cpp.ref @@ -26,7 +26,7 @@ return s_globalTest8b()->q; } -Test8b::Test8b( ) +Test8b::Test8b( ) : Test8a() { Q_ASSERT(!s_globalTest8b()->q); diff --git a/autotests/kconfig_compiler/test8c.h.ref b/autotests/kconfig_compiler/test8c.h.ref --- a/autotests/kconfig_compiler/test8c.h.ref +++ b/autotests/kconfig_compiler/test8c.h.ref @@ -55,7 +55,7 @@ } protected: - Test8c(KSharedConfig::Ptr config); + Test8c(KSharedConfig::Ptr config, QObject *parent = nullptr); friend class Test8cHelper; diff --git a/autotests/kconfig_compiler/test8c.cpp.ref b/autotests/kconfig_compiler/test8c.cpp.ref --- a/autotests/kconfig_compiler/test8c.cpp.ref +++ b/autotests/kconfig_compiler/test8c.cpp.ref @@ -45,9 +45,10 @@ s_globalTest8c()->q->read(); } -Test8c::Test8c( KSharedConfig::Ptr config ) +Test8c::Test8c( KSharedConfig::Ptr config, QObject *parent ) : KConfigSkeleton( config ) { + setParent(parent); Q_ASSERT(!s_globalTest8c()->q); s_globalTest8c()->q = this; setCurrentGroup( QStringLiteral( "Group" ) ); diff --git a/autotests/kconfig_compiler/test8c.kcfgc b/autotests/kconfig_compiler/test8c.kcfgc --- a/autotests/kconfig_compiler/test8c.kcfgc +++ b/autotests/kconfig_compiler/test8c.kcfgc @@ -1,4 +1,5 @@ File=test8c.kcfg ClassName=Test8c +ParentInConstructor=true Mutators=true Singleton=true diff --git a/autotests/kconfig_compiler/test9.cpp.ref b/autotests/kconfig_compiler/test9.cpp.ref --- a/autotests/kconfig_compiler/test9.cpp.ref +++ b/autotests/kconfig_compiler/test9.cpp.ref @@ -3,7 +3,7 @@ #include "test9.h" -Test9::Test9( const QString & transport, const QString & folder ) +Test9::Test9( const QString & transport, const QString & folder ) : KConfigSkeleton( QStringLiteral( "examplerc" ) ) , mParamtransport(transport) , mParamfolder(folder) diff --git a/autotests/kconfig_compiler/test_dpointer.cpp.ref b/autotests/kconfig_compiler/test_dpointer.cpp.ref --- a/autotests/kconfig_compiler/test_dpointer.cpp.ref +++ b/autotests/kconfig_compiler/test_dpointer.cpp.ref @@ -65,7 +65,7 @@ return s_globalTestDPointer()->q; } -TestDPointer::TestDPointer( ) +TestDPointer::TestDPointer( ) : KConfigSkeleton( QStringLiteral( "korganizerrc" ) ) { d = new TestDPointerPrivate; diff --git a/autotests/kconfig_compiler/test_notifiers.cpp.ref b/autotests/kconfig_compiler/test_notifiers.cpp.ref --- a/autotests/kconfig_compiler/test_notifiers.cpp.ref +++ b/autotests/kconfig_compiler/test_notifiers.cpp.ref @@ -3,7 +3,7 @@ #include "test_notifiers.h" -TestNotifiers::TestNotifiers( int Number ) +TestNotifiers::TestNotifiers( int Number ) : KConfigSkeleton( QStringLiteral( "test7rc" ) ) , mParamNumber(Number) { diff --git a/autotests/kconfig_compiler/test_qdebugcategory.cpp.ref b/autotests/kconfig_compiler/test_qdebugcategory.cpp.ref --- a/autotests/kconfig_compiler/test_qdebugcategory.cpp.ref +++ b/autotests/kconfig_compiler/test_qdebugcategory.cpp.ref @@ -3,7 +3,7 @@ #include "test_qdebugcategory.h" -TestQCategory::TestQCategory( int Number ) +TestQCategory::TestQCategory( int Number ) : KConfigSkeleton( QStringLiteral( "test7rc" ) ) , mParamNumber(Number) { diff --git a/autotests/kconfig_compiler/test_signal.cpp.ref b/autotests/kconfig_compiler/test_signal.cpp.ref --- a/autotests/kconfig_compiler/test_signal.cpp.ref +++ b/autotests/kconfig_compiler/test_signal.cpp.ref @@ -26,7 +26,7 @@ return s_globalTestSignal()->q; } -TestSignal::TestSignal( ) +TestSignal::TestSignal( ) : KConfigSkeleton( QStringLiteral( "kconfig_compiler_kf5_test_rc" ) ) , mSettingsChanged(0) { diff --git a/autotests/kconfig_compiler/test_translation_kde.cpp.ref b/autotests/kconfig_compiler/test_translation_kde.cpp.ref --- a/autotests/kconfig_compiler/test_translation_kde.cpp.ref +++ b/autotests/kconfig_compiler/test_translation_kde.cpp.ref @@ -7,7 +7,7 @@ using namespace TestNameSpace; -TestTranslationKde::TestTranslationKde( ) +TestTranslationKde::TestTranslationKde( ) : KConfigSkeleton( QStringLiteral( "test_translation_rc" ) ) { setCurrentGroup( QStringLiteral( "General" ) ); diff --git a/autotests/kconfig_compiler/test_translation_kde_domain.cpp.ref b/autotests/kconfig_compiler/test_translation_kde_domain.cpp.ref --- a/autotests/kconfig_compiler/test_translation_kde_domain.cpp.ref +++ b/autotests/kconfig_compiler/test_translation_kde_domain.cpp.ref @@ -7,7 +7,7 @@ using namespace TestNameSpace; -TestTranslationKdeDomain::TestTranslationKdeDomain( ) +TestTranslationKdeDomain::TestTranslationKdeDomain( ) : KConfigSkeleton( QStringLiteral( "test_translation_rc" ) ) { setCurrentGroup( QStringLiteral( "General" ) ); diff --git a/autotests/kconfig_compiler/test_translation_qt.cpp.ref b/autotests/kconfig_compiler/test_translation_qt.cpp.ref --- a/autotests/kconfig_compiler/test_translation_qt.cpp.ref +++ b/autotests/kconfig_compiler/test_translation_qt.cpp.ref @@ -5,7 +5,7 @@ using namespace TestNameSpace; -TestTranslationQt::TestTranslationQt( ) +TestTranslationQt::TestTranslationQt( ) : KConfigSkeleton( QStringLiteral( "test_translation_rc" ) ) { setCurrentGroup( QStringLiteral( "General" ) ); diff --git a/src/kconfig_compiler/kconfig_compiler.cpp b/src/kconfig_compiler/kconfig_compiler.cpp --- a/src/kconfig_compiler/kconfig_compiler.cpp +++ b/src/kconfig_compiler/kconfig_compiler.cpp @@ -80,6 +80,7 @@ if (!visibility.isEmpty()) { visibility += ' '; } + parentInConstructor = codegenConfig.value(QStringLiteral("ParentInConstructor"), false).toBool(); forceStringFilename = codegenConfig.value(QStringLiteral("ForceStringFilename"), false).toBool(); singleton = codegenConfig.value(QStringLiteral("Singleton"), false).toBool(); staticAccessors = singleton; @@ -125,6 +126,7 @@ QString className; // The class name to be generated QString inherits; // The class the generated class inherits (if empty, from KConfigSkeleton) QString visibility; + bool parentInConstructor; // The class has the optional parent parameter in its constructor bool forceStringFilename; bool singleton; // The class will be a singleton bool staticAccessors; // provide or not static accessors @@ -1895,6 +1897,12 @@ } h << " " << param((*it).type) << " " << (*it).name; } + if (cfg.parentInConstructor) { + if (cfgFileNameArg || !parameters.isEmpty()) { + h << ","; + } + h << " QObject *parent = nullptr"; + } h << " );" << endl; } else { h << " static " << cfg.className << " *self();" << endl; @@ -2125,6 +2133,12 @@ if (cfgFileNameArg) { h << "KSharedConfig::Ptr config"; } + if (cfg.parentInConstructor) { + if (cfgFileNameArg) { + h << ", "; + } + h << "QObject *parent = nullptr"; + } h << ");" << endl; h << " friend class " << cfg.className << "Helper;" << endl << endl; } @@ -2357,14 +2371,14 @@ } // Constructor - cpp << cfg.className << "::" << cfg.className << "( "; + cpp << cfg.className << "::" << cfg.className << "("; if (cfgFileNameArg) { if (! cfg.forceStringFilename) { cpp << " KSharedConfig::Ptr config"; } else { cpp << " const QString& config"; } - cpp << (parameters.isEmpty() ? " " : ", "); + cpp << (parameters.isEmpty() ? "" : ","); } for (QList::ConstIterator it = parameters.constBegin(); @@ -2374,6 +2388,13 @@ } cpp << " " << param((*it).type) << " " << (*it).name; } + + if (cfg.parentInConstructor) { + if (cfgFileNameArg || !parameters.isEmpty()) { + cpp << ","; + } + cpp << " QObject *parent"; + } cpp << " )" << endl; cpp << " : " << cfg.inherits << "("; @@ -2400,6 +2421,10 @@ cpp << "{" << endl; + if (cfg.parentInConstructor) { + cpp << " setParent(parent);" << endl; + } + if (cfg.dpointer) { cpp << " d = new " + cfg.className + "Private;" << endl; if (hasNonModifySignals) {