Skip to content

Commit

Permalink
Enable regexp search in QPlainTextEdit prior to ver.5.13
Browse files Browse the repository at this point in the history
  • Loading branch information
joern274 committed Oct 31, 2023
1 parent f7b2a66 commit db4fa7f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
15 changes: 12 additions & 3 deletions plugins/gui/src/code_editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
#include <QTextBlock>
#include <QDebug>

#if QT_VERSION >= QT_VERSION_CHECK(5,13,0)
#include <QRegularExpression>
#else
#include <QRegExp>
#endif

namespace hal
{

Expand Down Expand Up @@ -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));
Expand Down
13 changes: 11 additions & 2 deletions plugins/gui/src/comment_system/widgets/comment_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
#include <QToolButton>
#include <QDebug>
#include "gui/gui_utils/graphics.h"
#if QT_VERSION >= QT_VERSION_CHECK(5,13,0)
#include <QRegularExpression>
#else
#include <QRegExp>
#endif

namespace hal
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit db4fa7f

Please sign in to comment.