diff options
| author | Henri Chain <henri.chain@enioka.com> | 2020-02-18 23:21:30 +0100 | 
|---|---|---|
| committer | Henri Chain <henri.chain@enioka.com> | 2020-02-25 15:46:53 +0100 | 
| commit | d218b93a535085c85889164d45a83c3a519f9f4b (patch) | |
| tree | b9c051db2691321c6ef604cd138342b0f3e39fea | |
| parent | c8bf5e96cf2f25bb85330cf2587e2e365e6f0f71 (diff) | |
| download | kconfig-d218b93a535085c85889164d45a83c3a519f9f4b.tar.gz kconfig-d218b93a535085c85889164d45a83c3a519f9f4b.tar.bz2 | |
Fix code generation for entries with min/max
Summary:
- When GenerateProperties and Mutators are activated, the generated code
  did not handle min/max properly
- In the case of a parameterized entry, generated code also did not
  handle min/max
BUG: 418146
Test Plan: - auto tests included
Reviewers: meven, crossi, ervin, bport, tcanabrava
Reviewed By: meven, ervin
Subscribers: kde-frameworks-devel
Tags: #frameworks
Differential Revision: https://phabricator.kde.org/D27497
18 files changed, 445 insertions, 42 deletions
| diff --git a/autotests/kconfig_compiler/CMakeLists.txt b/autotests/kconfig_compiler/CMakeLists.txt index c459243d..93ab9b09 100644 --- a/autotests/kconfig_compiler/CMakeLists.txt +++ b/autotests/kconfig_compiler/CMakeLists.txt @@ -218,6 +218,25 @@ ecm_add_test(${kconfigcompiler_test_signals_SRCS}      LINK_LIBRARIES Qt5::Test KF5::ConfigGui  ) +########### next target ############### + +set(test_properties_minmax_SRCS test_properties_minmax_main.cpp) +gen_kcfg_test_source(test_properties_minmax test_properties_minmax_SRCS GENERATE_MOC) + +ecm_add_test(${test_properties_minmax_SRCS} +    TEST_NAME test-properties-minmax +    LINK_LIBRARIES KF5::ConfigGui +) + +########### next target ############### + +set(test_param_minmax_SRCS test_param_minmax_main.cpp) +gen_kcfg_test_source(test_param_minmax test_param_minmax_SRCS GENERATE_MOC) + +ecm_add_test(${test_param_minmax_SRCS} +    TEST_NAME test-param-minmax +    LINK_LIBRARIES KF5::ConfigGui +)  ########### next target ############### diff --git a/autotests/kconfig_compiler/kconfigcompiler_test.cpp b/autotests/kconfig_compiler/kconfigcompiler_test.cpp index d5b7baa2..e4892e4f 100644 --- a/autotests/kconfig_compiler/kconfigcompiler_test.cpp +++ b/autotests/kconfig_compiler/kconfigcompiler_test.cpp @@ -53,6 +53,8 @@ static CompilerTestSet testCases = {      "test_translation_kde_domain.cpp", "test_translation_kde_domain.h",      "test_translation_qt.cpp", "test_translation_qt.h",      "test_emptyentries.cpp", "test_emptyentries.h", +    "test_properties_minmax.cpp", "test_properties_minmax.h", +    "test_param_minmax.cpp", "test_param_minmax.h",      nullptr  }; @@ -78,6 +80,8 @@ static CompilerTestSet testCasesToRun = {      "test_translation_kde_domain",      "test_translation_qt",      "test_emptyentries", +    "test_properties_minmax", +    "test_param_minmax",      nullptr  }; diff --git a/autotests/kconfig_compiler/test13.cpp.ref b/autotests/kconfig_compiler/test13.cpp.ref index 3fa79b18..c038c93c 100644 --- a/autotests/kconfig_compiler/test13.cpp.ref +++ b/autotests/kconfig_compiler/test13.cpp.ref @@ -14,7 +14,9 @@ Test13::Test13( )    itemPicturesDir = new KConfigSkeleton::ItemUrl( currentGroup(), QStringLiteral( "picturesDir" ), mPicturesDir );    addItem( itemPicturesDir, QStringLiteral( "picturesDir" ) );    KConfigCompilerSignallingItem  *itemBrightness; -  itemBrightness = new KConfigCompilerSignallingItem(new KConfigSkeleton::ItemDouble( currentGroup(), QStringLiteral( "brightness" ), mBrightness ), this, notifyFunction, signalBrightnessChanged); +  KConfigSkeleton::ItemDouble  *innerItemBrightness; +  innerItemBrightness = new KConfigSkeleton::ItemDouble( currentGroup(), QStringLiteral( "brightness" ), mBrightness ); +  itemBrightness = new KConfigCompilerSignallingItem(innerItemBrightness, this, notifyFunction, signalBrightnessChanged);    addItem( itemBrightness, QStringLiteral( "brightness" ) );    KConfigSkeleton::ItemBool  *itemStartsWithUppercase;    itemStartsWithUppercase = new KConfigSkeleton::ItemBool( currentGroup(), QStringLiteral( "StartsWithUppercase" ), mStartsWithUppercase ); diff --git a/autotests/kconfig_compiler/test_param_minmax.cpp.ref b/autotests/kconfig_compiler/test_param_minmax.cpp.ref new file mode 100644 index 00000000..ceb224b2 --- /dev/null +++ b/autotests/kconfig_compiler/test_param_minmax.cpp.ref @@ -0,0 +1,41 @@ +// This file is generated by kconfig_compiler_kf5 from test_param_minmax.kcfg. +// All changes you do to this file will be lost. + +#include "test_param_minmax.h" + +TestParamMinMax::TestParamMinMax( KSharedConfig::Ptr config ) +  : KConfigSkeleton( std::move( config ) ) +{ +  setCurrentGroup( QStringLiteral( "Something" ) ); + +  KConfigSkeleton::ItemDouble  *itemFoo[6]; +  itemFoo[0] = new KConfigSkeleton::ItemDouble( currentGroup(), QStringLiteral( "foo_#0" ), mFoo[0], 1.23 ); +  itemFoo[0]->setMinValue(0.01); +  itemFoo[0]->setMaxValue(89898.23); +  addItem( itemFoo[0], QStringLiteral( "Foo0" ) ); +  itemFoo[1] = new KConfigSkeleton::ItemDouble( currentGroup(), QStringLiteral( "foo_#1" ), mFoo[1], 1.23 ); +  itemFoo[1]->setMinValue(0.01); +  itemFoo[1]->setMaxValue(89898.23); +  addItem( itemFoo[1], QStringLiteral( "Foo1" ) ); +  itemFoo[2] = new KConfigSkeleton::ItemDouble( currentGroup(), QStringLiteral( "foo_#2" ), mFoo[2], 1.23 ); +  itemFoo[2]->setMinValue(0.01); +  itemFoo[2]->setMaxValue(89898.23); +  addItem( itemFoo[2], QStringLiteral( "Foo2" ) ); +  itemFoo[3] = new KConfigSkeleton::ItemDouble( currentGroup(), QStringLiteral( "foo_#3" ), mFoo[3], 1.23 ); +  itemFoo[3]->setMinValue(0.01); +  itemFoo[3]->setMaxValue(89898.23); +  addItem( itemFoo[3], QStringLiteral( "Foo3" ) ); +  itemFoo[4] = new KConfigSkeleton::ItemDouble( currentGroup(), QStringLiteral( "foo_#4" ), mFoo[4], 1.23 ); +  itemFoo[4]->setMinValue(0.01); +  itemFoo[4]->setMaxValue(89898.23); +  addItem( itemFoo[4], QStringLiteral( "Foo4" ) ); +  itemFoo[5] = new KConfigSkeleton::ItemDouble( currentGroup(), QStringLiteral( "foo_#5" ), mFoo[5], 1.23 ); +  itemFoo[5]->setMinValue(0.01); +  itemFoo[5]->setMaxValue(89898.23); +  addItem( itemFoo[5], QStringLiteral( "Foo5" ) ); +} + +TestParamMinMax::~TestParamMinMax() +{ +} + diff --git a/autotests/kconfig_compiler/test_param_minmax.h.ref b/autotests/kconfig_compiler/test_param_minmax.h.ref new file mode 100644 index 00000000..3cc8717c --- /dev/null +++ b/autotests/kconfig_compiler/test_param_minmax.h.ref @@ -0,0 +1,64 @@ +// This file is generated by kconfig_compiler_kf5 from test_param_minmax.kcfg. +// All changes you do to this file will be lost. +#ifndef TESTPARAMMINMAX_H +#define TESTPARAMMINMAX_H + +#include <qglobal.h> +#include <kconfigskeleton.h> +#include <QCoreApplication> +#include <QDebug> + +class TestParamMinMax : public KConfigSkeleton +{ +  public: + +    TestParamMinMax( KSharedConfig::Ptr config = KSharedConfig::openConfig() ); +    ~TestParamMinMax(); + +    /** +      Set foo_#$(myparam) +    */ +    void setFoo( int i, double v ) +    { +      if (v < 0.01) +      { +        qDebug() << "setFoo: value " << v << " is less than the minimum value of 0.01"; +        v = 0.01; +      } + +      if (v > 89898.23) +      { +        qDebug() << "setFoo: value " << v << " is greater than the maximum value of 89898.23"; +        v = 89898.23; +      } + +      if (!isFooImmutable( i )) +        mFoo[i] = v; +    } + +    /** +      Get foo_#$(myparam) +    */ +    double foo( int i ) const +    { +      return mFoo[i]; +    } + +    /** +      Is foo_#$(myparam) Immutable +    */ +    bool isFooImmutable( int i ) const +    { +      return isImmutable( QStringLiteral( "Foo%1" ).arg( i ) ); +    } + +  protected: + +    // Something +    double mFoo[6]; + +  private: +}; + +#endif + diff --git a/autotests/kconfig_compiler/test_param_minmax.kcfg b/autotests/kconfig_compiler/test_param_minmax.kcfg new file mode 100644 index 00000000..32046fd3 --- /dev/null +++ b/autotests/kconfig_compiler/test_param_minmax.kcfg @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Author: Henri Chain --> +<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 arg="true"/> +  <group name="Something"> +    <entry name="Foo$(myparam)" type="double" key="foo_#$(myparam)"> +      <parameter name="myparam" type="Int" max="5"/> +      <default>1.23</default> +      <min>0.01</min> +      <max>89898.23</max> +    </entry> +  </group> +</kcfg> + diff --git a/autotests/kconfig_compiler/test_param_minmax.kcfgc b/autotests/kconfig_compiler/test_param_minmax.kcfgc new file mode 100644 index 00000000..3d9d2768 --- /dev/null +++ b/autotests/kconfig_compiler/test_param_minmax.kcfgc @@ -0,0 +1,4 @@ +ClassName=TestParamMinMax +File=test_param_minmax.kcfgc +Mutators=true + diff --git a/autotests/kconfig_compiler/test_param_minmax_main.cpp b/autotests/kconfig_compiler/test_param_minmax_main.cpp new file mode 100644 index 00000000..57fc26a7 --- /dev/null +++ b/autotests/kconfig_compiler/test_param_minmax_main.cpp @@ -0,0 +1,29 @@ +/* +Copyright (c) 2020 Henri chain <henri.chain@enioka.com> + +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_param_minmax.h" + +int main(int, char **) +{ +    TestParamMinMax *t = new TestParamMinMax(); +    delete t; +    return 0; +} + diff --git a/autotests/kconfig_compiler/test_properties_minmax.cpp.ref b/autotests/kconfig_compiler/test_properties_minmax.cpp.ref new file mode 100644 index 00000000..1736889b --- /dev/null +++ b/autotests/kconfig_compiler/test_properties_minmax.cpp.ref @@ -0,0 +1,35 @@ +// This file is generated by kconfig_compiler_kf5 from test_properties_minmax.kcfg. +// All changes you do to this file will be lost. + +#include "test_properties_minmax.h" + +TestPropertiesMinMax::TestPropertiesMinMax( KSharedConfig::Ptr config ) +  : KConfigSkeleton( std::move( config ) ) +{ +  KConfigCompilerSignallingItem::NotifyFunction notifyFunction = static_cast<KConfigCompilerSignallingItem::NotifyFunction>(&TestPropertiesMinMax::itemChanged); + +  setCurrentGroup( QStringLiteral( "Something" ) ); + +  KConfigCompilerSignallingItem  *itemBar; +  KConfigSkeleton::ItemInt  *innerItemBar; +  innerItemBar = new KConfigSkeleton::ItemInt( currentGroup(), QStringLiteral( "bar" ), mBar, 42 ); +  itemBar = new KConfigCompilerSignallingItem(innerItemBar, this, notifyFunction, signalBarChanged); +  innerItemBar->setMinValue(36); +  innerItemBar->setMaxValue(102); +  addItem( itemBar, QStringLiteral( "bar" ) ); +} + +TestPropertiesMinMax::~TestPropertiesMinMax() +{ +} + + +void TestPropertiesMinMax::itemChanged(quint64 flags) { + +  if ( flags & signalBarChanged ) { +    Q_EMIT barChanged(); +  } +} + +#include "test_properties_minmax.moc" + diff --git a/autotests/kconfig_compiler/test_properties_minmax.h.ref b/autotests/kconfig_compiler/test_properties_minmax.h.ref new file mode 100644 index 00000000..26b79e63 --- /dev/null +++ b/autotests/kconfig_compiler/test_properties_minmax.h.ref @@ -0,0 +1,80 @@ +// This file is generated by kconfig_compiler_kf5 from test_properties_minmax.kcfg. +// All changes you do to this file will be lost. +#ifndef TESTPROPERTIESMINMAX_H +#define TESTPROPERTIESMINMAX_H + +#include <qglobal.h> +#include <kconfigskeleton.h> +#include <QCoreApplication> +#include <QDebug> + +class TestPropertiesMinMax : public KConfigSkeleton +{ +  Q_OBJECT +  public: + +    TestPropertiesMinMax( KSharedConfig::Ptr config = KSharedConfig::openConfig() ); +    ~TestPropertiesMinMax(); + +    /** +      Set bar +    */ +    void setBar( int v ) +    { +      if (v < 36) +      { +        qDebug() << "setBar: value " << v << " is less than the minimum value of 36"; +        v = 36; +      } + +      if (v > 102) +      { +        qDebug() << "setBar: value " << v << " is greater than the maximum value of 102"; +        v = 102; +      } + +      if (v != mBar && !isBarImmutable()) { +        mBar = v; +        Q_EMIT barChanged(); +      } +    } + +    Q_PROPERTY(int bar READ bar WRITE setBar NOTIFY barChanged) +    Q_PROPERTY(bool isBarImmutable CONSTANT) +    /** +      Get bar +    */ +    int bar() const +    { +      return mBar; +    } + +    /** +      Is bar Immutable +    */ +    bool isBarImmutable() const +    { +      return isImmutable( QStringLiteral( "bar" ) ); +    } + + +    enum { +      signalBarChanged = 0x1 +    }; + +  Q_SIGNALS: +    void barChanged(); + +  private: +    void itemChanged(quint64 flags); + +  protected: + +    // Something +    int mBar; + +  private: +}; + +#endif + diff --git a/autotests/kconfig_compiler/test_properties_minmax.kcfg b/autotests/kconfig_compiler/test_properties_minmax.kcfg new file mode 100644 index 00000000..621a793a --- /dev/null +++ b/autotests/kconfig_compiler/test_properties_minmax.kcfg @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Author: Henri Chain --> +<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 arg="true"/> +  <group name="Something"> +    <entry name="bar" type="Int"> +      <default>42</default> +      <min>36</min> +      <max>102</max> +    </entry> +  </group> +</kcfg> diff --git a/autotests/kconfig_compiler/test_properties_minmax.kcfgc b/autotests/kconfig_compiler/test_properties_minmax.kcfgc new file mode 100644 index 00000000..5cda329b --- /dev/null +++ b/autotests/kconfig_compiler/test_properties_minmax.kcfgc @@ -0,0 +1,5 @@ +ClassName=TestPropertiesMinMax +GenerateProperties=true +File=test_properties_minmax.kcfgc +Mutators=true + diff --git a/autotests/kconfig_compiler/test_properties_minmax_main.cpp b/autotests/kconfig_compiler/test_properties_minmax_main.cpp new file mode 100644 index 00000000..6d789718 --- /dev/null +++ b/autotests/kconfig_compiler/test_properties_minmax_main.cpp @@ -0,0 +1,28 @@ +/* +Copyright (c) 2020 Henri Chain <henri.chain@enioka.com> + +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_properties_minmax.h" + +int main(int, char **) +{ +    TestPropertiesMinMax *t = new TestPropertiesMinMax(); +    delete t; +    return 0; +} diff --git a/autotests/kconfig_compiler/test_signal.cpp.ref b/autotests/kconfig_compiler/test_signal.cpp.ref index be06a745..71ab7a09 100644 --- a/autotests/kconfig_compiler/test_signal.cpp.ref +++ b/autotests/kconfig_compiler/test_signal.cpp.ref @@ -37,16 +37,24 @@ TestSignal::TestSignal( )    setCurrentGroup( QStringLiteral( "Appearance" ) );    KConfigCompilerSignallingItem  *itemEmoticonTheme; -  itemEmoticonTheme = new KConfigCompilerSignallingItem(new KConfigSkeleton::ItemString( currentGroup(), QStringLiteral( "emoticonTheme" ), mEmoticonTheme, QStringLiteral( "Default" ) ), this, notifyFunction, signalEmoticonSettingsChanged); +  KConfigSkeleton::ItemString  *innerItemEmoticonTheme; +  innerItemEmoticonTheme = new KConfigSkeleton::ItemString( currentGroup(), QStringLiteral( "emoticonTheme" ), mEmoticonTheme, QStringLiteral( "Default" ) ); +  itemEmoticonTheme = new KConfigCompilerSignallingItem(innerItemEmoticonTheme, this, notifyFunction, signalEmoticonSettingsChanged);    addItem( itemEmoticonTheme, QStringLiteral( "emoticonTheme" ) );    KConfigCompilerSignallingItem  *itemUseEmoticon; -  itemUseEmoticon = new KConfigCompilerSignallingItem(new KConfigSkeleton::ItemBool( currentGroup(), QStringLiteral( "useEmoticon" ), mUseEmoticon, true ), this, notifyFunction, signalEmoticonSettingsChanged); +  KConfigSkeleton::ItemBool  *innerItemUseEmoticon; +  innerItemUseEmoticon = new KConfigSkeleton::ItemBool( currentGroup(), QStringLiteral( "useEmoticon" ), mUseEmoticon, true ); +  itemUseEmoticon = new KConfigCompilerSignallingItem(innerItemUseEmoticon, this, notifyFunction, signalEmoticonSettingsChanged);    addItem( itemUseEmoticon, QStringLiteral( "useEmoticon" ) );    KConfigCompilerSignallingItem  *itemEmoticonRequireSpace; -  itemEmoticonRequireSpace = new KConfigCompilerSignallingItem(new KConfigSkeleton::ItemBool( currentGroup(), QStringLiteral( "emoticonRequireSpace" ), mEmoticonRequireSpace, true ), this, notifyFunction, signalEmoticonSettingsChanged); +  KConfigSkeleton::ItemBool  *innerItemEmoticonRequireSpace; +  innerItemEmoticonRequireSpace = new KConfigSkeleton::ItemBool( currentGroup(), QStringLiteral( "emoticonRequireSpace" ), mEmoticonRequireSpace, true ); +  itemEmoticonRequireSpace = new KConfigCompilerSignallingItem(innerItemEmoticonRequireSpace, this, notifyFunction, signalEmoticonSettingsChanged);    addItem( itemEmoticonRequireSpace, QStringLiteral( "emoticonRequireSpace" ) );    KConfigCompilerSignallingItem  *itemStylePath; -  itemStylePath = new KConfigCompilerSignallingItem(new KConfigSkeleton::ItemString( currentGroup(), QStringLiteral( "stylePath" ), mStylePath ), this, notifyFunction, signalStyleChanged); +  KConfigSkeleton::ItemString  *innerItemStylePath; +  innerItemStylePath = new KConfigSkeleton::ItemString( currentGroup(), QStringLiteral( "stylePath" ), mStylePath ); +  itemStylePath = new KConfigCompilerSignallingItem(innerItemStylePath, this, notifyFunction, signalStyleChanged);    addItem( itemStylePath, QStringLiteral( "stylePath" ) );    KConfigSkeleton::ItemString  *itemStyleCSSVariant;    itemStyleCSSVariant = new KConfigSkeleton::ItemString( currentGroup(), QStringLiteral( "styleVariant" ), mStyleCSSVariant ); diff --git a/src/kconfig_compiler/KConfigCommonStructs.h b/src/kconfig_compiler/KConfigCommonStructs.h index 71bf666e..06c8b80f 100644 --- a/src/kconfig_compiler/KConfigCommonStructs.h +++ b/src/kconfig_compiler/KConfigCommonStructs.h @@ -155,6 +155,11 @@ QString varPath(const QString &n, const KConfigParameters &cfg);  // like using d-> in case of dpointer  QString itemVar(const CfgEntry *e, const KConfigParameters &cfg); +// returns the name of the local inner item if there is one +// (before wrapping with KConfigCompilerSignallingItem) +// Otherwise return itemVar() +QString innerItemVar(const CfgEntry *e, const KConfigParameters &cfg); +  QString itemPath(const CfgEntry *e, const KConfigParameters &cfg);  QString filenameOnly(const QString &path); @@ -170,9 +175,16 @@ QString translatedString(  // TODO: Sanitize those functions.  QString newItem( -    const CfgEntry* entry,  +    const CfgEntry *entry, +    const QString &key, +    const QString &defaultValue, +    const KConfigParameters &cfg, +    const QString ¶m = QString()); + +QString newInnerItem( +    const CfgEntry *entry,      const QString &key, -    const QString& defaultValue, +    const QString &defaultValue,      const KConfigParameters &cfg,      const QString ¶m = QString()); diff --git a/src/kconfig_compiler/KConfigSourceGenerator.cpp b/src/kconfig_compiler/KConfigSourceGenerator.cpp index 63f5b6b4..33e0ed69 100644 --- a/src/kconfig_compiler/KConfigSourceGenerator.cpp +++ b/src/kconfig_compiler/KConfigSourceGenerator.cpp @@ -313,14 +313,21 @@ void KConfigSourceGenerator::createEnums(const CfgEntry *entry)  void KConfigSourceGenerator::createNormalEntry(const CfgEntry *entry, const QString &key)  { -   stream() << "  " << itemPath(entry, cfg()) << " = " +    const QString innerItemVarStr = innerItemVar(entry, cfg()); +    if (!entry->signalList.isEmpty()) { +        stream() << "  " << innerItemVarStr << " = " +            << newInnerItem(entry, key, entry->defaultValue, cfg()) << '\n'; +    } + +    stream() << "  " << itemPath(entry, cfg()) << " = "          << newItem(entry, key, entry->defaultValue, cfg()) << '\n';      if (!entry->min.isEmpty()) { -        stream() << "  " << itemPath(entry, cfg()) << "->setMinValue(" << entry->min << ");\n"; +        stream() << "  " << innerItemVarStr << "->setMinValue(" << entry->min << ");\n";      } +      if (!entry->max.isEmpty()) { -        stream() << "  " << itemPath(entry, cfg()) << "->setMaxValue(" << entry->max << ");\n"; +        stream() << "  " << innerItemVarStr << "->setMaxValue(" << entry->max << ");\n";      }      if (cfg().setUserTexts) { @@ -343,14 +350,29 @@ void KConfigSourceGenerator::createNormalEntry(const CfgEntry *entry, const QStr  void KConfigSourceGenerator::createIndexedEntry(const CfgEntry *entry, const QString &key)  {      for (int i = 0; i <= entry->paramMax; i++) { -        QString itemVarStr(itemPath(entry, cfg()) + QStringLiteral("[%1]").arg(i)); +        const QString argBracket = QStringLiteral("[%1]").arg(i); +        const QString innerItemVarStr = innerItemVar(entry, cfg()) + argBracket; + +        const QString defaultStr = !entry->paramDefaultValues[i].isEmpty() +            ? entry->paramDefaultValues[i] +            : !entry->defaultValue.isEmpty() ? paramString(entry->defaultValue, entry, i) : defaultValue(entry->type); + +        if (!entry->signalList.isEmpty()) { +            stream() << "  " << innerItemVarStr << " = " +                     << newInnerItem(entry, paramString(key, entry, i), defaultStr, cfg(), argBracket) << '\n'; +        } + +        const QString itemVarStr = itemPath(entry, cfg()) + argBracket; -        QString defaultStr = !entry->paramDefaultValues[i].isEmpty() ? entry->paramDefaultValues[i] -                           : !entry->defaultValue.isEmpty() ? paramString(entry->defaultValue, entry, i) -                           : defaultValue(entry->type); -                  stream() << "  " << itemVarStr << " = " -            << newItem(entry, paramString(key, entry, i), defaultStr, cfg(), QStringLiteral("[%1]").arg(i)) << '\n'; +                 << newItem(entry, paramString(key, entry, i), defaultStr, cfg(), argBracket) << '\n'; + +        if (!entry->min.isEmpty()) { +            stream() << "  " << innerItemVarStr << "->setMinValue(" << entry->min << ");\n"; +        } +        if (!entry->max.isEmpty()) { +            stream() << "  " << innerItemVarStr << "->setMaxValue(" << entry->max << ");\n"; +        }          if (cfg().setUserTexts) {              stream() << userTextsFunctions(entry, cfg(), itemVarStr, entry->paramName); @@ -366,7 +388,7 @@ void KConfigSourceGenerator::createIndexedEntry(const CfgEntry *entry, const QSt          QString paramName = entry->paramName;          stream() << "  addItem( " << itemVarStr << ", QStringLiteral( \""; -        stream() << paramName.replace(QStringLiteral("$(") + entry->param + QLatin1Char(')'), QLatin1String("%1")).arg( arg ); +        stream() << paramName.replace(QStringLiteral("$(") + entry->param + QLatin1Char(')'), QLatin1String("%1")).arg(arg);          stream() << "\" ) );\n";      }  } @@ -440,9 +462,7 @@ void KConfigSourceGenerator::doConstructor()          }          createEnums(entry); -        if (!cfg().dpointer) { -            stream() << itemDeclaration(entry, cfg()); -        } +        stream() << itemDeclaration(entry, cfg());          if (entry->param.isEmpty()) {              createNormalEntry(entry, key); diff --git a/src/kconfig_compiler/KConfigXmlParser.cpp b/src/kconfig_compiler/KConfigXmlParser.cpp index b403dbd5..2f31beb9 100644 --- a/src/kconfig_compiler/KConfigXmlParser.cpp +++ b/src/kconfig_compiler/KConfigXmlParser.cpp @@ -362,7 +362,6 @@ CfgEntry *KConfigXmlParser::parseEntry(const QString &group, const QDomElement &      readGroupElements(readEntry, element); -    createChangedSignal(readEntry);      validateNameAndKey(readEntry, element);      if (readEntry.label.isEmpty()) { @@ -431,6 +430,7 @@ CfgEntry *KConfigXmlParser::parseEntry(const QString &group, const QDomElement &      }      result->min = readEntry.min;      result->max = readEntry.max; +    createChangedSignal(*result);      return result;  } diff --git a/src/kconfig_compiler/kconfig_compiler.cpp b/src/kconfig_compiler/kconfig_compiler.cpp index 989e2609..4e76f375 100644 --- a/src/kconfig_compiler/kconfig_compiler.cpp +++ b/src/kconfig_compiler/kconfig_compiler.cpp @@ -394,21 +394,23 @@ QString itemType(const QString &type)  QString itemDeclaration(const CfgEntry *e, const KConfigParameters &cfg)  { -    if (cfg.itemAccessors) { -        return QString(); +    const QString type = cfg.inherits + "::Item" + itemType(e->type); + +    QString fCap = e->name; +    fCap[0] = fCap[0].toUpper(); +    const QString argSuffix = (!e->param.isEmpty()) ? (QStringLiteral("[%1]").arg(e->paramMax + 1)) : QString(); +    QString result; + +    if (!cfg.itemAccessors && !cfg.dpointer) { +        result += "  " + (!e->signalList.isEmpty() ? QStringLiteral("KConfigCompilerSignallingItem") : type) + +            "  *item" + fCap + argSuffix + ";\n";      } -    QString type;      if (!e->signalList.isEmpty()) { -        type = QStringLiteral("KConfigCompilerSignallingItem"); -    } else { -        type = cfg.inherits + "::Item" + itemType(e->type); +        result += "  " + type + "  *" + innerItemVar(e, cfg) + argSuffix + ";\n";      } -    QString fCap = e->name; -    fCap[0] = fCap[0].toUpper(); -    return "  " + type + "  *item" + fCap + -            ( (!e->param.isEmpty())?(QStringLiteral("[%1]").arg(e->paramMax+1)) : QString()) + ";\n"; +    return result;  }  // returns the name of an item variable @@ -432,6 +434,20 @@ QString itemVar(const CfgEntry *e, const KConfigParameters &cfg)      return result;  } +// returns the name of the local inner item if there is one +// (before wrapping with KConfigCompilerSignallingItem) +// Otherwise return itemVar() +QString innerItemVar(const CfgEntry *e, const KConfigParameters &cfg) +{ +    if (e->signalList.isEmpty()) { +        return itemVar(e, cfg); +    } else { +        QString result = "innerItem" + e->name; +        result[9] = result[9].toUpper(); +        return result; +    } +} +  QString itemPath(const CfgEntry *e, const KConfigParameters &cfg)  {      QString result; @@ -443,15 +459,9 @@ QString itemPath(const CfgEntry *e, const KConfigParameters &cfg)      return result;  } -QString newItem(const CfgEntry* entry, const QString &key, const QString& defaultValue, +QString newInnerItem(const CfgEntry *entry, const QString &key, const QString &defaultValue,                  const KConfigParameters &cfg, const QString ¶m) { - -    QList<Signal> sigs = entry->signalList; -    QString t; -    if (!sigs.isEmpty()) { -        t += QLatin1String("new KConfigCompilerSignallingItem("); -    } -    t += "new "+ cfg.inherits + "::Item" + itemType(entry->type) + "( currentGroup(), " +    QString t = "new "+ cfg.inherits + "::Item" + itemType(entry->type) + "( currentGroup(), "              + key + ", " + varPath( entry->name, cfg ) + param;      if (entry->type == QLatin1String("Enum")) { @@ -460,9 +470,18 @@ QString newItem(const CfgEntry* entry, const QString &key, const QString& defaul      if (!defaultValue.isEmpty()) {          t += QLatin1String(", ") + defaultValue;      } -    t += QLatin1String(" )"); +    t += QLatin1String(" );"); + +    return t; +} + +QString newItem(const CfgEntry *entry, const QString &key, const QString &defaultValue, +                const KConfigParameters &cfg, const QString ¶m) { +    QList<Signal> sigs = entry->signalList; +    QString t;      if (!sigs.isEmpty()) { +        t += QLatin1String("new KConfigCompilerSignallingItem(") + innerItemVar(entry, cfg) + param;          t += QLatin1String(", this, notifyFunction, ");          //append the signal flags          for (int i = 0; i < sigs.size(); ++i) { @@ -470,9 +489,10 @@ QString newItem(const CfgEntry* entry, const QString &key, const QString& defaul                  t += QLatin1String(" | ");              t += signalEnumName(sigs[i].name);          } -        t += QLatin1String(")"); +        t += QLatin1String(");"); +    } else { +        t += newInnerItem(entry, key, defaultValue, cfg, param);      } -    t += QLatin1String(";");      return t;  } | 
