Skip to content

Commit

Permalink
[PyQt6] Add scope for enums and get rid of PyQt5.XXX import
Browse files Browse the repository at this point in the history
this has been done automatically with the following comand line

./scripts/3to4/3to4.py --only-qgis3-compatible-changes ./python/plugins/
./scripts/3to4/3to4.py --only-qgis3-compatible-changes ./tests/src/python/
  • Loading branch information
troopa81 authored and nyalldawson committed Jan 10, 2024
1 parent 7ba07fa commit 9d12ae8
Show file tree
Hide file tree
Showing 202 changed files with 3,059 additions and 3,017 deletions.
40 changes: 20 additions & 20 deletions python/plugins/MetaSearch/dialogs/maindialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(self, iface):
self.btnSearch.clicked.connect(self.search)
self.leKeywords.returnPressed.connect(self.search)
# prevent dialog from closing upon pressing enter
self.buttonBox.button(QDialogButtonBox.Close).setAutoDefault(False)
self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setAutoDefault(False)
# launch help from button
self.buttonBox.helpRequested.connect(self.help)
self.btnCanvasBbox.setAutoDefault(False)
Expand Down Expand Up @@ -302,7 +302,7 @@ def add_connection(self):

conn_new = NewConnectionDialog()
conn_new.setWindowTitle(self.tr('New Catalog Service'))
if conn_new.exec_() == QDialog.Accepted: # add to service list
if conn_new.exec_() == QDialog.DialogCode.Accepted: # add to service list
self.populate_connection_list()
self.textMetadata.clear()

Expand All @@ -325,7 +325,7 @@ def edit_connection(self):
conn_edit.cmbCatalogType.setCurrentText(
self.settings.value('/MetaSearch/%s/catalog-type' % current_text))

if conn_edit.exec_() == QDialog.Accepted: # update service list
if conn_edit.exec_() == QDialog.DialogCode.Accepted: # update service list
self.populate_connection_list()

def delete_connection(self):
Expand All @@ -339,8 +339,8 @@ def delete_connection(self):

result = QMessageBox.question(
self, self.tr('Delete Service'), msg,
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if result == QMessageBox.Yes: # remove service from list
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, QMessageBox.StandardButton.No)
if result == QMessageBox.StandardButton.Yes: # remove service from list
self.settings.remove(key)
index_to_delete = self.cmbConnectionsServices.currentIndex()
self.cmbConnectionsServices.removeItem(index_to_delete)
Expand Down Expand Up @@ -374,8 +374,8 @@ def add_default_connections(self):
msg = self.tr('{0} exists. Overwrite?').format(name)
res = QMessageBox.warning(self,
self.tr('Loading connections'), msg,
QMessageBox.Yes | QMessageBox.No)
if res != QMessageBox.Yes:
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
if res != QMessageBox.StandardButton.Yes:
continue

# no dups detected or overwrite is allowed
Expand Down Expand Up @@ -480,7 +480,7 @@ def search(self):
# TODO: allow users to select resources types
# to find ('service', 'dataset', etc.)
try:
with OverrideCursor(Qt.WaitCursor):
with OverrideCursor(Qt.CursorShape.WaitCursor):
self.catalog.query_records(bbox, keywords, self.maxrecords,
self.startfrom)

Expand Down Expand Up @@ -657,9 +657,9 @@ def navigate(self):
msg = self.tr('End of results. Go to start?')
res = QMessageBox.information(self, self.tr('Navigation'),
msg,
(QMessageBox.Ok |
QMessageBox.Cancel))
if res == QMessageBox.Ok:
(QMessageBox.StandardButton.Ok |
QMessageBox.StandardButton.Cancel))
if res == QMessageBox.StandardButton.Ok:
self.startfrom = 1
else:
return
Expand All @@ -670,9 +670,9 @@ def navigate(self):
msg = self.tr('Start of results. Go to end?')
res = QMessageBox.information(self, self.tr('Navigation'),
msg,
(QMessageBox.Ok |
QMessageBox.Cancel))
if res == QMessageBox.Ok:
(QMessageBox.StandardButton.Ok |
QMessageBox.StandardButton.Cancel))
if res == QMessageBox.StandardButton.Ok:
self.startfrom = (self.catalog.matches -
self.maxrecords + 1)
else:
Expand All @@ -693,7 +693,7 @@ def navigate(self):
keywords = self.leKeywords.text()

try:
with OverrideCursor(Qt.WaitCursor):
with OverrideCursor(Qt.CursorShape.WaitCursor):
self.catalog.query_records(bbox, keywords,
limit=self.maxrecords,
offset=self.startfrom)
Expand Down Expand Up @@ -761,10 +761,10 @@ def add_to_ows(self):
msg = self.tr('Connection {0} exists. Overwrite?').format(sname)
res = QMessageBox.warning(
self, self.tr('Saving server'), msg,
QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel)
if res == QMessageBox.No: # assign new name with serial
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No | QMessageBox.StandardButton.Cancel)
if res == QMessageBox.StandardButton.No: # assign new name with serial
sname = serialize_string(sname)
elif res == QMessageBox.Cancel:
elif res == QMessageBox.StandardButton.Cancel:
return

# no dups detected or overwrite is allowed
Expand Down Expand Up @@ -852,7 +852,7 @@ def show_metadata(self):
pass

try:
with OverrideCursor(Qt.WaitCursor):
with OverrideCursor(Qt.CursorShape.WaitCursor):
cat = get_catalog_service(self.catalog_url, # spellok
catalog_type=self.catalog_type,
timeout=self.timeout,
Expand Down Expand Up @@ -946,7 +946,7 @@ def _get_catalog(self):
pass

# connect to the server
with OverrideCursor(Qt.WaitCursor):
with OverrideCursor(Qt.CursorShape.WaitCursor):
try:
self.catalog = get_catalog_service(
self.catalog_url, catalog_type=self.catalog_type,
Expand Down
14 changes: 7 additions & 7 deletions python/plugins/MetaSearch/dialogs/manageconnectionsdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ def manage_gui(self):

if self.mode == 1:
self.label.setText(self.tr('Load from file'))
self.buttonBox.button(QDialogButtonBox.Ok).setText(self.tr('Load'))
self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setText(self.tr('Load'))
else:
self.label.setText(self.tr('Save to file'))
self.buttonBox.button(QDialogButtonBox.Ok).setText(self.tr('Save'))
self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setText(self.tr('Save'))
self.populate()

self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False)

def select_file(self):
"""select file ops"""
Expand Down Expand Up @@ -90,7 +90,7 @@ def select_file(self):
if self.mode == 1:
self.populate()

self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(True)
self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(True)

def populate(self):
"""populate connections list from settings"""
Expand Down Expand Up @@ -159,8 +159,8 @@ def load(self, items):
conn_name)
res = QMessageBox.warning(self, self.tr('Loading Connections'),
label,
QMessageBox.Yes | QMessageBox.No)
if res != QMessageBox.Yes:
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
if res != QMessageBox.StandardButton.Yes:
continue

# no dups detected or overwrite is allowed
Expand All @@ -187,7 +187,7 @@ def accept(self):
self.filename = None
self.leFileName.clear()
self.listConnections.clear()
self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False)

def reject(self):
"""back out of manage connections dialogue"""
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/MetaSearch/dialogs/newconnectiondialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def accept(self):
res = QMessageBox.warning(
self, self.tr('Save Connection'),
self.tr('Overwrite {0}?').format(conn_name),
QMessageBox.Ok | QMessageBox.Cancel)
if res == QMessageBox.Cancel:
QMessageBox.StandardButton.Ok | QMessageBox.StandardButton.Cancel)
if res == QMessageBox.StandardButton.Cancel:
return

# on rename delete original entry first
Expand Down
26 changes: 13 additions & 13 deletions python/plugins/db_manager/db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DBManager(QMainWindow):

def __init__(self, iface, parent=None):
QMainWindow.__init__(self, parent)
self.setAttribute(Qt.WA_DeleteOnClose)
self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
self.setupUi()
self.iface = iface

Expand Down Expand Up @@ -79,7 +79,7 @@ def closeEvent(self, e):
QMainWindow.closeEvent(self, e)

def refreshItem(self, item=None):
with OverrideCursor(Qt.WaitCursor):
with OverrideCursor(Qt.CursorShape.WaitCursor):
try:
if item is None:
item = self.tree.currentItem()
Expand All @@ -88,7 +88,7 @@ def refreshItem(self, item=None):
DlgDbError.showError(e, self)

def itemChanged(self, item):
with OverrideCursor(Qt.WaitCursor):
with OverrideCursor(Qt.CursorShape.WaitCursor):
try:
self.reloadButtons()
# Force-reload information on the layer
Expand Down Expand Up @@ -117,7 +117,7 @@ def reloadButtons(self):
self._lastDb.registerAllActions(self)

def tabChanged(self, index):
with OverrideCursor(Qt.WaitCursor):
with OverrideCursor(Qt.CursorShape.WaitCursor):
try:
self.refreshTabs()
except BaseError as e:
Expand Down Expand Up @@ -300,7 +300,7 @@ def invokeCallback(self, callback, *params):
This method takes care to override and restore the cursor,
but also catches exceptions and displays the error dialog.
"""
with OverrideCursor(Qt.WaitCursor):
with OverrideCursor(Qt.CursorShape.WaitCursor):
try:
callback(self.tree.currentItem(), self.sender(), self, *params)
except BaseError as e:
Expand Down Expand Up @@ -369,9 +369,9 @@ def close_tab(self, index):
widget.deleteLater()

def toolBarOrientation(self):
button_style = Qt.ToolButtonIconOnly
if self.toolBar.orientation() == Qt.Horizontal:
button_style = Qt.ToolButtonTextBesideIcon
button_style = Qt.ToolButtonStyle.ToolButtonIconOnly
if self.toolBar.orientation() == Qt.Orientation.Horizontal:
button_style = Qt.ToolButtonStyle.ToolButtonTextBesideIcon

widget = self.toolBar.widgetForAction(self.actionImport)
widget.setToolButtonStyle(button_style)
Expand Down Expand Up @@ -399,28 +399,28 @@ def setupUi(self):
self.tabs.tabCloseRequested.connect(self.close_tab)
tabbar = self.tabs.tabBar()
for i in range(3):
btn = tabbar.tabButton(i, QTabBar.RightSide) if tabbar.tabButton(i, QTabBar.RightSide) else tabbar.tabButton(i, QTabBar.LeftSide)
btn = tabbar.tabButton(i, QTabBar.ButtonPosition.RightSide) if tabbar.tabButton(i, QTabBar.ButtonPosition.RightSide) else tabbar.tabButton(i, QTabBar.ButtonPosition.LeftSide)
btn.resize(0, 0)
btn.hide()

# Creates layout for message bar
self.layout = QGridLayout(self.info)
self.layout.setContentsMargins(0, 0, 0, 0)
spacerItem = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
spacerItem = QSpacerItem(20, 40, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding)
self.layout.addItem(spacerItem, 1, 0, 1, 1)
# init messageBar instance
self.infoBar = QgsMessageBar(self.info)
sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
sizePolicy = QSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Fixed)
self.infoBar.setSizePolicy(sizePolicy)
self.layout.addWidget(self.infoBar, 0, 0, 1, 1)

# create database tree
self.dock = QDockWidget(self.tr("Providers"), self)
self.dock.setObjectName("DB_Manager_DBView")
self.dock.setFeatures(QDockWidget.DockWidgetMovable)
self.dock.setFeatures(QDockWidget.DockWidgetFeature.DockWidgetMovable)
self.tree = DBTree(self)
self.dock.setWidget(self.tree)
self.addDockWidget(Qt.LeftDockWidgetArea, self.dock)
self.addDockWidget(Qt.DockWidgetArea.LeftDockWidgetArea, self.dock)

# create status bar
self.statusBar = QStatusBar(self)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/db_manager/db_manager_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def run(self):
self.dlg.destroyed.connect(self.onDestroyed)
self.dlg.show()
self.dlg.raise_()
self.dlg.setWindowState(self.dlg.windowState() & ~Qt.WindowMinimized)
self.dlg.setWindowState(self.dlg.windowState() & ~Qt.WindowState.WindowMinimized)
self.dlg.activateWindow()

def onDestroyed(self, obj):
Expand Down
24 changes: 12 additions & 12 deletions python/plugins/db_manager/db_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,12 @@ def data(self, index, role):
if not index.isValid():
return None

if role == Qt.DecorationRole and index.column() == 0:
if role == Qt.ItemDataRole.DecorationRole and index.column() == 0:
icon = index.internalPointer().icon()
if icon:
return icon

if role != Qt.DisplayRole and role != Qt.EditRole:
if role != Qt.ItemDataRole.DisplayRole and role != Qt.ItemDataRole.EditRole:
return None

retval = index.internalPointer().data(index.column())
Expand All @@ -394,33 +394,33 @@ def flags(self, index):
if not index.isValid():
return Qt.NoItemFlags

flags = Qt.ItemIsEnabled | Qt.ItemIsSelectable
flags = Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemIsSelectable

if index.column() == 0:
item = index.internalPointer()

if isinstance(item, SchemaItem) or isinstance(item, TableItem):
flags |= Qt.ItemIsEditable
flags |= Qt.ItemFlag.ItemIsEditable

if isinstance(item, TableItem):
flags |= Qt.ItemIsDragEnabled
flags |= Qt.ItemFlag.ItemIsDragEnabled

# vectors/tables can be dropped on connected databases to be imported
if isImportVectorAvail:
if isinstance(item, ConnectionItem) and item.populated:
flags |= Qt.ItemIsDropEnabled
flags |= Qt.ItemFlag.ItemIsDropEnabled

if isinstance(item, (SchemaItem, TableItem)):
flags |= Qt.ItemIsDropEnabled
flags |= Qt.ItemFlag.ItemIsDropEnabled

# SL/Geopackage db files can be dropped everywhere in the tree
if self.hasSpatialiteSupport or self.hasGPKGSupport:
flags |= Qt.ItemIsDropEnabled
flags |= Qt.ItemFlag.ItemIsDropEnabled

return flags

def headerData(self, section, orientation, role):
if orientation == Qt.Horizontal and role == Qt.DisplayRole and section < len(self.header):
if orientation == Qt.Orientation.Horizontal and role == Qt.ItemDataRole.DisplayRole and section < len(self.header):
return self.header[section]
return None

Expand Down Expand Up @@ -457,7 +457,7 @@ def hasChildren(self, parent):
return parentItem.childCount() > 0 or not parentItem.populated

def setData(self, index, value, role):
if role != Qt.EditRole or index.column() != 0:
if role != Qt.ItemDataRole.EditRole or index.column() != 0:
return False

item = index.internalPointer()
Expand All @@ -470,7 +470,7 @@ def setData(self, index, value, role):
if new_value == obj.name:
return False

with OverrideCursor(Qt.WaitCursor):
with OverrideCursor(Qt.CursorShape.WaitCursor):
try:
obj.rename(new_value)
self._onDataChanged(index)
Expand All @@ -490,7 +490,7 @@ def removeRows(self, row, count, parent):
self.endRemoveRows()

def _refreshIndex(self, index, force=False):
with OverrideCursor(Qt.WaitCursor):
with OverrideCursor(Qt.CursorShape.WaitCursor):
try:
item = index.internalPointer() if index.isValid() else self.rootItem
prevPopulated = item.populated
Expand Down
Loading

0 comments on commit 9d12ae8

Please sign in to comment.