diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-07-07 10:06:31 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-07-07 10:06:31 +0200 |
commit | 5ce20bd3efde4e1c44dee6c4af33b184b520b06b (patch) | |
tree | ab2f69dfc9cfda5b1c910a06462339d69d105796 /examples/widgets | |
parent | 6a116c6465451e5a58d1467ec926563b68ac677f (diff) | |
parent | 39c6018e484d2a6850d239de03fef89df730f357 (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: I299a65f15fb6b7eb900256590bbe76ad0568f546
Diffstat (limited to 'examples/widgets')
-rw-r--r-- | examples/widgets/dialogs/classwizard/classwizard.py | 2 | ||||
-rw-r--r-- | examples/widgets/itemviews/addressbook/addresswidget.py | 9 | ||||
-rw-r--r-- | examples/widgets/richtext/syntaxhighlighter.py | 56 |
3 files changed, 38 insertions, 29 deletions
diff --git a/examples/widgets/dialogs/classwizard/classwizard.py b/examples/widgets/dialogs/classwizard/classwizard.py index fc2feb498..d0e970f94 100644 --- a/examples/widgets/dialogs/classwizard/classwizard.py +++ b/examples/widgets/dialogs/classwizard/classwizard.py @@ -325,7 +325,7 @@ class CodeStylePage(QtWidgets.QWizardPage): if not is_baseClass: self.baseIncludeLineEdit.clear() - elif QtCore.QRegExp('Q[A-Z].*').exactMatch(baseClass): + elif QtCore.QRegularExpression('^Q[A-Z].*$').match(baseClass).hasMatch(): self.baseIncludeLineEdit.setText('<' + baseClass + '>') else: self.baseIncludeLineEdit.setText('"' + baseClass.lower() + '.h"') diff --git a/examples/widgets/itemviews/addressbook/addresswidget.py b/examples/widgets/itemviews/addressbook/addresswidget.py index b70b44b0a..d0c1747fb 100644 --- a/examples/widgets/itemviews/addressbook/addresswidget.py +++ b/examples/widgets/itemviews/addressbook/addresswidget.py @@ -45,7 +45,7 @@ try: except ImportError: import pickle -from PySide2.QtCore import (Qt, Signal, QRegExp, QModelIndex, +from PySide2.QtCore import (Qt, Signal, QRegularExpression, QModelIndex, QItemSelection, QSortFilterProxyModel) from PySide2.QtWidgets import QTabWidget, QMessageBox, QTableView, QAbstractItemView @@ -193,9 +193,10 @@ class AddressWidget(QTabWidget): # tab. The regex will end up looking like "^[ABC].*", only # allowing this tab to display items where the name starts with # "A", "B", or "C". Notice that we set it to be case-insensitive. - reFilter = "^[%s].*" % group - - proxyModel.setFilterRegExp(QRegExp(reFilter, Qt.CaseInsensitive)) + re = QRegularExpression("^[{}].*".format(group)) + assert re.isValid() + re.setPatternOptions(QRegularExpression.CaseInsensitiveOption) + proxyModel.setFilterRegularExpression(re) proxyModel.setFilterKeyColumn(0) # Filter on the "name" column proxyModel.sort(0, Qt.AscendingOrder) diff --git a/examples/widgets/richtext/syntaxhighlighter.py b/examples/widgets/richtext/syntaxhighlighter.py index 82e4c79a1..9be299401 100644 --- a/examples/widgets/richtext/syntaxhighlighter.py +++ b/examples/widgets/richtext/syntaxhighlighter.py @@ -130,65 +130,73 @@ class Highlighter(QtGui.QSyntaxHighlighter): "\\bunion\\b", "\\bunsigned\\b", "\\bvirtual\\b", "\\bvoid\\b", "\\bvolatile\\b"] - self.highlightingRules = [(QtCore.QRegExp(pattern), keywordFormat) + self.highlightingRules = [(QtCore.QRegularExpression(pattern), keywordFormat) for pattern in keywordPatterns] classFormat = QtGui.QTextCharFormat() classFormat.setFontWeight(QtGui.QFont.Bold) classFormat.setForeground(QtCore.Qt.darkMagenta) - self.highlightingRules.append((QtCore.QRegExp("\\bQ[A-Za-z]+\\b"), - classFormat)) + pattern = QtCore.QRegularExpression(r'\bQ[A-Za-z]+\b') + assert pattern.isValid() + self.highlightingRules.append((pattern, classFormat)) singleLineCommentFormat = QtGui.QTextCharFormat() singleLineCommentFormat.setForeground(QtCore.Qt.red) - self.highlightingRules.append((QtCore.QRegExp("//[^\n]*"), - singleLineCommentFormat)) + pattern = QtCore.QRegularExpression('//[^\n]*') + assert pattern.isValid() + self.highlightingRules.append((pattern, singleLineCommentFormat)) self.multiLineCommentFormat = QtGui.QTextCharFormat() self.multiLineCommentFormat.setForeground(QtCore.Qt.red) quotationFormat = QtGui.QTextCharFormat() quotationFormat.setForeground(QtCore.Qt.darkGreen) - self.highlightingRules.append((QtCore.QRegExp("\".*\""), - quotationFormat)) + pattern = QtCore.QRegularExpression('".*"') + assert pattern.isValid() + self.highlightingRules.append((pattern, quotationFormat)) functionFormat = QtGui.QTextCharFormat() functionFormat.setFontItalic(True) functionFormat.setForeground(QtCore.Qt.blue) - self.highlightingRules.append((QtCore.QRegExp("\\b[A-Za-z0-9_]+(?=\\()"), - functionFormat)) + pattern = QtCore.QRegularExpression(r'\b[A-Za-z0-9_]+(?=\()') + assert pattern.isValid() + self.highlightingRules.append((pattern, functionFormat)) - self.commentStartExpression = QtCore.QRegExp("/\\*") - self.commentEndExpression = QtCore.QRegExp("\\*/") + self.commentStartExpression = QtCore.QRegularExpression(r'/\*') + assert self.commentStartExpression.isValid() + self.commentEndExpression = QtCore.QRegularExpression(r'\*/') + assert self.commentEndExpression.isValid() def highlightBlock(self, text): for pattern, format in self.highlightingRules: - expression = QtCore.QRegExp(pattern) - index = expression.indexIn(text) - while index >= 0: - length = expression.matchedLength() + match = pattern.match(text) + while match.hasMatch(): + index = match.capturedStart(0) + length = match.capturedLength(0) self.setFormat(index, length, format) - index = expression.indexIn(text, index + length) + match = pattern.match(text, index + length) self.setCurrentBlockState(0) startIndex = 0 if self.previousBlockState() != 1: - startIndex = self.commentStartExpression.indexIn(text) + match = self.commentStartExpression.match(text) + startIndex = match.capturedStart(0) if match.hasMatch() else -1 while startIndex >= 0: - endIndex = self.commentEndExpression.indexIn(text, startIndex) - - if endIndex == -1: + match = self.commentEndExpression.match(text, startIndex) + if match.hasMatch(): + endIndex = match.capturedStart(0) + length = match.capturedLength(0) + commentLength = endIndex - startIndex + length + else: self.setCurrentBlockState(1) commentLength = len(text) - startIndex - else: - commentLength = endIndex - startIndex + self.commentEndExpression.matchedLength() self.setFormat(startIndex, commentLength, self.multiLineCommentFormat) - startIndex = self.commentStartExpression.indexIn(text, - startIndex + commentLength) + match = self.commentStartExpression.match(text, startIndex + commentLength) + startIndex = match.capturedStart(0) if match.hasMatch() else -1 if __name__ == '__main__': |