diff options
| author | Kevin Ottens <kevin.ottens@enioka.com> | 2019-10-08 13:19:31 +0200 | 
|---|---|---|
| committer | Kevin Ottens <kevin.ottens@enioka.com> | 2019-10-08 18:13:01 +0200 | 
| commit | 5fa1a3312ab24908d870ce2a2399695ac98d828d (patch) | |
| tree | e08e4d3134ae2318d65dcb50bee930831f3a6403 | |
| parent | db2315d79a1565c4dedf97af36c873f42a286bb2 (diff) | |
| download | kconfig-5fa1a3312ab24908d870ce2a2399695ac98d828d.tar.gz kconfig-5fa1a3312ab24908d870ce2a2399695ac98d828d.tar.bz2 | |
Make kconfig_compiler generate ctors with the optional parent arg
Reviewers: #plasma, #frameworks, dfaure, mart, apol
Reviewed By: apol
Subscribers: kossebau, apol, kde-frameworks-devel
Tags: #frameworks
Differential Revision: https://phabricator.kde.org/D24490
35 files changed, 66 insertions, 31 deletions
| diff --git a/autotests/kconfig_compiler/test1.cpp.ref b/autotests/kconfig_compiler/test1.cpp.ref index f0432d45..c0d94eef 100644 --- 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.h.ref b/autotests/kconfig_compiler/test1.h.ref index bbef760d..77c3b65f 100644 --- a/autotests/kconfig_compiler/test1.h.ref +++ b/autotests/kconfig_compiler/test1.h.ref @@ -17,7 +17,7 @@ class Test1 : public KConfigSkeleton        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.kcfgc b/autotests/kconfig_compiler/test1.kcfgc index a96bcfc1..e33118fa 100644 --- 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 index f5590c20..94d9f311 100644 --- a/autotests/kconfig_compiler/test10.cpp.ref +++ b/autotests/kconfig_compiler/test10.cpp.ref @@ -26,7 +26,7 @@ Test10 *Test10::self()    return s_globalTest10()->q;  } -Test10::Test10(  ) +Test10::Test10( )    : KConfigSkeleton( QStringLiteral( "test10rc" ) )  {    Q_ASSERT(!s_globalTest10()->q); diff --git a/autotests/kconfig_compiler/test11.cpp.ref b/autotests/kconfig_compiler/test11.cpp.ref index 76792357..6d05662a 100644 --- 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.h.ref b/autotests/kconfig_compiler/test11.h.ref index 1af66a95..395810ef 100644 --- a/autotests/kconfig_compiler/test11.h.ref +++ b/autotests/kconfig_compiler/test11.h.ref @@ -21,7 +21,7 @@ class Test11 : public MyPrefs      };      enum MailClient { sendmail, kmail }; -    Test11( ); +    Test11( QObject *parent = nullptr );      ~Test11();      /** diff --git a/autotests/kconfig_compiler/test11.kcfgc b/autotests/kconfig_compiler/test11.kcfgc index f54591f8..cea079c7 100644 --- 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 index fa486fd3..cad39428 100644 --- 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 index da6670a0..67af002e 100644 --- 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 index 0f62dc96..3fa79b18 100644 --- 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<KConfigCompilerSignallingItem::NotifyFunction>(&Test13::itemChanged); diff --git a/autotests/kconfig_compiler/test2.cpp.ref b/autotests/kconfig_compiler/test2.cpp.ref index 53b0935f..239ed60b 100644 --- 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 index aa9fb919..a9e3d6fc 100644 --- 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 index 4ff193db..b1166c10 100644 --- 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 index 29498c2c..e99a1ae9 100644 --- a/autotests/kconfig_compiler/test4.cpp.ref +++ b/autotests/kconfig_compiler/test4.cpp.ref @@ -28,7 +28,7 @@ Test4 *Test4::self()  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.cpp.ref b/autotests/kconfig_compiler/test5.cpp.ref index dfa27f3b..2ee3dbfd 100644 --- a/autotests/kconfig_compiler/test5.cpp.ref +++ b/autotests/kconfig_compiler/test5.cpp.ref @@ -28,9 +28,10 @@ Test5 *Test5::self()  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.h.ref b/autotests/kconfig_compiler/test5.h.ref index 76041741..07049cab 100644 --- a/autotests/kconfig_compiler/test5.h.ref +++ b/autotests/kconfig_compiler/test5.h.ref @@ -106,7 +106,7 @@ class Test5 : public KConfigSkeleton      }    protected: -    Test5(); +    Test5(QObject *parent = nullptr);      friend class Test5Helper; diff --git a/autotests/kconfig_compiler/test5.kcfgc b/autotests/kconfig_compiler/test5.kcfgc index 1c8f1613..219c369c 100644 --- 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 index 53f88c73..19aff0af 100644 --- 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 index 2e40848c..0badcdb7 100644 --- 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.cpp.ref b/autotests/kconfig_compiler/test8a.cpp.ref index 3b7d95aa..7c2b81ad 100644 --- 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.h.ref b/autotests/kconfig_compiler/test8a.h.ref index e47fbcab..3e890946 100644 --- a/autotests/kconfig_compiler/test8a.h.ref +++ b/autotests/kconfig_compiler/test8a.h.ref @@ -12,7 +12,7 @@ class Test8a : public KConfigSkeleton  {    public: -    Test8a( KSharedConfig::Ptr config = KSharedConfig::openConfig() ); +    Test8a( KSharedConfig::Ptr config = KSharedConfig::openConfig(), QObject *parent = nullptr );      ~Test8a();      /** diff --git a/autotests/kconfig_compiler/test8a.kcfgc b/autotests/kconfig_compiler/test8a.kcfgc index 5f63c31c..90abfcb1 100644 --- 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 index 367d8051..d2ee566b 100644 --- a/autotests/kconfig_compiler/test8b.cpp.ref +++ b/autotests/kconfig_compiler/test8b.cpp.ref @@ -26,7 +26,7 @@ Test8b *Test8b::self()    return s_globalTest8b()->q;  } -Test8b::Test8b(  ) +Test8b::Test8b( )    : Test8a()  {    Q_ASSERT(!s_globalTest8b()->q); diff --git a/autotests/kconfig_compiler/test8c.cpp.ref b/autotests/kconfig_compiler/test8c.cpp.ref index 98654e5e..e2bd027c 100644 --- a/autotests/kconfig_compiler/test8c.cpp.ref +++ b/autotests/kconfig_compiler/test8c.cpp.ref @@ -45,9 +45,10 @@ void Test8c::instance(KSharedConfig::Ptr config)    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.h.ref b/autotests/kconfig_compiler/test8c.h.ref index 8ed9962c..57469dca 100644 --- a/autotests/kconfig_compiler/test8c.h.ref +++ b/autotests/kconfig_compiler/test8c.h.ref @@ -55,7 +55,7 @@ class Test8c : public KConfigSkeleton      }    protected: -    Test8c(KSharedConfig::Ptr config); +    Test8c(KSharedConfig::Ptr config, QObject *parent = nullptr);      friend class Test8cHelper; diff --git a/autotests/kconfig_compiler/test8c.kcfgc b/autotests/kconfig_compiler/test8c.kcfgc index e53e5a04..7c1ba850 100644 --- 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 index c5eb772b..995f7164 100644 --- 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 index 9c6eae37..c69d38a4 100644 --- a/autotests/kconfig_compiler/test_dpointer.cpp.ref +++ b/autotests/kconfig_compiler/test_dpointer.cpp.ref @@ -65,7 +65,7 @@ TestDPointer *TestDPointer::self()    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 index 1049137e..a5e24504 100644 --- 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 index 1eb6ed96..2934b589 100644 --- 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 index 44366218..be06a745 100644 --- a/autotests/kconfig_compiler/test_signal.cpp.ref +++ b/autotests/kconfig_compiler/test_signal.cpp.ref @@ -26,7 +26,7 @@ TestSignal *TestSignal::self()    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 index c42408e5..62524cc1 100644 --- 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 index 6704c005..0fcf1c3b 100644 --- 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 index e0685be3..1771f08f 100644 --- 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 index c7f2d9d9..c648d7d0 100644 --- a/src/kconfig_compiler/kconfig_compiler.cpp +++ b/src/kconfig_compiler/kconfig_compiler.cpp @@ -80,6 +80,7 @@ public:          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 @@ public:      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 @@ int main(int argc, char **argv)              }              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 @@ int main(int argc, char **argv)          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 @@ int main(int argc, char **argv)      }      // 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<Param>::ConstIterator it = parameters.constBegin(); @@ -2374,6 +2388,13 @@ int main(int argc, char **argv)          }          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 @@ int main(int argc, char **argv)      cpp << "{" << endl; +    if (cfg.parentInConstructor) { +        cpp << "  setParent(parent);" << endl; +    } +      if (cfg.dpointer) {          cpp << "  d = new " + cfg.className + "Private;" << endl;          if (hasNonModifySignals) { | 
