Skip to content

Commit 2228016

Browse files
committed
Replace use of QRegExp in db manager
1 parent 0bd5038 commit 2228016

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

python/plugins/db_manager/db_plugins/data_model.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from qgis.PyQt.QtCore import (Qt,
2222
QTime,
23-
QRegExp,
23+
QRegularExpression,
2424
QAbstractTableModel,
2525
pyqtSignal,
2626
QObject)
@@ -286,11 +286,11 @@ def getObject(self, row):
286286
fld = val if val is not None else self._getNewObject()
287287
fld.name = self.data(self.index(row, 0)) or ""
288288
typestr = self.data(self.index(row, 1)) or ""
289-
regex = QRegExp("([^\\(]+)\\(([^\\)]+)\\)")
290-
startpos = regex.indexIn(typestr)
291-
if startpos >= 0:
292-
fld.dataType = regex.cap(1).strip()
293-
fld.modifier = regex.cap(2).strip()
289+
regex = QRegularExpression(r"([^\(]+)\(([^\)]+)\)")
290+
match = regex.match(typestr)
291+
if match.hasMatch():
292+
fld.dataType = match.captured(1).strip()
293+
fld.modifier = regex.captured(2).strip()
294294
else:
295295
fld.modifier = None
296296
fld.dataType = typestr

python/plugins/db_manager/db_plugins/postgis/connector.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from functools import cmp_to_key
2424

2525
from qgis.PyQt.QtCore import (
26-
QRegExp,
26+
QRegularExpression,
2727
QFile,
2828
QVariant,
2929
QDateTime,
@@ -848,9 +848,10 @@ def getSpatialRefInfo(self, srid):
848848

849849
srtext = sr[0]
850850
# try to extract just SR name (should be quoted in double quotes)
851-
regex = QRegExp('"([^"]+)"')
852-
if regex.indexIn(srtext) > -1:
853-
srtext = regex.cap(1)
851+
regex = QRegularExpression('"([^"]+)"')
852+
match = regex.match(srtext)
853+
if match.hasMatch():
854+
srtext = match.captured(1)
854855
return srtext
855856

856857
def isVectorTable(self, table):

python/plugins/db_manager/db_plugins/postgis/plugin.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
# this will disable the dbplugin if the connector raise an ImportError
2222
from .connector import PostGisDBConnector
2323

24-
from qgis.PyQt.QtCore import Qt, QRegExp, QCoreApplication
24+
from qgis.PyQt.QtCore import (
25+
Qt,
26+
QRegularExpression,
27+
QCoreApplication
28+
)
2529
from qgis.PyQt.QtGui import QIcon
2630
from qgis.PyQt.QtWidgets import QAction, QApplication, QMessageBox
2731
from qgis.core import Qgis, QgsApplication, QgsSettings
@@ -407,10 +411,10 @@ def __init__(self, row, table):
407411

408412
# get modifier (e.g. "precision,scale") from formatted type string
409413
trimmedTypeStr = typeStr.strip()
410-
regex = QRegExp("\\((.+)\\)$")
411-
startpos = regex.indexIn(trimmedTypeStr)
412-
if startpos >= 0:
413-
self.modifier = regex.cap(1).strip()
414+
regex = QRegularExpression(r"\((.+)\)$")
415+
match = regex.match(trimmedTypeStr)
416+
if match.hasMatch():
417+
self.modifier = match.captured(1).strip()
414418
else:
415419
self.modifier = None
416420

0 commit comments

Comments
 (0)