diff --git a/autotests/kconfig_compiler/CMakeLists.txt b/autotests/kconfig_compiler/CMakeLists.txt --- a/autotests/kconfig_compiler/CMakeLists.txt +++ b/autotests/kconfig_compiler/CMakeLists.txt @@ -218,6 +218,25 @@ 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 --- a/autotests/kconfig_compiler/kconfigcompiler_test.cpp +++ b/autotests/kconfig_compiler/kconfigcompiler_test.cpp @@ -53,6 +53,8 @@ "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 @@ "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 --- a/autotests/kconfig_compiler/test13.cpp.ref +++ b/autotests/kconfig_compiler/test13.cpp.ref @@ -14,7 +14,9 @@ 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.h.ref b/autotests/kconfig_compiler/test_param_minmax.h.ref new file mode 100644 --- /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 +#include +#include +#include + +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.cpp.ref b/autotests/kconfig_compiler/test_param_minmax.cpp.ref new file mode 100644 --- /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.kcfg b/autotests/kconfig_compiler/test_param_minmax.kcfg new file mode 100644 --- /dev/null +++ b/autotests/kconfig_compiler/test_param_minmax.kcfg @@ -0,0 +1,17 @@ + + + + + + + + 1.23 + 0.01 + 89898.23 + + + + diff --git a/autotests/kconfig_compiler/test_param_minmax.kcfgc b/autotests/kconfig_compiler/test_param_minmax.kcfgc new file mode 100644 --- /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 --- /dev/null +++ b/autotests/kconfig_compiler/test_param_minmax_main.cpp @@ -0,0 +1,29 @@ +/* +Copyright (c) 2020 Henri chain + +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.h.ref b/autotests/kconfig_compiler/test_properties_minmax.h.ref new file mode 100644 --- /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 +#include +#include +#include + +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.cpp.ref b/autotests/kconfig_compiler/test_properties_minmax.cpp.ref new file mode 100644 --- /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(&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.kcfg b/autotests/kconfig_compiler/test_properties_minmax.kcfg new file mode 100644 --- /dev/null +++ b/autotests/kconfig_compiler/test_properties_minmax.kcfg @@ -0,0 +1,15 @@ + + + + + + + 42 + 36 + 102 + + + diff --git a/autotests/kconfig_compiler/test_properties_minmax.kcfgc b/autotests/kconfig_compiler/test_properties_minmax.kcfgc new file mode 100644 --- /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 --- /dev/null +++ b/autotests/kconfig_compiler/test_properties_minmax_main.cpp @@ -0,0 +1,28 @@ +/* +Copyright (c) 2020 Henri Chain + +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 --- a/autotests/kconfig_compiler/test_signal.cpp.ref +++ b/autotests/kconfig_compiler/test_signal.cpp.ref @@ -37,16 +37,24 @@ 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 --- a/src/kconfig_compiler/KConfigCommonStructs.h +++ b/src/kconfig_compiler/KConfigCommonStructs.h @@ -155,6 +155,11 @@ // 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 @@ // 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 --- a/src/kconfig_compiler/KConfigSourceGenerator.cpp +++ b/src/kconfig_compiler/KConfigSourceGenerator.cpp @@ -313,14 +313,21 @@ 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::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 @@ 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 @@ } 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 --- a/src/kconfig_compiler/KConfigXmlParser.cpp +++ b/src/kconfig_compiler/KConfigXmlParser.cpp @@ -362,7 +362,6 @@ readGroupElements(readEntry, element); - createChangedSignal(readEntry); validateNameAndKey(readEntry, element); if (readEntry.label.isEmpty()) { @@ -431,6 +430,7 @@ } 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 --- a/src/kconfig_compiler/kconfig_compiler.cpp +++ b/src/kconfig_compiler/kconfig_compiler.cpp @@ -394,21 +394,23 @@ 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 @@ 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,36 +459,40 @@ 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 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")) { t += ", values" + entry->name; } 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 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) { if (i != 0) t += QLatin1String(" | "); t += signalEnumName(sigs[i].name); } - t += QLatin1String(")"); + t += QLatin1String(");"); + } else { + t += newInnerItem(entry, key, defaultValue, cfg, param); } - t += QLatin1String(";"); return t; }