diff options
| author | Ahmad Samir <a.samirh78@gmail.com> | 2021-02-23 16:23:22 +0200 | 
|---|---|---|
| committer | Ahmad Samir <a.samirh78@gmail.com> | 2021-03-06 01:35:09 +0200 | 
| commit | 23f55a865bdc1b5f7f462b35e8788ea3e2cbc121 (patch) | |
| tree | ec343b3df49555d6264d011d35cdf1303b82e4d2 | |
| parent | 9d87348260316af729892c58bc29f159a173abf1 (diff) | |
| download | kconfig-23f55a865bdc1b5f7f462b35e8788ea3e2cbc121.tar.gz kconfig-23f55a865bdc1b5f7f462b35e8788ea3e2cbc121.tar.bz2 | |
kconfig_compiler: change how paramString() creates strings
Now it creates C++ code that uses QString::arg(Args...) instead of
arg().arg().
AFAICS, the type of the "Args" is QString, so this should work.
| -rw-r--r-- | autotests/kconfig_compiler/test1.cpp.ref | 2 | ||||
| -rw-r--r-- | src/kconfig_compiler/kconfig_compiler.cpp | 19 | 
2 files changed, 16 insertions, 5 deletions
| diff --git a/autotests/kconfig_compiler/test1.cpp.ref b/autotests/kconfig_compiler/test1.cpp.ref index c0d94eef..16b1833b 100644 --- a/autotests/kconfig_compiler/test1.cpp.ref +++ b/autotests/kconfig_compiler/test1.cpp.ref @@ -63,7 +63,7 @@ Test1::Test1( const QString & transport, const QString & folder, QObject *parent    itemMyStringListHidden = new KConfigSkeleton::ItemStringList( currentGroup(), QStringLiteral( "MyStringListHidden" ), mMyStringListHidden, defaultMyStringListHidden );    addItem( itemMyStringListHidden, QStringLiteral( "MyStringListHidden" ) );    KConfigSkeleton::ItemInt  *itemMyNumber; -  itemMyNumber = new KConfigSkeleton::ItemInt( currentGroup(), QStringLiteral( "List-%1-%2" ).arg( mParamtransport ).arg( mParamfolder ), mMyNumber, 1 ); +  itemMyNumber = new KConfigSkeleton::ItemInt( currentGroup(), QStringLiteral( "List-%1-%2" ).arg( mParamtransport, mParamfolder ), mMyNumber, 1 );    addItem( itemMyNumber, QStringLiteral( "MyNumber" ) );  } diff --git a/src/kconfig_compiler/kconfig_compiler.cpp b/src/kconfig_compiler/kconfig_compiler.cpp index 50c54f8f..d278414e 100644 --- a/src/kconfig_compiler/kconfig_compiler.cpp +++ b/src/kconfig_compiler/kconfig_compiler.cpp @@ -490,19 +490,30 @@ QString paramString(const QString &group, const QList<Param> ¶meters)      QString paramString = group;      QString arguments;      int i = 1; +    bool firstArg = true;      for (const auto ¶m : parameters) {          const QString paramName = param.name;          const QString str = QLatin1String{"$("} + paramName + QLatin1Char{')'};          if (paramString.contains(str)) {              const QString tmp = QStringLiteral("%%1").arg(i++);              paramString.replace(str, tmp); -            // TODO: change the code here to get C++ code generated by KConfig to use -            // QString::arg(QString, QString, QString) instead of QString().arg().arg() -            arguments += QLatin1String{".arg( mParam"} + paramName + QLatin1String{" )"}; + +            if (firstArg) { +                arguments += QLatin1String{".arg( "}; +                firstArg = false; +            } + +            arguments += QLatin1String{"mParam"} + paramName + QLatin1String{", "};          }      } -    if (arguments.isEmpty()) { +    if (!arguments.isEmpty()) { +        // Remove the last ", " +        arguments.chop(2); + +        // Close the ".arg( " +        arguments += QLatin1String{" )"}; +    } else {          return QLatin1String{"QStringLiteral( \""} + group + QLatin1String{"\" )"};      } | 
