Skip to content

Commit

Permalink
Merge pull request #887 from Giswater/dev-3.5
Browse files Browse the repository at this point in the history
Dev 3.5
  • Loading branch information
smaspons authored May 10, 2023
2 parents b2ff457 + c31080c commit 80135c2
Show file tree
Hide file tree
Showing 15 changed files with 13,711 additions and 13,681 deletions.
12 changes: 7 additions & 5 deletions core/shared/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3206,8 +3206,8 @@ def _fill_tbl_visit(self, widget, table_name, filter_, geom_type):
tools_qt.fill_table(widget, table_name, filter_)
self._set_filter_dates('startdate', 'enddate', table_name, self.date_visit_from, self.date_visit_to,
column_filter=feature_key, value_filter=self.feature_id, widget=widget)
# Manage config_form_tableview
tools_gw.set_tablemodel_config(self.dlg_cf, widget, table_name)
# Manage config_form_tableview
tools_gw.set_tablemodel_config(self.dlg_cf, widget, table_name)


def _open_generic_visit(self, widget, table_name):
Expand Down Expand Up @@ -3259,8 +3259,9 @@ def _set_filter_table_visit(self, widget, table_name, visit_class=False, column_
tools_qgis.show_warning(message, dialog=self.dlg_cf)
return

if type(table_name) is dict:
table_name = str(table_name[tools_qt.get_combo_value(self.dlg_cf, self.cmb_visit_class, 0)])
cmb_visit_class_value = tools_qt.get_combo_value(self.dlg_cf, self.cmb_visit_class, 0)
if type(table_name) is dict and cmb_visit_class_value not in (None, ''):
table_name = str(table_name[cmb_visit_class_value])

# Set model of selected widget
if visit_class:
Expand All @@ -3275,7 +3276,8 @@ def _set_filter_table_visit(self, widget, table_name, visit_class=False, column_
tbl_name = table_name.split(".")[1]
else:
tbl_name = table_name
tools_gw.set_tablemodel_config(self.dlg_cf, widget, tbl_name)
if type(tbl_name) is not dict:
tools_gw.set_tablemodel_config(self.dlg_cf, widget, tbl_name)

# Set filter to model
expr = self.field_id + " = '" + self.feature_id + "'"
Expand Down
43 changes: 35 additions & 8 deletions core/shared/nonvisual.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ def manage_nonvisual(self):
self.manager_dlg.btn_cancel.clicked.connect(self.manager_dlg.reject)
self.manager_dlg.finished.connect(partial(tools_gw.close_dialog, self.manager_dlg))
self.manager_dlg.btn_print.clicked.connect(partial(self._print_object))
self.manager_dlg.chk_active.stateChanged.connect(partial(self._filter_active, self.manager_dlg))

self.manager_dlg.main_tab.currentChanged.connect(
partial(self._manage_tabs_changed))
self.manager_dlg.main_tab.currentChanged.connect(partial(self._manage_tabs_changed))
self.manager_dlg.main_tab.currentChanged.connect(partial(self._filter_active, self.manager_dlg, None))
self._manage_tabs_changed()

# Open dialog
tools_gw.open_dialog(self.manager_dlg, dlg_name=f'dlg_nonvisual_manager')
Expand All @@ -111,12 +113,19 @@ def _manage_tabs_manager(self):

def _manage_tabs_changed(self):

tab_idx = self.manager_dlg.main_tab.currentIndex()
if tab_idx == 0:
self.manager_dlg.btn_print.setVisible(True)
tab_name = self.manager_dlg.main_tab.currentWidget().objectName()

else:
self.manager_dlg.btn_print.setVisible(False)
visibility_settings = { # tab_name: (chk_active, btn_print)
'v_edit_inp_curve': (False, True),
'v_edit_inp_pattern': (False, False),
'inp_lid': (False, False),
}
default_visibility = (True, False)

chk_active_visible, btn_print_visible = visibility_settings.get(tab_name, default_visibility)

self.manager_dlg.chk_active.setVisible(chk_active_visible)
self.manager_dlg.btn_print.setVisible(btn_print_visible)


def _get_nonvisual_object(self, tbl_view, function_name):
Expand Down Expand Up @@ -176,6 +185,24 @@ def _filter_table(self, dialog, text):
widget_table.model().select()


def _filter_active(self, dialog, active):
""" Filters manager table by active """

widget_table = dialog.main_tab.currentWidget()
id_field = 'active'
if active is None:
active = dialog.chk_active.checkState()
active = 'true' if active == 2 else None

expr = ""
if active is not None:
expr = f"{id_field} = {active}"

# Refresh model with selected filter
widget_table.model().setFilter(expr)
widget_table.model().select()


def _create_object(self, dialog):
""" Creates a new non-visual object from the manager """

Expand Down Expand Up @@ -667,7 +694,7 @@ def _manage_curve_plot(self, dialog, table, plot_widget, file_name=None, geom1=N
plot_widget.axes.plot(aux_y_list, aux_x_list, color="grey", alpha=0.5, linestyle="dashed")

if file_name:
fig_title = f"{file_name} (S: {round(area*100, 2)} dm2 - {round(geom1, 2)}x{round(geom2, 2)})"
fig_title = f"{file_name} (S: {round(area*100, 2)} dm2 - {round(geom1, 2)} x {round(geom2, 2)})"
plot_widget.axes.text(min(y_list_inverted)*1.1, max(x_list)*1.07, f"{fig_title}", fontsize=8)
else:
plot_widget.axes.plot(x_list, y_list, color='indianred')
Expand Down
55 changes: 25 additions & 30 deletions core/shared/psector.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def get_psector(self, psector_id=None, list_coord=None):
self.qtbl_connec.selectionModel().selectionChanged.connect(partial(
self._manage_tab_feature_buttons
))
self.qtbl_connec.model().flags = lambda index: self.flags(index, self.qtbl_connec.model(), ['arc_id', 'link_id'])

# tbl_psector_x_gully
if self.project_type.upper() == 'UD':
Expand All @@ -266,6 +267,7 @@ def get_psector(self, psector_id=None, list_coord=None):
self.qtbl_gully.selectionModel().selectionChanged.connect(partial(
self._manage_tab_feature_buttons
))
self.qtbl_gully.model().flags = lambda index: self.flags(index, self.qtbl_gully.model(), ['arc_id', 'link_id'])

if psector_id is not None:

Expand Down Expand Up @@ -431,7 +433,7 @@ def get_psector(self, psector_id=None, list_coord=None):
self.dlg_plan_psector.btn_insert.clicked.connect(
partial(tools_gw.insert_feature, self, self.dlg_plan_psector, table_object, True, True, None, None))
self.dlg_plan_psector.btn_delete.clicked.connect(
partial(tools_gw.delete_records, self, self.dlg_plan_psector, table_object, True, None, None))
partial(tools_gw.delete_records, self, self.dlg_plan_psector, table_object, True, None, None, "state"))
self.dlg_plan_psector.btn_delete.clicked.connect(
partial(tools_gw.set_model_signals, self))
self.dlg_plan_psector.btn_snapping.clicked.connect(
Expand Down Expand Up @@ -514,6 +516,16 @@ def get_psector(self, psector_id=None, list_coord=None):
tools_gw.open_dialog(self.dlg_plan_psector, dlg_name='plan_psector')


def flags(self, index, model, editable_columns=None):

column_name = model.headerData(index.column(), Qt.Horizontal, Qt.DisplayRole)
if editable_columns and column_name not in editable_columns:
flags = Qt.ItemIsSelectable | Qt.ItemIsEnabled
return flags

return QSqlTableModel.flags(model, index)


def fill_widget(self, dialog, widget, row):

if type(widget) is str or type(widget) is str:
Expand Down Expand Up @@ -1535,25 +1547,19 @@ def show_status_warning(self):
msg = ""
status = tools_qt.get_combo_value(self.dlg_plan_psector, self.cmb_status)
if status == '0':
msg = "WARNING: You have updated the status value to EXECUTED (Obsolete). If you click 'Accept' on " \
"the main dialog, a process will update all the features that belong to the psector changing its " \
"state to OBSOLETE and its state_type according to system variable " \
"'plan_psector_execute', 'done_planified' and 'done_ficticius'."
elif status == '2':
msg = "WARNING: You have updated the status value to PLANNED. If you click 'Accept' on the main dialog, " \
"a process will update all the features that belong to the psector changing its state to " \
"OBSOLETE and its state_type according to system variable " \
"'plan_statetype_vdefault', 'plan_statetype_planned' and 'plan_statetype_ficticius'."
msg = "WARNING: You have updated the status value to EXECUTED (Save Trace). If you click 'Accept' on " \
"the main dialog, this psector relations will be deleted. Previously they will be saved into " \
"psector traceability tables indicating that features belog to an Executed psector."
elif status == '3':
msg = "WARNING: You have updated the status value to CANCELED. If you click 'Accept' on the main dialog, " \
"a process will update all the features that belong to the psector changing its state to OBSOLETE " \
"and its state_type according to system variable 'plan_psector_execute', 'canceled_planified' and " \
"'canceled_ficticius'."
msg = "WARNING: You have updated the status value to CANCELED (Save Trace). If you click 'Accept' on " \
"the main dialog, this psector relations will be deleted. Previously they will be saved into " \
"psector traceability tables indicating that features belog to a Canceled psector."
elif status == '4':
msg = "WARNING: You have updated the status value to EXECUTED (On Service). If you click 'Accept' on the " \
"main dialog, this psector will be executed. Planified features will turn ON SERVICE and deleted " \
"features will turn OBSOLETE. To mantain traceability, a copy of planified features will be " \
"inserted on the psector."
msg = "WARNING: You have updated the status value to EXECUTED (Set OPERATIVE and Save Trace). If you " \
"click 'Accept' on the main dialog, this psector will be executed. Planified features will turn " \
"OPERATIVE and deleted features will turn OBSOLETE. Finally, psector relations will be deleted " \
"but saving them into psector traceability tables indicating that features belong to an Executed " \
"psector."
if msg:
tools_qt.show_details(msg, 'Message warning')

Expand Down Expand Up @@ -2490,7 +2496,7 @@ def _manage_btn_toggle(self, dialog):
""" Fill btn_toggle QMenu """

# Functions
values = [[0, "Toggle state"], [1, "Toggle doable"]]
values = [[0, "Toggle doable"]]

# Create and populate QMenu
toggle_menu = QMenu()
Expand Down Expand Up @@ -2538,17 +2544,6 @@ def _toggle_feature_psector(self, dialog, idx):
return

if idx == 0:
for i in range(0, len(selected_list)):
row = selected_list[i].row()
feature_id = qtbl_feature.model().record(row).value(f"{feature_type}_id")
state = qtbl_feature.model().record(row).value("state")
if state == 1:
sql += f"UPDATE {list_tables[feature_type]} SET state = 0 WHERE {feature_type}_id = '{feature_id}' AND psector_id = {selected_psector};"
elif state == 0:
sql += f"UPDATE {list_tables[feature_type]} SET state = 1 WHERE {feature_type}_id = '{feature_id}' AND psector_id = {selected_psector};"


elif idx == 1:
for i in range(0, len(selected_list)):
row = selected_list[i].row()
feature_id = qtbl_feature.model().record(row).value(f"{feature_type}_id")
Expand Down
4 changes: 4 additions & 0 deletions core/shared/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class GwSelector:
def __init__(self):
self.checkall = False
self.help_button = None
self.scrolled_amount = 0


def open_selector(self, selector_type="selector_basic", reload_dlg=None):
Expand All @@ -37,6 +38,8 @@ def open_selector(self, selector_type="selector_basic", reload_dlg=None):
else:
current_tab = tools_gw.get_config_parser('dialogs_tab', "dlg_selector_basic", "user", "session")
reload_dlg.main_tab.clear()
if self.scrolled_amount:
reload_dlg.scrollArea.verticalScrollBar().setValue(self.scrolled_amount)
self.get_selector(reload_dlg, selector_type, current_tab=current_tab, aux_params=aux_params)
return

Expand Down Expand Up @@ -374,6 +377,7 @@ def _set_selector(self, dialog, widget, is_alone, disable_parent, check_all_over
layer.setExtent(canvas_extent)
global_vars.iface.mapCanvas().refresh()

self.scrolled_amount = dialog.scrollArea.verticalScrollBar().value()
# Reload selectors dlg
self.open_selector(selector_type, reload_dlg=dialog)

Expand Down
3 changes: 3 additions & 0 deletions core/toolbars/edit/feature_delete_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ def _delete_feature_relation(self):
if not change_tab:
tools_gw.close_dialog(self.dlg_feature_delete)

# Refresh canvas
tools_qgis.refresh_map_canvas()


def _selection_init(self):
""" Set canvas map tool to an instance of class 'GwSelectManager' """
Expand Down
4 changes: 2 additions & 2 deletions core/toolbars/epa/dscenario_manager_btn.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,11 @@ def _fill_dscenario_table(self, set_edit_triggers=QTableView.DoubleClicked, expr

# Hide unwanted columns
col_idx = tools_qt.get_col_index_by_col_name(widget, 'dscenario_id')
if col_idx is not False:
if col_idx not in (None, False):
widget.setColumnHidden(col_idx, True)

geom_col_idx = tools_qt.get_col_index_by_col_name(widget, 'the_geom')
if geom_col_idx is not False:
if geom_col_idx not in (None, False):
widget.setColumnHidden(geom_col_idx, True)

# Sort the table by feature id
Expand Down
10 changes: 8 additions & 2 deletions core/toolbars/epa/go2epa_manager_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ..dialog import GwAction
from ...ui.ui_manager import GwEpaManagerUi
from ...utils import tools_gw
from ....lib import tools_qt, tools_db, tools_qgis
from ....lib import tools_qt, tools_db, tools_qgis, tools_os


class GwGo2EpaManagerButton(GwAction):
Expand Down Expand Up @@ -281,12 +281,16 @@ def _epa2data(self, widget, column_id):
return

result_id = ""
set_corporate = True
for i in range(0, len(selected_list)):
row = selected_list[i].row()
col = tools_qt.get_col_index_by_col_name(widget, str(column_id))
result_id = widget.model().index(row, col).data()
col = tools_qt.get_col_index_by_col_name(widget, "iscorporate")
set_corporate = widget.model().index(row, col).data()
set_corporate = not tools_os.set_boolean(set_corporate, False)

extras = f'"resultId":"{result_id}"'
extras = f'"resultId":"{result_id}", "isCorporate": {str(set_corporate).lower()}'
body = tools_gw.create_body(extras=extras)
result = tools_gw.execute_procedure('gw_fct_epa2data', body)
if not result or result.get('status') != 'Accepted':
Expand All @@ -295,5 +299,7 @@ def _epa2data(self, widget, column_id):
return
message = "Epa2data execution successful."
tools_qgis.show_info(message, dialog=self.dlg_manager)
# Refresh table
self._fill_manager_table()

# endregion
Loading

0 comments on commit 80135c2

Please sign in to comment.