Skip to content

Commit

Permalink
fix: split features bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MDavidson17 committed Apr 6, 2020
1 parent 25465d1 commit fa95a8d
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 16 deletions.
4 changes: 3 additions & 1 deletion buildings/gui/production_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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):
"""
Expand Down
32 changes: 17 additions & 15 deletions buildings/gui/production_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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"
)
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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)
85 changes: 85 additions & 0 deletions buildings/styles/production_outlines.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis version="3.10.3-A Coruña" styleCategories="Symbology">
<renderer-v2 symbollevels="0" forceraster="0" enableorderby="0" type="categorizedSymbol" attr="&quot;end_lifespan&quot; is null">
<categories>
<category render="true" symbol="0" label="Building Outlines" value="1"/>
<category render="true" symbol="1" label="Historic Outlines" value=""/>
</categories>
<symbols>
<symbol force_rhr="0" type="fill" clip_to_extent="1" name="0" alpha="1">
<layer pass="0" enabled="1" locked="0" class="SimpleFill">
<prop v="3x:0,0,0,0,0,0" k="border_width_map_unit_scale"/>
<prop v="104,186,234,0" k="color"/>
<prop v="bevel" k="joinstyle"/>
<prop v="0,0" k="offset"/>
<prop v="3x:0,0,0,0,0,0" k="offset_map_unit_scale"/>
<prop v="MM" k="offset_unit"/>
<prop v="17,239,255,255" k="outline_color"/>
<prop v="solid" k="outline_style"/>
<prop v="0.66" k="outline_width"/>
<prop v="MM" k="outline_width_unit"/>
<prop v="solid" k="style"/>
<data_defined_properties>
<Option type="Map">
<Option type="QString" name="name" value=""/>
<Option name="properties"/>
<Option type="QString" name="type" value="collection"/>
</Option>
</data_defined_properties>
</layer>
</symbol>
<symbol force_rhr="0" type="fill" clip_to_extent="1" name="1" alpha="1">
<layer pass="0" enabled="1" locked="0" class="SimpleFill">
<prop v="3x:0,0,0,0,0,0" k="border_width_map_unit_scale"/>
<prop v="241,238,236,0" k="color"/>
<prop v="bevel" k="joinstyle"/>
<prop v="0,0" k="offset"/>
<prop v="3x:0,0,0,0,0,0" k="offset_map_unit_scale"/>
<prop v="MM" k="offset_unit"/>
<prop v="247,30,23,255" k="outline_color"/>
<prop v="dash" k="outline_style"/>
<prop v="0.26" k="outline_width"/>
<prop v="MM" k="outline_width_unit"/>
<prop v="solid" k="style"/>
<data_defined_properties>
<Option type="Map">
<Option type="QString" name="name" value=""/>
<Option name="properties"/>
<Option type="QString" name="type" value="collection"/>
</Option>
</data_defined_properties>
</layer>
</symbol>
</symbols>
<source-symbol>
<symbol force_rhr="0" type="fill" clip_to_extent="1" name="0" alpha="1">
<layer pass="0" enabled="1" locked="0" class="SimpleFill">
<prop v="3x:0,0,0,0,0,0" k="border_width_map_unit_scale"/>
<prop v="196,60,57,255" k="color"/>
<prop v="bevel" k="joinstyle"/>
<prop v="0,0" k="offset"/>
<prop v="3x:0,0,0,0,0,0" k="offset_map_unit_scale"/>
<prop v="MM" k="offset_unit"/>
<prop v="35,35,35,255" k="outline_color"/>
<prop v="solid" k="outline_style"/>
<prop v="0.26" k="outline_width"/>
<prop v="MM" k="outline_width_unit"/>
<prop v="solid" k="style"/>
<data_defined_properties>
<Option type="Map">
<Option type="QString" name="name" value=""/>
<Option name="properties"/>
<Option type="QString" name="type" value="collection"/>
</Option>
</data_defined_properties>
</layer>
</symbol>
</source-symbol>
<colorramp type="randomcolors" name="[source]"/>
<rotation/>
<sizescale/>
</renderer-v2>
<blendMode>0</blendMode>
<featureBlendMode>0</featureBlendMode>
<layerGeometryType>2</layerGeometryType>
</qgis>

0 comments on commit fa95a8d

Please sign in to comment.