diff options
| -rw-r--r-- | autotests/kconfig_compiler/CMakeLists.txt | 9 | ||||
| -rw-r--r-- | autotests/kconfig_compiler/kconfigcompiler_test.cpp | 1 | ||||
| -rw-r--r-- | autotests/kconfig_compiler/test_notifiers.cpp.ref | 34 | ||||
| -rw-r--r-- | autotests/kconfig_compiler/test_notifiers.h.ref | 94 | ||||
| -rw-r--r-- | autotests/kconfig_compiler/test_notifiers.kcfg | 25 | ||||
| -rw-r--r-- | autotests/kconfig_compiler/test_notifiers.kcfgc | 8 | ||||
| -rw-r--r-- | autotests/kconfig_compiler/test_notifiers_main.cpp | 32 | ||||
| -rw-r--r-- | src/core/kcoreconfigskeleton.cpp | 36 | ||||
| -rw-r--r-- | src/core/kcoreconfigskeleton.h | 18 | ||||
| -rw-r--r-- | src/core/kcoreconfigskeleton_p.h | 2 | ||||
| -rw-r--r-- | src/kconfig_compiler/kconfig_compiler.cpp | 8 | 
11 files changed, 252 insertions, 15 deletions
| diff --git a/autotests/kconfig_compiler/CMakeLists.txt b/autotests/kconfig_compiler/CMakeLists.txt index 70b2dbb8..8a6289f9 100644 --- a/autotests/kconfig_compiler/CMakeLists.txt +++ b/autotests/kconfig_compiler/CMakeLists.txt @@ -189,6 +189,15 @@ gen_kcfg_test_source(test_signal test_signal_SRCS GENERATE_MOC)  ecm_add_test(TEST_NAME test_signal ${test_signal_SRCS})  target_link_libraries(test_signal KF5::ConfigGui) + +########### next target ############### + +set(test_notifiers_SRCS test_notifiers_main.cpp ) +gen_kcfg_test_source(test_notifiers test_notifiers_SRCS) +ecm_add_test(TEST_NAME test_notifiers ${test_notifiers_SRCS}) +target_link_libraries(test_notifiers KF5::ConfigGui) + +  ########### next target ###############  set(kconfigcompiler_test_signals_SRCS kconfigcompiler_test_signals.cpp) diff --git a/autotests/kconfig_compiler/kconfigcompiler_test.cpp b/autotests/kconfig_compiler/kconfigcompiler_test.cpp index 24854612..383745b1 100644 --- a/autotests/kconfig_compiler/kconfigcompiler_test.cpp +++ b/autotests/kconfig_compiler/kconfigcompiler_test.cpp @@ -48,6 +48,7 @@ static CompilerTestSet testCases = {      "test_dpointer.cpp", "test_dpointer.h",      "test_qdebugcategory.cpp", "test_qdebugcategory.h",      "test_signal.cpp", "test_signal.h", +    "test_notifiers.cpp", "test_notifiers.h",      "test_translation_kde.cpp", "test_translation_kde.h",      "test_translation_kde_domain.cpp", "test_translation_kde_domain.h",      "test_translation_qt.cpp", "test_translation_qt.h", diff --git a/autotests/kconfig_compiler/test_notifiers.cpp.ref b/autotests/kconfig_compiler/test_notifiers.cpp.ref new file mode 100644 index 00000000..1049137e --- /dev/null +++ b/autotests/kconfig_compiler/test_notifiers.cpp.ref @@ -0,0 +1,34 @@ +// This file is generated by kconfig_compiler_kf5 from test_notifiers.kcfg. +// All changes you do to this file will be lost. + +#include "test_notifiers.h" + +TestNotifiers::TestNotifiers(  int Number ) +  : KConfigSkeleton( QStringLiteral( "test7rc" ) ) +  , mParamNumber(Number) +{ +  setCurrentGroup( QStringLiteral( "Foo" ) ); + +  KConfigSkeleton::ItemColor  *itemColor; +  itemColor = new KConfigSkeleton::ItemColor( currentGroup(), QStringLiteral( "color #%1" ).arg( mParamNumber ), mColor, QColor( "red" ) ); +  itemColor->setWriteFlags(KConfigBase::Notify); +  addItem( itemColor, QStringLiteral( "Color" ) ); + +  setCurrentGroup( QStringLiteral( "Bar%1" ).arg( mParamNumber ) ); + +  KConfigSkeleton::ItemString  *itemFooBar; +  itemFooBar = new KConfigSkeleton::ItemString( currentGroup(), QStringLiteral( "foo bar" ), mFooBar ); +  itemFooBar->setWriteFlags(KConfigBase::Notify); +  addItem( itemFooBar, QStringLiteral( "FooBar" ) ); +  KConfigSkeleton::ItemInt  *itemAge; +  itemAge = new KConfigSkeleton::ItemInt( currentGroup(), QStringLiteral( "Age" ), mAge, 35 ); +  itemAge->setMinValue(8); +  itemAge->setMaxValue(88); +  itemAge->setWriteFlags(KConfigBase::Notify); +  addItem( itemAge, QStringLiteral( "Age" ) ); +} + +TestNotifiers::~TestNotifiers() +{ +} + diff --git a/autotests/kconfig_compiler/test_notifiers.h.ref b/autotests/kconfig_compiler/test_notifiers.h.ref new file mode 100644 index 00000000..588427e2 --- /dev/null +++ b/autotests/kconfig_compiler/test_notifiers.h.ref @@ -0,0 +1,94 @@ +// This file is generated by kconfig_compiler_kf5 from test_notifiers.kcfg. +// All changes you do to this file will be lost. +#ifndef TESTNOTIFIERS_H +#define TESTNOTIFIERS_H + +#include <kconfigskeleton.h> +#include <QCoreApplication> +#include <QDebug> + +class TestNotifiers : public KConfigSkeleton +{ +  public: + +    TestNotifiers( int Number ); +    ~TestNotifiers(); + +    /** +      Set Block colors. +    */ +    void setColor( const QColor & v ) +    { +      if (!isImmutable( QStringLiteral( "Color" ) )) +        mColor = v; +    } + +    /** +      Get Block colors. +    */ +    QColor color() const +    { +      return mColor; +    } + +    /** +      Set foo bar +    */ +    void setFooBar( const QString & v ) +    { +      if (!isImmutable( QStringLiteral( "FooBar" ) )) +        mFooBar = v; +    } + +    /** +      Get foo bar +    */ +    QString fooBar() const +    { +      return mFooBar; +    } + +    /** +      Set Age +    */ +    void setAge( int v ) +    { +      if (v < 8) +      { +        qDebug() << "setAge: value " << v << " is less than the minimum value of 8"; +        v = 8; +      } + +      if (v > 88) +      { +        qDebug() << "setAge: value " << v << " is greater than the maximum value of 88"; +        v = 88; +      } + +      if (!isImmutable( QStringLiteral( "Age" ) )) +        mAge = v; +    } + +    /** +      Get Age +    */ +    int age() const +    { +      return mAge; +    } + +  protected: +    int mParamNumber; + +    // Foo +    QColor mColor; + +    // Bar$(Number) +    QString mFooBar; +    int mAge; + +  private: +}; + +#endif + diff --git a/autotests/kconfig_compiler/test_notifiers.kcfg b/autotests/kconfig_compiler/test_notifiers.kcfg new file mode 100644 index 00000000..2f54f608 --- /dev/null +++ b/autotests/kconfig_compiler/test_notifiers.kcfg @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0" +      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +      xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 +                          http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" > +  <kcfgfile name="test7rc"> +      <parameter name="Number" type="Int"/> +  </kcfgfile> + +  <group name="Foo"> +    <entry name="Color" type="Color" key="color #$(Number)"> +      <label>Block colors.</label> +      <default>red</default> +    </entry> +  </group> +  <group name="Bar$(Number)"> +    <entry name="FooBar" key="foo bar" type="String"/> +    <entry name="Age" type="Int"> +      <default>35</default> +      <min>8</min> +      <max>88</max> +    </entry> +  </group> + +</kcfg> diff --git a/autotests/kconfig_compiler/test_notifiers.kcfgc b/autotests/kconfig_compiler/test_notifiers.kcfgc new file mode 100644 index 00000000..bfc85f34 --- /dev/null +++ b/autotests/kconfig_compiler/test_notifiers.kcfgc @@ -0,0 +1,8 @@ +# Code generation options for kconfig_compiler_kf5 +File=test_notifiers.kcfg +ClassName=TestNotifiers +Singleton=false +Mutators=true +GlobalEnums=true +ItemAccessors=false +Notifiers=true diff --git a/autotests/kconfig_compiler/test_notifiers_main.cpp b/autotests/kconfig_compiler/test_notifiers_main.cpp new file mode 100644 index 00000000..a4c6ba2c --- /dev/null +++ b/autotests/kconfig_compiler/test_notifiers_main.cpp @@ -0,0 +1,32 @@ +/* +Copyright (c) 2019 Kai Uwe Broulik <kde@privat.broulik.de> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "test_notifiers.h" +#include <QGuiApplication> + +int main(int argc, char **argv) +{ +    QGuiApplication app(argc, argv); +    Q_UNUSED(app); +    TestNotifiers *t = new TestNotifiers(42); +    delete t; +    return 0; +} diff --git a/src/core/kcoreconfigskeleton.cpp b/src/core/kcoreconfigskeleton.cpp index 50f91e93..384efdb4 100644 --- a/src/core/kcoreconfigskeleton.cpp +++ b/src/core/kcoreconfigskeleton.cpp @@ -110,6 +110,16 @@ QString KConfigSkeletonItem::whatsThis() const      return d->mWhatsThis;  } +void KConfigSkeletonItem::setWriteFlags(KConfigBase::WriteConfigFlags flags) +{ +    d->mWriteFlags = flags; +} + +KConfigBase::WriteConfigFlags KConfigSkeletonItem::writeFlags() const +{ +    return d->mWriteFlags; +} +  QVariant KConfigSkeletonItem::minValue() const  {      return QVariant(); @@ -144,13 +154,13 @@ void KCoreConfigSkeleton::ItemString::writeConfig(KConfig *config)      if (mReference != mLoadedValue) { // WABA: Is this test needed?          KConfigGroup cg(config, mGroup);          if ((mDefault == mReference) && !cg.hasDefault(mKey)) { -            cg.revertToDefault(mKey); +            cg.revertToDefault(mKey, writeFlags());          } else if (mType == Path) { -            cg.writePathEntry(mKey, mReference); +            cg.writePathEntry(mKey, mReference, writeFlags());          } else if (mType == Password) { -            cg.writeEntry(mKey, obscuredString(mReference)); +            cg.writeEntry(mKey, obscuredString(mReference), writeFlags());          } else { -            cg.writeEntry(mKey, mReference); +            cg.writeEntry(mKey, mReference, writeFlags());          }          mLoadedValue = mReference;      } @@ -215,9 +225,9 @@ void KCoreConfigSkeleton::ItemUrl::writeConfig(KConfig *config)      if (mReference != mLoadedValue) { // WABA: Is this test needed?          KConfigGroup cg(config, mGroup);          if ((mDefault == mReference) && !cg.hasDefault(mKey)) { -            cg.revertToDefault(mKey); +            cg.revertToDefault(mKey, writeFlags());          } else { -            cg.writeEntry<QString>(mKey, mReference.toString()); +            cg.writeEntry<QString>(mKey, mReference.toString(), writeFlags());          }          mLoadedValue = mReference;      } @@ -479,11 +489,11 @@ void KCoreConfigSkeleton::ItemEnum::writeConfig(KConfig *config)      if (mReference != mLoadedValue) { // WABA: Is this test needed?          KConfigGroup cg(config, mGroup);          if ((mDefault == mReference) && !cg.hasDefault(mKey)) { -            cg.revertToDefault(mKey); +            cg.revertToDefault(mKey, writeFlags());          } else if ((mReference >= 0) && (mReference < mChoices.count())) { -            cg.writeEntry(mKey, mChoices[mReference].name); +            cg.writeEntry(mKey, mChoices[mReference].name, writeFlags());          } else { -            cg.writeEntry(mKey, mReference); +            cg.writeEntry(mKey, mReference, writeFlags());          }          mLoadedValue = mReference;      } @@ -879,10 +889,10 @@ void KCoreConfigSkeleton::ItemPathList::writeConfig(KConfig *config)      if (mReference != mLoadedValue) { // WABA: Is this test needed?          KConfigGroup cg(config, mGroup);          if ((mDefault == mReference) && !cg.hasDefault(mKey)) { -            cg.revertToDefault(mKey); +            cg.revertToDefault(mKey, writeFlags());          } else {              QStringList sl = mReference; -            cg.writePathEntry(mKey, sl); +            cg.writePathEntry(mKey, sl, writeFlags());          }          mLoadedValue = mReference;      } @@ -921,13 +931,13 @@ void KCoreConfigSkeleton::ItemUrlList::writeConfig(KConfig *config)      if (mReference != mLoadedValue) { // WABA: Is this test needed?          KConfigGroup cg(config, mGroup);          if ((mDefault == mReference) && !cg.hasDefault(mKey)) { -            cg.revertToDefault(mKey); +            cg.revertToDefault(mKey, writeFlags());          } else {              QStringList strList;              for (const QUrl &url : qAsConst(mReference)) {                  strList.append(url.toString());              } -            cg.writeEntry<QStringList>(mKey, strList); +            cg.writeEntry<QStringList>(mKey, strList, writeFlags());          }          mLoadedValue = mReference;      } diff --git a/src/core/kcoreconfigskeleton.h b/src/core/kcoreconfigskeleton.h index b384129d..771d8cc9 100644 --- a/src/core/kcoreconfigskeleton.h +++ b/src/core/kcoreconfigskeleton.h @@ -133,6 +133,19 @@ public:      QString whatsThis() const;      /** +      The write flags to be used when writing configuration. +      @since 5.58 +    */ +    void setWriteFlags(KConfigBase::WriteConfigFlags flags); + +    /** +      Return write flags to be used when writing configuration. +      They should be passed to every call of writeEntry() and revertToDefault(). +      @since 5.58 +    */ +    KConfigBase::WriteConfigFlags writeFlags() const; + +    /**       * This function is called by @ref KCoreConfigSkeleton to read the value for this setting       * from a config file.       */ @@ -141,6 +154,7 @@ public:      /**       * This function is called by @ref KCoreConfigSkeleton to write the value of this setting       * to a config file. +     * Make sure to pass writeFlags() to every call of writeEntry() and revertToDefault().       */      virtual void writeConfig(KConfig *) = 0; @@ -274,9 +288,9 @@ public:          if (mReference != mLoadedValue) { // Is this needed?              KConfigGroup cg(config, mGroup);              if ((mDefault == mReference) && !cg.hasDefault(mKey)) { -                cg.revertToDefault(mKey); +                cg.revertToDefault(mKey, writeFlags());              } else { -                cg.writeEntry(mKey, mReference); +                cg.writeEntry(mKey, mReference, writeFlags());              }              mLoadedValue = mReference;          } diff --git a/src/core/kcoreconfigskeleton_p.h b/src/core/kcoreconfigskeleton_p.h index 88a41d8d..41005c6f 100644 --- a/src/core/kcoreconfigskeleton_p.h +++ b/src/core/kcoreconfigskeleton_p.h @@ -52,8 +52,10 @@ class KConfigSkeletonItemPrivate  public:      KConfigSkeletonItemPrivate()          : mIsImmutable(true) +        , mWriteFlags(KConfigBase::Normal)      {}      bool mIsImmutable; ///< Indicates this item is immutable +    KConfigBase::WriteConfigFlags mWriteFlags; ///< The flags to pass to calls of writeEntry() and revertToDefault()      QString mLabel; ///< The label for this item      QString mToolTip; ///< The ToolTip text for this item diff --git a/src/kconfig_compiler/kconfig_compiler.cpp b/src/kconfig_compiler/kconfig_compiler.cpp index b467a20a..abb8e115 100644 --- a/src/kconfig_compiler/kconfig_compiler.cpp +++ b/src/kconfig_compiler/kconfig_compiler.cpp @@ -94,6 +94,8 @@ public:          setUserTexts = codegenConfig.value(QStringLiteral("SetUserTexts"), false).toBool();          defaultGetters = codegenConfig.value(QStringLiteral("DefaultValueGetters"), QStringList()).toStringList();          allDefaultGetters = (defaultGetters.count() == 1) && (defaultGetters.at(0).toLower() == QLatin1String("true")); +        notifiers = codegenConfig.value(QStringLiteral("Notifiers"), QStringList()).toStringList(); +        allNotifiers = ((notifiers.count() == 1) && (notifiers.at(0).toLower() == QLatin1String("true")));          globalEnums = codegenConfig.value(QStringLiteral("GlobalEnums"), false).toBool();          useEnumTypes = codegenConfig.value(QStringLiteral("UseEnumTypes"), false).toBool();          const QString trString = codegenConfig.value(QStringLiteral("TranslationSystem")).toString().toLower(); @@ -132,6 +134,7 @@ public:      QStringList sourceIncludes;      QStringList mutators;      QStringList defaultGetters; +    QStringList notifiers;      QString qCategoryLoggingName;      QString headerExtension;      QString sourceExtension; @@ -142,6 +145,7 @@ public:      bool globalEnums;      bool useEnumTypes;      bool itemAccessors; +    bool allNotifiers;      TranslationSystem translationSystem;      QString translationDomain;      bool generateProperties; @@ -2484,6 +2488,10 @@ int main(int argc, char **argv)                  cpp << userTextsFunctions((*itEntry), cfg);              } +            if (cfg.allNotifiers || cfg.notifiers.contains((*itEntry)->name())) { +                cpp << "  " << itemPath(*itEntry, cfg) << "->setWriteFlags(KConfigBase::Notify);" << endl; +            } +              cpp << "  addItem( " << itemPath(*itEntry, cfg);              QString quotedName = (*itEntry)->name();              addQuotes(quotedName); | 
