Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions libqfieldsync/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ def cloud_action(self, action):
self._cloud_action = action

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

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

attachment_fields = {}
Expand Down Expand Up @@ -798,7 +798,7 @@ def available_actions(self):
)
)

if self.layer.type() == QgsMapLayer.VectorLayer:
if self.layer.type() == QgsMapLayer.LayerType.VectorLayer:
actions.append(
(
SyncAction.OFFLINE,
Expand Down Expand Up @@ -837,7 +837,7 @@ def available_cloud_actions(self):

return actions

if self.layer.type() == QgsMapLayer.VectorLayer:
if self.layer.type() == QgsMapLayer.LayerType.VectorLayer:
# all vector layers can be converted for offline editting
actions.append(
(
Expand Down Expand Up @@ -886,7 +886,7 @@ def preferred_cloud_action(self, prefer_online):
else:
if ( # noqa: SIM114
(self.is_file and not self.is_localized_path)
or self.layer.type() != QgsMapLayer.VectorLayer
or self.layer.type() != QgsMapLayer.LayerType.VectorLayer
) and action == SyncAction.NO_ACTION:
return idx, action
elif action == SyncAction.OFFLINE:
Expand All @@ -901,7 +901,7 @@ def is_supported(self):

@property
def can_lock_geometry(self):
return self.layer.type() == QgsMapLayer.VectorLayer
return self.layer.type() == QgsMapLayer.LayerType.VectorLayer

@property
def value_map_button_interface_threshold(self):
Expand Down Expand Up @@ -1182,7 +1182,7 @@ def filename(self) -> str:
metadata = self.metadata
filename = ""

if self.layer.type() == QgsMapLayer.VectorTileLayer:
if self.layer.type() == QgsMapLayer.LayerType.VectorTileLayer:
uri = QgsDataSourceUri()
uri.setEncodedUri(self.layer.source())
return uri.param("url")
Expand Down Expand Up @@ -1255,7 +1255,7 @@ def pk_attr_name(self) -> str:
def get_pk_attr_name(self) -> str:
pk_attr_name: str = ""

if self.layer.type() != QgsMapLayer.VectorLayer:
if self.layer.type() != QgsMapLayer.LayerType.VectorLayer:
raise ExpectedVectorLayerError()

pk_indexes = self.layer.primaryKeyAttributes()
Expand Down Expand Up @@ -1344,7 +1344,7 @@ def copy(self, target_path, copied_files, keep_existent=False):
uri.setDatabase(os.path.join(target_path, file_name))
uri.setTable(metadata["layerName"])
new_source = uri.uri()
elif self.layer.type() == QgsMapLayer.VectorTileLayer:
elif self.layer.type() == QgsMapLayer.LayerType.VectorTileLayer:
uri = QgsDataSourceUri()
uri.setEncodedUri(self.layer.source())
uri.setParam("url", os.path.join(target_path, file_name))
Expand All @@ -1366,7 +1366,10 @@ def convert_to_gpkg(self, target_path): # noqa: PLR0912, PLR0915
:param target_path: A path to a folder into which the data will be copied
:param keep_existent: if True and target file already exists, keep it as it is
"""
if self.layer.type() != QgsMapLayer.VectorLayer or not self.layer.isValid():
if (
self.layer.type() != QgsMapLayer.LayerType.VectorLayer
or not self.layer.isValid()
):
return None

assert isinstance(self.layer, QgsVectorLayer)
Expand Down Expand Up @@ -1421,7 +1424,7 @@ def convert_to_gpkg(self, target_path): # noqa: PLR0912, PLR0915
fields = source_layer.fields()
virtual_field_count = 0
for i in range(len(fields)):
if fields.fieldOrigin(i) == QgsFields.OriginExpression:
if fields.fieldOrigin(i) == QgsFields.FieldOrigin.OriginExpression:
source_layer.removeExpressionField(i - virtual_field_count)
virtual_field_count += 1

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

if error != QgsVectorFileWriter.NoError:
if error != QgsVectorFileWriter.WriterError.NoError:
return None
if returned_dest_file:
new_source = returned_dest_file
Expand Down
10 changes: 5 additions & 5 deletions libqfieldsync/offline_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ def _convert(self, project: QgsProject) -> None: # noqa: PLR0912, PLR0915

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

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

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

# check if value relations point to offline layers and adjust if necessary
for e_layer in project.mapLayers().values():
if e_layer.type() == QgsMapLayer.VectorLayer:
if e_layer.type() == QgsMapLayer.LayerType.VectorLayer:
remote_layer_id = e_layer.customProperty("QFieldSync/remoteLayerId")
if (
not remote_layer_id
Expand Down
12 changes: 6 additions & 6 deletions libqfieldsync/offliners.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def convert_to_offline(
layer_ids,
only_selected,
# containerType - GPKG or SpatiaLite
containerType=QgsOfflineEditing.GPKG,
containerType=QgsOfflineEditing.ContainerType.GPKG,
# layerNameSuffix - by default " (offlined)" is added as suffix
layerNameSuffix=None,
)
Expand Down Expand Up @@ -219,7 +219,7 @@ def qgis_crs_to_ogr_srs(
) -> osr.SpatialReference:
"""Converts a QGIS CRS to an OGR CRS."""
auth_id = crs.authid()
srs_wkt = crs.toWkt(QgsCoordinateReferenceSystem.WKT_PREFERRED_GDAL)
srs_wkt = crs.toWkt(QgsCoordinateReferenceSystem.WktVariant.WKT_PREFERRED_GDAL)
ogr_srs = osr.SpatialReference()

if auth_id:
Expand Down Expand Up @@ -365,16 +365,16 @@ def update_data_provider(self, layer: QgsVectorLayer, source: str) -> None:
# restore unique value constraints coming from original data provider
if (
field.constraints().constraints()
& QgsFieldConstraints.ConstraintUnique
& QgsFieldConstraints.Constraint.ConstraintUnique
):
layer.setFieldConstraint(
index, QgsFieldConstraints.ConstraintUnique
index, QgsFieldConstraints.Constraint.ConstraintUnique
)

# remove any undesired not null constraints coming from original data provider
if field.name() in not_null_field_names:
layer.removeFieldConstraint(
index, QgsFieldConstraints.ConstraintNotNull
index, QgsFieldConstraints.Constraint.ConstraintNotNull
)

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

Expand Down
4 changes: 2 additions & 2 deletions libqfieldsync/project_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def check_layer_has_utf8_datasources(
layer = layer_source.layer

if (
layer.type() == QgsMapLayer.VectorLayer
layer.type() == QgsMapLayer.LayerType.VectorLayer
and layer.dataProvider()
and layer.dataProvider().encoding() != "UTF-8"
# some providers return empty string as encoding, just ignore them
Expand Down Expand Up @@ -365,7 +365,7 @@ def check_layer_primary_key(

layer = layer_source.layer

if layer.type() != QgsMapLayer.VectorLayer:
if layer.type() != QgsMapLayer.LayerType.VectorLayer:
return None

# when the layer is configured as "no_action" and it is an "online" layer, then QFieldCloud is not responsible for the PKs,
Expand Down
2 changes: 1 addition & 1 deletion libqfieldsync/utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, message, exception=None, long_message=None, tag="QFieldSync")
if self.exception is not None:
log_message = f"\nException:\n {self.long_message}"

QgsMessageLog.logMessage(log_message, tag, Qgis.Critical)
QgsMessageLog.logMessage(log_message, tag, Qgis.MessageLevel.Critical)


class NoProjectFoundError(QFieldSyncError):
Expand Down
Loading