From ef24e63bec6e57e7c385eb74bd5cc684fb3285cb Mon Sep 17 00:00:00 2001
From: Benjamin Jakimow <benjamin.jakimow@geo.hu-berlin.de>
Date: Tue, 3 Nov 2020 21:21:10 +0100
Subject: [PATCH] tbd

Signed-off-by: Benjamin Jakimow <benjamin.jakimow@geo.hu-berlin.de>
---
 eotimeseriesviewer/__init__.py               | 29 ++++++--------------
 eotimeseriesviewer/externals/qps/__init__.py | 14 ++++++----
 2 files changed, 16 insertions(+), 27 deletions(-)

diff --git a/eotimeseriesviewer/__init__.py b/eotimeseriesviewer/__init__.py
index 8b88dd28..1d05d721 100644
--- a/eotimeseriesviewer/__init__.py
+++ b/eotimeseriesviewer/__init__.py
@@ -110,34 +110,21 @@ def initResources():
     from eotimeseriesviewer.externals.qps.resources import initQtResources
     initQtResources(pathlib.Path(__file__).parent)
 
-def initMapLayerConfigWidgetFactories():
-
-    from .externals.qps import \
-        registerMapLayerConfigWidgetFactories, \
-        mapLayerConfigWidgetFactories, \
-        registerMapLayerConfigWidgetFactory
-    from .labeling import registerLabelShortcutEditorWidget
-    registerMapLayerConfigWidgetFactories()
-    for factory in mapLayerConfigWidgetFactories():
-        qgis.utils.iface.registerMapLayerConfigWidgetFactory(factory)
-
-def initEditorWidgets():
-    """
-    Initialises QgsEditorWidgets
-    """
-    debugLog('initEditorWidgets')
-    import eotimeseriesviewer.externals.qps as qps
-    qps.registerEditorWidgets()
-
 
 def initAll():
     """
     Calls all required init routines
     :return:
     """
+    from .externals.qps import registerEditorWidgets, registerMapLayerConfigWidgetFactories
+    registerEditorWidgets()
+    registerMapLayerConfigWidgetFactories()
+
     initResources()
-    initEditorWidgets()
-    initMapLayerConfigWidgetFactories()
+
+    from .labeling import registerLabelShortcutEditorWidget
+    registerLabelShortcutEditorWidget()
+
 
 def icon() -> QIcon:
     """
diff --git a/eotimeseriesviewer/externals/qps/__init__.py b/eotimeseriesviewer/externals/qps/__init__.py
index 0e27247f..d17f90ec 100644
--- a/eotimeseriesviewer/externals/qps/__init__.py
+++ b/eotimeseriesviewer/externals/qps/__init__.py
@@ -40,7 +40,7 @@ DIR_UI_FILES = DIR_QPS / 'ui'
 DIR_ICONS = DIR_UI_FILES / 'icons'
 QPS_RESOURCE_FILE = DIR_QPS / 'qpsresources_rc.py'
 
-MAPLAYER_CONFIGWIDGET_FACTORIES: typing.List[QgsMapLayerConfigWidgetFactory] = list()
+MAPLAYER_CONFIGWIDGET_FACTORIES: typing.Dict[str, QgsMapLayerConfigWidgetFactory] = dict()
 
 if Qgis.QGIS_VERSION < MIN_QGIS_VERSION:
     warnings.warn(f'Your QGIS ({Qgis.QGIS_VERSION}) is outdated. '
@@ -57,8 +57,8 @@ def registerMapLayerConfigWidgetFactory(factory: QgsMapLayerConfigWidgetFactory)
     """
     global MAPLAYER_CONFIGWIDGET_FACTORIES
     assert isinstance(factory, QgsMapLayerConfigWidgetFactory)
-    if factory not in MAPLAYER_CONFIGWIDGET_FACTORIES:
-        MAPLAYER_CONFIGWIDGET_FACTORIES.append(factory)
+    if factory.title() not in MAPLAYER_CONFIGWIDGET_FACTORIES.keys():
+        MAPLAYER_CONFIGWIDGET_FACTORIES[factory.title()] = factory
         qgis.utils.iface.registerMapLayerConfigWidgetFactory(factory)
 
 
@@ -72,17 +72,19 @@ def unregisterMapLayerConfigWidgetFactory(factory: QgsMapLayerConfigWidgetFactor
     """
     global MAPLAYER_CONFIGWIDGET_FACTORIES
     assert isinstance(factory, QgsMapLayerConfigWidgetFactory)
-    while factory in MAPLAYER_CONFIGWIDGET_FACTORIES:
-        MAPLAYER_CONFIGWIDGET_FACTORIES.remove(factory)
+    if factory.title() in MAPLAYER_CONFIGWIDGET_FACTORIES.keys():
+        MAPLAYER_CONFIGWIDGET_FACTORIES.pop(factory.title())
         qgis.utils.iface.unregisterMapLayerConfigWidgetFactory(factory)
 
+
 def mapLayerConfigWidgetFactories() -> typing.List[QgsMapLayerConfigWidgetFactory]:
     """
     Returns registered QgsMapLayerConfigWidgetFactories
     :return: list of QgsMapLayerConfigWidgetFactories
     :rtype:
     """
-    return MAPLAYER_CONFIGWIDGET_FACTORIES[:]
+    global MAPLAYER_CONFIGWIDGET_FACTORIES
+    return list(MAPLAYER_CONFIGWIDGET_FACTORIES.values())
 
 
 def registerEditorWidgets():
-- 
GitLab