diff options
10 files changed, 232 insertions, 3 deletions
| diff --git a/autotests/kconfig_compiler/CMakeLists.txt b/autotests/kconfig_compiler/CMakeLists.txt index 73e89bd2..0cca6052 100644 --- a/autotests/kconfig_compiler/CMakeLists.txt +++ b/autotests/kconfig_compiler/CMakeLists.txt @@ -222,6 +222,7 @@ ecm_add_test(${kconfigcompiler_test_signals_SRCS}      LINK_LIBRARIES Qt5::Test KF5::ConfigGui  ) +  ########### next target ###############  ecm_add_test(kconfigcompiler_test.cpp @@ -229,6 +230,16 @@ ecm_add_test(kconfigcompiler_test.cpp      LINK_LIBRARIES Qt5::Test  ) + +########### next target ############### + +set(test_qcategory_SRCS test_qdebugcategorymain.cpp test_qdebugcategory_debug.cpp) +gen_kcfg_test_source(test_qdebugcategory test_qcategory_SRCS) +add_executable(test_qdebugcategory ${test_qcategory_SRCS}) +ecm_mark_as_test(test_qdebugcategory) +target_link_libraries(test_qdebugcategory KF5::ConfigGui) + +  ########### install files ############### diff --git a/autotests/kconfig_compiler/kconfigcompiler_test.cpp b/autotests/kconfig_compiler/kconfigcompiler_test.cpp index cfe86e05..43623cef 100644 --- a/autotests/kconfig_compiler/kconfigcompiler_test.cpp +++ b/autotests/kconfig_compiler/kconfigcompiler_test.cpp @@ -45,6 +45,7 @@ static CompilerTestSet testCases = {      "test12.h", "test12.cpp",      "test_dpointer.cpp", "test_dpointer.h",      "test_signal.cpp", "test_signal.h", +    "test_qdebugcategory.cpp", "test_qdebugcategory.h",      Q_NULLPTR  }; @@ -64,6 +65,7 @@ static CompilerTestSet testCasesToRun = {      "test12",      "test_dpointer",      "test_signal", +    "test_qdebugcategory",      Q_NULLPTR  }; diff --git a/autotests/kconfig_compiler/test_qdebugcategory.cpp.ref b/autotests/kconfig_compiler/test_qdebugcategory.cpp.ref new file mode 100644 index 00000000..f2eea333 --- /dev/null +++ b/autotests/kconfig_compiler/test_qdebugcategory.cpp.ref @@ -0,0 +1,31 @@ +// This file is generated by kconfig_compiler_kf5 from test_qdebugcategory.kcfg. +// All changes you do to this file will be lost. + +#include "test_qdebugcategory.h" + +TestQCategory::TestQCategory(  int Number ) +  : KConfigSkeleton( QLatin1String( "test7rc" ) ) +  , mParamNumber(Number) +{ +  setCurrentGroup( QLatin1String( "Foo" ) ); + +  KConfigSkeleton::ItemColor  *itemColor; +  itemColor = new KConfigSkeleton::ItemColor( currentGroup(), QString( QLatin1String( "color #%1" ) ).arg( mParamNumber ), mColor, QColor( "red" ) ); +  addItem( itemColor, QLatin1String( "Color" ) ); + +  setCurrentGroup( QString( QLatin1String( "Bar%1" ) ).arg( mParamNumber ) ); + +  KConfigSkeleton::ItemString  *itemFooBar; +  itemFooBar = new KConfigSkeleton::ItemString( currentGroup(), QLatin1String( "foo bar" ), mFooBar ); +  addItem( itemFooBar, QLatin1String( "FooBar" ) ); +  KConfigSkeleton::ItemInt  *itemAge; +  itemAge = new KConfigSkeleton::ItemInt( currentGroup(), QLatin1String( "Age" ), mAge, 35 ); +  itemAge->setMinValue(8); +  itemAge->setMaxValue(88); +  addItem( itemAge, QLatin1String( "Age" ) ); +} + +TestQCategory::~TestQCategory() +{ +} + diff --git a/autotests/kconfig_compiler/test_qdebugcategory.h.ref b/autotests/kconfig_compiler/test_qdebugcategory.h.ref new file mode 100644 index 00000000..b6d16fc0 --- /dev/null +++ b/autotests/kconfig_compiler/test_qdebugcategory.h.ref @@ -0,0 +1,96 @@ +// This file is generated by kconfig_compiler_kf5 from test_qdebugcategory.kcfg. +// All changes you do to this file will be lost. +#ifndef TESTQCATEGORY_H +#define TESTQCATEGORY_H + +#include <test_qdebugcategory_debug.h> + +#include <kconfigskeleton.h> +#include <QCoreApplication> +#include <QDebug> + +class TestQCategory : public KConfigSkeleton +{ +  public: + +    TestQCategory( int Number ); +    ~TestQCategory(); + +    /** +      Set Block colors. +    */ +    void setColor( const QColor & v ) +    { +      if (!isImmutable( QString::fromLatin1( "Color" ) )) +        mColor = v; +    } + +    /** +      Get Block colors. +    */ +    QColor color() const +    { +      return mColor; +    } + +    /** +      Set foo bar +    */ +    void setFooBar( const QString & v ) +    { +      if (!isImmutable( QString::fromLatin1( "FooBar" ) )) +        mFooBar = v; +    } + +    /** +      Get foo bar +    */ +    QString fooBar() const +    { +      return mFooBar; +    } + +    /** +      Set Age +    */ +    void setAge( int v ) +    { +      if (v < 8) +      { +        qCDebug(CATEGORY_LOG) << "setAge: value " << v << " is less than the minimum value of 8"; +        v = 8; +      } + +      if (v > 88) +      { +        qCDebug(CATEGORY_LOG) << "setAge: value " << v << " is greater than the maximum value of 88"; +        v = 88; +      } + +      if (!isImmutable( QString::fromLatin1( "Age" ) )) +        mAge = v; +    } + +    /** +      Get Age +    */ +    int age() const +    { +      return mAge; +    } + +  protected: +    int mParamNumber; + +    // Foo +    QColor mColor; + +    // Bar$(Number) +    QString mFooBar; +    int mAge; + +  private: +}; + +#endif + diff --git a/autotests/kconfig_compiler/test_qdebugcategory.kcfg b/autotests/kconfig_compiler/test_qdebugcategory.kcfg new file mode 100644 index 00000000..2f54f608 --- /dev/null +++ b/autotests/kconfig_compiler/test_qdebugcategory.kcfg @@ -0,0 +1,25 @@ +<?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="test7rc"> +      <parameter name="Number" type="Int"/> +  </kcfgfile> + +  <group name="Foo"> +    <entry name="Color" type="Color" key="color #$(Number)"> +      <label>Block colors.</label> +      <default>red</default> +    </entry> +  </group> +  <group name="Bar$(Number)"> +    <entry name="FooBar" key="foo bar" type="String"/> +    <entry name="Age" type="Int"> +      <default>35</default> +      <min>8</min> +      <max>88</max> +    </entry> +  </group> + +</kcfg> diff --git a/autotests/kconfig_compiler/test_qdebugcategory.kcfgc b/autotests/kconfig_compiler/test_qdebugcategory.kcfgc new file mode 100644 index 00000000..a7ae26e7 --- /dev/null +++ b/autotests/kconfig_compiler/test_qdebugcategory.kcfgc @@ -0,0 +1,9 @@ +# Code generation options for kconfig_compiler_kf5 +File=test_qdebugcategory.kcfgc +ClassName=TestQCategory +Singleton=false +Mutators=true +GlobalEnums=true +ItemAccessors=false +CategoryLoggingName=CATEGORY_LOG +IncludeFiles=test_qdebugcategory_debug.h diff --git a/autotests/kconfig_compiler/test_qdebugcategory_debug.cpp b/autotests/kconfig_compiler/test_qdebugcategory_debug.cpp new file mode 100644 index 00000000..7c4f9f55 --- /dev/null +++ b/autotests/kconfig_compiler/test_qdebugcategory_debug.cpp @@ -0,0 +1,4 @@ +#include "test_qdebugcategory_debug.h" +Q_LOGGING_CATEGORY(CATEGORY_LOG, "log_category") + + diff --git a/autotests/kconfig_compiler/test_qdebugcategory_debug.h b/autotests/kconfig_compiler/test_qdebugcategory_debug.h new file mode 100644 index 00000000..88ac4f35 --- /dev/null +++ b/autotests/kconfig_compiler/test_qdebugcategory_debug.h @@ -0,0 +1,8 @@ +#ifndef TEST_QCATEGORY_DEBUG_H +#define TEST_QCATEGORY_DEBUG_H + +#include <QLoggingCategory> +Q_DECLARE_LOGGING_CATEGORY(CATEGORY_LOG) + +#endif + diff --git a/autotests/kconfig_compiler/test_qdebugcategorymain.cpp b/autotests/kconfig_compiler/test_qdebugcategorymain.cpp new file mode 100644 index 00000000..247ffe4c --- /dev/null +++ b/autotests/kconfig_compiler/test_qdebugcategorymain.cpp @@ -0,0 +1,32 @@ +/* +Copyright (c) 2004 Waldo Bastian <bastian@kde.org> + +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_qdebugcategory.h" +#include <QGuiApplication> + +int main(int argc, char **argv) +{ +    QGuiApplication app(argc, argv); +    Q_UNUSED(app); +    TestQCategory *t = new TestQCategory(42); +    delete t; +    return 0; +} diff --git a/src/kconfig_compiler/kconfig_compiler.cpp b/src/kconfig_compiler/kconfig_compiler.cpp index 28b151c5..7be74226 100644 --- a/src/kconfig_compiler/kconfig_compiler.cpp +++ b/src/kconfig_compiler/kconfig_compiler.cpp @@ -96,7 +96,6 @@ public:          allDefaultGetters = (defaultGetters.count() == 1) && (defaultGetters.at(0).toLower() == "true");          globalEnums = codegenConfig.value("GlobalEnums", false).toBool();          useEnumTypes = codegenConfig.value("UseEnumTypes", false).toBool(); -          const QString trString = codegenConfig.value("TranslationSystem").toString().toLower();          if (trString == "kde") {              translationSystem = KdeTranslation; @@ -106,6 +105,7 @@ public:              }              translationSystem = QtTranslation;          } +        qCategoryLoggingName = codegenConfig.value("CategoryLoggingName", QString()).toString();      }  public: @@ -128,6 +128,7 @@ public:      QStringList sourceIncludes;      QStringList mutators;      QStringList defaultGetters; +    QString qCategoryLoggingName;      bool allMutators;      bool setUserTexts;      bool allDefaultGetters; @@ -1364,6 +1365,16 @@ QString memberAccessorBody(CfgEntry *e, bool globalEnums, const CfgConfig &cfg)  // returns the member mutator implementation  // which should go in the h file if inline  // or the cpp file if not inline + +void addDebugMethod(QTextStream &out, const CfgConfig &cfg, const QString &n) +{ +    if (cfg.qCategoryLoggingName.isEmpty()) { +       out << "  qDebug() << \"" << setFunction(n); +    } else { +       out << "  qCDebug(" << cfg.qCategoryLoggingName << ") << \"" << setFunction(n); +    } +} +  QString memberMutatorBody(CfgEntry *e, const CfgConfig &cfg)  {      QString result; @@ -1375,7 +1386,7 @@ QString memberMutatorBody(CfgEntry *e, const CfgConfig &cfg)          if (e->minValue() != "0" || !isUnsigned(t)) { // skip writing "if uint<0" (#187579)              out << "if (v < " << e->minValue() << ")" << endl;              out << "{" << endl; -            out << "  qDebug() << \"" << setFunction(n); +            addDebugMethod(out, cfg, n);              out << ": value \" << v << \" is less than the minimum value of ";              out << e->minValue() << "\";" << endl;              out << "  v = " << e->minValue() << ";" << endl; @@ -1386,7 +1397,7 @@ QString memberMutatorBody(CfgEntry *e, const CfgConfig &cfg)      if (!e->maxValue().isEmpty()) {          out << endl << "if (v > " << e->maxValue() << ")" << endl;          out << "{" << endl; -        out << "  qDebug() << \"" << setFunction(n); +        addDebugMethod(out, cfg, n);          out << ": value \" << v << \" is greater than the maximum value of ";          out << e->maxValue() << "\";" << endl;          out << "  v = " << e->maxValue() << ";" << endl; | 
