Commit a92f72aa authored by Benjamin Jakimow's avatar Benjamin Jakimow
Browse files
parent aa2c36df
Pipeline #13943 failed with stage
in 6 seconds
...@@ -26,10 +26,12 @@ ...@@ -26,10 +26,12 @@
import pathlib import pathlib
import sys import sys
import os
import typing import typing
import warnings import warnings
from qgis.core import QgsApplication, Qgis from qgis.core import QgsApplication, Qgis
from qgis.gui import QgsMapLayerConfigWidgetFactory from qgis.gui import QgsMapLayerConfigWidgetFactory, QgisInterface
MIN_QGIS_VERSION = '3.14' MIN_QGIS_VERSION = '3.14'
__version__ = '1.0' __version__ = '1.0'
...@@ -46,6 +48,8 @@ if Qgis.QGIS_VERSION < MIN_QGIS_VERSION: ...@@ -46,6 +48,8 @@ if Qgis.QGIS_VERSION < MIN_QGIS_VERSION:
f'Please update to QGIS >= {MIN_QGIS_VERSION}', RuntimeWarning) f'Please update to QGIS >= {MIN_QGIS_VERSION}', RuntimeWarning)
KEY_MAPLAYERCONFIGWIDGETFACTORIES = 'QPS_MAPLAYER_CONFIGWIDGET_FACTORIES'
def registerMapLayerConfigWidgetFactory(factory: QgsMapLayerConfigWidgetFactory): def registerMapLayerConfigWidgetFactory(factory: QgsMapLayerConfigWidgetFactory):
""" """
Register a new tab in the map layer properties dialog. Register a new tab in the map layer properties dialog.
...@@ -56,9 +60,16 @@ def registerMapLayerConfigWidgetFactory(factory: QgsMapLayerConfigWidgetFactory) ...@@ -56,9 +60,16 @@ def registerMapLayerConfigWidgetFactory(factory: QgsMapLayerConfigWidgetFactory)
""" """
global MAPLAYER_CONFIGWIDGET_FACTORIES global MAPLAYER_CONFIGWIDGET_FACTORIES
assert isinstance(factory, QgsMapLayerConfigWidgetFactory) assert isinstance(factory, QgsMapLayerConfigWidgetFactory)
if factory not in MAPLAYER_CONFIGWIDGET_FACTORIES: name: str = factory.__class__.__name__
MAPLAYER_CONFIGWIDGET_FACTORIES.append(factory)
registered = os.environ.get(KEY_MAPLAYERCONFIGWIDGETFACTORIES, '').split('::')
from qgis.utils import iface
if isinstance(iface, QgisInterface) and factory not in MAPLAYER_CONFIGWIDGET_FACTORIES and name not in registered:
MAPLAYER_CONFIGWIDGET_FACTORIES.append(factory)
registered.append(name)
os.environ[KEY_MAPLAYERCONFIGWIDGETFACTORIES] = '::'.join(registered)
iface.registerMapLayerConfigWidgetFactory(factory)
def unregisterMapLayerConfigWidgetFactory(factory: QgsMapLayerConfigWidgetFactory): def unregisterMapLayerConfigWidgetFactory(factory: QgsMapLayerConfigWidgetFactory):
""" """
...@@ -70,9 +81,19 @@ def unregisterMapLayerConfigWidgetFactory(factory: QgsMapLayerConfigWidgetFactor ...@@ -70,9 +81,19 @@ def unregisterMapLayerConfigWidgetFactory(factory: QgsMapLayerConfigWidgetFactor
""" """
assert isinstance(factory, QgsMapLayerConfigWidgetFactory) assert isinstance(factory, QgsMapLayerConfigWidgetFactory)
global MAPLAYER_CONFIGWIDGET_FACTORIES global MAPLAYER_CONFIGWIDGET_FACTORIES
name: str = factory.__class__.__name__
while factory in MAPLAYER_CONFIGWIDGET_FACTORIES: while factory in MAPLAYER_CONFIGWIDGET_FACTORIES:
MAPLAYER_CONFIGWIDGET_FACTORIES.remove(factory) MAPLAYER_CONFIGWIDGET_FACTORIES.remove(factory)
registered = os.environ.get(KEY_MAPLAYERCONFIGWIDGETFACTORIES, '').split('::')
while name in registered:
registered.remove(name)
os.environ[KEY_MAPLAYERCONFIGWIDGETFACTORIES] = '::'.join(registered)
from qgis.utils import iface
if isinstance(iface, QgisInterface):
iface.unregisterMapLayerConfigWidgetFactory(factory)
def mapLayerConfigWidgetFactories() -> typing.List[QgsMapLayerConfigWidgetFactory]: def mapLayerConfigWidgetFactories() -> typing.List[QgsMapLayerConfigWidgetFactory]:
""" """
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment