From db4fa7ffe174939fde700899dd596df9bed4fb6d Mon Sep 17 00:00:00 2001 From: joern274 Date: Tue, 31 Oct 2023 12:00:45 +0100 Subject: [PATCH] Enable regexp search in QPlainTextEdit prior to ver.5.13 --- plugins/gui/src/code_editor/code_editor.cpp | 15 ++++++++++++--- .../src/comment_system/widgets/comment_item.cpp | 13 +++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/plugins/gui/src/code_editor/code_editor.cpp b/plugins/gui/src/code_editor/code_editor.cpp index 5cd270ff923..ad724c6dc47 100644 --- a/plugins/gui/src/code_editor/code_editor.cpp +++ b/plugins/gui/src/code_editor/code_editor.cpp @@ -13,6 +13,12 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5,13,0) + #include +#else + #include +#endif + namespace hal { @@ -213,9 +219,12 @@ namespace hal if(searchOpts.isRegularExpression()) { - QRegularExpression* regEx = new QRegularExpression(string, searchOpts.isCaseSensitive() ? QRegularExpression::NoPatternOption : QRegularExpression::CaseInsensitiveOption); - - while (find(*regEx, options)) +#if QT_VERSION >= QT_VERSION_CHECK(5,13,0) + QRegularExpression regExp(string, searchOpts.isCaseSensitive() ? QRegularExpression::NoPatternOption : QRegularExpression::CaseInsensitiveOption); +#else + QRegExp regExp(string, searchOpts.isCaseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive); +#endif + while (find(regExp, options)) { QTextEdit::ExtraSelection extra; extra.format.setForeground(QBrush(color)); diff --git a/plugins/gui/src/comment_system/widgets/comment_item.cpp b/plugins/gui/src/comment_system/widgets/comment_item.cpp index ca519bdddaf..3b3133be087 100644 --- a/plugins/gui/src/comment_system/widgets/comment_item.cpp +++ b/plugins/gui/src/comment_system/widgets/comment_item.cpp @@ -11,6 +11,11 @@ #include #include #include "gui/gui_utils/graphics.h" +#if QT_VERSION >= QT_VERSION_CHECK(5,13,0) + #include +#else + #include +#endif namespace hal { @@ -61,9 +66,13 @@ namespace hal if(searchOpts.isRegularExpression()) { qInfo() << "is regex"; - QRegularExpression* regEx = new QRegularExpression(string, searchOpts.isCaseSensitive() ? QRegularExpression::NoPatternOption : QRegularExpression::CaseInsensitiveOption); +#if QT_VERSION >= QT_VERSION_CHECK(5,13,0) + QRegularExpression regExp(string, searchOpts.isCaseSensitive() ? QRegularExpression::NoPatternOption : QRegularExpression::CaseInsensitiveOption); +#else + QRegExp regExp(string, searchOpts.isCaseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive); +#endif - while (mTextEdit->find(*regEx, options)) + while (mTextEdit->find(regExp, options)) { found = true; // just return if something is found, position doesnt matter QTextEdit::ExtraSelection extra;