diff options
| author | Alexander Lohnau <alexander.lohnau@gmx.de> | 2021-09-14 07:30:32 +0200 | 
|---|---|---|
| committer | Alexander Lohnau <alexander.lohnau@gmx.de> | 2021-09-19 07:50:10 +0200 | 
| commit | 0b0a4464fb3d1145eb612b1ab7edacfa9581c8c9 (patch) | |
| tree | db94f2c4daba14f23e13aa65d55a05257f86ab41 /src | |
| parent | 782750149a0819053d47960fb144f17b7c719d13 (diff) | |
| download | kconfig-0b0a4464fb3d1145eb612b1ab7edacfa9581c8c9.tar.gz kconfig-0b0a4464fb3d1145eb612b1ab7edacfa9581c8c9.tar.bz2 | |
Allow KConfigXT to use KSharedConfig::openStateConfig
Otherwise we force consumers to use the config location for state data,
which is what we are trying to avoid.
Task: https://phabricator.kde.org/T12549
Diffstat (limited to 'src')
| -rw-r--r-- | src/kconfig_compiler/KConfigCommonStructs.h | 1 | ||||
| -rw-r--r-- | src/kconfig_compiler/KConfigHeaderGenerator.cpp | 7 | ||||
| -rw-r--r-- | src/kconfig_compiler/KConfigSourceGenerator.cpp | 8 | ||||
| -rw-r--r-- | src/kconfig_compiler/KConfigXmlParser.cpp | 1 | ||||
| -rw-r--r-- | src/kconfig_compiler/README.dox | 5 | ||||
| -rw-r--r-- | src/kconfig_compiler/kcfg.xsd | 1 | 
6 files changed, 21 insertions, 2 deletions
| diff --git a/src/kconfig_compiler/KConfigCommonStructs.h b/src/kconfig_compiler/KConfigCommonStructs.h index 43e981cb..bac10c70 100644 --- a/src/kconfig_compiler/KConfigCommonStructs.h +++ b/src/kconfig_compiler/KConfigCommonStructs.h @@ -114,6 +114,7 @@ public:  struct ParseResult {      QString cfgFileName;      bool cfgFileNameArg = false; +    bool cfgStateConfig = false;      QList<Param> parameters;      QList<Signal> signalList;      QStringList includes; diff --git a/src/kconfig_compiler/KConfigHeaderGenerator.cpp b/src/kconfig_compiler/KConfigHeaderGenerator.cpp index 9938599c..ea5a2c75 100644 --- a/src/kconfig_compiler/KConfigHeaderGenerator.cpp +++ b/src/kconfig_compiler/KConfigHeaderGenerator.cpp @@ -324,10 +324,17 @@ void KConfigHeaderGenerator::createConstructor()      if (parseResult.cfgFileNameArg) {          if (cfg().forceStringFilename) {              stream() << " const QString &cfgfilename" << (parseResult.parameters.isEmpty() ? " = QString()" : ", "); +        } else if (parseResult.cfgStateConfig) { +            stream() << " KSharedConfig::Ptr config" << (parseResult.parameters.isEmpty() ? " = KSharedConfig::openStateConfig()" : ", ");          } else {              stream() << " KSharedConfig::Ptr config" << (parseResult.parameters.isEmpty() ? " = KSharedConfig::openConfig()" : ", ");          }      } +    if (cfg().forceStringFilename && parseResult.cfgStateConfig) { +        std::cerr << "One can not use ForceStringFilename and use the stateConfig attribute, consider " +                     "removing the ForceStringFilename kcfgc option if you want to use state data" +                  << std::endl; +    }      bool first = true;      for (const auto ¶meter : std::as_const(parseResult.parameters)) { diff --git a/src/kconfig_compiler/KConfigSourceGenerator.cpp b/src/kconfig_compiler/KConfigSourceGenerator.cpp index a8a05f4b..45299a4f 100644 --- a/src/kconfig_compiler/KConfigSourceGenerator.cpp +++ b/src/kconfig_compiler/KConfigSourceGenerator.cpp @@ -170,7 +170,9 @@ void KConfigSourceGenerator::createSingletonImplementation()              stream() << "     return;\n";              stream() << "  }\n";              stream() << "  new " << cfg().className << "("; -            if (isString) { +            if (parseResult.cfgStateConfig) { +                stream() << "KSharedConfig::openStateConfig(" << arg << ")"; +            } else if (isString) {                  stream() << "KSharedConfig::openConfig(" << arg << ")";              } else {                  stream() << "std::move(" << arg << ")"; @@ -232,7 +234,9 @@ void KConfigSourceGenerator::createConstructorParameterList()  void KConfigSourceGenerator::createParentConstructorCall()  {      stream() << cfg().inherits << "("; -    if (!parseResult.cfgFileName.isEmpty()) { +    if (parseResult.cfgStateConfig) { +        stream() << " KSharedConfig::openStateConfig(QStringLiteral( \"" << parseResult.cfgFileName << "\") "; +    } else if (!parseResult.cfgFileName.isEmpty()) {          stream() << " QStringLiteral( \"" << parseResult.cfgFileName << "\" ";      }      if (parseResult.cfgFileNameArg) { diff --git a/src/kconfig_compiler/KConfigXmlParser.cpp b/src/kconfig_compiler/KConfigXmlParser.cpp index 3d054522..fbcd4b92 100644 --- a/src/kconfig_compiler/KConfigXmlParser.cpp +++ b/src/kconfig_compiler/KConfigXmlParser.cpp @@ -522,6 +522,7 @@ void KConfigXmlParser::readGroupTag(const QDomElement &e)  void KConfigXmlParser::readKcfgfileTag(const QDomElement &e)  {      mParseResult.cfgFileName = e.attribute(QStringLiteral("name")); +    mParseResult.cfgStateConfig = e.attribute(QStringLiteral("stateConfig")).toLower() == QLatin1String("true");      mParseResult.cfgFileNameArg = e.attribute(QStringLiteral("arg")).toLower() == QLatin1String("true");      for (QDomElement e2 = e.firstChildElement(); !e2.isNull(); e2 = e2.nextSiblingElement()) {          if (e2.tagName() == QLatin1String("parameter")) { diff --git a/src/kconfig_compiler/README.dox b/src/kconfig_compiler/README.dox index 671e9c5b..4c22a452 100644 --- a/src/kconfig_compiler/README.dox +++ b/src/kconfig_compiler/README.dox @@ -385,6 +385,11 @@ Example 1:  In this case passing "Group2" as the 'groupname' parameter to the generated class  will make it use group "Group2" for the entry "Text". +By setting the stateConfig attribute of kcfgfile to "true", KSharedConfig::openStateConfig is used. +This should be used when one stores volatile data, like window sizes or autocompletion texts. +It is recommended to have at least two separate kcfg files for the different kinds of data. +NOTE: This option is ignored when ForceStringFilename is set. +  \subsection enums Enums  By default, if <b>GlobalEnums</b> is set to false, a separate named enum will be generated diff --git a/src/kconfig_compiler/kcfg.xsd b/src/kconfig_compiler/kcfg.xsd index f9175a1d..6825819b 100644 --- a/src/kconfig_compiler/kcfg.xsd +++ b/src/kconfig_compiler/kcfg.xsd @@ -68,6 +68,7 @@                              <!-- FIXME: Are really unbounded occurrences of parameter allowed? -->                          </xsd:sequence>                          <xsd:attribute name="name" type="xsd:string" use="optional"/> +                        <xsd:attribute name="stateConfig" type="xsd:boolean" use="optional"/>                          <xsd:attribute name="arg" type="xsd:boolean" use="optional"/>                      </xsd:complexType>                  </xsd:element> | 
