Skip to content

Commit b830a70

Browse files
committed
Fix Qt6 enum errors
1 parent 86bf100 commit b830a70

File tree

5 files changed

+29
-26
lines changed

5 files changed

+29
-26
lines changed

libqfieldsync/layer.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ def cloud_action(self, action):
655655
self._cloud_action = action
656656

657657
def get_attachment_field_type(self, field_name: str) -> Optional[AttachmentType]:
658-
if self.layer.type() != QgsMapLayer.VectorLayer:
658+
if self.layer.type() != QgsMapLayer.LayerType.VectorLayer:
659659
raise ExpectedVectorLayerError(
660660
f'Cannot get attachment field types for non-vector layer "{self.layer.name()}"!'
661661
)
@@ -670,7 +670,7 @@ def get_attachment_field_type(self, field_name: str) -> Optional[AttachmentType]
670670
return self.get_attachment_type_by_int_value(resource_type)
671671

672672
def get_attachment_fields(self) -> Dict[str, AttachmentType]:
673-
if self.layer.type() != QgsMapLayer.VectorLayer:
673+
if self.layer.type() != QgsMapLayer.LayerType.VectorLayer:
674674
return {}
675675

676676
attachment_fields = {}
@@ -798,7 +798,7 @@ def available_actions(self):
798798
)
799799
)
800800

801-
if self.layer.type() == QgsMapLayer.VectorLayer:
801+
if self.layer.type() == QgsMapLayer.LayerType.VectorLayer:
802802
actions.append(
803803
(
804804
SyncAction.OFFLINE,
@@ -837,7 +837,7 @@ def available_cloud_actions(self):
837837

838838
return actions
839839

840-
if self.layer.type() == QgsMapLayer.VectorLayer:
840+
if self.layer.type() == QgsMapLayer.LayerType.VectorLayer:
841841
# all vector layers can be converted for offline editting
842842
actions.append(
843843
(
@@ -886,7 +886,7 @@ def preferred_cloud_action(self, prefer_online):
886886
else:
887887
if ( # noqa: SIM114
888888
(self.is_file and not self.is_localized_path)
889-
or self.layer.type() != QgsMapLayer.VectorLayer
889+
or self.layer.type() != QgsMapLayer.LayerType.VectorLayer
890890
) and action == SyncAction.NO_ACTION:
891891
return idx, action
892892
elif action == SyncAction.OFFLINE:
@@ -901,7 +901,7 @@ def is_supported(self):
901901

902902
@property
903903
def can_lock_geometry(self):
904-
return self.layer.type() == QgsMapLayer.VectorLayer
904+
return self.layer.type() == QgsMapLayer.LayerType.VectorLayer
905905

906906
@property
907907
def value_map_button_interface_threshold(self):
@@ -1182,7 +1182,7 @@ def filename(self) -> str:
11821182
metadata = self.metadata
11831183
filename = ""
11841184

1185-
if self.layer.type() == QgsMapLayer.VectorTileLayer:
1185+
if self.layer.type() == QgsMapLayer.LayerType.VectorTileLayer:
11861186
uri = QgsDataSourceUri()
11871187
uri.setEncodedUri(self.layer.source())
11881188
return uri.param("url")
@@ -1255,7 +1255,7 @@ def pk_attr_name(self) -> str:
12551255
def get_pk_attr_name(self) -> str:
12561256
pk_attr_name: str = ""
12571257

1258-
if self.layer.type() != QgsMapLayer.VectorLayer:
1258+
if self.layer.type() != QgsMapLayer.LayerType.VectorLayer:
12591259
raise ExpectedVectorLayerError()
12601260

12611261
pk_indexes = self.layer.primaryKeyAttributes()
@@ -1344,7 +1344,7 @@ def copy(self, target_path, copied_files, keep_existent=False):
13441344
uri.setDatabase(os.path.join(target_path, file_name))
13451345
uri.setTable(metadata["layerName"])
13461346
new_source = uri.uri()
1347-
elif self.layer.type() == QgsMapLayer.VectorTileLayer:
1347+
elif self.layer.type() == QgsMapLayer.LayerType.VectorTileLayer:
13481348
uri = QgsDataSourceUri()
13491349
uri.setEncodedUri(self.layer.source())
13501350
uri.setParam("url", os.path.join(target_path, file_name))
@@ -1366,7 +1366,10 @@ def convert_to_gpkg(self, target_path): # noqa: PLR0912, PLR0915
13661366
:param target_path: A path to a folder into which the data will be copied
13671367
:param keep_existent: if True and target file already exists, keep it as it is
13681368
"""
1369-
if self.layer.type() != QgsMapLayer.VectorLayer or not self.layer.isValid():
1369+
if (
1370+
self.layer.type() != QgsMapLayer.LayerType.VectorLayer
1371+
or not self.layer.isValid()
1372+
):
13701373
return None
13711374

13721375
assert isinstance(self.layer, QgsVectorLayer)
@@ -1421,7 +1424,7 @@ def convert_to_gpkg(self, target_path): # noqa: PLR0912, PLR0915
14211424
fields = source_layer.fields()
14221425
virtual_field_count = 0
14231426
for i in range(len(fields)):
1424-
if fields.fieldOrigin(i) == QgsFields.OriginExpression:
1427+
if fields.fieldOrigin(i) == QgsFields.FieldOrigin.OriginExpression:
14251428
source_layer.removeExpressionField(i - virtual_field_count)
14261429
virtual_field_count += 1
14271430

@@ -1437,7 +1440,7 @@ def convert_to_gpkg(self, target_path): # noqa: PLR0912, PLR0915
14371440
source_layer, dest_file, QgsCoordinateTransformContext(), options
14381441
)
14391442

1440-
if error != QgsVectorFileWriter.NoError:
1443+
if error != QgsVectorFileWriter.WriterError.NoError:
14411444
return None
14421445
if returned_dest_file:
14431446
new_source = returned_dest_file

libqfieldsync/offline_converter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ def _convert(self, project: QgsProject) -> None: # noqa: PLR0912, PLR0915
221221

222222
# Set flags that usually significantly speed-up project file read
223223
read_flags = QgsProject.ReadFlags()
224-
read_flags |= QgsProject.FlagDontResolveLayers
225-
read_flags |= QgsProject.FlagDontLoadLayouts
224+
read_flags |= QgsProject.ReadFlag.FlagDontResolveLayers
225+
read_flags |= QgsProject.ReadFlag.FlagDontLoadLayouts
226226
if Qgis.versionInt() >= 32600: # noqa: PLR2004
227-
read_flags |= QgsProject.FlagDontLoad3DViews
227+
read_flags |= QgsProject.ReadFlag.FlagDontLoad3DViews
228228

229229
# Make a new function object that we can connect and disconnect easily
230230
on_original_project_read = self._on_original_project_read_wrapper(
@@ -301,7 +301,7 @@ def _convert(self, project: QgsProject) -> None: # noqa: PLR0912, PLR0915
301301
else layer_source.cloud_action
302302
)
303303

304-
if layer.isValid() and layer.type() == QgsMapLayer.VectorLayer:
304+
if layer.isValid() and layer.type() == QgsMapLayer.LayerType.VectorLayer:
305305
if layer_source.pk_attr_name:
306306
# NOTE even though `QFieldSync/sourceDataPrimaryKeys` is in plural, we never supported composite (multi-column) PKs and always stored a single value
307307
layer.setCustomProperty(
@@ -458,7 +458,7 @@ def post_process_offline_layers(self):
458458

459459
# check if value relations point to offline layers and adjust if necessary
460460
for e_layer in project.mapLayers().values():
461-
if e_layer.type() == QgsMapLayer.VectorLayer:
461+
if e_layer.type() == QgsMapLayer.LayerType.VectorLayer:
462462
remote_layer_id = e_layer.customProperty("QFieldSync/remoteLayerId")
463463
if (
464464
not remote_layer_id

libqfieldsync/offliners.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def convert_to_offline(
150150
layer_ids,
151151
only_selected,
152152
# containerType - GPKG or SpatiaLite
153-
containerType=QgsOfflineEditing.GPKG,
153+
containerType=QgsOfflineEditing.ContainerType.GPKG,
154154
# layerNameSuffix - by default " (offlined)" is added as suffix
155155
layerNameSuffix=None,
156156
)
@@ -219,7 +219,7 @@ def qgis_crs_to_ogr_srs(
219219
) -> osr.SpatialReference:
220220
"""Converts a QGIS CRS to an OGR CRS."""
221221
auth_id = crs.authid()
222-
srs_wkt = crs.toWkt(QgsCoordinateReferenceSystem.WKT_PREFERRED_GDAL)
222+
srs_wkt = crs.toWkt(QgsCoordinateReferenceSystem.WktVariant.WKT_PREFERRED_GDAL)
223223
ogr_srs = osr.SpatialReference()
224224

225225
if auth_id:
@@ -365,16 +365,16 @@ def update_data_provider(self, layer: QgsVectorLayer, source: str) -> None:
365365
# restore unique value constraints coming from original data provider
366366
if (
367367
field.constraints().constraints()
368-
& QgsFieldConstraints.ConstraintUnique
368+
& QgsFieldConstraints.Constraint.ConstraintUnique
369369
):
370370
layer.setFieldConstraint(
371-
index, QgsFieldConstraints.ConstraintUnique
371+
index, QgsFieldConstraints.Constraint.ConstraintUnique
372372
)
373373

374374
# remove any undesired not null constraints coming from original data provider
375375
if field.name() in not_null_field_names:
376376
layer.removeFieldConstraint(
377-
index, QgsFieldConstraints.ConstraintNotNull
377+
index, QgsFieldConstraints.Constraint.ConstraintNotNull
378378
)
379379

380380
def _convert_to_offline_project(
@@ -478,7 +478,7 @@ def _get_datasource_mapping(
478478
# A dict that maps data sources (tables) to a list of layers connecting them
479479
datasource_mapping = defaultdict(list)
480480
for layer in project.mapLayers().values():
481-
if layer.type() != QgsMapLayer.VectorLayer:
481+
if layer.type() != QgsMapLayer.LayerType.VectorLayer:
482482
logger.info(f"Skipping layer {layer.name()} :: not a vector layer")
483483
continue
484484

libqfieldsync/project_checker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def check_layer_has_utf8_datasources(
326326
layer = layer_source.layer
327327

328328
if (
329-
layer.type() == QgsMapLayer.VectorLayer
329+
layer.type() == QgsMapLayer.LayerType.VectorLayer
330330
and layer.dataProvider()
331331
and layer.dataProvider().encoding() != "UTF-8"
332332
# some providers return empty string as encoding, just ignore them
@@ -365,7 +365,7 @@ def check_layer_primary_key(
365365

366366
layer = layer_source.layer
367367

368-
if layer.type() != QgsMapLayer.VectorLayer:
368+
if layer.type() != QgsMapLayer.LayerType.VectorLayer:
369369
return None
370370

371371
# when the layer is configured as "no_action" and it is an "online" layer, then QFieldCloud is not responsible for the PKs,

libqfieldsync/utils/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, message, exception=None, long_message=None, tag="QFieldSync")
4343
if self.exception is not None:
4444
log_message = f"\nException:\n {self.long_message}"
4545

46-
QgsMessageLog.logMessage(log_message, tag, Qgis.Critical)
46+
QgsMessageLog.logMessage(log_message, tag, Qgis.MessageLevel.Critical)
4747

4848

4949
class NoProjectFoundError(QFieldSyncError):

0 commit comments

Comments
 (0)