Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Viestiminen käyttäjän kanssa ja tallentamisen pysäytys virheen sattuessa #188

Merged
merged 6 commits into from
Feb 25, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add wait cursor override for primary save/delete functions
nmaarnio committed Feb 25, 2025
commit 65679abca9c5fed876b04bacc5b7e1644a15c27c
5 changes: 5 additions & 0 deletions arho_feature_template/core/plan_manager.py
Original file line number Diff line number Diff line change
@@ -60,6 +60,7 @@
handle_unsaved_changes,
iface,
set_active_plan_id,
use_wait_cursor,
)

if TYPE_CHECKING:
@@ -533,6 +534,7 @@ def _delete_feature(feature: QgsFeature, layer: QgsVectorLayer, delete_text: str
return layer.commitChanges(stopEditing=False)


@use_wait_cursor
def save_plan(plan: Plan) -> QgsFeature | None:
feature = PlanLayer.feature_from_model(plan)
layer = PlanLayer.get_from_project()
@@ -586,6 +588,7 @@ def save_plan(plan: Plan) -> QgsFeature | None:
return feature


@use_wait_cursor
def save_plan_feature(plan_model: PlanFeature, plan_id: str | None = None) -> QgsFeature | None:
layer_name = plan_model.layer_name
if not layer_name:
@@ -631,6 +634,7 @@ def save_plan_feature(plan_model: PlanFeature, plan_id: str | None = None) -> Qg
return plan_feature


@use_wait_cursor
def save_regulation_group(regulation_group: RegulationGroup, plan_id: str | None = None) -> QgsFeature | None:
feature = RegulationGroupLayer.feature_from_model(regulation_group, plan_id)
layer = RegulationGroupLayer.get_from_project()
@@ -676,6 +680,7 @@ def save_regulation_group(regulation_group: RegulationGroup, plan_id: str | None
return feature


@use_wait_cursor
def delete_regulation_group(regulation_group: RegulationGroup, plan_id: str | None = None) -> bool:
if regulation_group.id_ is None:
iface.messageBar().pushCritical("", "Kaavamääräysryhmän poistaminen epäonnistui (ei IDtä).")
12 changes: 10 additions & 2 deletions arho_feature_template/utils/misc_utils.py
Original file line number Diff line number Diff line change
@@ -5,9 +5,9 @@
from typing import TYPE_CHECKING, Any, cast

from qgis.core import QgsExpressionContextUtils, QgsProject, QgsVectorLayer
from qgis.PyQt.QtCore import QSettings, pyqtBoundSignal
from qgis.PyQt.QtCore import QSettings, Qt, pyqtBoundSignal
from qgis.PyQt.QtWidgets import QMessageBox
from qgis.utils import iface
from qgis.utils import OverrideCursor, iface

if TYPE_CHECKING:
from qgis.core import QgsMapLayer
@@ -128,3 +128,11 @@ def deserialize_localized_text(text_value: dict[str, str] | None | Any) -> str |
if isinstance(text_value, dict):
text = text_value.get(LANGUAGE)
return text


def use_wait_cursor(func):
def wrapper(*args, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dekoraattorillahan tää kannattikin tehdä, hyvä!
Tässä voisi vielä hyvin tapojen mukaisesti käyttää functools.wraps metodia, niin dekoraattoria käyttävien funktioiden signature pysyy samana.

Suggested change
def use_wait_cursor(func):
def wrapper(*args, **kwargs):
from functools import wraps
def use_wait_cursor(func):
@wraps(func)
def wrapper(*args, **kwargs):

with OverrideCursor(Qt.WaitCursor):
return func(*args, **kwargs)

return wrapper