From df2904ed7107271c81566be6e1bc43f2b5dc4a8c Mon Sep 17 00:00:00 2001 From: David Erill Date: Sun, 2 Oct 2016 10:35:41 +0200 Subject: [PATCH] SearchPlus: Bug fix getting layers Bug fix loading QML's --- search/search_plus.py | 51 ++++++++++++++++++++++++------------------- ui/config.ui | 20 ++++++++--------- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/search/search_plus.py b/search/search_plus.py index 574f1adc9..29e200cd8 100644 --- a/search/search_plus.py +++ b/search/search_plus.py @@ -66,9 +66,9 @@ def load_plugin_settings(self): ''' Load plugin settings ''' self.QML_PORTAL = self.settings.value('layers/QML_PORTAL', 'portal.qml').lower() - self.QML_PPOINT = None - self.QML_HYDROMETER = None - self.QML_URBAN = None + self.QML_PPOINT = self.settings.value('layers/QML_PPOINT', 'point.qml').lower() + self.QML_HYDROMETER = self.settings.value('layers/QML_HYDROMETER', 'hydrometer.qml').lower() + self.QML_URBAN = self.settings.value('layers/QML_URBAN', 'urban.qml').lower() # get initial Scale self.scale_zoom = self.settings.value('status/scale_zoom', 2500) @@ -102,23 +102,28 @@ def get_layers(self): self.hydrometerMemLayerTo = None self.urbanMemLayer = None - # Iterate over all layers - self.layers = {} + # Check if we have any layer loaded layers = self.iface.legendInterface().layers() - for cur_layer in layers: - name = cur_layer.name().lower() - if self.params['street_layer'] == name: - self.layers['street_layer'] = cur_layer - elif self.params['portal_layer'] == name: - self.layers['portal_layer'] = cur_layer - elif self.params['ppoint_layer'] == name: - self.layers['ppoint_layer'] = cur_layer - elif self.params['hydrometer_layer'] == name: - self.layers['hydrometer_layer'] = cur_layer - if self.params['hydrometer_urban_propierties_layer'] == name: - self.layers['hydrometer_urban_propierties_layer'] = cur_layer - if self.params['urban_propierties_layer'] == name: - self.layers['urban_propierties_layer'] = cur_layer + if len(layers) == 0: + return + + # Iterate over all layers to get the ones specified in 'db' config section + self.layers = {} + for cur_layer in layers: + (uri_schema, uri_table) = self.controller.get_layer_source(cur_layer) #@UnusedVariable + if uri_table is not None: + if self.params['street_layer'] in uri_table: + self.layers['street_layer'] = cur_layer + elif self.params['portal_layer'] in uri_table: + self.layers['portal_layer'] = cur_layer + elif self.params['ppoint_layer'] in uri_table: + self.layers['ppoint_layer'] = cur_layer + elif self.params['hydrometer_layer'] in uri_table: + self.layers['hydrometer_layer'] = cur_layer + if self.params['hydrometer_urban_propierties_layer'] in uri_table: + self.layers['hydrometer_urban_propierties_layer'] = cur_layer + if self.params['urban_propierties_layer'] in uri_table: + self.layers['urban_propierties_layer'] = cur_layer def populate_dialog(self): @@ -401,7 +406,7 @@ def hydrometer_zoom(self, fieldname, combo): # Load style if self.QML_HYDROMETER is not None: - self.load_style(self.ppointMemLayer, self.QML_HYDROMETER) + self.load_style(self.hydrometerMemLayerTo, self.QML_HYDROMETER) def urban_populate(self, layer): @@ -568,8 +573,10 @@ def copy_selected(self, layer, mem_layer, geom_type): def load_style(self, layer, qml): ''' Load QML style file into selected layer ''' - path_qml = self.stylesFolder+qml - if os.path.exists(path_qml): + if layer is None: + return + path_qml = self.stylesFolder+qml + if os.path.exists(path_qml) and os.path.isfile(path_qml): layer.loadNamedStyle(path_qml) diff --git a/ui/config.ui b/ui/config.ui index 17e6d92a8..4ae0377d7 100644 --- a/ui/config.ui +++ b/ui/config.ui @@ -39,7 +39,7 @@ Cancel - + 20 @@ -49,7 +49,7 @@ - 2 + 0 @@ -723,7 +723,7 @@ Search - + 20 @@ -733,7 +733,7 @@ - 3 + 0 @@ -1394,7 +1394,7 @@ - 20 + 10 90 171 22 @@ -1430,7 +1430,7 @@ - 40 + 30 120 151 22 @@ -1505,7 +1505,7 @@ - 18 + 10 20 191 22 @@ -1541,7 +1541,7 @@ - 38 + 30 50 151 22 @@ -1587,10 +1587,10 @@ - + - 40 + 30 150 151 22