Skip to content

Commit

Permalink
QRegExp -> QRegularExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 20, 2021
1 parent 965bc1f commit ae6f4ad
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/gui/qgsdoublevalidator.h
Expand Up @@ -21,7 +21,7 @@
#define QGSDOUBLEVALIDATOR_H

#include <limits>
#include <QRegExpValidator>
#include <QRegularExpressionValidator>
#include <QLocale>
#include "qgis_gui.h"
#include "qgis_sip.h"
Expand Down
19 changes: 10 additions & 9 deletions src/gui/qgsexpressionhighlighter.cpp
Expand Up @@ -29,18 +29,18 @@ QgsExpressionHighlighter::QgsExpressionHighlighter( QTextDocument *parent )
const auto constKeywordPatterns = keywordPatterns;
for ( const QString &pattern : constKeywordPatterns )
{
rule.pattern = QRegExp( pattern, Qt::CaseInsensitive );
rule.pattern = QRegularExpression( pattern, QRegularExpression::CaseInsensitiveOption );
rule.format = keywordFormat;
highlightingRules.append( rule );
}

quotationFormat.setForeground( Qt::darkGreen );
rule.pattern = QRegExp( "\'[^\'\r\n]*\'" );
rule.pattern = QRegularExpression( "\'[^\'\r\n]*\'" );
rule.format = quotationFormat;
highlightingRules.append( rule );

columnNameFormat.setForeground( Qt::darkRed );
rule.pattern = QRegExp( "\"[^\"\r\n]*\"" );
rule.pattern = QRegularExpression( "\"[^\"\r\n]*\"" );
rule.format = columnNameFormat;
highlightingRules.append( rule );
}
Expand All @@ -54,7 +54,7 @@ void QgsExpressionHighlighter::addFields( const QStringList &fieldList )
{
if ( field.isEmpty() ) // this really happened :)
continue;
rule.pattern = QRegExp( "\\b" + field + "\\b" );
rule.pattern = QRegularExpression( "\\b" + field + "\\b" );
rule.format = columnNameFormat;
highlightingRules.append( rule );
}
Expand All @@ -65,15 +65,16 @@ void QgsExpressionHighlighter::highlightBlock( const QString &text )
const auto constHighlightingRules = highlightingRules;
for ( const HighlightingRule &rule : constHighlightingRules )
{
QRegExp expression( rule.pattern );
int index = expression.indexIn( text );
while ( index >= 0 )
QRegularExpression expression( rule.pattern );
QRegularExpressionMatch match = expression.match( text );
while ( match.hasMatch() )
{
int length = expression.matchedLength();
int index = match.capturedStart();
int length = match.capturedLength();
if ( length == 0 )
break; // avoid infinite loops
setFormat( index, length, rule.format );
index = expression.indexIn( text, index + length );
match = expression.match( text, index + length );
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsexpressionhighlighter.h
Expand Up @@ -21,6 +21,7 @@
#include <QHash>
#include <QTextCharFormat>
#include <QStringList>
#include <QRegularExpression>
#include "qgis_gui.h"

class QTextDocument;
Expand All @@ -43,7 +44,7 @@ class GUI_EXPORT QgsExpressionHighlighter : public QSyntaxHighlighter
private:
struct HighlightingRule
{
QRegExp pattern;
QRegularExpression pattern;
QTextCharFormat format;
};
QVector<HighlightingRule> highlightingRules;
Expand Down
5 changes: 3 additions & 2 deletions src/gui/raster/qgsrasterlayerproperties.cpp
Expand Up @@ -88,6 +88,7 @@
#include <QMenu>
#include <QScreen>
#include <QRegularExpressionValidator>
#include <QRegularExpression>

QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanvas *canvas, QWidget *parent, Qt::WindowFlags fl )
: QgsOptionsDialogBase( QStringLiteral( "RasterLayerProperties" ), parent, fl )
Expand Down Expand Up @@ -1674,7 +1675,7 @@ void QgsRasterLayerProperties::pbnImportTransparentPixelValues_clicked()
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
QStringList myTokens = myInputLine.split( QRegExp( "\\s+" ), QString::SkipEmptyParts );
#else
QStringList myTokens = myInputLine.split( QRegExp( "\\s+" ), Qt::SkipEmptyParts );
QStringList myTokens = myInputLine.split( QRegularExpression( "\\s+" ), Qt::SkipEmptyParts );
#endif
if ( myTokens.count() != 4 )
{
Expand Down Expand Up @@ -1711,7 +1712,7 @@ void QgsRasterLayerProperties::pbnImportTransparentPixelValues_clicked()
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
QStringList myTokens = myInputLine.split( QRegExp( "\\s+" ), QString::SkipEmptyParts );
#else
QStringList myTokens = myInputLine.split( QRegExp( "\\s+" ), Qt::SkipEmptyParts );
QStringList myTokens = myInputLine.split( QRegularExpression( "\\s+" ), Qt::SkipEmptyParts );
#endif
if ( myTokens.count() != 3 && myTokens.count() != 2 ) // 2 for QGIS < 1.9 compatibility
{
Expand Down
5 changes: 3 additions & 2 deletions src/gui/raster/qgsrastertransparencywidget.cpp
Expand Up @@ -18,6 +18,7 @@
#include <QTextStream>
#include <QMessageBox>
#include <QFileDialog>
#include <QRegularExpression>

#include "qgssettings.h"
#include "qgsrastertransparencywidget.h"
Expand Down Expand Up @@ -353,7 +354,7 @@ void QgsRasterTransparencyWidget::pbnImportTransparentPixelValues_clicked()
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
QStringList myTokens = myInputLine.split( QRegExp( "\\s+" ), QString::SkipEmptyParts );
#else
QStringList myTokens = myInputLine.split( QRegExp( "\\s+" ), Qt::SkipEmptyParts );
QStringList myTokens = myInputLine.split( QRegularExpression( "\\s+" ), Qt::SkipEmptyParts );
#endif
if ( myTokens.count() != 4 )
{
Expand Down Expand Up @@ -390,7 +391,7 @@ void QgsRasterTransparencyWidget::pbnImportTransparentPixelValues_clicked()
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
QStringList myTokens = myInputLine.split( QRegExp( "\\s+" ), QString::SkipEmptyParts );
#else
QStringList myTokens = myInputLine.split( QRegExp( "\\s+" ), Qt::SkipEmptyParts );
QStringList myTokens = myInputLine.split( QRegularExpression( "\\s+" ), Qt::SkipEmptyParts );
#endif
if ( myTokens.count() != 3 && myTokens.count() != 2 ) // 2 for QGIS < 1.9 compatibility
{
Expand Down

0 comments on commit ae6f4ad

Please sign in to comment.