pyqt5_to_pyqt6.py run

This commit is contained in:
Nyall Dawson 2024-10-17 13:32:59 +10:00
parent cd1dcbf8ca
commit 2c34056199
10 changed files with 44 additions and 44 deletions

View File

@ -50,7 +50,7 @@ class MetaSearchPlugin:
"""startup"""
# run
log_message('Initializing plugin', Qgis.Info)
log_message('Initializing plugin', Qgis.MessageLevel.Info)
run_icon = QIcon('{}/{}'.format(self.context.ppath, 'images/MetaSearch.svg'))
self.action_run = QAction(run_icon, 'MetaSearch',
@ -82,7 +82,7 @@ class MetaSearchPlugin:
def unload(self):
"""teardown"""
log_message('Unloading plugin', Qgis.Info)
log_message('Unloading plugin', Qgis.MessageLevel.Info)
# remove the plugin menu item and icon
self.iface.removePluginWebMenu(self.web_menu, self.action_run)
@ -92,7 +92,7 @@ class MetaSearchPlugin:
def run(self):
"""open MetaSearch"""
log_message('Running plugin', Qgis.Info)
log_message('Running plugin', Qgis.MessageLevel.Info)
self.dialog.exec()

View File

@ -88,7 +88,7 @@ class CSW202Search(SearchBase):
self.record_info_template = 'record_metadata_dc.html'
self.constraints = []
log_message(f'Connecting to CSW: {self.url}', Qgis.Info)
log_message(f'Connecting to CSW: {self.url}', Qgis.MessageLevel.Info)
self.conn = CatalogueServiceWeb(self.url, # spellok
timeout=self.timeout,
username=self.username,
@ -106,7 +106,7 @@ class CSW202Search(SearchBase):
# even for a global bbox, if a spatial filter is applied, then
# the CSW server will skip records without a bbox
if bbox and bbox != ['-180', '-90', '180', '90']:
log_message(f'Setting bbox filter ({bbox})', Qgis.Info)
log_message(f'Setting bbox filter ({bbox})', Qgis.MessageLevel.Info)
minx, miny, maxx, maxy = bbox
self.constraints.append(BBox([miny, minx, maxy, maxx],
crs='urn:ogc:def:crs:EPSG::4326'))
@ -114,20 +114,20 @@ class CSW202Search(SearchBase):
# keywords
if keywords:
# TODO: handle multiple word searches
log_message(f'Setting csw:AnyText filter {keywords}', Qgis.Info)
log_message(f'Setting csw:AnyText filter {keywords}', Qgis.MessageLevel.Info)
self.constraints.append(PropertyIsLike('csw:AnyText', keywords))
if len(self.constraints) > 1: # exclusive search (a && b)
self.constraints = [self.constraints]
log_message('Searching CSW: {self.url}', Qgis.Info)
log_message('Searching CSW: {self.url}', Qgis.MessageLevel.Info)
self.conn.getrecords2(constraints=self.constraints, maxrecords=limit,
startposition=offset, esn='full')
self.matches = self.conn.results['matches']
self.returned = self.conn.results['returned']
log_message(f'Matches: {self.matches}', Qgis.Info)
log_message(f'Returned: {self.returned}', Qgis.Info)
log_message(f'Matches: {self.matches}', Qgis.MessageLevel.Info)
log_message(f'Returned: {self.returned}', Qgis.MessageLevel.Info)
self.request = self.conn.request
self.response = self.conn.response
@ -161,7 +161,7 @@ class CSW202Search(SearchBase):
return recs
def get_record(self, identifier):
log_message(f'Searching CSW for record: {identifier}', Qgis.Info)
log_message(f'Searching CSW for record: {identifier}', Qgis.MessageLevel.Info)
self.conn.getrecordbyid([identifier])
return self.conn.records[identifier]
@ -185,7 +185,7 @@ class OARecSearch(SearchBase):
self.record_collection = None
if '/collections/' in self.url: # catalog is a collection
log_message('OARec endpoint is a collection', Qgis.Info)
log_message('OARec endpoint is a collection', Qgis.MessageLevel.Info)
self.base_url, self.record_collection = self.url.split('/collections/') # noqa
self.conn = Records(
self.base_url, timeout=self.timeout, auth=self.auth)
@ -198,7 +198,7 @@ class OARecSearch(SearchBase):
pass
self.request = self.conn.request
else:
log_message('OARec endpoint is not a collection', Qgis.Info)
log_message('OARec endpoint is not a collection', Qgis.MessageLevel.Info)
self.conn = Records(self.url, timeout=self.timeout, auth=self.auth)
self.request = None
@ -216,21 +216,21 @@ class OARecSearch(SearchBase):
}
if keywords:
log_message(f'Setting keyword search {keywords}', Qgis.Info)
log_message(f'Setting keyword search {keywords}', Qgis.MessageLevel.Info)
params['q'] = keywords
if bbox and bbox != ['-180', '-90', '180', '90']:
log_message(f'Setting bbox search {bbox}', Qgis.Info)
log_message(f'Setting bbox search {bbox}', Qgis.MessageLevel.Info)
params['bbox'] = bbox
log_message(f'Searching OARec: {self.url}', Qgis.Info)
log_message(f'Searching OARec: {self.url}', Qgis.MessageLevel.Info)
self.response = self.conn.collection_items(**params)
self.matches = self.response.get('numberMatched', 0)
self.returned = self.response.get('numberReturned', 0)
self.request = self.conn.request
log_message(f'Matches: {self.matches}', Qgis.Info)
log_message(f'Returned: {self.returned}', Qgis.Info)
log_message(f'Matches: {self.matches}', Qgis.MessageLevel.Info)
log_message(f'Returned: {self.returned}', Qgis.MessageLevel.Info)
def records(self):
recs = []
@ -260,7 +260,7 @@ class OARecSearch(SearchBase):
def get_record(self, identifier):
log_message(f'Searching OARec endpoint for item {identifier}',
Qgis.Info)
Qgis.MessageLevel.Info)
return self.conn.collection_item(self.record_collection, identifier)
def parse_link(self, link):
@ -279,10 +279,10 @@ class OARecSearch(SearchBase):
def get_catalog_service(url, catalog_type, timeout, username, password,
auth=None):
if catalog_type in [None, CATALOG_TYPES[0]]:
log_message('CSW endpoint detected', Qgis.Info)
log_message('CSW endpoint detected', Qgis.MessageLevel.Info)
return CSW202Search(url, timeout, username, password, auth)
elif catalog_type == CATALOG_TYPES[1]:
log_message('OARec endpoint detected', Qgis.Info)
log_message('OARec endpoint detected', Qgis.MessageLevel.Info)
if not OWSLIB_OAREC_SUPPORTED:
raise ValueError("OGC API - Records requires OWSLib 0.25 or above")
return OARecSearch(url, timeout, auth)

View File

@ -168,7 +168,7 @@ def clean_ows_url(url):
return url.toString()
def log_message(message, level=Qgis.Info):
def log_message(message, level=Qgis.MessageLevel.Info):
"""helper function to emit logging messages"""
LOGGER.logMessage(message, 'MetaSearch', level)

View File

@ -75,7 +75,7 @@ class fillnodata(GdalAlgorithm):
self.tr('Do not use the default validity mask for the input band'),
defaultValue=False,
optional=True)
nomask_param.setFlags(nomask_param.flags() | QgsProcessingParameterDefinition.FlagHidden)
nomask_param.setFlags(nomask_param.flags() | QgsProcessingParameterDefinition.Flag.FlagHidden)
self.addParameter(nomask_param)
self.addParameter(QgsProcessingParameterRasterLayer(self.MASK_LAYER,

View File

@ -140,7 +140,7 @@ class StatisticsByCategories(QgisAlgorithm):
fields.append(QgsField('q1', QMetaType.Type.Double))
fields.append(QgsField('q3', QMetaType.Type.Double))
fields.append(QgsField('iqr', QMetaType.Type.Double))
elif value_field.type() in (QMetaType.Type.QDate, QMetaType.QTime, QMetaType.QDateTime):
elif value_field.type() in (QMetaType.Type.QDate, QMetaType.Type.QTime, QMetaType.Type.QDateTime):
field_type = 'datetime'
fields.append(QgsField('count', QMetaType.Type.Int))
fields.append(QgsField('unique', QMetaType.Type.Int))

View File

@ -440,7 +440,7 @@ class TestPyQgsHanaProvider(QgisTestCase, ProviderTestCase):
self.assertEqual(fields.at(fields.indexFromName('emb')).length(), 3)
values = {feat['id']: feat['emb'] for feat in vl.getFeatures()}
expected = {1: '[0.1,0.2,0.1]', 2: QVariant()}
expected = {1: '[0.1,0.2,0.1]', 2: NULL}
self.assertEqual(values, expected)
def testRealVectorTypeEdit(self):

View File

@ -577,7 +577,7 @@ class TestQgsAnnotationRectangleTextItem(QgisTestCase):
format.setSize(20)
item.setFormat(format)
item.setAlignment(Qt.AlignRight | Qt.AlignBottom)
item.setAlignment(Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignBottom)
settings = QgsMapSettings()
settings.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:4326'))

View File

@ -265,7 +265,7 @@ class TestQgsRelation(QgisTestCase):
referencingLayer = rel.referencingLayer()
# Set Not Null constraint on the field
referencingLayer.setFieldConstraint(referencingLayer.fields().indexFromName('foreignkey'), QgsFieldConstraints.ConstraintNotNull)
referencingLayer.setFieldConstraint(referencingLayer.fields().indexFromName('foreignkey'), QgsFieldConstraints.Constraint.ConstraintNotNull)
self.assertFalse(rel.referencingFieldsAllowNull())

View File

@ -440,7 +440,7 @@ class TestQgsServerWMS(TestQgsServerWMSTestBase):
project = QgsProject()
fields = QgsFields()
fields.append(QgsField('int', QVariant.Int))
layer = QgsMemoryProviderUtils.createMemoryLayer('pointlabel', fields, QgsWkbTypes.Point, QgsCoordinateReferenceSystem(4326))
layer = QgsMemoryProviderUtils.createMemoryLayer('pointlabel', fields, QgsWkbTypes.Type.Point, QgsCoordinateReferenceSystem(4326))
layer.setLabelsEnabled(True)
settings = QgsPalLayerSettings()
settings.xOffset = -10

View File

@ -24,24 +24,24 @@ class TestQgsVariantUtils(unittest.TestCase):
def test_is_numeric_type(self):
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.Int))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.UInt))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.LongLong))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.ULongLong))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.Double))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.Float))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.Short))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.UShort))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.Char))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.UChar))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.SChar))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.Type.Int))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.Type.UInt))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.Type.LongLong))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.Type.ULongLong))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.Type.Double))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.Type.Float))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.Type.Short))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.Type.UShort))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.Type.Char))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.Type.UChar))
self.assertTrue(QgsVariantUtils.isNumericType(QMetaType.Type.SChar))
self.assertFalse(QgsVariantUtils.isNumericType(QMetaType.Bool))
self.assertFalse(QgsVariantUtils.isNumericType(QMetaType.QString))
self.assertFalse(QgsVariantUtils.isNumericType(QMetaType.QByteArray))
self.assertFalse(QgsVariantUtils.isNumericType(QMetaType.QDateTime))
self.assertFalse(QgsVariantUtils.isNumericType(QMetaType.QDate))
self.assertFalse(QgsVariantUtils.isNumericType(QMetaType.QTime))
self.assertFalse(QgsVariantUtils.isNumericType(QMetaType.Type.Bool))
self.assertFalse(QgsVariantUtils.isNumericType(QMetaType.Type.QString))
self.assertFalse(QgsVariantUtils.isNumericType(QMetaType.Type.QByteArray))
self.assertFalse(QgsVariantUtils.isNumericType(QMetaType.Type.QDateTime))
self.assertFalse(QgsVariantUtils.isNumericType(QMetaType.Type.QDate))
self.assertFalse(QgsVariantUtils.isNumericType(QMetaType.Type.QTime))
if __name__ == '__main__':