From 4d4420da347c6ce16fa0387a78e3009f6039b3df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Kr=C3=B6ger?= Date: Tue, 18 Jul 2023 10:18:23 +0200 Subject: [PATCH 1/2] Remove unused import --- controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controller.py b/controller.py index 82cbd90..058d81b 100644 --- a/controller.py +++ b/controller.py @@ -9,7 +9,7 @@ from .filters import FilterDefinition, Predicate from .helpers import getSupportedLayers, removeFilterFromLayer, addFilterToLayer, refreshLayerTree, hasLayerException, \ warnAboutCurveGeoms -from .settings import FILTER_COMMENT_START, FILTER_COMMENT_STOP +from .settings import FILTER_COMMENT_START class FilterController(QObject): From 6cc0555b7778aeff8590e4149daa2c0b73778bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Kr=C3=B6ger?= Date: Tue, 18 Jul 2023 11:28:55 +0200 Subject: [PATCH 2/2] Add (localized) plugin name to messagebar messages --- controller.py | 10 +- filters.py | 8 +- helpers.py | 9 +- i18n/spatial_filter.pro | 2 +- i18n/spatial_filter_de.qm | Bin 5503 -> 5760 bytes i18n/spatial_filter_de.ts | 204 +------------------------------------- settings.py | 8 ++ spatial_filter.py | 8 +- 8 files changed, 33 insertions(+), 216 deletions(-) diff --git a/controller.py b/controller.py index 058d81b..47a10ac 100644 --- a/controller.py +++ b/controller.py @@ -9,7 +9,7 @@ from .filters import FilterDefinition, Predicate from .helpers import getSupportedLayers, removeFilterFromLayer, addFilterToLayer, refreshLayerTree, hasLayerException, \ warnAboutCurveGeoms -from .settings import FILTER_COMMENT_START +from .settings import FILTER_COMMENT_START, LOCALIZED_PLUGIN_NAME class FilterController(QObject): @@ -72,13 +72,13 @@ def refreshFilter(self): def setFilterFromSelection(self): layer = iface.activeLayer() if not layer or not layer.type() == QgsMapLayerType.VectorLayer: - iface.messageBar().pushInfo('', self.tr('Select a polygon layer')) + iface.messageBar().pushInfo(LOCALIZED_PLUGIN_NAME, self.tr('Select a polygon layer')) return if not layer.geometryType() == QgsWkbTypes.PolygonGeometry: - iface.messageBar().pushInfo('', self.tr('Select a polygon layer')) + iface.messageBar().pushInfo(LOCALIZED_PLUGIN_NAME, self.tr('Select a polygon layer')) return if not layer.selectedFeatureCount(): - iface.messageBar().pushInfo('', self.tr('No features selected')) + iface.messageBar().pushInfo(LOCALIZED_PLUGIN_NAME, self.tr('No features selected')) return crs = iface.activeLayer().crs() geom = QgsGeometry().unaryUnion([feature.geometry() for feature in layer.selectedFeatures()]) @@ -114,7 +114,7 @@ def stopSketchingTool(self): def onSketchFinished(self, geometry: QgsGeometry): self.stopSketchingTool() if not geometry.isGeosValid(): - iface.messageBar().pushMessage(self.tr("Geometry is not valid"), level=Qgis.Warning, duration=3) + iface.messageBar().pushWarning(LOCALIZED_PLUGIN_NAME, self.tr("Geometry is not valid")) return self.initFilter() self.currentFilter.name = self.tr('New filter from sketch') diff --git a/filters.py b/filters.py index bbc06d4..401336d 100644 --- a/filters.py +++ b/filters.py @@ -6,7 +6,7 @@ from qgis.core import QgsVectorLayer, QgsGeometry, QgsCoordinateReferenceSystem from qgis.utils import iface -from .settings import FILTER_COMMENT_START, FILTER_COMMENT_STOP +from .settings import FILTER_COMMENT_START, FILTER_COMMENT_STOP, LOCALIZED_PLUGIN_NAME from .helpers import tr, saveSettingsValue, readSettingsValue, allSettingsValues, removeSettingsValue, \ getLayerGeomName, matchFormatString @@ -140,13 +140,13 @@ def loadAllFilterDefinitions() -> List[FilterDefinition]: def saveFilterDefinition(filterDef: FilterDefinition) -> None: if not filterDef: - iface.messageBar().pushInfo("", tr("No current filter")) + iface.messageBar().pushInfo(LOCALIZED_PLUGIN_NAME, tr("No current filter")) return if not filterDef.isValid: - iface.messageBar().pushInfo("", tr("Current filter definition is not valid")) + iface.messageBar().pushInfo(LOCALIZED_PLUGIN_NAME, tr("Current filter definition is not valid")) return if not filterDef.name: - iface.messageBar().pushInfo("", tr("Please provide a name for the filter")) + iface.messageBar().pushInfo(LOCALIZED_PLUGIN_NAME, tr("Please provide a name for the filter")) return if filterDef.isSaved: return diff --git a/helpers.py b/helpers.py index 4dd30d1..34da726 100644 --- a/helpers.py +++ b/helpers.py @@ -5,11 +5,12 @@ from osgeo import ogr from qgis.PyQt.QtCore import QCoreApplication -from qgis.core import Qgis, QgsExpressionContextUtils, QgsSettings, QgsMapLayer, QgsMapLayerType, QgsVectorLayer,\ +from qgis.core import QgsExpressionContextUtils, QgsSettings, QgsMapLayer, QgsMapLayerType, QgsVectorLayer,\ QgsWkbTypes from qgis.utils import iface -from .settings import SUPPORTED_STORAGE_TYPES, GROUP, FILTER_COMMENT_START, FILTER_COMMENT_STOP, LAYER_EXCEPTION_VARIABLE +from .settings import SUPPORTED_STORAGE_TYPES, GROUP, FILTER_COMMENT_START, FILTER_COMMENT_STOP, \ + LAYER_EXCEPTION_VARIABLE, LOCALIZED_PLUGIN_NAME def tr(message): @@ -181,6 +182,6 @@ def warnAboutCurveGeoms(layers: Iterable[QgsMapLayer]): continue if layer.storageType().upper() in ['GPKG', 'SQLITE'] and QgsWkbTypes.isCurvedType(layer.wkbType()): txt = tr('The layer "{layername}" has an unsupported geometry type: ' - '"Circularstring", "CompoundCurve", "CurvePolygon", "MultiCurve", "MultiSurface", ' + '"CircularString", "CompoundCurve", "CurvePolygon", "MultiCurve", "MultiSurface", ' '"Curve" or "Surface".').format(layername=layer.name()) - iface.messageBar().pushMessage(txt, level=Qgis.Warning) + iface.messageBar().pushWarning(LOCALIZED_PLUGIN_NAME, txt) diff --git a/i18n/spatial_filter.pro b/i18n/spatial_filter.pro index 4e9801e..b0616ec 100644 --- a/i18n/spatial_filter.pro +++ b/i18n/spatial_filter.pro @@ -1,3 +1,3 @@ FORMS = ../ui/named_filters_dialog.ui -SOURCES = ../spatial_filter.py ../filters.py ../widgets.py ../helpers.py ../models.py ../controller.py +SOURCES = ../spatial_filter.py ../filters.py ../widgets.py ../helpers.py ../models.py ../controller.py ../settings.py TRANSLATIONS = spatial_filter_de.ts diff --git a/i18n/spatial_filter_de.qm b/i18n/spatial_filter_de.qm index a5c335c4da8c84823a85ae3c96bb51c2d36cf486..71716e1942283cbd37e1886f671efc749a657609 100644 GIT binary patch delta 911 zcma)&T}V@59LAq>cD8di^(?1Ff)^@LD0Wj4R)+bpDNz{PO+}dE{KT)uHj$_;Eg^_R zmf(e0Uf73}h9Za|f*O`945P1$Kxk4LX;@@LS`VvWVpLcE_q^x%`2FASN#5mGXbFuQfV$=IuB`RALjtHZTC2HV4m0lgfAesZa1)D z5(jp*0+BL~o6?!!M@!BqpiZFkSOADxMt9RJ5Vj;*?l%CMH=^}%7QgE~qIcyIpfqdj zseLrmY2MjHKsP6q-TVZ|snV_FE(Tkq+sg`IY?Q{&jIp>w^1H2o2(9HoD*Y?kJCTbl zhR#+~K_IuT_h=6wrO4*j1W*#?-a+O@6v+Pl*jRwsH28-ziU0yyny<$jw zK1c8_L(+Q_U>Ny1jWLGN$tk|*!!Yk#>cis0)elQRy3iEfF+zaojEHB`jWp~~(^^JJ zI;6HgdCI^{wf!TfY1ZhtI8AcDaUhW(Vl(NYhx@yQd5sAPup$5#s!)k?6rs#_SB}-& zY73p^g_Us@-;BH|Tlj)(6vKfy97G}Nf1S7DB#kw2VlPh7{`*fgPgT^MMu@^UuH7j( zeV?`4JR!HpVyT0*uAtum8`B)Tt43+48_Dcm>#Jc$E!$nx+L_~`&&}3Q)p{3I`9axX zS}VCqDQERxO^1STPD1@xiSMc|rs$s#>rms!VgJL!+JcLf@JWl-F6W!q(^b delta 657 zcmYL_ZAepb7{$-FyWP9H?XGPI3VpCk1P+B>psW_F*3u#vY)}#rg-e~7tJxHZ+Muu( zqOxi9VMKl?DoQ0OBnn|#k*g*~Z&VPZlu8*D1yb43Y<{`VbN=@{zvuk_@uEp*%+(#t z?H^CJKAtzXXGh!Jw`&2-X$Y02fbA@V+pAdbLx1ibYZ<%`<^!fllr}5}tgo?gX)7=% z7u)P^0BJOrqyWoHv~3*%91^ZJ4b!jF`UgCKd|Vsj>4Pu7ehVG{Gi|Gitx$@XC} hZ_zAeb}FB&U^Zo7npeSm @default - - - Filter Toolbar - Filterwerkzeugleiste - Current filter definition is not valid @@ -38,66 +33,6 @@ Delete? Löschen? - - - Set rectangular filter - Rechteckigen Filter setzen - - - - Change Name - Namen ändern - - - - New Name: - Neuer Name: - - - - Chose geometric predicate - Geometrisches Prädikat wählen - - - - Toggle filter on/off - Filter ein/aus - - - - Set rectangular filter geometry - Rechteckige Filtergeometrie erstellen - - - - Set filter geometry from selection - Filtergeometrie aus Auswahl erstellen - - - - Save current filter - Filter speichern - - - - Manage filters - Filter verwalten - - - - No filter geometry set - Keine Filtergeometrie gesetzt - - - - Chose a polygon-Layer - Polygonlayer auswählen - - - - No features selected - Keine Features gewählt - Current settings will be lost. Apply anyway? @@ -123,38 +58,15 @@ Unknown filter Unbekannter Filter - - - The layer "{layername}" has an unsupported geometry type: "Circularstring", "CompoundCurve", "CurvePolygon", "MultiCurve", "MultiSurface", "Curve" or "Surface". - Der Layer "{layername}" hat einen nicht unterstüzten Geometrietyp: "Circularstring", "CompoundCurve", "CurvePolygon", "MultiCurve", "MultiSurface", "Curve" oder "Surface". - - A layer contains an unsupported geometry type: "Circularstring", "CompoundCurve", "CurvePolygon", "MultiCurve", "MultiSurface", "Curve" oder "Surface". - Ein Layer hat einen unicht unterstützten Geometrietyp: "Circularstring", "CompoundCurve", "CurvePolygon", "MultiCurve", "MultiSurface", "Curve" oder "Surface". - - - - Controller - - - No filter geometry set - Keine Filtergeometrie gesetzt + The layer "{layername}" has an unsupported geometry type: "CircularString", "CompoundCurve", "CurvePolygon", "MultiCurve", "MultiSurface", "Curve" or "Surface". + Der Layer &quot;{layername}&quot; hat einen nicht unterstützten Geometrietyp: &quot;CircularString&quot;, &quot;CompoundCurve&quot;, &quot;CurvePolygon&quot;, &quot;MultiCurve&quot;, &quot;MultiSurface&quot;, &quot;Curve&quot; oder &quot;Surface&quot;. - - Select a polygon layer - Polygonlayer auswählen - - - - No features selected - Keine Features gewählt - - - - New Filter - Neuer Filter + + Spatial Filter + Räumlicher Filter @@ -172,11 +84,6 @@ FilterController - - - New Filter - Neuer Filter - Select a polygon layer @@ -203,49 +110,6 @@ Neuer Filter aus Skizze - - FilterManager - - - Current filter definition is not valid - Aktuelle Filterdefinition ist ungültig - - - - Please provide a name for the filter - Bitte zuerst einen Filternamen vergeben - - - - Overwrite settings for filter - Einstellungen überschreiben für Filter - - - - Overwrite? - Überschreiben? - - - - Delete filter - Filter löschen - - - - Delete? - Löschen? - - - - Current settings will be lost. Apply anyway? - Aktuelle Einstellungen gehen verloren. Trotzdem anwenden? - - - - Continue? - Fortfahren? - - FilterToolbar @@ -258,16 +122,6 @@ Filter from selected features Filter aus gewählten Features - - - Toggle filter on/off - Filter ein/aus - - - - Save current filter - Filter speichern - Manage filters @@ -283,16 +137,6 @@ Show filter geometry Filtergeometrie anzeigen - - - Activate filter - Filter aktivieren - - - - Deactivate filter - Filter deaktivieren - No filter geometry set @@ -313,11 +157,6 @@ Draw a filter polygon on the canvas Filter-Polygon in der Karte zeichnen - - - Geometry is not valid - Geometrie ist ungültig - Remove current filter @@ -372,11 +211,6 @@ Active Filter: Aktiver Filter: - - - Name... - Name... - Named Filters: @@ -397,30 +231,12 @@ Close Schließen - - - Change Name - Namen ändern - - - - New Name: - Neuer Name: - Save Speichern - - PredicateAction - - - Geometric predicate - Räumlicher Operator - - PredicateButton @@ -443,21 +259,11 @@ BBOX BBOX - - - Compare features to the filters bounding box - Vergleiche Features mit Bounding Box des Filters - GEOM GEOM - - - Compare features to the exact filter geometry - Vergleiche Features mit exakter Filtergeometrie - intersects diff --git a/settings.py b/settings.py index c3f6e44..5263872 100644 --- a/settings.py +++ b/settings.py @@ -1,3 +1,11 @@ +from qgis.PyQt.QtCore import QCoreApplication + +def tr(message): + return QCoreApplication.translate('@default', message) + + +LOCALIZED_PLUGIN_NAME = tr("Spatial Filter") # for use in messages etc. + GROUP = 'SpatialFilter' # The section name for filter definitions stored in QSettings GROUP_SYMBOL = 'SpatialFilterSymbol' # Section to store symbol settings LAYER_EXCEPTION_VARIABLE = 'SpatialFilterException' diff --git a/spatial_filter.py b/spatial_filter.py index 8181bc1..888626c 100644 --- a/spatial_filter.py +++ b/spatial_filter.py @@ -24,9 +24,6 @@ import os.path -from .controller import FilterController -from .widgets import FilterToolbar - class SpatialFilter: @@ -42,6 +39,11 @@ def __init__(self, iface): QCoreApplication.installTranslator(self.translator) def initGui(self): + # we import just now because we need the QCoreApplication translator + # to be installed already (e.g. for the LOCALIZED_PLUGIN_NAME) + from .controller import FilterController + from .widgets import FilterToolbar + self.toolbar = FilterToolbar(FilterController(), self.iface.mainWindow()) self.iface.mainWindow().addToolBar(self.toolbar)