diff --git a/buildings/gui/production_changes.py b/buildings/gui/production_changes.py index b1543bc2..4d4283fe 100644 --- a/buildings/gui/production_changes.py +++ b/buildings/gui/production_changes.py @@ -808,16 +808,17 @@ def edit_save_clicked(self, commit_status): self.edit_dialog.db.execute_no_commit(sql, (key,)) self.disable_UI_functions() + if commit_status: self.edit_dialog.db.commit_open_cursor() self.edit_dialog.geoms = {} self.new_attrs = {} self.edit_dialog.editing_layer.triggerRepaint() - self.parent_frame.reload_production_layer() if len(self.edit_dialog.split_geoms) > 0: self.edit_reset_clicked() self.edit_dialog.split_geoms = {} + self.parent_frame.reload_production_layer() def edit_reset_clicked(self): """ @@ -835,6 +836,7 @@ def edit_reset_clicked(self): iface.activeLayer().removeSelection() # reset and disable comboboxes self.disable_UI_functions() + iface.mapCanvas().currentLayer().reload() def geometry_changed(self, qgsfId, geom): """ diff --git a/buildings/gui/production_frame.py b/buildings/gui/production_frame.py index 6533ee61..3b867ff8 100644 --- a/buildings/gui/production_frame.py +++ b/buildings/gui/production_frame.py @@ -31,11 +31,10 @@ def __init__(self, dockwidget, parent=None): self.layer_registry = LayerRegistry() self.db = db self.db.connect() - self.building_layer = QgsVectorLayer() self.add_outlines() + self.change_instance = None # Set up edit dialog self.edit_dialog = EditDialog(self) - self.change_instance = None self.cb_production.setChecked(True) @@ -85,7 +84,6 @@ def add_outlines(self): Add building outlines to canvas """ path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "styles/") - self.layer_registry.remove_layer(self.building_layer) self.building_historic = self.layer_registry.add_postgres_layer( "historic_outlines", "building_outlines", "shape", "buildings", "", "end_lifespan is not NULL" ) @@ -94,16 +92,19 @@ def add_outlines(self): self.building_layer = self.layer_registry.add_postgres_layer( "building_outlines", "building_outlines", "shape", "buildings", "", "end_lifespan is NULL" ) - self.building_layer.loadNamedStyle(path + "building_blue.qml") + self.building_layer.loadNamedStyle(path + "production_outlines.qml") iface.setActiveLayer(self.building_layer) @pyqtSlot(bool) def cb_production_clicked(self, checked): - group = QgsProject.instance().layerTreeRoot().findGroup("Building Tool Layers") + layer_tree_layer = QgsProject.instance().layerTreeRoot().findLayer(self.building_layer.id()) + layer_tree_model = iface.layerTreeView().model() + categories = layer_tree_model.layerLegendNodes(layer_tree_layer) + current_category = [ln for ln in categories if ln.data(Qt.DisplayRole) == "Building Outlines"] if checked: - group.setItemVisibilityCheckedRecursive(True) + current_category[0].setData(Qt.Checked, Qt.CheckStateRole) else: - group.setItemVisibilityCheckedRecursive(False) + current_category[0].setData(Qt.Unchecked, Qt.CheckStateRole) def canvas_add_outline(self): """ @@ -162,21 +163,21 @@ def close_frame(self): """ if self.change_instance is not None: self.edit_dialog.close() - iface.actionCancelEdits().trigger() QgsProject.instance().layerWillBeRemoved.disconnect(self.layers_removed) + iface.actionCancelEdits().trigger() self.layer_registry.remove_layer(self.building_layer) self.layer_registry.remove_layer(self.building_historic) - # reset toolbar - for action in iface.building_toolbar.actions(): - if action.objectName() not in ["mActionPan"]: - iface.building_toolbar.removeAction(action) - iface.building_toolbar.hide() from buildings.gui.menu_frame import MenuFrame dw = self.dockwidget dw.stk_options.removeWidget(dw.stk_options.currentWidget()) dw.new_widget(MenuFrame(dw)) + # reset toolbar + for action in iface.building_toolbar.actions(): + if action.objectName() not in ["mActionPan"]: + iface.building_toolbar.removeAction(action) + iface.building_toolbar.hide() @pyqtSlot() def edit_cancel_clicked(self): @@ -188,7 +189,7 @@ def edit_cancel_clicked(self): pass elif isinstance(self.change_instance, production_changes.EditGeometry): try: - self.building_layer.geometryChanged.disconnect() + self.building_layer.geometryChanged.disconnect(self.change_instance.geometry_changed) except TypeError: pass elif isinstance(self.change_instance, production_changes.AddProduction): @@ -233,4 +234,5 @@ def layers_removed(self, layerids): def reload_production_layer(self): """To ensure QGIS has most up to date ID for the newly split feature see #349""" - self.building_layer.dataProvider().reloadData() + self.cb_production_clicked(False) + self.cb_production_clicked(True) diff --git a/buildings/styles/production_outlines.qml b/buildings/styles/production_outlines.qml new file mode 100644 index 00000000..9149f211 --- /dev/null +++ b/buildings/styles/production_outlines.qml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + 0 + 2 +