Skip to content

Commit

Permalink
Merge pull request #854 from Giswater/dev-3.5
Browse files Browse the repository at this point in the history
Dev 3.5
  • Loading branch information
edgarfuste authored Mar 2, 2022
2 parents adf3064 + d487191 commit ca31b68
Show file tree
Hide file tree
Showing 99 changed files with 137,723 additions and 85,353 deletions.
5 changes: 2 additions & 3 deletions config/giswater.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ enable_python_console = FALSE # Show/Hide QGIS Python console
use_notify = TRUE # Use postgres notify
show_help = 0
locale = en_US, es_ES, ca_ES, pt_BR, pt_PT, fr_FR
lower_postgresql_version = 90500
upper_postgresql_version = 119999
deprecated_section_init = psector_rapport, cadtools, search, qgis_toolbar_hidebuttons, dialogs, btn_search,
current_selections, action_shortcuts
deprecated_section_session = psector_rapport, cadtools, visit, import_file, search
Expand All @@ -23,7 +21,7 @@ basic = 37, 142, 143
om = 26, 27, 56, 57, 43, 64, 65, 84
edit = 01, 02, 16, 17, 28, 44, 20, 68, 69, 39, 34, 66, 33, 67
cad = 71, 72
epa = 23, 25, 29
epa = 23, 25, 29, 215
plan = 45, 46, 50
utilities = 206, 99, 83, 58, 214, 59
toc = 306
Expand Down Expand Up @@ -68,6 +66,7 @@ ud = 26, 27
23 = GwGo2EpaButton
25 = GwGo2EpaManagerButton
29 = GwGo2EpaSelectorButton
215 = GwDscenarioManagerButton
# plan
45 = GwPsectorButton
46 = GwPsectorManagerButton
Expand Down
47 changes: 46 additions & 1 deletion config/user_params.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ force_tab_expl = False #Always open selectors with tab exploitation open
exec_procedure_max_retries = 3 #Maximum number of execution retries of a PostgreSQL function
force_superuser = False #Forces the main Giswater dialog to be enabled, even if the user doesn't have permission to administrate project schemas
disable_updateall_attributetable = False #Disables button "Update all" from attribute table
show_psector_ruberband_duration = 5 #Manage rubberband duration
force_create_qgis_group_layer = False #Creates missing groups in ToC when adding layers

[init.log]
log_level = 20 #Default log level. CRITICAL = 50, FATAL = CRITICAL, ERROR = 40, WARNING = 30, WARN = WARNING, INFO = 20, DEBUG = 10, NOTSET = 0
Expand Down Expand Up @@ -62,6 +64,7 @@ shortcut_toggle_log_db = Alt+1 #Shortcut to show DB&Notify logs
23 = None #GwGo2EpaButton
25 = None #GwGo2EpaManagerButton
29 = None #GwGo2EpaSelectorButton
215 = None #GwDscenarioManagerButton
# plan
45 = None #GwPsectorButton
46 = None #GwPsectorManagerButton
Expand Down Expand Up @@ -250,6 +253,10 @@ dlg_replace_in_file_width = None
dlg_replace_in_file_height = None
_dlg_mincut_hydrometer_width = None
_dlg_mincut_hydrometer_height = None
_dlg_dscenario_manager_width = None
_dlg_dscenario_manager_height = None
_dlg_dscenario_width = None
_dlg_dscenario_height = None

[session.dialogs_position]
dlg_admin_translation_x = None
Expand Down Expand Up @@ -394,10 +401,15 @@ dlg_replace_in_file_x = None
dlg_replace_in_file_y = None
_dlg_mincut_hydrometer_x = None
_dlg_mincut_hydrometer_y = None
_dlg_dscenario_manager_x = None
_dlg_dscenario_manager_y = None
_dlg_dscenario_x = None
_dlg_dscenario_y = None

[session.dialogs_tab]
_dlg_selector_basic = None
_dlg_selector_mincut = None
_selector_basic = None

[session.btn_search]
_search_csv_path = None
Expand Down Expand Up @@ -592,8 +604,17 @@ _gw_fct_create_dscenario_from_toc_cmb_feature_type = None
_gw_fct_create_dscenario_from_toc_cmb_layers = None
_gw_fct_create_dscenario_from_toc_rbt_previous = None
_gw_fct_create_dscenario_from_toc_name = None
_gw_fct_create_dscenario_from_toc_descript = None
_gw_fct_create_dscenario_from_toc_type = None
_gw_fct_create_dscenario_from_toc_exploitation = None
_gw_fct_create_dscenario_from_crm_cmb_feature_type = None
_gw_fct_create_dscenario_from_crm_cmb_layers = None
_gw_fct_create_dscenario_from_crm_rbt_previous = None
_gw_fct_create_dscenario_from_crm_name = None
_gw_fct_create_dscenario_from_crm_descript = None
_gw_fct_create_dscenario_from_crm_exploitation = None
_gw_fct_create_dscenario_from_crm_period = None
_gw_fct_create_dscenario_from_crm_pattern = None
_gw_fct_create_dscenario_from_crm_demandunits = None
_gw_fct_manage_dwf_values_cmb_feature_type = None
_gw_fct_manage_dwf_values_cmb_layers = None
_gw_fct_manage_dwf_values_rbt_previous = None
Expand All @@ -604,7 +625,28 @@ _gw_fct_create_dscenario_demand_cmb_layers = None
_gw_fct_create_dscenario_demand_rbt_previous = None
_gw_fct_create_dscenario_demand_name = None
_gw_fct_create_dscenario_demand_descript = None
_gw_fct_manage_dscenario_values_cmb_feature_type = None
_gw_fct_manage_dscenario_values_cmb_layers = None
_gw_fct_manage_dscenario_values_rbt_previous = None
_gw_fct_manage_dscenario_values_target = None
_gw_fct_manage_dscenario_values_action = None
_gw_fct_manage_dscenario_values_copyfrom = None
_gw_fct_create_dscenario_from_toc_exploitation = None
_gw_fct_create_dscenario_demand_exploitation = None
_gw_fct_grafanalytics_mapzones_advanced_valuefordisconnected = None
_gw_fct_create_empty_dscenario_cmb_feature_type = None
_gw_fct_create_empty_dscenario_cmb_layers = None
_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_expl = None
_gw_fct_create_empty_dscenario_parent = None
_gw_fct_admin_manage_migra_cmb_feature_type = None
_gw_fct_admin_manage_migra_cmb_layers = None
_gw_fct_admin_manage_migra_rbt_previous = None
_gw_fct_admin_manage_migra_action = None

[session.docker]
_position = None
Expand Down Expand Up @@ -654,3 +696,6 @@ _psector_rapport_chk_csv = None
[session.btn_info]
_rb_action_interpolate = None

[session.visit]
_om_visit_table_name = None

61 changes: 37 additions & 24 deletions core/admin/admin_btn.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self):
self.form_enabled = True
self.lower_postgresql_version = int(tools_qgis.get_plugin_metadata('minorPgVersion', '9.5', global_vars.plugin_dir)
.replace('.', ''))
self.upper_postgresql_version = int(tools_qgis.get_plugin_metadata('majorPgVersion', '11.99', global_vars.plugin_dir)
self.upper_postgresql_version = int(tools_qgis.get_plugin_metadata('majorPgVersion', '14.99', global_vars.plugin_dir)
.replace('.', ''))
self.total_sql_files = 0 # Total number of SQL files to process
self.current_sql_file = 0 # Current number of SQL file
Expand Down Expand Up @@ -174,7 +174,7 @@ def create_project_data_schema(self, project_name_schema=None, project_descript=
tools_qt.show_info_box(msg, "Warning")
return

elif self.rdb_sample.isChecked() or self.rdb_sample_dev.isChecked():
elif self.rdb_sample.isChecked():

if self.locale != 'en_US' or str(self.project_epsg) != '25831':
msg = ("This functionality is only allowed with the locality 'en_US' and SRID 25831."
Expand Down Expand Up @@ -336,8 +336,9 @@ def update(self, project_type):
schema_name = self._get_schema_name()
sql = f"DELETE FROM {schema_name}.audit_check_data WHERE fid = 133 AND cur_user = current_user;"
tools_db.execute_sql(sql)
status = self.load_updates(project_type, update_changelog=True)
status = self.load_updates(project_type, update_changelog=True, schema_name=schema_name)
if status:
# Set info project
self._set_info_project()
if 'body' in status:
tools_gw.fill_tab_log(self.dlg_readsql_show_info, status['body']['data'], True, True, 1)
Expand Down Expand Up @@ -381,6 +382,8 @@ def load_updates(self, project_type=None, update_changelog=False, schema_name=No
status = self.update_31to39(project_type=project_type)
self.task1.setProgress(60)
if status:
# Check if schema utils exists and execute update
self._update_utils(schema_name)
status = self.execute_last_process(schema_name=schema_name, locale=True)
self.task1.setProgress(100)

Expand Down Expand Up @@ -409,7 +412,6 @@ def init_dialog_create_project(self, project_type=None):
self.project_name = self.dlg_readsql_create_project.findChild(QLineEdit, 'project_name')
self.project_descript = self.dlg_readsql_create_project.findChild(QLineEdit, 'project_descript')
self.rdb_sample = self.dlg_readsql_create_project.findChild(QRadioButton, 'rdb_sample')
self.rdb_sample_dev = self.dlg_readsql_create_project.findChild(QRadioButton, 'rdb_sample_dev')
self.rdb_data = self.dlg_readsql_create_project.findChild(QRadioButton, 'rdb_data')
self.rdb_import_data = self.dlg_readsql_create_project.findChild(QRadioButton, 'rdb_import_data')
self.data_file = self.dlg_readsql_create_project.findChild(QLineEdit, 'data_file')
Expand All @@ -431,9 +433,6 @@ def init_dialog_create_project(self, project_type=None):
# TODO: do and call listener for buton + table -> temp_csv
self.btn_push_file = self.dlg_readsql_create_project.findChild(QPushButton, 'btn_push_file')

if global_vars.user_level['level'] not in global_vars.user_level['showadminadvanced']:
self.rdb_sample_dev.setVisible(False)

# Manage SRID
self._manage_srid()

Expand Down Expand Up @@ -632,6 +631,7 @@ def update_30to31(self, new_project=False, project_type=False, set_progress_bar=

def load_sample_data(self, project_type):

global_vars.dao.commit()
folder = os.path.join(self.folder_example, 'user', project_type)
status = self._execute_files(folder, set_progress_bar=True)
if not status and self.dev_commit is False:
Expand Down Expand Up @@ -1195,7 +1195,7 @@ def _check_project_name(self, project_name, project_descript):
new_name = self._bk_schema_name(list_schemas, f"{project_name}_bk_", 0)

msg = f"This 'Project_name' is already exist. Do you want rename old schema to '{new_name}"
result = tools_qt.show_question(msg, "Info")
result = tools_qt.show_question(msg, "Info", force_action=True)
if result:
self._rename_project_data_schema(str(project_name), str(new_name))
return True
Expand Down Expand Up @@ -2140,9 +2140,13 @@ def _add_replace_widgets(self, replace_json):

def _dlg_replace_accept(self):

dict_to_replace = {}
dict_to_replace_unordered = {}
for widget in self.dlg_replace.findChildren(QLineEdit):
dict_to_replace[f'{widget.objectName()}'] = f'{widget.text()}'
dict_to_replace_unordered[f'{widget.objectName()}'] = f'{widget.text()}'

dict_to_replace = {}
for k in sorted(dict_to_replace_unordered, key=len, reverse=True):
dict_to_replace[k] = dict_to_replace_unordered[k]

all_valid = True
news = []
Expand Down Expand Up @@ -3152,13 +3156,16 @@ def _create_utils(self):
QgsApplication.taskManager().triggerTask(self.task_create_schema)


def _update_utils(self):
def _update_utils(self, schema_name=None):

self.ws_project_name = tools_qt.get_text(self.dlg_readsql, self.dlg_readsql.cmb_utils_ws, return_string_null=False)
if schema_name is None:
self.ws_project_name = tools_qt.get_text(self.dlg_readsql, self.dlg_readsql.cmb_utils_ws, return_string_null=False)
else:
self.ws_project_name = schema_name
sql = f"SELECT value FROM utils.config_param_system WHERE parameter = 'utils_version'"
row = tools_db.get_row(sql)
if row:
self._update_utils_schema(row)
self._update_utils_schema(row, schema_name)


def _load_base_utils(self):
Expand All @@ -3183,7 +3190,7 @@ def _load_base_utils(self):
return True


def _update_utils_schema(self, schema_version=None):
def _update_utils_schema(self, schema_version=None, schema_name=None):

folder_utils_updates = os.path.join(self.sql_dir, 'corporate', 'utils', 'updates')

Expand All @@ -3204,16 +3211,22 @@ def _update_utils_schema(self, schema_version=None):
status = self._load_sql(folder_update, utils_schema_name='utils')
if status is False:
return False
folder_update = os.path.join(folder_utils_updates, folder, sub_folder, 'ws')
if self._process_folder(folder_update):
status = self._load_sql(folder_update, utils_schema_name=self.ws_project_name)
if status is False:
return False
folder_update = os.path.join(folder_utils_updates, folder, sub_folder, 'ud')
if self._process_folder(folder_update):
status = self._load_sql(folder_update, utils_schema_name=self.ud_project_name)
if status is False:
return False
if self.project_type_selected == 'ws':
folder_update = os.path.join(folder_utils_updates, folder, sub_folder, 'ws')
if self._process_folder(folder_update):
if schema_name is None:
schema_name = self.ws_project_name
status = self._load_sql(folder_update, utils_schema_name=schema_name)
if status is False:
return False
if self.project_type_selected == 'ud':
folder_update = os.path.join(folder_utils_updates, folder, sub_folder, 'ud')
if self._process_folder(folder_update):
if schema_name is None:
schema_name = self.ud_project_name
status = self._load_sql(folder_update, utils_schema_name=schema_name)
if status is False:
return False
folder_update = os.path.join(folder_utils_updates, folder, sub_folder, 'i18n', self.locale)
if self._process_folder(folder_update) is True:
status = self._execute_files(folder_update, True)
Expand Down
6 changes: 3 additions & 3 deletions core/load_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from .ui.ui_manager import GwDialogTextUi, GwSearchUi
from .shared.search import GwSearch
from .utils import tools_gw
from .load_project_check import GwLoadProjectCheck
from .threads.project_layers_config import GwProjectLayersConfig
from .threads.project_check import GwProjectCheckTask
from .threads.notify import GwNotify
from .. import global_vars
from ..lib import tools_qgis, tools_log, tools_db, tools_qt, tools_os
Expand Down Expand Up @@ -498,7 +498,7 @@ def _manage_layers(self):

if global_vars.project_type in ('ws', 'ud'):
QApplication.setOverrideCursor(Qt.ArrowCursor)
self.check_project = GwLoadProjectCheck()
self.check_project = GwProjectCheckTask()

# check project
status, result = self.check_project.fill_check_project_table(layers, "true")
Expand Down Expand Up @@ -639,7 +639,7 @@ def _manage_attribute_table(self):
def _manage_focus_changed(self, old, new):
""" Disable button "Update all" of QGIS attribute table dialog. Parameters are passed by the signal itself. """

if new is None:
if new is None or not hasattr(new, 'window'):
return

table_dialog = new.window()
Expand Down
2 changes: 1 addition & 1 deletion core/load_project_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def read_menu(self, project_loaded):
if project_loaded:
# region Toolbar
toolbars_menu = QMenu(f"Toolbars", self.iface.mainWindow().menuBar())
icon_path = f"{icon_folder}{os.sep}dialogs{os.sep}20x20{os.sep}36.png"
icon_path = f"{icon_folder}{os.sep}dialogs{os.sep}24x24{os.sep}36.png"
toolbars_icon = QIcon(icon_path)
toolbars_menu.setIcon(toolbars_icon)
self.main_menu.addMenu(toolbars_menu)
Expand Down
10 changes: 6 additions & 4 deletions core/shared/dimensioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ def open_dimensioning_form(self, qgis_feature=None, layer=None, db_return=None,
return False
db_return = json_result

# get id from db response
self.fid = db_return['body']['feature']['id']

# get id from db response
self.fid = int(db_return['body']['feature']['id']) + 1
else:
self.fid = int(db_return['body']['feature']['id'])
# ACTION SIGNALS
action_snapping = self.dlg_dim.findChild(QAction, "actionSnapping")
action_snapping.triggered.connect(partial(self._snapping, action_snapping))
Expand Down Expand Up @@ -138,7 +139,8 @@ def open_dimensioning_form(self, qgis_feature=None, layer=None, db_return=None,
tools_gw.enable_widgets(self.dlg_dim, db_return['body']['data'], False)

tools_qt.hide_void_groupbox(self.dlg_dim)

self.iface.actionPan().trigger()

title = f"DIMENSIONING - {self.fid}"
tools_gw.open_dialog(self.dlg_dim, dlg_name='dimensioning', title=title)
return False, False
Expand Down
11 changes: 8 additions & 3 deletions core/shared/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@
from functools import partial

from qgis.PyQt.QtWidgets import QAbstractItemView, QTableView, QFileDialog
from qgis.PyQt.QtCore import pyqtSignal, QObject

from ..utils import tools_gw
from ..ui.ui_manager import GwDocUi, GwDocManagerUi
from ... import global_vars
from ...lib import tools_qt, tools_db, tools_qgis, tools_os


class GwDocument:
class GwDocument(QObject):
doc_added = pyqtSignal()

def __init__(self, single_tool=True):
""" Class to control action 'Add document' of toolbar 'edit' """

QObject.__init__(self)
# parameter to set if the document manager is working as
# single tool or integrated in another tool
self.single_tool_mode = single_tool
Expand Down Expand Up @@ -79,8 +82,8 @@ def get_document(self, tablename=None, qtable=None, item_id=None, feature=None,
layer.selectByIds([feature.id()])

# Set icons
tools_gw.add_icon(self.dlg_add_doc.btn_insert, "111")
tools_gw.add_icon(self.dlg_add_doc.btn_delete, "112")
tools_gw.add_icon(self.dlg_add_doc.btn_insert, "111", sub_folder="24x24")
tools_gw.add_icon(self.dlg_add_doc.btn_delete, "112", sub_folder="24x24")
tools_gw.add_icon(self.dlg_add_doc.btn_snapping, "137")
self.dlg_add_doc.tabWidget.setTabEnabled(1, False)

Expand Down Expand Up @@ -263,6 +266,7 @@ def _manage_document_accept(self, table_object, tablename=None, qtable=None, ite
sql = (f"INSERT INTO doc (id, doc_type, path, observ, date)"
f" VALUES ('{doc_id}', '{doc_type}', '{path}', '{observ}', '{date}');")
self._update_doc_tables(sql, doc_id, table_object, tablename, item_id, qtable)
self.doc_added.emit()
else:
# Ask question before executing
msg = ("You have selected multiple documents. In this case, doc_id will be a sequencial number for "
Expand All @@ -272,6 +276,7 @@ def _manage_document_accept(self, table_object, tablename=None, qtable=None, ite
for file in self.files_path:
sql, doc_id = self._insert_doc_sql(doc_type, observ, date, file)
self._update_doc_tables(sql, doc_id, table_object, tablename, item_id, qtable)
self.doc_added.emit()
# If document exists perform an UPDATE
else:
message = "Are you sure you want to update the data?"
Expand Down
Loading

0 comments on commit ca31b68

Please sign in to comment.