Skip to content

Commit

Permalink
refactor: Update QGIS version handling for QMetaType/QVariant compati…
Browse files Browse the repository at this point in the history
…bility
  • Loading branch information
Fanchengyan committed Dec 24, 2024
1 parent f3f5d5e commit 59d60d2
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tools/canvasTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from PyQt5.QtGui import QColor
from qgis._gui import QgsMapMouseEvent
from qgis.core import (
QgsFeature,
Qgis,
QgsField,
QgsFields,
QgsFillSymbol,
Expand Down Expand Up @@ -46,13 +46,15 @@
from .messageTool import MessageTool
from .ulid import GroupId

qgis_version = Qgis.QGIS_VERSION_INT

# QVariant has been deprecated in version 3.38, use QMetaType instead
try:
from qgis.PyQt.QtCore import QMetaType
except ImportError:
if qgis_version < 33800:
from qgis.PyQt.QtCore import QVariant as QMetaType

QMetaType.QString = QMetaType.String

else:
from qgis.PyQt.QtCore import QMetaType

SAM_Feature_Fields = [
QgsField("group_ulid", QMetaType.QString),
Expand Down Expand Up @@ -885,13 +887,13 @@ def add_geojson_feature_to_canvas(
for coord in coordinates:
# transform pointXY from img_crs to polygon layer crs, if not match
point = QgsPointXY(*coord)

# show the point on canvas in project crs
pt_project_crs = self.img_crs_manager.img_point_to_crs(
point, self.qgis_project.crs()
)
points_project_crs.append(pt_project_crs)

# calculate the area in layer crs
pt_layer_crs = self.img_crs_manager.img_point_to_crs(
point, self.layer.crs()
Expand Down

0 comments on commit 59d60d2

Please sign in to comment.