Skip to content

Commit

Permalink
Merge pull request #874 from Giswater/dev-3.5
Browse files Browse the repository at this point in the history
Dev 3.5
  • Loading branch information
edgarfuste authored Aug 22, 2022
2 parents b240d73 + fc36362 commit 251867a
Show file tree
Hide file tree
Showing 70 changed files with 1,191 additions and 1,008 deletions.
2 changes: 1 addition & 1 deletion config/giswater.config
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ edit = 01, 02, 16, 17, 28, 44, 20, 68, 69, 39, 34, 66, 33, 67
cad = 71, 72
epa = 218, 23, 25, 29, 215
plan = 45, 46, 50
utilities = 206, 99, 83, 58, 214, 59
utilities = 99, 206, 214, 58, 83, 59
toc = 306

[project_exclusive]
Expand Down
4 changes: 2 additions & 2 deletions config/user_params.config
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ _gw_fct_create_empty_dscenario_rbt_previous = None
_gw_fct_create_empty_dscenario_name = None
_gw_fct_create_empty_dscenario_descript = None
_gw_fct_create_empty_dscenario_type = None
_gw_fct_create_empty_dscenario_active = None
_gw_fct_create_empty_dscenario_active = True
_gw_fct_create_empty_dscenario_expl = None
_gw_fct_create_empty_dscenario_parent = None
_gw_fct_admin_manage_migra_cmb_feature_type = None
Expand All @@ -704,7 +704,7 @@ _gw_fct_duplicate_dscenario_name = None
_gw_fct_duplicate_dscenario_descript = None
_gw_fct_duplicate_dscenario_parent = None
_gw_fct_duplicate_dscenario_type = None
_gw_fct_duplicate_dscenario_active = None
_gw_fct_duplicate_dscenario_active = True
_gw_fct_duplicate_dscenario_expl = None
_gw_fct_duplicate_dscenario_copyfrom = None
_gw_fct_create_dscenario_from_mincut_cmb_feature_type = None
Expand Down
23 changes: 13 additions & 10 deletions core/admin/admin_btn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2022,13 +2022,14 @@ def _execute_import_inp(self, accepted, project_name, project_type):

if complet_result['status'] == 'Failed':
msg = f'The importation process has failed!'
if 'replace' in complet_result['body']['data']:
replace = complet_result['body']['data'].get('replace')
if replace is not None:
msg += f'<br>This can be fixed in the next dialog.'
msg += f'<br>See Info log for more details.'
self._set_log_text(self.dlg_import_inp, complet_result['body']['data'])
tools_qt.show_info_box(msg, "Info")
if 'replace' in complet_result['body']['data']:
retry = self._build_replace_dlg(complet_result['body']['data']['replace'])
if replace is not None:
retry = self._build_replace_dlg(replace)
if retry:
sql = "DELETE FROM temp_csv WHERE fid = 239;"
tools_db.execute_sql(sql, commit=False)
Expand Down Expand Up @@ -2155,7 +2156,7 @@ def _dlg_replace_accept(self):
self.dlg_replace.findChild(QLineEdit, f'{old}').setToolTip('Another object has this name')
valid, all_valid = False, False
except Exception as e:
print(f"{type(e).__name__}: {e}")
tools_log.log_info(f"{type(e).__name__} --> {e}")
if valid:
news.append(new)
tools_qt.set_stylesheet(self.dlg_replace.findChild(QLineEdit, f'{old}'), style="")
Expand Down Expand Up @@ -2968,14 +2969,16 @@ def _manage_result_message(self, status, msg_ok=None, msg_error=None, parameter=
def _manage_json_message(self, json_result, parameter=None, title=None):
""" Manage message depending result @status """

if 'message' in json_result:
message = json_result.get('message')
if message:

level = 1
if 'level' in json_result['message']:
level = int(json_result['message']['level'])
if 'text' in json_result['message']:
msg = json_result['message']['text']
level = message.get('level')
if level is not None:
level = int(level)
else:
level = 1
msg = message.get('text')
if msg is None:
msg = "Key on returned json from ddbb is missed"

tools_qgis.show_message(msg, level, parameter=parameter, title=title)
Expand Down
62 changes: 41 additions & 21 deletions core/load_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ def project_read(self, show_warning=True):
# Removes all deprecated variables defined at giswater.config
tools_gw.remove_deprecated_config_vars()


# Manage variables not configured
if 'project_role' not in global_vars.project_vars or ('project_role' in global_vars.project_vars and global_vars.project_vars['project_role'] in (None, '')):
global_vars.project_vars['project_role'] = tools_gw.get_role_permissions(None)
project_role = global_vars.project_vars.get('project_role')
global_vars.project_vars['project_role'] = tools_gw.get_role_permissions(project_role)

# Check if user has config files 'init' and 'session' and its parameters
tools_gw.user_params_to_userconfig()
Expand Down Expand Up @@ -124,8 +122,15 @@ def project_read(self, show_warning=True):
# Create menu
tools_gw.create_giswater_menu(True)

# Get 'utils_use_gw_snapping' parameter
use_gw_snapping = tools_gw.get_config_value('utils_use_gw_snapping', table='config_param_system')
if use_gw_snapping:
use_gw_snapping = tools_os.set_boolean(use_gw_snapping[0])
global_vars.use_gw_snapping = use_gw_snapping

# Manage snapping layers
self._manage_snapping_layers()
if global_vars.use_gw_snapping is True:
self._manage_snapping_layers()

# Manage actions of the different plugin_toolbars
self._manage_toolbars()
Expand Down Expand Up @@ -158,6 +163,23 @@ def project_read(self, show_warning=True):
# Manage versions of Giswater and PostgreSQL
plugin_version = tools_qgis.get_plugin_metadata('version', 0, global_vars.plugin_dir)
project_version = tools_gw.get_project_version(schema_name)
# Only get the x.y.zzz, not x.y.zzz.n
try:
plugin_version_l = str(plugin_version).split('.')
if len(plugin_version_l) >= 4:
plugin_version = f'{plugin_version_l[0]}'
for i in range(1, 3):
plugin_version = f"{plugin_version}.{plugin_version_l[i]}"
except Exception:
pass
try:
project_version_l = str(project_version).split('.')
if len(project_version_l) >= 4:
project_version = f'{project_version_l[0]}'
for i in range(1, 3):
project_version = f"{project_version}.{project_version_l[i]}"
except Exception:
pass
if project_version == plugin_version:
message = "Project read finished"
tools_log.log_info(message)
Expand Down Expand Up @@ -292,17 +314,13 @@ def _check_layers_from_distinct_schema(self):
repeated_layers[layer_source['schema'].replace('"', '')] = 'v_edit_node'

if len(repeated_layers) > 1:
if global_vars.project_vars['main_schema'] is None or global_vars.project_vars['add_schema'] is None:
self.dlg_dtext = GwDialogTextUi()
self.dlg_dtext.btn_accept.hide()
self.dlg_dtext.btn_close.clicked.connect(lambda: self.dlg_dtext.close())
if global_vars.project_vars['main_schema'] in (None, '', 'null', 'NULL') \
or global_vars.project_vars['add_schema'] in (None, '', 'null', 'NULL'):
msg = "QGIS project has more than one v_edit_node layer coming from different schemas. " \
"If you are looking to manage two schemas, it is mandatory to define which is the master and " \
"which isn't. To do this, you need to configure the QGIS project setting this project's " \
"variables: gwMainSchema and gwAddSchema."

self.dlg_dtext.txt_infolog.setText(msg)
self.dlg_dtext.open()
tools_qt.show_info_box(msg)
return False

# If there are layers with a different schema, the one that the user has in the project variable
Expand Down Expand Up @@ -475,9 +493,11 @@ def _config_layers(self):
status, result = self._manage_layers()
if not status:
return False
if result and 'variables' in result['body']:
if 'setQgisLayers' in result['body']['variables']:
if result['body']['variables']['setQgisLayers'] in (False, 'False', 'false'):
if result:
variables = result['body'].get('variables')
if variables:
setQgisLayers = variables.get('setQgisLayers')
if setQgisLayers in (False, 'False', 'false'):
return

# Set project layers with gw_fct_getinfofromid: This process takes time for user
Expand Down Expand Up @@ -524,12 +544,12 @@ def _manage_layers(self):
# check project
status, result = self.check_project.fill_check_project_table(layers, "true")
try:
if 'variables' in result['body']:
if 'useGuideMap' in result['body']['variables']:
guided_map = result['body']['variables']['useGuideMap']
if guided_map:
tools_log.log_info("manage_guided_map")
self._manage_guided_map()
variables = result['body'].get('variables')
if variables:
guided_map = variables.get('useGuidedMap')
if guided_map:
tools_log.log_info("manage_guided_map")
self._manage_guided_map()
except Exception as e:
tools_log.log_info(str(e))
finally:
Expand Down
15 changes: 8 additions & 7 deletions core/shared/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ def _add_combobox(self, field):
widget.setObjectName(field['columnname'])
widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
self._fill_combo(widget, field)
if 'selectedId' in field:
tools_qt.set_combo_value(widget, field['selectedId'], 0)
tools_qt.set_combo_value(widget, field.get('selectedId'), 0)

return widget

Expand All @@ -199,10 +198,12 @@ def _fill_combo(self, widget, field):
widget.clear()
widget.blockSignals(False)
combolist = []
if 'comboIds' in field:
for i in range(0, len(field['comboIds'])):
if field['comboIds'][i] is not None and field['comboNames'][i] is not None:
elem = [field['comboIds'][i], field['comboNames'][i]]
comboIds = field.get('comboIds')
comboNames = field.get('comboNames')
if None not in (comboIds, comboNames):
for i in range(0, len(comboIds)):
if comboIds[i] is not None and comboNames[i] is not None:
elem = [comboIds[i], comboNames[i]]
combolist.append(elem)
records_sorted = sorted(combolist, key=operator.itemgetter(1))
# Populate combo
Expand All @@ -227,7 +228,7 @@ def _fill_geomcat_id(self, previous_dialog, widget_name):
widget.setFocus()
else:
message = "Widget not found"
tools_qgis.show_message(message, 2, parameter=str(widget_name))
tools_qgis.show_message(message, 2, parameter=str(widget_name), dialog=previous_dialog)

tools_gw.close_dialog(self.dlg_catalog)

Expand Down
10 changes: 6 additions & 4 deletions core/shared/dimensioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def open_dimensioning_form(self, qgis_feature=None, layer=None, db_return=None,

layout_list = []
for field in db_return['body']['data']['fields']:
if 'hidden' in field and field['hidden']:
if field.get('hidden'):
continue

label, widget = self._set_widgets(self.dlg_dim, db_return, field)
Expand Down Expand Up @@ -461,10 +461,12 @@ def _set_widgets(self, dialog, db_return, field):
label = QLabel()
label.setObjectName('lbl_' + field['widgetname'])
label.setText(field['label'].capitalize())
if 'stylesheet' in field and field['stylesheet'] is not None and 'label' in field['stylesheet']:
stylesheet = field.get('stylesheet')
if stylesheet and 'label' in stylesheet:
label = tools_gw.set_stylesheet(field, label)
if 'tooltip' in field:
label.setToolTip(field['tooltip'])
tooltip = field.get('tooltip')
if tooltip:
label.setToolTip(tooltip)
else:
label.setToolTip(field['label'].capitalize())
if field['widgettype'] == 'text' or field['widgettype'] == 'typeahead':
Expand Down
4 changes: 2 additions & 2 deletions core/shared/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def _manage_document_accept(self, table_object, tablename=None, qtable=None, ite

if doc_type in (None, '', -1):
message = "You need to insert doc_type"
tools_qgis.show_warning(message)
tools_qgis.show_warning(message, dialog=self.dlg_add_doc)
return

# Check if this document already exists
Expand Down Expand Up @@ -374,7 +374,7 @@ def _open_selected_object_document(self, dialog, widget, table_object):
selected_list = widget.selectionModel().selectedRows()
if len(selected_list) == 0:
message = "Any record selected"
tools_qgis.show_warning(message)
tools_qgis.show_warning(message, dialog=dialog)
return

row = selected_list[0].row()
Expand Down
8 changes: 4 additions & 4 deletions core/shared/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,15 +388,15 @@ def _manage_element_accept(self, table_object):
# Check mandatory fields
message = "You need to insert value for field"
if elementcat_id == '':
tools_qgis.show_warning(message, parameter="elementcat_id")
tools_qgis.show_warning(message, parameter="elementcat_id", dialog=self.dlg_add_element)
return
num_elements = tools_qt.get_text(self.dlg_add_element, "num_elements", return_string_null=False)
if num_elements == '':
tools_qgis.show_warning(message, parameter="num_elements")
tools_qgis.show_warning(message, parameter="num_elements", dialog=self.dlg_add_element)
return
state = tools_qt.get_combo_value(self.dlg_add_element, self.dlg_add_element.state)
if state == '':
tools_qgis.show_warning(message, parameter="state_id")
tools_qgis.show_warning(message, parameter="state_id", dialog=self.dlg_add_element)
return

state_type = tools_qt.get_combo_value(self.dlg_add_element, self.dlg_add_element.state_type)
Expand Down Expand Up @@ -571,7 +571,7 @@ def _open_selected_object_element(self, dialog, widget, table_object):
selected_list = widget.selectionModel().selectedRows()
if len(selected_list) == 0:
message = "Any record selected"
tools_qgis.show_warning(message)
tools_qgis.show_warning(message, dialog=dialog)
return

row = selected_list[0].row()
Expand Down
Loading

0 comments on commit 251867a

Please sign in to comment.