@@ -35,38 +35,53 @@ QtPythonSyntaxHighlighter::QtPythonSyntaxHighlighter (QTextDocument* parent)
3535 << " \\ b__\\ *\\ b" ;
3636 foreach (const QString& pattern, keywordPatterns)
3737 {
38+ #ifdef QT_5
3839 rule.pattern = QRegExp (pattern);
40+ #else // QT_5
41+ rule.pattern = QRegularExpression (pattern);
42+ #endif // QT_5
43+
3944 rule.format = keywordFormat;
4045 _highlightingRules.append (rule);
4146 } // foreach (const QString& pattern, keywordPatterns)
4247
4348 quotationFormat.setForeground (Qt::red);
49+ #ifdef QT_5
4450 rule.pattern = QRegExp (" \" .*\" " );
51+ #else // QT_5
52+ rule.pattern = QRegularExpression (" \" .*\" " );
53+ #endif // QT_5
4554 rule.format = quotationFormat;
4655 _highlightingRules.append (rule);
4756 quotationFormat.setFontItalic (true );
4857 quotationFormat.setForeground (Qt::cyan);
58+ #ifdef QT_5
4959 rule.pattern = QRegExp (" \\ b[A-Za-z0-9__]+(?=\\ ()" );
60+ #else // QT_5
61+ rule.pattern = QRegularExpression (" \\ b[A-Za-z0-9__]+(?=\\ ()" );
62+ #endif // QT_5
5063 rule.format = functionFormat;
5164 _highlightingRules.append (rule);
5265 singleLineFormat.setForeground (Qt::blue);
66+ #ifdef QT_5
5367 rule.pattern = QRegExp (" #[^\n ]*" );
68+ #else // QT_5
69+ rule.pattern = QRegularExpression (" #[^\n ]*" );
70+ #endif // QT_5
5471 rule.format = singleLineFormat;
5572 _highlightingRules.append (rule);
5673} // QtPythonSyntaxHighlighter::QtPythonSyntaxHighlighter
5774
5875
5976
60- QtPythonSyntaxHighlighter::QtPythonSyntaxHighlighter (
61- const QtPythonSyntaxHighlighter&)
77+ QtPythonSyntaxHighlighter::QtPythonSyntaxHighlighter (const QtPythonSyntaxHighlighter&)
6278 : QSyntaxHighlighter ((QTextDocument*)0)
6379{
6480 assert (0 && " QtPythonSyntaxHighlighter copy constructor is not allowed." );
6581} // QtPythonSyntaxHighlighter::QtPythonSyntaxHighlighter
6682
6783
68- QtPythonSyntaxHighlighter& QtPythonSyntaxHighlighter::operator = (
69- const QtPythonSyntaxHighlighter&)
84+ QtPythonSyntaxHighlighter& QtPythonSyntaxHighlighter::operator = (const QtPythonSyntaxHighlighter&)
7085{
7186 assert (0 && " QtPythonSyntaxHighlighter copy constructor is not allowed." );
7287 return *this ;
@@ -82,7 +97,9 @@ void QtPythonSyntaxHighlighter::highlightBlock (const QString& text)
8297{
8398 foreach (const HighlightingRule& rule, _highlightingRules)
8499 {
100+ #ifdef QT_5
85101 QRegExp expression (rule.pattern );
102+
86103 int index = expression.indexIn (text);
87104 while (index >= 0 )
88105 {
@@ -93,12 +110,20 @@ void QtPythonSyntaxHighlighter::highlightBlock (const QString& text)
93110 // Sécurité contre une expression mal formulée (=> boucle infinie) :
94111 if (length <= 0 )
95112 {
96- cerr << __FILE__ << ' ' << __LINE__
97- << " Erreur de formulation de l'expression régulière "
98- << expression.pattern ( ).toStdString ( ) << endl;
113+ cerr << __FILE__ << ' ' << __LINE__ << " Erreur de formulation de l'expression régulière " << expression.pattern ( ).toStdString ( ) << endl;
99114 break ;
100115 } // if (length <= 0)
101116 } // while (index >= 0)
117+ #else // QT_5
118+ QRegularExpression expression (rule.pattern );
119+
120+ QRegularExpressionMatchIterator it = expression.globalMatch (text);
121+ while (it.hasNext ( ))
122+ {
123+ QRegularExpressionMatch match = it.next ( );
124+ setFormat (match.capturedStart ( ), match.capturedLength ( ), rule.format );
125+ } // while (it.hasNext ( ))
126+ #endif // QT_5
102127 } // foreach (const HighlightingRule& rule, _highlightingRules)
103128} // QtPythonSyntaxHighlighter::highlightBlock
104129
0 commit comments