r24853 by craig - Qt6 build fixes, latex QRegExp replacement

scribus-commit scribus-commit at lists.scribus.net
Sun Jan 30 14:24:43 UTC 2022


Author: craig
Date: Sun Jan 30 14:24:43 2022
New Revision: 24853

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24853
Log:
Qt6 build fixes, latex QRegExp replacement

Modified:
    trunk/Scribus/scribus/latexhelpers.cpp
    trunk/Scribus/scribus/latexhelpers.h
    trunk/Scribus/scribus/pdflib_core.cpp

Modified: trunk/Scribus/scribus/latexhelpers.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24853&path=/trunk/Scribus/scribus/latexhelpers.cpp
==============================================================================
--- trunk/Scribus/scribus/latexhelpers.cpp	(original)
+++ trunk/Scribus/scribus/latexhelpers.cpp	Sun Jan 30 14:24:43 2022
@@ -42,38 +42,26 @@
 {
 	//This is required to fix a Qt incompatibility. See error message below for details.
 	static bool disable_highlighting = false;
-	if (disable_highlighting) return;
-
-	if (!m_rules) return;
+	if (disable_highlighting)
+		return;
+	if (!m_rules)
+		return;
 	foreach (LatexHighlighterRule *rule, *m_rules)
 	{
-		int index = text.indexOf(rule->regex);
-		while (index >= 0) {
-			int length;
-			if (rule->regex.captureCount() == 0)
-			{
-				length = rule->regex.matchedLength();
-			}
-			else
-			{
-				length = rule->regex.cap(1).length();
-				index = rule->regex.pos(1);
-			}
+		QRegularExpressionMatch match = rule->regex.match(text);
+		int n = 0;
+		int index = match.capturedStart(n);
+		while (index>=0)
+		{
+			int length = match.capturedLength(n);
+			index = match.capturedStart(n);
 			if (length == 0)
 			{
 				qWarning() << "Highlighter pattern" << rule->regex.pattern() << "matched a zero length string. This would lead to an infinite loop. Aborting. Please fix this pattern!";
 				break;
 			}
 			setFormat(index, length, rule->format);
-			
-			int oldindex = index;
-			int offset = index + length;
-			index = text.indexOf(rule->regex, offset);
-			if (index >= 0 && (index == oldindex || index <= offset)) {
-				qWarning() << QObject::tr("Highlighter error: Invalid index returned by Qt's QString.indexOf(). This is a incompatibility between different Qt versions and it can only be fixed by recompiling Scribus with the same Qt version that is running on this system. Syntax highlighting is disabled now, but render frames should continue to work without problems.") << "Additional debugging info: old index:" << oldindex << "new index:"<< index << "offset:" << offset;
-				disable_highlighting = true;
-				return;
-			}
+			index = match.capturedStart(++n);
 		}
 	}
 }
@@ -223,7 +211,7 @@
 			newRule->format.setFontWeight(QFont::Bold);
 		newRule->format.setFontUnderline(underline);
 		newRule->regex.setPattern(regex);
-		newRule->regex.setMinimal(minimal);
+		newRule->regex.setPatternOptions(QRegularExpression::InvertedGreedinessOption);
 		highlighterRules.append(newRule);
 	}
 }

Modified: trunk/Scribus/scribus/latexhelpers.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24853&path=/trunk/Scribus/scribus/latexhelpers.h
==============================================================================
--- trunk/Scribus/scribus/latexhelpers.h	(original)
+++ trunk/Scribus/scribus/latexhelpers.h	Sun Jan 30 14:24:43 2022
@@ -25,6 +25,7 @@
 
 #include <QObject>
 #include <QPointer>
+#include <QRegularExpression>
 #include <QString>
 #include <QStringRef>
 #include <QStringView>
@@ -34,10 +35,10 @@
 class LatexHighlighterRule
 {
 	public:
-		LatexHighlighterRule(){multiline=false;}
-		QRegExp regex;
+		LatexHighlighterRule();
+		QRegularExpression regex;
 		QTextCharFormat format;
-		bool multiline;
+		bool multiline {false};
 };
 
 class LatexHighlighter : public QSyntaxHighlighter

Modified: trunk/Scribus/scribus/pdflib_core.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24853&path=/trunk/Scribus/scribus/pdflib_core.cpp
==============================================================================
--- trunk/Scribus/scribus/pdflib_core.cpp	(original)
+++ trunk/Scribus/scribus/pdflib_core.cpp	Sun Jan 30 14:24:43 2022
@@ -56,7 +56,6 @@
 #include <QString>
 #include <QTemporaryFile>
 #include <QTextCodec>
-#include <QtXml>
 #include <QUuid>
 
 #include "cmsettings.h"




More information about the scribus-commit mailing list