If running with Qt 5.13 or higher, search/replace uses the QRegularExpression class instead of just QRegExp

This commit is contained in:
Veronica K. B. Olsen
2020-07-03 23:06:56 +02:00
parent 9130db1fe2
commit a2b2910bd7
+23 -9
View File
@@ -35,7 +35,9 @@ import nw
from time import time from time import time
from PyQt5.QtCore import Qt, QSize, QThread, QTimer, pyqtSlot, QRegExp from PyQt5.QtCore import (
Qt, QSize, QThread, QTimer, pyqtSlot, QRegExp, QRegularExpression
)
from PyQt5.QtGui import ( from PyQt5.QtGui import (
QTextCursor, QTextOption, QKeySequence, QFont, QColor, QPalette, QIcon, QTextCursor, QTextOption, QKeySequence, QFont, QColor, QPalette, QIcon,
QTextDocument, QCursor, QPixmap QTextDocument, QCursor, QPixmap
@@ -1517,14 +1519,26 @@ class GuiDocEditSearch(QFrame):
expression object. expression object.
""" """
theText = self.searchBox.text() theText = self.searchBox.text()
if self.isRegEx and self.mainConf.verQtValue >= 50300: if self.isRegEx:
if self.isCaseSense: # Using the Unicode-capable QRegularExpression class was
rxCase = Qt.CaseSensitive # only added in Qt 5.13. Otherwise, 5.3 and up supports
else: # only the QRegExp class.
rxCase = Qt.CaseInsensitive if self.mainConf.verQtValue >= 51300:
theRegEx = QRegExp(theText, rxCase) rxOpt = QRegularExpression.UseUnicodePropertiesOption
self._alertSearchValid(theRegEx.isValid()) if not self.isCaseSense:
return theRegEx rxOpt |= QRegularExpression.CaseInsensitiveOption
theRegEx = QRegularExpression(theText, rxOpt)
self._alertSearchValid(theRegEx.isValid())
return theRegEx
elif self.mainConf.verQtValue >= 50300:
if self.isCaseSense:
rxOpt = Qt.CaseSensitive
else:
rxOpt = Qt.CaseInsensitive
theRegEx = QRegExp(theText, rxOpt)
self._alertSearchValid(theRegEx.isValid())
return theRegEx
return theText return theText