aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-07-07 10:06:31 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-07-07 10:06:31 +0200
commit5ce20bd3efde4e1c44dee6c4af33b184b520b06b (patch)
treeab2f69dfc9cfda5b1c910a06462339d69d105796 /examples
parent6a116c6465451e5a58d1467ec926563b68ac677f (diff)
parent39c6018e484d2a6850d239de03fef89df730f357 (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Diffstat (limited to 'examples')
-rw-r--r--examples/opengl/grabber.py10
-rw-r--r--examples/widgets/dialogs/classwizard/classwizard.py2
-rw-r--r--examples/widgets/itemviews/addressbook/addresswidget.py9
-rw-r--r--examples/widgets/richtext/syntaxhighlighter.py56
-rw-r--r--examples/xmlpatterns/schema/schema.py43
5 files changed, 70 insertions, 50 deletions
diff --git a/examples/opengl/grabber.py b/examples/opengl/grabber.py
index 9b5358a85..04a16fcbc 100644
--- a/examples/opengl/grabber.py
+++ b/examples/opengl/grabber.py
@@ -414,11 +414,13 @@ class MainWindow(QtWidgets.QMainWindow):
if not ok:
return QtCore.QSize()
- regExp = QtCore.QRegExp("([0-9]+) *x *([0-9]+)")
+ regExp = QtCore.QRegularExpression("([0-9]+) *x *([0-9]+)")
+ assert regExp.isValid()
- if regExp.exactMatch(text):
- width = int(regExp.cap(1))
- height = int(regExp.cap(2))
+ match = regExp.match(text)
+ if match.hasMatch():
+ width = int(match.captured(1))
+ height = int(match.captured(2))
if width > 0 and width < 2048 and height > 0 and height < 2048:
return QtCore.QSize(width, height)
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__':
diff --git a/examples/xmlpatterns/schema/schema.py b/examples/xmlpatterns/schema/schema.py
index 677b56498..d3c22c184 100644
--- a/examples/xmlpatterns/schema/schema.py
+++ b/examples/xmlpatterns/schema/schema.py
@@ -77,19 +77,22 @@ class XmlSyntaxHighlighter(QtGui.QSyntaxHighlighter):
format = QtGui.QTextCharFormat()
format.setForeground(QtCore.Qt.darkBlue)
format.setFontWeight(QtGui.QFont.Bold)
- pattern = QtCore.QRegExp("(<[a-zA-Z:]+\\b|<\\?[a-zA-Z:]+\\b|\\?>|>|/>|</[a-zA-Z:]+>)")
+ pattern = QtCore.QRegularExpression(r'(<[a-zA-Z:]+\b|<\?[a-zA-Z:]+\b|\?>|>|/>|</[a-zA-Z:]+>)')
+ assert pattern.isValid()
self.highlightingRules.append((pattern, format))
# Attribute format.
format = QtGui.QTextCharFormat()
format.setForeground(QtCore.Qt.darkGreen)
- pattern = QtCore.QRegExp("[a-zA-Z:]+=")
+ pattern = QtCore.QRegularExpression('[a-zA-Z:]+=')
+ assert pattern.isValid()
self.highlightingRules.append((pattern, format))
# Attribute content format.
format = QtGui.QTextCharFormat()
format.setForeground(QtCore.Qt.red)
- pattern = QtCore.QRegExp("(\"[^\"]*\"|'[^']*')")
+ pattern = QtCore.QRegularExpression("(\"[^\"]*\"|'[^']*')")
+ assert pattern.isValid()
self.highlightingRules.append((pattern, format))
# Comment format.
@@ -97,35 +100,41 @@ class XmlSyntaxHighlighter(QtGui.QSyntaxHighlighter):
self.commentFormat.setForeground(QtCore.Qt.lightGray)
self.commentFormat.setFontItalic(True)
- self.commentStartExpression = QtCore.QRegExp("<!--")
- self.commentEndExpression = QtCore.QRegExp("-->")
+ self.commentStartExpression = QtCore.QRegularExpression("<!--")
+ assert self.commentStartExpression.isValid()
+ self.commentEndExpression = QtCore.QRegularExpression("-->")
+ 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()
+ 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)
+ endIndex = match.capturedStart(0) if match.hasMatch() else -1
+ if match.hasMatch():
+ endIndex = match.capturedStart(0)
+ length = match.capturedLength(0)
+ commentLength = endIndex - startIndex + length
+ else:
self.setCurrentBlockState(1)
commentLength = text.length() - startIndex
- else:
- commentLength = endIndex - startIndex + self.commentEndExpression.matchedLength()
self.setFormat(startIndex, commentLength, self.commentFormat)
- startIndex = self.commentStartExpression.indexIn(text,
- startIndex + commentLength)
+ match = self.commentStartExpression.match(text, startIndex + commentLength)
+ startIndex = match.capturedStart(0) if match.hasMatch() else -1
class MessageHandler(QtXmlPatterns.QAbstractMessageHandler):