Skip to content

Commit ce49a03

Browse files
committed
Merged in feature/make-qmllint-ready (pull request #3)
Feature/make qmllint ready Approved-by: Helmuth Ploner-Bernard Approved-by: Johann Anhofer
2 parents 719ac3a + 859744b commit ce49a03

23 files changed

+330
-29
lines changed

.github/workflows/cmake-ubuntu.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
strategy:
2222
matrix:
2323
os: [ubuntu-22.04]
24-
qt_version: [6.2.4, 6.5.3, 6.6.3, 6.7.2, 6.8.0]
24+
qt_version: [6.2.4, 6.5.3, 6.6.3, 6.7.2, 6.8.1]
2525

2626
steps:
2727
- name: Install ninja

CMakeLists.txt

+8-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ if(BUILD_STATIC_LOG4CXX_LIB)
2525
endif()
2626

2727
# With Database logging support or without
28-
option(BUILD_WITH_DB_LOGGING "Build with database logging support, link against Qt sql lib (default: on)" OFF)
28+
option(BUILD_WITH_DB_LOGGING "Build with database logging support, link against Qt sql lib (default: off)" OFF)
2929

3030
# With Telnet logging support or without
31-
option(BUILD_WITH_TELNET_LOGGING "Build with telnet logging support, link against Qt network lib (default: on)" OFF)
31+
option(BUILD_WITH_TELNET_LOGGING "Build with telnet logging support, link against Qt network lib (default: off)" OFF)
32+
33+
# With qml logging support or without
34+
option(BUILD_WITH_QML_LOGGING "Build with qml logging support, link against Qt qml lib (default: off)" OFF)
3235

3336
# Enable documentation generation with doxygen
3437
OPTION(BUILD_WITH_DOCS "Enable documentation generation (default: off)" OFF)
@@ -81,6 +84,9 @@ endif()
8184
if(BUILD_WITH_TELNET_LOGGING)
8285
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Network REQUIRED)
8386
endif()
87+
if(BUILD_WITH_QML_LOGGING)
88+
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Qml REQUIRED)
89+
endif()
8490

8591
add_definitions(-DQT_USE_QSTRINGBUILDER)
8692
add_definitions(-DQT_NO_CAST_TO_ASCII)

appveyor.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ environment:
2121
CMD_VCVARSALL: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64'
2222
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
2323
# Qt 6.6
24-
- QTDIR: C:\Qt\6.6\msvc2019_64
25-
CMD_VCVARSALL: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64'
26-
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
24+
#- QTDIR: C:\Qt\6.6\msvc2019_64
25+
# CMD_VCVARSALL: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64'
26+
# APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
2727
branches:
2828
only:
2929
- master

src/log4qt/CMakeLists.txt

+45-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ set(log4qt_SOURCES
4141
ndc.cpp
4242
patternlayout.cpp
4343
propertyconfigurator.cpp
44-
qmllogger.cpp
4544
rollingbinaryfileappender.cpp
4645
rollingfileappender.cpp
4746
signalappender.cpp
@@ -94,7 +93,6 @@ set(log4qt_HEADERS
9493
ndc.h
9594
patternlayout.h
9695
propertyconfigurator.h
97-
qmllogger.h
9896
rollingbinaryfileappender.h
9997
rollingfileappender.h
10098
signalappender.h
@@ -152,6 +150,43 @@ target_link_libraries(log4qt
152150
Qt${QT_VERSION_MAJOR}::Concurrent
153151
)
154152

153+
if(BUILD_WITH_QML_LOGGING)
154+
target_sources(log4qt
155+
PRIVATE
156+
qmllogger.cpp
157+
qmllogger.h
158+
)
159+
# append to log4qt_HEADERS or proper install
160+
list(APPEND log4qt_HEADERS
161+
qmllogger.h
162+
)
163+
164+
target_link_libraries(log4qt PRIVATE Qt${QT_VERSION_MAJOR}::Qml)
165+
target_include_directories(log4qt
166+
PUBLIC
167+
$<TARGET_PROPERTY:Qt::Qml,INTERFACE_INCLUDE_DIRECTORIES>
168+
)
169+
170+
if (QT_VERSION_MAJOR GREATER 6 OR (QT_VERSION_MAJOR EQUAL 6 AND QT_VERSION_MINOR GREATER 1))
171+
qt_add_qml_module(
172+
log4qt
173+
URI org.log4qt
174+
VERSION 1.0
175+
OUTPUT_DIRECTORY
176+
${CMAKE_BINARY_DIR}/bin/org/log4qt
177+
SOURCES
178+
qmllogger.cpp qmllogger.h
179+
NO_PLUGIN
180+
RESOURCE_PREFIX
181+
"/qt/qml"
182+
)
183+
message(STATUS "Log4Qt: Registered logging support as qml module (org.log4qt)")
184+
endif()
185+
message(STATUS "Log4Qt: Enabling qml logging support")
186+
else()
187+
message(STATUS "Log4Qt: Disabling qml logging support - disabled by cmake option")
188+
endif()
189+
155190
target_include_directories(log4qt PUBLIC
156191
$<BUILD_INTERFACE:${LOG4QT_BUILD_INCLUDE_DIR}>
157192
$<INSTALL_INTERFACE:include>)
@@ -171,7 +206,10 @@ if(BUILD_WITH_DB_LOGGING)
171206
databaseappender.h
172207
databaselayout.h
173208
)
174-
209+
target_compile_definitions(log4qt
210+
PRIVATE
211+
LOG4QT_DB_LOGGING_SUPPORT
212+
)
175213
target_link_libraries(log4qt PRIVATE Qt${QT_VERSION_MAJOR}::Sql)
176214
target_include_directories(log4qt
177215
PUBLIC
@@ -195,6 +233,10 @@ if(BUILD_WITH_TELNET_LOGGING)
195233
list(APPEND log4qt_HEADERS
196234
telnetappender.h
197235
)
236+
target_compile_definitions(log4qt
237+
PRIVATE
238+
LOG4QT_TELNET_LOGGING_SUPPORT
239+
)
198240
target_link_libraries(log4qt PRIVATE Qt${QT_VERSION_MAJOR}::Network)
199241
target_include_directories(log4qt
200242
PUBLIC

src/log4qt/asyncappender.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
#include <QReadLocker>
2727
#include <QThread>
2828

29+
#if (__cplusplus >= 201703L) // C++17 or later
30+
#include <utility>
31+
#endif
32+
2933
namespace Log4Qt
3034
{
3135

@@ -85,9 +89,14 @@ void AsyncAppender::closeInternal()
8589

8690
void AsyncAppender::callAppenders(const LoggingEvent &event) const
8791
{
92+
Q_UNUSED(event)
8893
QReadLocker locker(&mAppenderGuard);
8994

95+
#if (__cplusplus >= 201703L)
96+
for (auto &&pAppender : std::as_const(mAppenders))
97+
#else
9098
for (auto &&pAppender : qAsConst(mAppenders))
99+
#endif
91100
pAppender->doAppend(event);
92101
}
93102

src/log4qt/colorconsoleappender.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
#include <QTextStream>
2727

28+
#if (__cplusplus >= 201703L) // C++17 or later
29+
#include <utility>
30+
#endif
31+
2832
#define NIX_BACK_BLACK 40
2933
#define NIX_BACK_RED 41
3034
#define NIX_BACK_GREEN 42
@@ -130,7 +134,11 @@ static void colorOutputString(HANDLE hConsole, const QString &output)
130134
parsedWordString = it.mid(1, indexOfM - 1);
131135

132136
escParams = parsedWordString.split(';');
137+
#if (__cplusplus >= 201703L)
138+
for (const auto &param : std::as_const(escParams))
139+
#else
133140
for (const auto &param : qAsConst(escParams))
141+
#endif
134142
{
135143
WORD color = param.toUInt();
136144
switch (color)

src/log4qt/dailyfileappender.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#include <QtConcurrentRun>
3232
#include <QStringBuilder>
3333

34+
#if (__cplusplus >= 201703L) // C++17 or later
35+
#include <utility>
36+
#endif
37+
3438
namespace Log4Qt
3539
{
3640

@@ -125,7 +129,11 @@ void deleteObsoleteFiles(
125129
}
126130
}
127131

132+
#if (__cplusplus >= 201703L)
133+
for (const auto &fileName : std::as_const(obsoleteLogFileNames))
134+
#else
128135
for (const auto &fileName : qAsConst(obsoleteLogFileNames))
136+
#endif
129137
{
130138
QFile::remove(logDir.filePath(fileName));
131139
}

src/log4qt/databaselayout.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ QSqlRecord DatabaseLayout::formatRecord(const LoggingEvent &event)
4242
if (!mTimeStamp.isEmpty())
4343
{
4444
field.setName(mTimeStamp);
45-
field.setType(QVariant::DateTime);
45+
field.setMetaType(QMetaType(QMetaType::QDateTime));
4646
field.setGenerated(true);
4747
field.setValue(DateTime::fromMSecsSinceEpoch(event.timeStamp()));
4848
record.append(field);
@@ -51,7 +51,7 @@ QSqlRecord DatabaseLayout::formatRecord(const LoggingEvent &event)
5151
if (!mLoggename.isEmpty())
5252
{
5353
field.setName(mLoggename);
54-
field.setType(QVariant::String);
54+
field.setMetaType(QMetaType(QMetaType::QString));
5555
field.setGenerated(true);
5656
field.setValue(event.loggename());
5757
record.append(field);
@@ -60,7 +60,7 @@ QSqlRecord DatabaseLayout::formatRecord(const LoggingEvent &event)
6060
if (!mThreadName.isEmpty())
6161
{
6262
field.setName(mThreadName);
63-
field.setType(QVariant::String);
63+
field.setMetaType(QMetaType(QMetaType::QString));
6464
field.setGenerated(true);
6565
field.setValue(event.threadName());
6666
record.append(field);
@@ -69,7 +69,7 @@ QSqlRecord DatabaseLayout::formatRecord(const LoggingEvent &event)
6969
if (!mLevel.isEmpty())
7070
{
7171
field.setName(mLevel);
72-
field.setType(QVariant::String);
72+
field.setMetaType(QMetaType(QMetaType::QString));
7373
field.setGenerated(true);
7474
field.setValue(event.level().toString());
7575
record.append(field);
@@ -78,7 +78,7 @@ QSqlRecord DatabaseLayout::formatRecord(const LoggingEvent &event)
7878
if (!mMessage.isEmpty())
7979
{
8080
field.setName(mMessage);
81-
field.setType(QVariant::String);
81+
field.setMetaType(QMetaType(QMetaType::QString));
8282
field.setGenerated(true);
8383
field.setValue(event.message());
8484
record.append(field);

src/log4qt/helpers/appenderattachable.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
#include "varia/listappender.h"
2323
#include "appender.h"
2424

25+
#if (__cplusplus >= 201703L) // C++17 or later
26+
#include <utility>
27+
#endif
28+
2529
namespace Log4Qt
2630
{
2731

@@ -42,7 +46,11 @@ AppenderSharedPtr AppenderAttachable::appender(const QString &name) const
4246
{
4347
QReadLocker locker(&mAppenderGuard);
4448

49+
#if (__cplusplus >= 201703L)
50+
for (auto &&pAppender : std::as_const(mAppenders))
51+
#else
4552
for (auto &&pAppender : qAsConst(mAppenders))
53+
#endif
4654
if (pAppender->name() == name)
4755
return pAppender;
4856
return AppenderSharedPtr();

src/log4qt/helpers/datetime.h

+34
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "log4qt/log4qtshared.h"
2525

2626
#include <QDateTime>
27+
#include <QTimeZone>
2728

2829
namespace Log4Qt
2930
{
@@ -55,6 +56,7 @@ class LOG4QT_EXPORT DateTime : public QDateTime
5556

5657
DateTime(const DateTime &other);
5758

59+
#if QT_VERSION < 0x060500
5860
/*!
5961
* Constructs a datetime with the given \a date and \a time, using
6062
* the time specification defined by \a timeSpec.
@@ -65,6 +67,18 @@ class LOG4QT_EXPORT DateTime : public QDateTime
6567
DateTime(QDate date,
6668
QTime time,
6769
Qt::TimeSpec timeSpec = Qt::LocalTime);
70+
#else
71+
/*!
72+
* Constructs a datetime with the given \a date and \a time, using
73+
* the time zone defined by \a QTimeZone.
74+
*
75+
* \sa QDateTime::QDateTime(const QDate &date, const QTime &time,
76+
* QTimeZone = QTimeZone(QTimeZone::LocalTime))
77+
*/
78+
DateTime(QDate date,
79+
QTime time,
80+
QTimeZone = QTimeZone(QTimeZone::LocalTime));
81+
#endif
6882

6983
/*!
7084
* Assigns \a other to this DateTime and returns a reference to it.
@@ -112,7 +126,12 @@ class LOG4QT_EXPORT DateTime : public QDateTime
112126
* \sa QDateTime::currentDateTime()
113127
*/
114128
static DateTime currentDateTime();
129+
#if QT_VERSION < 0x060500
115130
static DateTime fromMSecsSinceEpoch(qint64 msecs, Qt::TimeSpec spec, int offsetSeconds = 0);
131+
#else
132+
static DateTime fromMSecsSinceEpoch(qint64 msecs, QTimeZone timeZone);
133+
#endif
134+
116135
static DateTime fromMSecsSinceEpoch(qint64 msecs);
117136

118137
private:
@@ -122,11 +141,19 @@ class LOG4QT_EXPORT DateTime : public QDateTime
122141
inline DateTime::DateTime(const QDateTime &other) : QDateTime(other)
123142
{}
124143

144+
#if QT_VERSION < 0x060500
125145
inline DateTime::DateTime(QDate date,
126146
QTime time,
127147
Qt::TimeSpec timeSpec) :
128148
QDateTime(date, time, timeSpec)
129149
{}
150+
#else
151+
inline DateTime::DateTime(QDate date,
152+
QTime time,
153+
QTimeZone timeZone) :
154+
QDateTime(date, time, timeZone)
155+
{}
156+
#endif
130157

131158
inline DateTime &DateTime::operator=(const DateTime &other)
132159
{
@@ -144,10 +171,17 @@ inline DateTime DateTime::fromMSecsSinceEpoch(qint64 msecs)
144171
return DateTime(QDateTime::fromMSecsSinceEpoch(msecs));
145172
}
146173

174+
#if QT_VERSION < 0x060500
147175
inline DateTime DateTime::fromMSecsSinceEpoch(qint64 msecs, Qt::TimeSpec spec, int offsetSeconds)
148176
{
149177
return DateTime(QDateTime::fromMSecsSinceEpoch(msecs, spec, offsetSeconds));
150178
}
179+
#else
180+
inline DateTime DateTime::fromMSecsSinceEpoch(qint64 msecs, QTimeZone timeZone)
181+
{
182+
return DateTime(QDateTime::fromMSecsSinceEpoch(msecs, timeZone));
183+
}
184+
#endif
151185

152186
} // namespace Log4Qt
153187

0 commit comments

Comments
 (0)