diff options
-rw-r--r-- | autotests/kconfig_compiler/CMakeLists.txt | 10 | ||||
-rw-r--r-- | autotests/kconfig_compiler/kconfigcompiler_test.cpp | 2 | ||||
-rw-r--r-- | autotests/kconfig_compiler/test_subgroups.cpp.ref | 47 | ||||
-rw-r--r-- | autotests/kconfig_compiler/test_subgroups.h.ref | 102 | ||||
-rw-r--r-- | autotests/kconfig_compiler/test_subgroups.kcfg | 31 | ||||
-rw-r--r-- | autotests/kconfig_compiler/test_subgroups.kcfgc | 3 | ||||
-rw-r--r-- | autotests/kconfig_compiler/test_subgroups_main.cpp | 32 | ||||
-rw-r--r-- | src/kconfig_compiler/KConfigCommonStructs.h | 1 | ||||
-rw-r--r-- | src/kconfig_compiler/KConfigSourceGenerator.cpp | 30 | ||||
-rw-r--r-- | src/kconfig_compiler/KConfigSourceGenerator.h | 1 | ||||
-rw-r--r-- | src/kconfig_compiler/KConfigXmlParser.cpp | 8 | ||||
-rw-r--r-- | src/kconfig_compiler/KConfigXmlParser.h | 2 | ||||
-rw-r--r-- | src/kconfig_compiler/kcfg.xsd | 1 |
13 files changed, 265 insertions, 5 deletions
diff --git a/autotests/kconfig_compiler/CMakeLists.txt b/autotests/kconfig_compiler/CMakeLists.txt index 2b31a4da..2a4b343b 100644 --- a/autotests/kconfig_compiler/CMakeLists.txt +++ b/autotests/kconfig_compiler/CMakeLists.txt @@ -181,6 +181,16 @@ target_link_libraries(test_emptyentries KF5::ConfigGui) ########### next target ############### +set(test_subgroups_SRCS test_subgroups_main.cpp ) + +gen_kcfg_test_source(test_subgroups test_subgroups_SRCS GENERATE_MOC) + +ecm_add_test(TEST_NAME test_subgroups ${test_subgroups_SRCS}) +target_link_libraries(test_subgroups KF5::ConfigGui) + + +########### next target ############### + set(test_dpointer_SRCS test_dpointer_main.cpp ) gen_kcfg_test_source(test_dpointer test_dpointer_SRCS) diff --git a/autotests/kconfig_compiler/kconfigcompiler_test.cpp b/autotests/kconfig_compiler/kconfigcompiler_test.cpp index dc848f9d..bb4dd7c0 100644 --- a/autotests/kconfig_compiler/kconfigcompiler_test.cpp +++ b/autotests/kconfig_compiler/kconfigcompiler_test.cpp @@ -48,6 +48,7 @@ static CompilerTestSet testCases = { "test_emptyentries.cpp", "test_emptyentries.h", "test_properties_minmax.cpp", "test_properties_minmax.h", "test_param_minmax.cpp", "test_param_minmax.h", + "test_subgroups.cpp", "test_subgroups.h", nullptr }; @@ -75,6 +76,7 @@ static CompilerTestSet testCasesToRun = { "test_emptyentries", "test_properties_minmax", "test_param_minmax", + "test_subgroups", nullptr }; diff --git a/autotests/kconfig_compiler/test_subgroups.cpp.ref b/autotests/kconfig_compiler/test_subgroups.cpp.ref new file mode 100644 index 00000000..0c16742a --- /dev/null +++ b/autotests/kconfig_compiler/test_subgroups.cpp.ref @@ -0,0 +1,47 @@ +// This file is generated by kconfig_compiler_kf5 from test_subgroups.kcfg. +// All changes you do to this file will be lost. + +#include "test_subgroups.h" + +TestSubgroups::TestSubgroups( const QString & GeneralGroup, const QString & SubGroup, const QString & AnotherSubGroup ) + : KConfigSkeleton( QStringLiteral( "kconfig_compiler_kf5_test_rc" ) ) + , mParamGeneralGroup(GeneralGroup) + , mParamSubGroup(SubGroup) + , mParamAnotherSubGroup(AnotherSubGroup) +{ + KConfigGroup cgGeneralGroup(this->config(), QStringLiteral( "%1" ).arg( mParamGeneralGroup )); + KConfigGroup cgSubGroup = cgGeneralGroup.group(QStringLiteral( "%1" ).arg( mParamSubGroup )); + KConfigSkeleton::ItemBool *itemFoo; + itemFoo = new KConfigSkeleton::ItemBool( currentGroup(), QStringLiteral( "Foo" ), mFoo, true ); + itemFoo->setWriteFlags(KConfigBase::Notify); + itemFoo->setGroup(cgSubGroup); + addItem( itemFoo, QStringLiteral( "Foo" ) ); + + KConfigGroup cgother = cgGeneralGroup.group(QStringLiteral( "other" )); + KConfigSkeleton::ItemInt *itemBar; + itemBar = new KConfigSkeleton::ItemInt( currentGroup(), QStringLiteral( "Bar" ), mBar, 42 ); + itemBar->setWriteFlags(KConfigBase::Notify); + itemBar->setGroup(cgother); + addItem( itemBar, QStringLiteral( "Bar" ) ); + + KConfigGroup cgParentGroup(this->config(), QStringLiteral( "ParentGroup" )); + KConfigGroup cgAnotherSubGroup = cgParentGroup.group(QStringLiteral( "%1" ).arg( mParamAnotherSubGroup )); + KConfigSkeleton::ItemBool *itemBaz; + itemBaz = new KConfigSkeleton::ItemBool( currentGroup(), QStringLiteral( "Baz" ), mBaz, true ); + itemBaz->setWriteFlags(KConfigBase::Notify); + itemBaz->setGroup(cgAnotherSubGroup); + addItem( itemBaz, QStringLiteral( "Baz" ) ); + + KConfigGroup cgSimpleParentGroup(this->config(), QStringLiteral( "SimpleParentGroup" )); + KConfigGroup cgSimpleGroup = cgSimpleParentGroup.group(QStringLiteral( "SimpleGroup" )); + KConfigSkeleton::ItemBool *itemFoobar; + itemFoobar = new KConfigSkeleton::ItemBool( currentGroup(), QStringLiteral( "Foobar" ), mFoobar, true ); + itemFoobar->setWriteFlags(KConfigBase::Notify); + itemFoobar->setGroup(cgSimpleGroup); + addItem( itemFoobar, QStringLiteral( "Foobar" ) ); +} + +TestSubgroups::~TestSubgroups() +{ +} + diff --git a/autotests/kconfig_compiler/test_subgroups.h.ref b/autotests/kconfig_compiler/test_subgroups.h.ref new file mode 100644 index 00000000..11665710 --- /dev/null +++ b/autotests/kconfig_compiler/test_subgroups.h.ref @@ -0,0 +1,102 @@ +// This file is generated by kconfig_compiler_kf5 from test_subgroups.kcfg. +// All changes you do to this file will be lost. +#ifndef TESTSUBGROUPS_H +#define TESTSUBGROUPS_H + +#include <kconfigskeleton.h> +#include <QCoreApplication> +#include <QDebug> + +class TestSubgroups : public KConfigSkeleton +{ + public: + + TestSubgroups( const QString & GeneralGroup, const QString & SubGroup, const QString & AnotherSubGroup ); + ~TestSubgroups(); + + /** + Get Foo + */ + bool foo() const + { + return mFoo; + } + + /** + Is Foo Immutable + */ + bool isFooImmutable() const + { + return isImmutable( QStringLiteral( "Foo" ) ); + } + + /** + Get Bar + */ + int bar() const + { + return mBar; + } + + /** + Is Bar Immutable + */ + bool isBarImmutable() const + { + return isImmutable( QStringLiteral( "Bar" ) ); + } + + /** + Get Baz + */ + bool baz() const + { + return mBaz; + } + + /** + Is Baz Immutable + */ + bool isBazImmutable() const + { + return isImmutable( QStringLiteral( "Baz" ) ); + } + + /** + Get Foobar + */ + bool foobar() const + { + return mFoobar; + } + + /** + Is Foobar Immutable + */ + bool isFoobarImmutable() const + { + return isImmutable( QStringLiteral( "Foobar" ) ); + } + + protected: + QString mParamGeneralGroup; + QString mParamSubGroup; + QString mParamAnotherSubGroup; + + // $(SubGroup) + bool mFoo; + + // other + int mBar; + + // $(AnotherSubGroup) + bool mBaz; + + // SimpleGroup + bool mFoobar; + + private: +}; + +#endif + diff --git a/autotests/kconfig_compiler/test_subgroups.kcfg b/autotests/kconfig_compiler/test_subgroups.kcfg new file mode 100644 index 00000000..aa4ef948 --- /dev/null +++ b/autotests/kconfig_compiler/test_subgroups.kcfg @@ -0,0 +1,31 @@ +<?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="kconfig_compiler_kf5_test_rc"> + <parameter name="GeneralGroup" /> + <parameter name="SubGroup"/> + <parameter name="AnotherSubGroup"/> + </kcfgfile> + <group name="$(SubGroup)" parentGroupName="$(GeneralGroup)"> + <entry name="Foo" type="Bool"> + <default>true</default> + </entry> + </group> + <group name="other" parentGroupName="$(GeneralGroup)"> + <entry name="Bar" type="Int"> + <default>42</default> + </entry> + </group> + <group name="$(AnotherSubGroup)" parentGroupName="ParentGroup"> + <entry name="Baz" type="Bool"> + <default>true</default> + </entry> + </group> + <group name="SimpleGroup" parentGroupName="SimpleParentGroup"> + <entry name="Foobar" type="Bool"> + <default>true</default> + </entry> + </group> +</kcfg> diff --git a/autotests/kconfig_compiler/test_subgroups.kcfgc b/autotests/kconfig_compiler/test_subgroups.kcfgc new file mode 100644 index 00000000..971964b3 --- /dev/null +++ b/autotests/kconfig_compiler/test_subgroups.kcfgc @@ -0,0 +1,3 @@ +File=test_subgroups.kcfg +ClassName=TestSubgroups +Notifiers=true diff --git a/autotests/kconfig_compiler/test_subgroups_main.cpp b/autotests/kconfig_compiler/test_subgroups_main.cpp new file mode 100644 index 00000000..d034859c --- /dev/null +++ b/autotests/kconfig_compiler/test_subgroups_main.cpp @@ -0,0 +1,32 @@ +/* + This file is part of KDE. + + Copyright (C) 2020 Cyril Rossi <cyril.rossi@enioka.com> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "test_subgroups.h" +#include <QGuiApplication> + +int main(int argc, char **argv) +{ + QGuiApplication app(argc, argv); + Q_UNUSED(app); + TestSubgroups *t = new TestSubgroups(QStringLiteral("General"), QStringLiteral("Sub"), QStringLiteral("AnotherSub")); + delete t; + return 0; +} diff --git a/src/kconfig_compiler/KConfigCommonStructs.h b/src/kconfig_compiler/KConfigCommonStructs.h index 70249d47..8ed1d22f 100644 --- a/src/kconfig_compiler/KConfigCommonStructs.h +++ b/src/kconfig_compiler/KConfigCommonStructs.h @@ -83,6 +83,7 @@ public: public: QString group; + QString parentGroup; QString type; QString key; QString name; diff --git a/src/kconfig_compiler/KConfigSourceGenerator.cpp b/src/kconfig_compiler/KConfigSourceGenerator.cpp index 0da8d4df..bb2694b2 100644 --- a/src/kconfig_compiler/KConfigSourceGenerator.cpp +++ b/src/kconfig_compiler/KConfigSourceGenerator.cpp @@ -333,6 +333,10 @@ void KConfigSourceGenerator::createNormalEntry(const CfgEntry *entry, const QStr } } + if (!entry->parentGroup.isEmpty()) { + stream() << " " << itemVarStr << "->setGroup(cg" << QString(entry->group).remove(QRegExp(QStringLiteral("\\W"))) << ");\n"; + } + stream() << " addItem( " << itemVarStr; QString quotedName = entry->name; addQuotes(quotedName); @@ -342,6 +346,11 @@ void KConfigSourceGenerator::createNormalEntry(const CfgEntry *entry, const QStr stream() << " );\n"; } +// TODO : Some compiler option won't work or generate bogus settings file. +// * Does not manage properly Notifiers=true kcfgc option for parameterized entries : +// ** KConfigCompilerSignallingItem generated with wrong userData parameter (4th one). +// ** setWriteFlags() is missing. +// * Q_PROPERTY signal won't work void KConfigSourceGenerator::createIndexedEntry(const CfgEntry *entry, const QString &key) { for (int i = 0; i <= entry->paramMax; i++) { @@ -410,8 +419,25 @@ void KConfigSourceGenerator::handleCurrentGroupChange(const CfgEntry *entry) } mCurrentGroup = entry->group; - stream() << " setCurrentGroup( " << paramString(mCurrentGroup, parseResult.parameters) << " );"; - stream() << "\n\n"; + + if (!entry->parentGroup.isEmpty()) { + QString parentGroup = QString(entry->parentGroup).remove(QRegExp(QStringLiteral("\\W"))); + if (!mConfigGroupList.contains(parentGroup)) { + stream() << " KConfigGroup cg" << parentGroup + << "(this->config(), " << paramString(entry->parentGroup, parseResult.parameters) << ");\n"; + mConfigGroupList << parentGroup; + } + QString currentGroup = QString(mCurrentGroup).remove(QRegExp(QStringLiteral("\\W"))); + if (!mConfigGroupList.contains(currentGroup)) { + stream() << " KConfigGroup cg" << currentGroup + << " = cg" << QString(entry->parentGroup).remove(QRegExp(QStringLiteral("\\W"))) + << ".group(" << paramString(mCurrentGroup, parseResult.parameters) << ");\n"; + mConfigGroupList << currentGroup; + } + } else { + stream() << " setCurrentGroup( " << paramString(mCurrentGroup, parseResult.parameters) << " );"; + stream() << "\n\n"; + } } void KConfigSourceGenerator::doConstructor() diff --git a/src/kconfig_compiler/KConfigSourceGenerator.h b/src/kconfig_compiler/KConfigSourceGenerator.h index 76897f39..db2c8e72 100644 --- a/src/kconfig_compiler/KConfigSourceGenerator.h +++ b/src/kconfig_compiler/KConfigSourceGenerator.h @@ -68,6 +68,7 @@ private: private: QString mCurrentGroup; + QStringList mConfigGroupList; // keeps track of generated KConfigGroup; }; #endif diff --git a/src/kconfig_compiler/KConfigXmlParser.cpp b/src/kconfig_compiler/KConfigXmlParser.cpp index 46ce0921..3120d006 100644 --- a/src/kconfig_compiler/KConfigXmlParser.cpp +++ b/src/kconfig_compiler/KConfigXmlParser.cpp @@ -344,7 +344,7 @@ void KConfigXmlParser::readParamDefaultValues(CfgEntry &readEntry, const QDomEle } } -CfgEntry *KConfigXmlParser::parseEntry(const QString &group, const QDomElement &element) +CfgEntry *KConfigXmlParser::parseEntry(const QString &group, const QString &parentGroup, const QDomElement &element) { CfgEntry readEntry; readEntry.type = element.attribute(QStringLiteral("type")); @@ -352,6 +352,7 @@ CfgEntry *KConfigXmlParser::parseEntry(const QString &group, const QDomElement & readEntry.key = element.attribute(QStringLiteral("key")); readEntry.hidden = element.attribute(QStringLiteral("hidden")) == QLatin1String("true");; readEntry.group = group; + readEntry.parentGroup = parentGroup; const bool nameIsEmpty = readEntry.name.isEmpty(); @@ -400,6 +401,7 @@ CfgEntry *KConfigXmlParser::parseEntry(const QString &group, const QDomElement & // creating another one to fill the code. CfgEntry *result = new CfgEntry(); result->group = readEntry.group; + result->parentGroup = readEntry.parentGroup; result->type = readEntry.type; result->key = readEntry.key; result->name = readEntry.name; @@ -492,11 +494,13 @@ void KConfigXmlParser::readGroupTag(const QDomElement &e) exit (1); } + const QString parentGroup = e.attribute(QStringLiteral("parentGroupName")); + for (QDomElement e2 = e.firstChildElement(); !e2.isNull(); e2 = e2.nextSiblingElement()) { if (e2.tagName() != QLatin1String("entry")) { continue; } - CfgEntry *entry = parseEntry(group, e2); + CfgEntry *entry = parseEntry(group, parentGroup, e2); if (entry) { mParseResult.entries.append(entry); } else { diff --git a/src/kconfig_compiler/KConfigXmlParser.h b/src/kconfig_compiler/KConfigXmlParser.h index fa46e4b9..742cb496 100644 --- a/src/kconfig_compiler/KConfigXmlParser.h +++ b/src/kconfig_compiler/KConfigXmlParser.h @@ -46,7 +46,7 @@ private: // TODO: Use std::optional and CfgEntry (without heap allocation) for this function // *or* fail hard if the parse fails. - CfgEntry *parseEntry(const QString &group, const QDomElement &element); + CfgEntry *parseEntry(const QString &group, const QString &parentGroup, const QDomElement &element); // Steps void readIncludeTag(const QDomElement &element); diff --git a/src/kconfig_compiler/kcfg.xsd b/src/kconfig_compiler/kcfg.xsd index f28a70d7..1ec1dc81 100644 --- a/src/kconfig_compiler/kcfg.xsd +++ b/src/kconfig_compiler/kcfg.xsd @@ -155,6 +155,7 @@ </xsd:element> </xsd:sequence> <xsd:attribute name="name" use="required" type="xsd:string"/> + <xsd:attribute name="parentGroupName" use="optional" type="xsd:string"/> </xsd:complexType> </xsd:element> </xsd:sequence> |