Skip to content

Commit

Permalink
Merge pull request #23 from WhereGroup/plugin_name_in_msgbar
Browse files Browse the repository at this point in the history
Add (localized) plugin name to messagebar messages
  • Loading branch information
kannes authored Jul 19, 2023
2 parents df5a41f + 6cc0555 commit c76ea1d
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 216 deletions.
10 changes: 5 additions & 5 deletions controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, LOCALIZED_PLUGIN_NAME


class FilterController(QObject):
Expand Down Expand Up @@ -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()])
Expand Down Expand Up @@ -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')
Expand Down
8 changes: 4 additions & 4 deletions filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion i18n/spatial_filter.pro
Original file line number Diff line number Diff line change
@@ -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
Binary file modified i18n/spatial_filter_de.qm
Binary file not shown.
204 changes: 5 additions & 199 deletions i18n/spatial_filter_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
<TS version="2.1" language="de_DE" sourcelanguage="en_US">
<context>
<name>@default</name>
<message>
<location filename="../widgets.py" line="166"/>
<source>Filter Toolbar</source>
<translation type="obsolete">Filterwerkzeugleiste</translation>
</message>
<message>
<location filename="../filters.py" line="146"/>
<source>Current filter definition is not valid</source>
Expand Down Expand Up @@ -38,66 +33,6 @@
<source>Delete?</source>
<translation>Löschen?</translation>
</message>
<message>
<location filename="../widgets.py" line="35"/>
<source>Set rectangular filter</source>
<translation type="obsolete">Rechteckigen Filter setzen</translation>
</message>
<message>
<location filename="../widgets.py" line="124"/>
<source>Change Name</source>
<translation type="obsolete">Namen ändern</translation>
</message>
<message>
<location filename="../widgets.py" line="124"/>
<source>New Name:</source>
<translation type="obsolete">Neuer Name:</translation>
</message>
<message>
<location filename="../widgets.py" line="138"/>
<source>Chose geometric predicate</source>
<translation type="obsolete">Geometrisches Prädikat wählen</translation>
</message>
<message>
<location filename="../widgets.py" line="177"/>
<source>Toggle filter on/off</source>
<translation type="obsolete">Filter ein/aus</translation>
</message>
<message>
<location filename="../widgets.py" line="205"/>
<source>Set rectangular filter geometry</source>
<translation type="obsolete">Rechteckige Filtergeometrie erstellen</translation>
</message>
<message>
<location filename="../widgets.py" line="210"/>
<source>Set filter geometry from selection</source>
<translation type="obsolete">Filtergeometrie aus Auswahl erstellen</translation>
</message>
<message>
<location filename="../widgets.py" line="218"/>
<source>Save current filter</source>
<translation type="obsolete">Filter speichern</translation>
</message>
<message>
<location filename="../widgets.py" line="223"/>
<source>Manage filters</source>
<translation type="obsolete">Filter verwalten</translation>
</message>
<message>
<location filename="../controller.py" line="60"/>
<source>No filter geometry set</source>
<translation type="obsolete">Keine Filtergeometrie gesetzt</translation>
</message>
<message>
<location filename="../controller.py" line="71"/>
<source>Chose a polygon-Layer</source>
<translation type="obsolete">Polygonlayer auswählen</translation>
</message>
<message>
<location filename="../controller.py" line="74"/>
<source>No features selected</source>
<translation type="obsolete">Keine Features gewählt</translation>
</message>
<message>
<location filename="../filters.py" line="177"/>
<source>Current settings will be lost. Apply anyway?</source>
Expand All @@ -123,38 +58,15 @@
<source>Unknown filter</source>
<translation>Unbekannter Filter</translation>
</message>
<message>
<location filename="../helpers.py" line="181"/>
<source>The layer &quot;{layername}&quot; has an unsupported geometry type: &quot;Circularstring&quot;, &quot;CompoundCurve&quot;, &quot;CurvePolygon&quot;, &quot;MultiCurve&quot;, &quot;MultiSurface&quot;, &quot;Curve&quot; or &quot;Surface&quot;.</source>
<translation>Der Layer &quot;{layername}&quot; hat einen nicht unterstüzten Geometrietyp: &quot;Circularstring&quot;, &quot;CompoundCurve&quot;, &quot;CurvePolygon&quot;, &quot;MultiCurve&quot;, &quot;MultiSurface&quot;, &quot;Curve&quot; oder &quot;Surface&quot;.</translation>
</message>
<message>
<location filename="../helpers.py" line="184"/>
<source>A layer contains an unsupported geometry type: &quot;Circularstring&quot;, &quot;CompoundCurve&quot;, &quot;CurvePolygon&quot;, &quot;MultiCurve&quot;, &quot;MultiSurface&quot;, &quot;Curve&quot; oder &quot;Surface&quot;.</source>
<translation type="obsolete">Ein Layer hat einen unicht 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;.</translation>
</message>
</context>
<context>
<name>Controller</name>
<message>
<location filename="../controller.py" line="62"/>
<source>No filter geometry set</source>
<translation type="obsolete">Keine Filtergeometrie gesetzt</translation>
<source>The layer &quot;{layername}&quot; has an unsupported geometry type: &quot;CircularString&quot;, &quot;CompoundCurve&quot;, &quot;CurvePolygon&quot;, &quot;MultiCurve&quot;, &quot;MultiSurface&quot;, &quot;Curve&quot; or &quot;Surface&quot;.</source>
<translation>Der Layer &amp;quot;{layername}&amp;quot; hat einen nicht unterstützten Geometrietyp: &amp;quot;CircularString&amp;quot;, &amp;quot;CompoundCurve&amp;quot;, &amp;quot;CurvePolygon&amp;quot;, &amp;quot;MultiCurve&amp;quot;, &amp;quot;MultiSurface&amp;quot;, &amp;quot;Curve&amp;quot; oder &amp;quot;Surface&amp;quot;.</translation>
</message>
<message>
<location filename="../controller.py" line="70"/>
<source>Select a polygon layer</source>
<translation type="obsolete">Polygonlayer auswählen</translation>
</message>
<message>
<location filename="../controller.py" line="73"/>
<source>No features selected</source>
<translation type="obsolete">Keine Features gewählt</translation>
</message>
<message>
<location filename="../controller.py" line="19"/>
<source>New Filter</source>
<translation type="obsolete">Neuer Filter</translation>
<location filename="../settings.py" line="7"/>
<source>Spatial Filter</source>
<translation>Räumlicher Filter</translation>
</message>
</context>
<context>
Expand All @@ -172,11 +84,6 @@
</context>
<context>
<name>FilterController</name>
<message>
<location filename="../controller.py" line="21"/>
<source>New Filter</source>
<translation type="obsolete">Neuer Filter</translation>
</message>
<message>
<location filename="../controller.py" line="78"/>
<source>Select a polygon layer</source>
Expand All @@ -203,49 +110,6 @@
<translation>Neuer Filter aus Skizze</translation>
</message>
</context>
<context>
<name>FilterManager</name>
<message>
<location filename="../filters.py" line="110"/>
<source>Current filter definition is not valid</source>
<translation type="obsolete">Aktuelle Filterdefinition ist ungültig</translation>
</message>
<message>
<location filename="../filters.py" line="113"/>
<source>Please provide a name for the filter</source>
<translation type="obsolete">Bitte zuerst einen Filternamen vergeben</translation>
</message>
<message>
<location filename="../filters.py" line="132"/>
<source>Overwrite settings for filter</source>
<translation type="obsolete">Einstellungen überschreiben für Filter</translation>
</message>
<message>
<location filename="../filters.py" line="133"/>
<source>Overwrite?</source>
<translation type="obsolete">Überschreiben?</translation>
</message>
<message>
<location filename="../filters.py" line="138"/>
<source>Delete filter</source>
<translation type="obsolete">Filter löschen</translation>
</message>
<message>
<location filename="../filters.py" line="139"/>
<source>Delete?</source>
<translation type="obsolete">Löschen?</translation>
</message>
<message>
<location filename="../filters.py" line="127"/>
<source>Current settings will be lost. Apply anyway?</source>
<translation type="obsolete">Aktuelle Einstellungen gehen verloren. Trotzdem anwenden?</translation>
</message>
<message>
<location filename="../filters.py" line="128"/>
<source>Continue?</source>
<translation type="obsolete">Fortfahren?</translation>
</message>
</context>
<context>
<name>FilterToolbar</name>
<message>
Expand All @@ -258,16 +122,6 @@
<source>Filter from selected features</source>
<translation>Filter aus gewählten Features</translation>
</message>
<message>
<location filename="../widgets.py" line="176"/>
<source>Toggle filter on/off</source>
<translation type="obsolete">Filter ein/aus</translation>
</message>
<message>
<location filename="../widgets.py" line="338"/>
<source>Save current filter</source>
<translation type="obsolete">Filter speichern</translation>
</message>
<message>
<location filename="../widgets.py" line="349"/>
<source>Manage filters</source>
Expand All @@ -283,16 +137,6 @@
<source>Show filter geometry</source>
<translation>Filtergeometrie anzeigen</translation>
</message>
<message>
<location filename="../widgets.py" line="364"/>
<source>Activate filter</source>
<translation type="obsolete">Filter aktivieren</translation>
</message>
<message>
<location filename="../widgets.py" line="362"/>
<source>Deactivate filter</source>
<translation type="obsolete">Filter deaktivieren</translation>
</message>
<message>
<location filename="../widgets.py" line="397"/>
<source>No filter geometry set</source>
Expand All @@ -313,11 +157,6 @@
<source>Draw a filter polygon on the canvas</source>
<translation>Filter-Polygon in der Karte zeichnen</translation>
</message>
<message>
<location filename="../widgets.py" line="444"/>
<source>Geometry is not valid</source>
<translation type="obsolete">Geometrie ist ungültig</translation>
</message>
<message>
<location filename="../widgets.py" line="286"/>
<source>Remove current filter</source>
Expand Down Expand Up @@ -372,11 +211,6 @@
<source>Active Filter:</source>
<translation>Aktiver Filter:</translation>
</message>
<message>
<location filename="../ui/named_filters_dialog.ui" line="36"/>
<source>Name...</source>
<translation type="obsolete">Name...</translation>
</message>
<message>
<location filename="../ui/named_filters_dialog.ui" line="49"/>
<source>Named Filters:</source>
Expand All @@ -397,30 +231,12 @@
<source>Close</source>
<translation>Schließen</translation>
</message>
<message>
<location filename="../widgets.py" line="173"/>
<source>Change Name</source>
<translation type="obsolete">Namen ändern</translation>
</message>
<message>
<location filename="../widgets.py" line="173"/>
<source>New Name:</source>
<translation type="obsolete">Neuer Name:</translation>
</message>
<message>
<location filename="../ui/named_filters_dialog.ui" line="36"/>
<source>Save</source>
<translation>Speichern</translation>
</message>
</context>
<context>
<name>PredicateAction</name>
<message>
<location filename="../widgets.py" line="137"/>
<source>Geometric predicate</source>
<translation type="obsolete">Räumlicher Operator</translation>
</message>
</context>
<context>
<name>PredicateButton</name>
<message>
Expand All @@ -443,21 +259,11 @@
<source>BBOX</source>
<translation>BBOX</translation>
</message>
<message>
<location filename="../widgets.py" line="219"/>
<source>Compare features to the filters bounding box</source>
<translation type="obsolete">Vergleiche Features mit Bounding Box des Filters</translation>
</message>
<message>
<location filename="../widgets.py" line="222"/>
<source>GEOM</source>
<translation>GEOM</translation>
</message>
<message>
<location filename="../widgets.py" line="226"/>
<source>Compare features to the exact filter geometry</source>
<translation type="obsolete">Vergleiche Features mit exakter Filtergeometrie</translation>
</message>
<message>
<location filename="../widgets.py" line="188"/>
<source>intersects</source>
Expand Down
8 changes: 8 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Loading

0 comments on commit c76ea1d

Please sign in to comment.