Skip to content

Commit

Permalink
Merge pull request #881 from Giswater/dev-3.5
Browse files Browse the repository at this point in the history
Dev 3.5
  • Loading branch information
edgarfuste authored Nov 2, 2022
2 parents 0ec5481 + 0fa5b3f commit 6552361
Show file tree
Hide file tree
Showing 27 changed files with 2,484 additions and 1,841 deletions.
20 changes: 19 additions & 1 deletion core/load_project_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ def read_menu(self, project_loaded):

# endregion

# region Open plugin folder
if global_vars.plugin_dir:
icon_path = f"{icon_folder}{os.sep}dialogs{os.sep}20x20{os.sep}108.png"
folder_icon = QIcon(icon_path)
action_open_plugin_path = self.main_menu.addAction(f"Open plugin folder")
action_open_plugin_path.setIcon(folder_icon)
action_open_plugin_path.triggered.connect(self._open_plugin_path)
# endregion

# region Advanced
action_manage_file = self.main_menu.addAction(f"Advanced")
action_manage_file.triggered.connect(self._open_manage_file)
Expand All @@ -157,7 +166,7 @@ def read_menu(self, project_loaded):
log_folder_volume = f"{round(size / (1024 * 1024), 2)} MB"
icon_path = f"{icon_folder}{os.sep}dialogs{os.sep}20x20{os.sep}102.png"
folder_icon = QIcon(icon_path)
action_open_path = self.main_menu.addAction(f"Open folder ({log_folder_volume})")
action_open_path = self.main_menu.addAction(f"Open user folder ({log_folder_volume})")
action_open_path.setIcon(folder_icon)
action_open_path.triggered.connect(self._open_config_path)
# endregion
Expand Down Expand Up @@ -188,6 +197,15 @@ def _open_config_path(self):
tools_qgis.show_warning(message, parameter=path)


def _open_plugin_path(self):
""" Opens the OS-specific Plugin directory """

path = os.path.realpath(global_vars.plugin_dir)
status, message = tools_os.open_file(path)
if status is False and message is not None:
tools_qgis.show_warning(message, parameter=path)


def _open_manage_file(self):
""" Manage files dialog:: """

Expand Down
28 changes: 25 additions & 3 deletions core/shared/dimensioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def open_dimensioning_form(self, qgis_feature=None, layer=None, db_return=None,
else:
self.fid = int(db_return['body']['feature']['id'])
# ACTION SIGNALS
action_edit = self.dlg_dim.findChild(QAction, "actionEdit")
action_edit.setChecked(layer.isEditable())
action_edit.triggered.connect(partial(self._manage_edition, action_edit, qgis_feature, layer))
tools_gw.add_icon(action_edit, "101")

action_snapping = self.dlg_dim.findChild(QAction, "actionSnapping")
action_snapping.triggered.connect(partial(self._snapping, action_snapping))
tools_gw.add_icon(action_snapping, "103")
Expand All @@ -88,7 +93,7 @@ def open_dimensioning_form(self, qgis_feature=None, layer=None, db_return=None,

# WIDGETS SIGNALS
self.dlg_dim.btn_accept.clicked.connect(
partial(self._save_dimensioning, qgis_feature, layer))
partial(self._save_dimensioning, qgis_feature, layer, True))
self.dlg_dim.btn_cancel.clicked.connect(partial(self._cancel_dimensioning, action_snapping, action_orientation))
self.dlg_dim.key_escape.connect(partial(tools_gw.close_dialog, self.dlg_dim))
self.dlg_dim.dlg_closed.connect(partial(self._cancel_dimensioning, action_snapping, action_orientation))
Expand Down Expand Up @@ -161,7 +166,7 @@ def _cancel_dimensioning(self, action_snapping, action_orientation):
tools_gw.close_dialog(self.dlg_dim)


def _save_dimensioning(self, qgis_feature, layer):
def _save_dimensioning(self, qgis_feature, layer, close_dlg=True):

# Upsert feature into db
layer.updateFeature(qgis_feature)
Expand Down Expand Up @@ -204,7 +209,8 @@ def _save_dimensioning(self, qgis_feature, layer):
tools_gw.execute_procedure('gw_fct_setdimensioning', body)

# Close dialog
tools_gw.close_dialog(self.dlg_dim)
if close_dlg:
tools_gw.close_dialog(self.dlg_dim)


def _deactivate_signals(self, action, emit_point=None):
Expand All @@ -227,6 +233,22 @@ def _deactivate_signals(self, action, emit_point=None):
return False


def _manage_edition(self, action, qgis_feature, layer):

if action.isChecked():
self.layer_dimensions.startEditing()
else:
# ask if want to save changes
# if so: self.layer_dimensions.commitChanges()
# else: self.layer_dimensions.rollBack()
msg = 'Are you sure to save this feature?'
answer = tools_qt.show_question(msg, "Save feature", None)
if not answer:
tools_qt.set_action_checked(action, True)
return
self._save_dimensioning(qgis_feature, layer, close_dlg=False)


def _snapping(self, action):

# Set active layer and set signals
Expand Down
2 changes: 1 addition & 1 deletion core/shared/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def manage_documents(self):

# Set dignals
self.dlg_man.doc_id.textChanged.connect(
partial(tools_qt.filter_by_id, self.dlg_man, self.dlg_man.tbl_document, self.dlg_man.doc_id, table_object))
partial(tools_qt.filter_by_id, self.dlg_man, self.dlg_man.tbl_document, self.dlg_man.doc_id, table_object, "id"))
self.dlg_man.tbl_document.doubleClicked.connect(
partial(self._open_selected_object_document, self.dlg_man, self.dlg_man.tbl_document, table_object))
self.dlg_man.btn_cancel.clicked.connect(partial(tools_gw.close_dialog, self.dlg_man))
Expand Down
10 changes: 5 additions & 5 deletions core/shared/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def get_element(self, new_element_id=True, feature=None, feature_type=None, sele

# Adding auto-completion to a QLineEdit
table_object = "element"
tools_gw.set_completer_object(self.dlg_add_element, table_object)
tools_gw.set_completer_object(self.dlg_add_element, table_object, field_id='element_id')

# Set signals
excluded_layers = ["v_edit_arc", "v_edit_node", "v_edit_connec", "v_edit_element", "v_edit_gully",
Expand Down Expand Up @@ -272,8 +272,8 @@ def manage_elements(self):
self.dlg_man.tbl_element.setSelectionBehavior(QAbstractItemView.SelectRows)

# Adding auto-completion to a QLineEdit
table_object = "element"
tools_gw.set_completer_object(self.dlg_man, table_object)
table_object = "v_edit_element"
tools_gw.set_completer_object(self.dlg_man, table_object, field_id='element_id')

# Set a model with selected filter. Attach that model to selected table
message = tools_qt.fill_table(self.dlg_man.tbl_element, f"{self.schema_name}.{table_object}")
Expand All @@ -283,7 +283,7 @@ def manage_elements(self):

# Set signals
self.dlg_man.element_id.textChanged.connect(partial(
tools_qt.filter_by_id, self.dlg_man, self.dlg_man.tbl_element, self.dlg_man.element_id, table_object))
tools_qt.filter_by_id, self.dlg_man, self.dlg_man.tbl_element, self.dlg_man.element_id, table_object, "element_id"))
self.dlg_man.tbl_element.doubleClicked.connect(partial(
self._open_selected_object_element, self.dlg_man, self.dlg_man.tbl_element, table_object))
self.dlg_man.btn_cancel.clicked.connect(partial(tools_gw.close_dialog, self.dlg_man))
Expand Down Expand Up @@ -359,7 +359,7 @@ def _fill_tbl_new_element(self, dialog, feature_type, feature_id):

# Adding auto-completion to a QLineEdit
self.table_object = "element"
tools_gw.set_completer_object(dialog, self.table_object)
tools_gw.set_completer_object(dialog, self.table_object, field_id='element_id')


def _manage_element_accept(self, table_object):
Expand Down
37 changes: 34 additions & 3 deletions core/shared/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(self, tab_type):
self.snapper_manager.set_snapping_layers()
self.suppres_form = None
self.prev_action = None
self.previous_map_tool = None


def get_info_from_coordinates(self, point, tab_type):
Expand Down Expand Up @@ -101,6 +102,17 @@ def open_form(self, point=None, table_name=None, feature_id=None, feature_cat=No
self.layer = None
self.feature = None
self.my_json = {}
# Note about self.my_json: this variable is passed to tools_gw.get_values via connected signals.
# If it's reassigned after connecting the signal, it will most likely get a new position in memory, but
# the self.my_json variable passed to the signal will be pointing to the original self.my_json.
# For example, if we do this:
# self.my_json = {'test1': 'test1'}
# widget.signal.connect(partial(tools_gw.get_values, self.my_json))
# self.my_json = {}
# widget.signal.trigger()
# Now tools_gw.get_values() will read self.my_json as {'test1': 'test1'}
# So to clear the dictionary do this:
# self.my_json.clear()
self.tab_type = tab_type

# Get project variables
Expand Down Expand Up @@ -328,7 +340,7 @@ def get_snapped_feature_id(self, dialog, action, layer_name, option, widget_name
action.setChecked(False)
return
# Block the signals of de dialog so that the key ESC does not close it
dialog.blockSignals(True)
dialog.key_escape.disconnect()

self.vertex_marker = self.snapper_manager.vertex_marker

Expand All @@ -350,6 +362,7 @@ def get_snapped_feature_id(self, dialog, action, layer_name, option, widget_name

tools_gw.disconnect_signal('info_snapping', 'get_snapped_feature_id_ep_canvasClicked_get_id')
emit_point = QgsMapToolEmitPoint(self.canvas)
self.previous_map_tool = global_vars.canvas.mapTool()
self.canvas.setMapTool(emit_point)
tools_gw.connect_signal(emit_point.canvasClicked, partial(self._get_id, dialog, action, option, emit_point, child_type),
'info_snapping', 'get_snapped_feature_id_ep_canvasClicked_get_id')
Expand Down Expand Up @@ -736,6 +749,7 @@ def _manage_actions_signals(self, complet_result, list_points, new_feature, tab_
self.action_section.triggered.connect(partial(self._open_section_form))
self.action_help.triggered.connect(partial(self._open_help, self.feature_type))
self.ep = QgsMapToolEmitPoint(self.canvas)
self.previous_map_tool = global_vars.canvas.mapTool()
self.action_interpolate.triggered.connect(partial(self._activate_snapping, complet_result, self.ep))

# Disable action edit if user can't edit
Expand Down Expand Up @@ -863,6 +877,16 @@ def _disconnect_signals(self):
except Exception:
pass

try:
tools_gw.disconnect_signal('info_snapping')
except Exception:
pass

try:
global_vars.canvas.setMapTool(self.previous_map_tool)
except Exception:
pass

self.connected = False
global is_inserting
is_inserting = False
Expand Down Expand Up @@ -1150,6 +1174,7 @@ def _manage_action_copy_paste(self, dialog, feature_type, tab_type=None):
# Set map tool emit point and signals
tools_gw.disconnect_signal('info_snapping', 'manage_action_copy_paste_ep_canvasClicked')
emit_point = QgsMapToolEmitPoint(global_vars.canvas)
self.previous_map_tool = global_vars.canvas.mapTool()
global_vars.canvas.setMapTool(emit_point)
tools_gw.disconnect_signal('info_snapping', 'manage_action_copy_paste_xyCoordinates_mouse_move')
tools_gw.connect_signal(global_vars.canvas.xyCoordinates, self._manage_action_copy_paste_mouse_move,
Expand Down Expand Up @@ -1448,6 +1473,9 @@ def _manage_accept(self, dialog, action_edit, new_feature, my_json, close_dlg):
tools_qt.set_action_checked(action_edit, False)
tools_gw.enable_widgets(dialog, self.complet_result['body']['data'], False)
self._enable_actions(dialog, False)
# Force layers to reindex in order to fix some snapping issues
self.iface.mapCanvas().snappingUtils().clearAllLocators()
tools_qgis.force_refresh_map_canvas()


def _stop_editing(self, dialog, action_edit, layer, fid, my_json, new_feature=None):
Expand Down Expand Up @@ -1841,6 +1869,8 @@ def _accept(self, dialog, complet_result, _json, p_widget=None, clear_json=False
fields_reload = ""
list_mandatory = []
for field in complet_result['body']['data']['fields']:
if field.get('hidden') in (True, 'True', 'true'):
continue
if p_widget and (field['widgetname'] == p_widget.objectName()):
if field['widgetcontrols'] and 'autoupdateReloadFields' in field['widgetcontrols']:
fields_reload = field['widgetcontrols']['autoupdateReloadFields']
Expand Down Expand Up @@ -2111,7 +2141,7 @@ def _clean_my_json(self, widget):
def _reset_my_json(self):
""" Delete keys if exist, when widget is autoupdate """

self.my_json = {}
self.my_json.clear()


def _set_auto_update_lineedit(self, field, dialog, widget, new_feature=None):
Expand Down Expand Up @@ -4242,7 +4272,7 @@ def _get_id(self, dialog, action, option, emit_point, child_type, point, event):

def _set_to_arc(self, feat_id, child_type):
"""
Function called in def get_id(self, dialog, action, option, point, event):
Function called in def _get_id(self, dialog, action, option, emit_point, child_type, point, event):
getattr(self, options[option][1])(feat_id, child_type)
:param feat_id: Id of the snapped feature
Expand Down Expand Up @@ -4283,6 +4313,7 @@ def _cancel_snapping_tool(self, dialog, action):
tools_qgis.disconnect_snapping(False, None, self.vertex_marker)
tools_gw.disconnect_signal('info_snapping')
dialog.blockSignals(False)
dialog.key_escape.connect(partial(tools_gw.close_dialog, dialog))
action.setChecked(False)
self.signal_activate.emit()

Expand Down
Loading

0 comments on commit 6552361

Please sign in to comment.