Skip to content

Commit

Permalink
Move function to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinBuira committed Nov 4, 2024
1 parent 8f8fdbe commit b766621
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
16 changes: 1 addition & 15 deletions Mergin/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from qgis.PyQt.QtCore import QVariant

from qgis.PyQt.QtGui import QColor, QIcon
from qgis.PyQt.QtGui import QColor

from qgis.core import (
QgsApplication,
Expand Down Expand Up @@ -530,17 +530,3 @@ def style_diff_layer(layer, schema_table):
)
r = QgsRuleBasedRenderer(root_rule)
layer.setRenderer(r)


def icon_for_layer(layer) -> QIcon:
geom_type = layer.geometryType()
if geom_type == QgsWkbTypes.PointGeometry:
return QgsApplication.getThemeIcon("/mIconPointLayer.svg")
elif geom_type == QgsWkbTypes.LineGeometry:
return QgsApplication.getThemeIcon("/mIconLineLayer.svg")
elif geom_type == QgsWkbTypes.PolygonGeometry:
return QgsApplication.getThemeIcon("/mIconPolygonLayer.svg")
elif geom_type == QgsWkbTypes.UnknownGeometry:
return QgsApplication.getThemeIcon("/mIconGeometryCollectionLayer.svg")
else:
return QgsApplication.getThemeIcon("/mIconTableLayer.svg")
4 changes: 2 additions & 2 deletions Mergin/diff_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from qgis.utils import iface, OverrideCursor

from .mergin.merginproject import MerginProject
from .diff import make_local_changes_layer, make_version_changes_layers, icon_for_layer
from .utils import icon_path
from .diff import make_local_changes_layer, make_version_changes_layers
from .utils import icon_path, icon_for_layer

ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ui", "ui_diff_viewer_dialog.ui")

Expand Down
17 changes: 16 additions & 1 deletion Mergin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from qgis.PyQt.QtCore import QSettings, QVariant
from qgis.PyQt.QtWidgets import QMessageBox, QFileDialog
from qgis.PyQt.QtGui import QPalette, QColor
from qgis.PyQt.QtGui import QPalette, QColor, QIcon
from qgis.core import (
NULL,
Qgis,
Expand Down Expand Up @@ -1573,3 +1573,18 @@ def parse_user_agent(user_agent: str) -> str:
return "Mergin Maps Python Client"
else: # For uncommon user agent we display user agent as is
return user_agent


def icon_for_layer(layer) -> QIcon:
# Used in diff viewer and history viewer
geom_type = layer.geometryType()
if geom_type == QgsWkbTypes.PointGeometry:
return QgsApplication.getThemeIcon("/mIconPointLayer.svg")
elif geom_type == QgsWkbTypes.LineGeometry:
return QgsApplication.getThemeIcon("/mIconLineLayer.svg")
elif geom_type == QgsWkbTypes.PolygonGeometry:
return QgsApplication.getThemeIcon("/mIconPolygonLayer.svg")
elif geom_type == QgsWkbTypes.UnknownGeometry:
return QgsApplication.getThemeIcon("/mIconGeometryCollectionLayer.svg")
else:
return QgsApplication.getThemeIcon("/mIconTableLayer.svg")
3 changes: 2 additions & 1 deletion Mergin/version_viewer_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@
icon_path,
format_datetime,
parse_user_agent,
icon_for_layer,
)

from .mergin.merginproject import MerginProject
from .mergin.utils import bytes_to_human_size, int_version

from .mergin import MerginClient
from .diff import make_version_changes_layers, icon_for_layer
from .diff import make_version_changes_layers


ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ui", "ui_versions_viewer.ui")
Expand Down

0 comments on commit b766621

Please sign in to comment.