Allow to generate qloggingcategories support.

Add new variable to specify it in *.kcfgc : "CategoryLoggingName"

CHANGELOG: Allow to generate file with qloggingcategories support.

REVIEW: 122931
wilder
Montel Laurent 11 years ago
parent 270b5ef5ab
commit 094c91f86b
  1. 11
      autotests/kconfig_compiler/CMakeLists.txt
  2. 2
      autotests/kconfig_compiler/kconfigcompiler_test.cpp
  3. 31
      autotests/kconfig_compiler/test_qdebugcategory.cpp.ref
  4. 96
      autotests/kconfig_compiler/test_qdebugcategory.h.ref
  5. 25
      autotests/kconfig_compiler/test_qdebugcategory.kcfg
  6. 9
      autotests/kconfig_compiler/test_qdebugcategory.kcfgc
  7. 4
      autotests/kconfig_compiler/test_qdebugcategory_debug.cpp
  8. 8
      autotests/kconfig_compiler/test_qdebugcategory_debug.h
  9. 32
      autotests/kconfig_compiler/test_qdebugcategorymain.cpp
  10. 17
      src/kconfig_compiler/kconfig_compiler.cpp

@ -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 ###############

@ -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
};

@ -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()
{
}

@ -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

@ -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>

@ -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

@ -0,0 +1,4 @@
#include "test_qdebugcategory_debug.h"
Q_LOGGING_CATEGORY(CATEGORY_LOG, "log_category")

@ -0,0 +1,8 @@
#ifndef TEST_QCATEGORY_DEBUG_H
#define TEST_QCATEGORY_DEBUG_H
#include <QLoggingCategory>
Q_DECLARE_LOGGING_CATEGORY(CATEGORY_LOG)
#endif

@ -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;
}

@ -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;

Loading…
Cancel
Save