def open_dlg_rapports(self, previous_dialog): default_file_name = utils_giswater.getWidgetText(previous_dialog.name) self.dlg_psector_rapport = Psector_rapport() utils_giswater.setDialog(self.dlg_psector_rapport) self.load_settings(self.dlg_psector_rapport) utils_giswater.setWidgetText('txt_composer_path', default_file_name + " comp.pdf") utils_giswater.setWidgetText('txt_csv_detail_path', default_file_name + " detail.csv") utils_giswater.setWidgetText('txt_csv_path', default_file_name + ".csv") self.dlg_psector_rapport.btn_cancel.pressed.connect(partial(self.set_prev_dialog, self.dlg_psector_rapport, previous_dialog)) self.dlg_psector_rapport.btn_ok.pressed.connect(partial(self.generate_rapports, previous_dialog, self.dlg_psector_rapport)) self.dlg_psector_rapport.btn_path.pressed.connect(partial(self.get_folder_dialog, self.dlg_psector_rapport.txt_path)) utils_giswater.setWidgetText(self.dlg_psector_rapport.txt_path, self.controller.plugin_settings_value('psector_rapport_path')) utils_giswater.setChecked(self.dlg_psector_rapport.chk_composer, bool(self.controller.plugin_settings_value('psector_rapport_chk_composer'))) utils_giswater.setChecked(self.dlg_psector_rapport.chk_csv_detail, self.controller.plugin_settings_value('psector_rapport_chk_csv_detail')) utils_giswater.setChecked(self.dlg_psector_rapport.chk_csv, self.controller.plugin_settings_value('psector_rapport_chk_csv')) if utils_giswater.getWidgetText(self.dlg_psector_rapport.txt_path) == 'null': if 'nt' in sys.builtin_module_names: plugin_dir = os.path.expanduser("~\Documents") else: plugin_dir = os.path.expanduser("~") utils_giswater.setWidgetText(self.dlg_psector_rapport.txt_path, plugin_dir) # Open dialog self.open_dialog(self.dlg_psector_rapport, maximize_button=False)
def edit_document(self): """ Button 66: Edit document """ # Create the dialog self.dlg_man = DocManagement() utils_giswater.setDialog(self.dlg_man) self.load_settings(self.dlg_man) utils_giswater.set_table_selection_behavior(self.dlg_man.tbl_document) # Adding auto-completion to a QLineEdit table_object = "doc" self.set_completer_object(table_object) # Set a model with selected filter. Attach that model to selected table self.fill_table_object(self.dlg_man.tbl_document, self.schema_name + "." + table_object) self.set_table_columns(self.dlg_man.tbl_document, table_object) # Set dignals self.dlg_man.doc_id.textChanged.connect( partial(self.filter_by_id, self.dlg_man.tbl_document, self.dlg_man.doc_id, table_object)) self.dlg_man.tbl_document.doubleClicked.connect( partial(self.open_selected_object, self.dlg_man.tbl_document, table_object)) self.dlg_man.btn_cancel.pressed.connect( partial(self.close_dialog, self.dlg_man)) self.dlg_man.rejected.connect(partial(self.close_dialog, self.dlg_man)) self.dlg_man.btn_delete.clicked.connect( partial(self.delete_selected_object, self.dlg_man.tbl_document, table_object)) # Open form self.open_dialog(self.dlg_man)
def change_elem_type(self, feature): # Create the dialog, fill node_type and define its signals self.dlg = ChangeNodeType() utils_giswater.setDialog(self.dlg) self.load_settings(self.dlg) # Get nodetype_id from current node project_type = self.controller.get_project_type() if project_type == 'ws': node_type = feature.attribute('nodetype_id') if project_type == 'ud': node_type = feature.attribute('node_type') sql = "SELECT DISTINCT(id) FROM " + self.schema_name + ".cat_node ORDER BY id" rows = self.controller.get_rows(sql) utils_giswater.fillComboBox("node_nodecat_id", rows, allow_nulls=False) self.dlg.node_node_type.setText(node_type) self.dlg.node_node_type_new.currentIndexChanged.connect(self.edit_change_elem_type_get_value) self.dlg.btn_catalog.pressed.connect(partial(self.open_catalog_form, project_type, 'node')) self.dlg.btn_accept.pressed.connect(self.edit_change_elem_type_accept) self.dlg.btn_cancel.pressed.connect(self.close_dialog) # Fill 1st combo boxes-new system node type sql = "SELECT DISTINCT(id) FROM " + self.schema_name + ".node_type ORDER BY id" rows = self.controller.get_rows(sql) utils_giswater.fillComboBox("node_node_type_new", rows) # Open dialog self.open_dialog(self.dlg, dlg_name='change_node_type', maximize_button=False)
def fill_geomcat_id(self): catalog_id = utils_giswater.getWidgetText(self.dlg_cat.id) self.close_dialog(self.dlg_cat) utils_giswater.setDialog(self.dlg) utils_giswater.setWidgetEnabled(self.dlg.node_nodecat_id, True) utils_giswater.setWidgetText(self.dlg.node_nodecat_id, catalog_id)
def ud_hydrology_selector(self): """ Dialog hydrology_selector.ui """ self.dlg_hydrology_selector = HydrologySelector() utils_giswater.setDialog(self.dlg_hydrology_selector) self.load_settings(self.dlg_hydrology_selector) self.dlg_hydrology_selector.btn_accept.pressed.connect(self.save_hydrology) self.dlg_hydrology_selector.hydrology.currentIndexChanged.connect(self.update_labels) self.dlg_hydrology_selector.txt_name.textChanged.connect(partial(self.filter_cbx_by_text, "cat_hydrology", self.dlg_hydrology_selector.txt_name, self.dlg_hydrology_selector.hydrology)) sql = ("SELECT DISTINCT(name), hydrology_id FROM " + self.schema_name + ".cat_hydrology ORDER BY name") rows = self.controller.get_rows(sql) if not rows: message = "Any data found in table" self.controller.show_warning(message, parameter='cat_hydrology') return False utils_giswater.set_item_data(self.dlg_hydrology_selector.hydrology, rows) sql = ("SELECT DISTINCT(t1.name) FROM " + self.schema_name + ".cat_hydrology AS t1" " INNER JOIN " + self.schema_name + ".inp_selector_hydrology AS t2 ON t1.hydrology_id = t2.hydrology_id " " WHERE t2.cur_user = current_user") row = self.controller.get_rows(sql) if row: utils_giswater.setWidgetText("hydrology", row[0]) else: utils_giswater.setWidgetText("hydrology", 0) self.update_labels() self.dlg_hydrology_selector.exec_()
def mg_result_selector(self): ''' Button 25. Result selector ''' # Create the dialog and signals self.dlg = ResultCompareSelector() utils_giswater.setDialog(self.dlg) self.dlg.btn_accept.pressed.connect(self.mg_result_selector_accept) self.dlg.btn_cancel.pressed.connect(self.close_dialog) # Set values from widgets of type QComboBox sql = "SELECT DISTINCT(result_id) FROM "+self.schema_name+".rpt_cat_result ORDER BY result_id" rows = self.dao.get_rows(sql) utils_giswater.fillComboBox("rpt_selector_result_id", rows) utils_giswater.fillComboBox("rpt_selector_compare_id", rows) # Get current data from tables 'rpt_selector_result' and 'rpt_selector_compare' sql = "SELECT result_id FROM "+self.schema_name+".rpt_selector_result" row = self.dao.get_row(sql) if row: utils_giswater.setWidgetText("rpt_selector_result_id", row["result_id"]) sql = "SELECT result_id FROM "+self.schema_name+".rpt_selector_compare" row = self.dao.get_row(sql) if row: utils_giswater.setWidgetText("rpt_selector_compare_id", row["result_id"]) # Open the dialog self.dlg.exec_()
def config(self): """ B5-99: Config """ # Dialog multi_selector self.dlg_multi = Multi_selector() utils_giswater.setDialog(self.dlg_multi) self.tbl_config = self.dlg_multi.findChild(QTableView, "tbl") self.btn_insert = self.dlg_multi.findChild(QPushButton, "btn_insert") self.btn_delete = self.dlg_multi.findChild(QPushButton, "btn_delete") table = "anl_mincut_selector_valve" self.menu_valve = QMenu() self.dlg_multi.btn_insert.pressed.connect( partial(self.fill_insert_menu, table)) btn_cancel = self.dlg_multi.findChild(QPushButton, "btn_cancel") btn_cancel.pressed.connect(partial(self.close_dialog, self.dlg_multi)) self.menu_valve.clear() self.dlg_multi.btn_insert.setMenu(self.menu_valve) self.dlg_multi.btn_delete.pressed.connect( partial(self.delete_records_config, self.tbl_config, table)) self.fill_table_config(self.tbl_config, self.schema_name + "." + table) # Open form self.dlg_multi.setWindowFlags(Qt.WindowStaysOnTopHint) self.dlg_multi.open()
def init_create_point_form(self): # Create the dialog and signals self.dlg_create_point = Cad_add_point() utils_giswater.setDialog(self.dlg_create_point) self.load_settings(self.dlg_create_point) virtual_layer_name = "point" sql = ( "SELECT value FROM " + self.controller.schema_name + ".config_param_user" " WHERE cur_user = current_user AND parameter = 'virtual_layer_point'" ) row = self.controller.get_row(sql) if row: virtual_layer_name = row[0] if self.exist_virtual_layer(virtual_layer_name): self.get_point(virtual_layer_name) else: self.create_virtual_layer(virtual_layer_name) message = "Virtual layer not found. It's gonna be created" self.controller.show_info(message) self.iface.setActiveLayer(self.worker_layer) self.get_point(virtual_layer_name)
def master_psector_mangement(self): """ Button 46: Psector management """ # Create the dialog and signals self.dlg = Psector_management() utils_giswater.setDialog(self.dlg) self.load_settings(self.dlg) table_name = "plan_psector" column_id = "psector_id" # Tables qtbl_psm = self.dlg.findChild(QTableView, "tbl_psm") qtbl_psm.setSelectionBehavior(QAbstractItemView.SelectRows) # Set signals self.dlg.btn_cancel.pressed.connect(self.close_dialog) self.dlg.rejected.connect(self.close_dialog) self.dlg.btn_delete.clicked.connect( partial(self.multi_rows_delete, qtbl_psm, table_name, column_id)) self.dlg.btn_update_psector.clicked.connect( partial(self.update_current_psector, qtbl_psm)) self.dlg.txt_name.textChanged.connect( partial(self.filter_by_text, qtbl_psm, self.dlg.txt_name, "plan_psector")) self.dlg.tbl_psm.doubleClicked.connect( partial(self.charge_psector, qtbl_psm)) self.fill_table_psector(qtbl_psm, table_name) self.set_table_columns(qtbl_psm, table_name) self.set_label_current_psector() # Open form self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint) self.open_dialog(self.dlg, dlg_name="psector_management")
def master_estimate_result_selector(self): """ Button 49: Estimate result selector """ # Create dialog self.dlg = EstimateResultSelector() utils_giswater.setDialog(self.dlg) self.load_settings(self.dlg) # Populate combo self.populate_combo(self.dlg.rpt_selector_result_id, 'plan_result_selector') # Set current value table_name = "om_result_cat" sql = ( "SELECT name FROM " + self.schema_name + "." + table_name + " " " WHERE cur_user = current_user AND result_type = 1 AND result_id = (SELECT result_id FROM " + self.schema_name + ".plan_result_selector)") row = self.controller.get_row(sql) if row: utils_giswater.setWidgetText(self.dlg.rpt_selector_result_id, str(row[0])) # Set signals self.dlg.btn_accept.clicked.connect( partial(self.master_estimate_result_selector_accept)) self.dlg.btn_cancel.clicked.connect(self.close_dialog) # Manage i18n of the form and open it self.controller.translate_form(self.dlg, 'estimate_result_selector') self.open_dialog(self.dlg, dlg_name="plan_estimate_result_selector", maximize_button=False)
def info_show_info(self): """ Button 36: Info show info, open giswater and visit web page """ # Create form self.dlg_info = InfoShowInfo() utils_giswater.setDialog(self.dlg_info) self.load_settings(self.dlg_info) # Get Plugin, Giswater, PostgreSQL and Postgis version postgresql_version = self.controller.get_postgresql_version() postgis_version = self.controller.get_postgis_version() plugin_version = self.get_plugin_version() (giswater_file_path, giswater_build_version) = self.get_giswater_jar() #@UnusedVariable message = ("Plugin version: " + str(plugin_version) + "\n" "Giswater version: " + str(giswater_build_version) + "\n" "PostgreSQL version: " + str(postgresql_version) + "\n" "Postgis version: " + str(postgis_version)) utils_giswater.setWidgetText(self.dlg_info.txt_info, message) # Set signals self.dlg_info.btn_open_giswater.clicked.connect(self.open_giswater) self.dlg_info.btn_open_web.clicked.connect(partial(self.open_web_browser, None)) self.dlg_info.btn_close.clicked.connect(partial(self.close_dialog, self.dlg_info)) # Open dialog self.open_dialog(self.dlg_info, maximize_button=False)
def master_estimate_result_selector(self): """ Button 49: Estimate result selector """ # Create dialog self.dlg = EstimateResultSelector() utils_giswater.setDialog(self.dlg) # Set signals self.dlg.btn_accept.clicked.connect(self.master_estimate_result_selector_accept) self.dlg.btn_cancel.clicked.connect(self.close_dialog) # Fill combo box sql = "SELECT result_id FROM "+self.schema_name+".plan_result_cat " sql += " WHERE cur_user = current_user ORDER BY result_id" rows = self.controller.get_rows(sql) if not rows: return utils_giswater.fillComboBox("rpt_selector_result_id", rows, False) # Get selected value from table 'plan_selector_result' sql = "SELECT result_id FROM "+self.schema_name+".plan_selector_result" sql += " WHERE cur_user = current_user" row = self.controller.get_row(sql) if row: utils_giswater.setSelectedItem("rpt_selector_result_id", str(row[0])) elif row is None and self.controller.last_error: self.controller.log_info(sql) return # Manage i18n of the form and open it self.controller.translate_form(self.dlg, 'estimate_result_selector') self.dlg.exec_()
def master_config_master(self): """ Button 99: Open a dialog showing data from table 'config_param_system' """ # Create the dialog and signals self.dlg = ConfigMaster() utils_giswater.setDialog(self.dlg) self.load_settings(self.dlg) self.dlg.btn_accept.pressed.connect(self.master_config_master_accept) self.dlg.btn_cancel.pressed.connect(partial(self.close_dialog, self.dlg)) self.dlg.rejected.connect(partial(self.save_settings, self.dlg)) # Get records from tables 'config' and 'config_param_system' and fill corresponding widgets self.select_config("config") self.select_config_param_system("config_param_system") self.dlg.om_path_url.clicked.connect(partial(self.open_web_browser, "om_visit_absolute_path")) self.dlg.om_path_doc.clicked.connect(partial(self.get_folder_dialog, "om_visit_absolute_path")) self.dlg.doc_path_url.clicked.connect(partial(self.open_web_browser, "doc_absolute_path")) self.dlg.doc_path_doc.clicked.connect(partial(self.get_folder_dialog, "doc_absolute_path")) if self.project_type == 'ws': self.dlg.tab_topology.removeTab(1) sql = "SELECT name FROM" + self.schema_name + ".plan_psector ORDER BY name" rows = self.dao.get_rows(sql) utils_giswater.fillComboBox("psector_vdefault", rows) sql = "SELECT parameter, value FROM " + self.schema_name + ".config_param_user" sql += " WHERE parameter = 'psector_vdefault'" row = self.dao.get_row(sql) if row: utils_giswater.setChecked("chk_psector_enabled", True) utils_giswater.setWidgetText(str(row[0]), str(row[1])) self.dlg.exec_()
def formOpen(dialog, layer, feature): # Create class to manage Feature Form interaction global node_dialog utils_giswater.setDialog(dialog) node_dialog = NodeDialog(iface, dialog, layer, feature) initConfig()
def manage_close(self, table_object, cur_active_layer=None): """ Close dialog and disconnect snapping """ if cur_active_layer: self.iface.setActiveLayer(cur_active_layer) if hasattr(self, 'single_tool_mode'): # some tools can work differently if standalone or integrated in # another tool if self.single_tool_mode: self.remove_selection(True) else: self.remove_selection(True) self.reset_model(table_object, "arc") self.reset_model(table_object, "node") self.reset_model(table_object, "connec") self.reset_model(table_object, "element") if self.project_type == 'ud': self.reset_model(table_object, "gully") self.close_dialog() self.hide_generic_layers() self.disconnect_snapping() self.disconnect_signal_selection_changed() # reset previous dialog in not in single_tool_mode if hasattr(self, 'single_tool_mode') and not self.single_tool_mode: if hasattr(self, 'previous_dialog'): utils_giswater.setDialog(self.previous_dialog)
def init_replace_node_form(self): # Create the dialog and signals dlg_nodereplace = Node_replace() utils_giswater.setDialog(dlg_nodereplace) dlg_nodereplace.btn_accept.pressed.connect( partial(self.get_values, dlg_nodereplace)) dlg_nodereplace.btn_cancel.pressed.connect(dlg_nodereplace.close) sql = ("SELECT id FROM " + self.schema_name + ".cat_work ORDER BY id") rows = self.controller.get_rows(sql) if rows: utils_giswater.fillComboBox(dlg_nodereplace.workcat_id_end, rows) utils_giswater.set_autocompleter(dlg_nodereplace.workcat_id_end) sql = 'SELECT value FROM ' + self.schema_name + '.config_param_user' sql += ' WHERE "cur_user" = current_user AND parameter = ' + "'workcat_vdefault'" row = self.controller.get_row(sql) if row: dlg_nodereplace.workcat_id_end.setCurrentIndex( dlg_nodereplace.workcat_id_end.findText(row[0])) sql = 'SELECT value FROM ' + self.schema_name + '.config_param_user' sql += ' WHERE "cur_user" = current_user AND parameter = ' + "'enddate_vdefault'" row = self.controller.get_row(sql) if row: self.enddate_aux = datetime.strptime(row[0], '%Y-%m-%d').date() else: self.enddate_aux = datetime.strptime( QDate.currentDate().toString('yyyy-MM-dd'), '%Y-%m-%d').date() dlg_nodereplace.enddate.setDate(self.enddate_aux) dlg_nodereplace.exec_()
def open_selected_object(self, widget, table_object): """ Open object form with selected record of the table """ selected_list = widget.selectionModel().selectedRows() if len(selected_list) == 0: message = "Any record selected" self.controller.show_warning(message) return row = selected_list[0].row() # Get object_id from selected row field_object_id = "id" widget_id = table_object + "_id" if table_object == "element": field_object_id = table_object + "_id" if table_object == "om_visit": widget_id = "visit_id" selected_object_id = widget.model().record(row).value(field_object_id) # Close this dialog and open selected object self.dlg_man.close() # set previous dialog if hasattr(self, 'previous_dialog'): utils_giswater.setDialog(self.previous_dialog) if table_object == "doc": self.manage_document() utils_giswater.setWidgetText(widget_id, selected_object_id) elif table_object == "element": self.manage_element(new_element_id=False) utils_giswater.setWidgetText(widget_id, selected_object_id) elif table_object == "om_visit": self.manage_visit(visit_id=selected_object_id)
def go2epa_result_selector(self): """ Button 25. Result selector """ # Create the dialog and signals self.dlg = ResultCompareSelector() utils_giswater.setDialog(self.dlg) self.dlg.btn_accept.pressed.connect(self.result_selector_accept) self.dlg.btn_cancel.pressed.connect(self.close_dialog) # Set values from widgets of type QComboBox sql = "SELECT DISTINCT(result_id) FROM " + self.schema_name + ".rpt_cat_result ORDER BY result_id" rows = self.dao.get_rows(sql) utils_giswater.fillComboBox("rpt_selector_result_id", rows) utils_giswater.fillComboBox("rpt_selector_compare_id", rows) # Get current data from tables 'rpt_selector_result' and 'rpt_selector_compare' sql = "SELECT result_id FROM " + self.schema_name + ".rpt_selector_result" row = self.dao.get_row(sql) if row: utils_giswater.setWidgetText("rpt_selector_result_id", row["result_id"]) sql = "SELECT result_id FROM " + self.schema_name + ".rpt_selector_compare" row = self.dao.get_row(sql) if row: utils_giswater.setWidgetText("rpt_selector_compare_id", row["result_id"]) # Open the dialog self.dlg.exec_()
def go2epa(self): """ Button 23: Open form to set INP, RPT and project """ if not self.get_last_gsw_file(): return # Create dialog self.dlg = FileManager() utils_giswater.setDialog(self.dlg) self.load_settings(self.dlg) # self.dlg.setWindowTitle("Options Table") # Set widgets self.dlg.txt_file_inp.setText(self.file_inp) self.dlg.txt_file_rpt.setText(self.file_rpt) self.dlg.txt_result_name.setText(self.project_name) # Hide checkboxes self.dlg.chk_export.setVisible(False) self.dlg.chk_export_subcatch.setVisible(False) self.dlg.chk_exec.setVisible(False) self.dlg.chk_import.setVisible(False) # Set signals self.dlg.btn_file_inp.clicked.connect(self.go2epa_select_file_inp) self.dlg.btn_file_rpt.clicked.connect(self.go2epa_select_file_rpt) self.dlg.btn_accept.clicked.connect(self.go2epa_accept) self.dlg.btn_cancel.pressed.connect(self.close_dialog) if self.project_type == 'ws': self.dlg.btn_hs_ds.setText("Dscenario Selector") self.dlg.btn_options.clicked.connect(self.ws_options) self.dlg.btn_times.clicked.connect(self.ws_times) tableleft = "sector" tableright = "inp_selector_sector" field_id_left = "sector_id" field_id_right = "sector_id" self.dlg.btn_sector_selection.pressed.connect( partial(self.sector_selection, tableleft, tableright, field_id_left, field_id_right)) tableleft = "cat_dscenario" tableright = "inp_selector_dscenario" field_id_left = "dscenario_id" field_id_right = "dscenario_id" self.dlg.btn_hs_ds.pressed.connect( partial(self.sector_selection, tableleft, tableright, field_id_left, field_id_right)) if self.project_type == 'ud': self.dlg.btn_hs_ds.setText("Hydrology selector") self.dlg.btn_hs_ds.clicked.connect(self.ud_hydrology_selector) self.dlg.btn_options.clicked.connect(self.ud_options) self.dlg.btn_times.clicked.connect(self.ud_times) tableleft = "sector" tableright = "inp_selector_sector" field_id_left = "sector_id" field_id_right = "sector_id" self.dlg.btn_sector_selection.pressed.connect( partial(self.sector_selection, tableleft, tableright, field_id_left, field_id_right)) # Open dialog self.open_dialog(self.dlg, dlg_name='file_manager', maximize_button=False)
def formOpen(dialog, layer, feature): """ Function called when a connec is identified in the map """ global feature_dialog utils_giswater.setDialog(dialog) # Create class to manage Feature Form interaction feature_dialog = ManNodeDialog(dialog, layer, feature) init_config()
def formOpen(dialog, layer, feature): ''' Function called when an arc is identified in the map ''' global feature_dialog utils_giswater.setDialog(dialog) # Create class to manage Feature Form interaction feature_dialog = ArcDialog(dialog, layer, feature) init_config()
def formOpen(dialog, layer, feature): """ Function called when a node is identified in the map """ global feature_dialog utils_giswater.setDialog(dialog) # Create class to manage Feature Form interaction feature_dialog = NodeDialog(dialog, layer, feature) init_config()
def formOpen(dialog, layer, feature): ''' Function called when a connec is identified in the map ''' global feature_dialog utils_giswater.setDialog(dialog) # Create class to manage Feature Form interaction feature_dialog = ConnecDialog(iface, dialog, layer, feature) init_config()
def formOpen(dialog, layer, feature): ''' Function called when a node is identified in the map ''' global feature_dialog utils_giswater.setDialog(dialog) # Create class to manage Feature Form interaction feature_dialog = NodeDialog(dialog, layer, feature) feature_dialog.dialog.findChild(QPushButton, "btn_accept").clicked.connect(feature_dialog.save) feature_dialog.dialog.findChild(QPushButton, "btn_close").clicked.connect(feature_dialog.close)
def edit_visit(self, geom_type=None, feature_id=None): """ Button 65: Edit visit """ # Create the dialog self.dlg_man = VisitManagement() self.load_settings(self.dlg_man) # save previous dialog and set new one. # previous dialog will be set exiting the current one self.previous_dialog = utils_giswater.dialog() utils_giswater.setDialog(self.dlg_man) utils_giswater.set_table_selection_behavior(self.dlg_man.tbl_visit) if geom_type is None: # Set a model with selected filter. Attach that model to selected table table_object = "om_visit" self.fill_table_object(self.dlg_man.tbl_visit, self.schema_name + "." + table_object) self.set_table_columns(self.dlg_man.tbl_visit, table_object) else: # Set a model with selected filter. Attach that model to selected table table_object = "v_ui_om_visit_x_" + str(geom_type) expr_filter = geom_type + "_id = '" + feature_id + "'" # Refresh model with selected filter self.fill_table_object(self.dlg_man.tbl_visit, self.schema_name + "." + table_object, expr_filter) self.set_table_columns(self.dlg_man.tbl_visit, table_object) # manage save and rollback when closing the dialog self.dlg_man.rejected.connect(self.manage_rejected) self.dlg_man.rejected.connect(partial(self.close_dialog, self.dlg_man)) self.dlg_man.accepted.connect(partial(self.open_selected_object, self.dlg_man.tbl_visit, table_object)) # Set dignals self.dlg_man.tbl_visit.doubleClicked.connect( partial(self.open_selected_object, self.dlg_man.tbl_visit, table_object)) self.dlg_man.btn_open.pressed.connect( partial(self.open_selected_object, self.dlg_man.tbl_visit, table_object)) self.dlg_man.btn_delete.clicked.connect( partial(self.delete_selected_object, self.dlg_man.tbl_visit, table_object)) # set timeStart and timeEnd as the min/max dave values get from model current_date = QDate.currentDate() sql = ("SELECT MIN(startdate), MAX(enddate)" " FROM {}.{}".format(self.schema_name, 'om_visit')) row = self.controller.get_row(sql, log_info=False, commit=self.autocommit) if row: if row[0]: self.dlg_man.date_event_from.setDate(row[0]) if row[1]: self.dlg_man.date_event_to.setDate(row[1]) else: self.dlg_man.date_event_to.setDate(current_date) # set date events self.dlg_man.date_event_from.dateChanged.connect(self.set_visit_date_filter) self.dlg_man.date_event_to.dateChanged.connect(self.set_visit_date_filter) # Open form self.open_dialog(self.dlg_man, dlg_name="visit_management")
def activate(self): # Get version of pgRouting sql = "SELECT version FROM pgr_version()" row = self.controller.get_row(sql) if not row: message = "Error getting pgRouting version" self.controller.show_warning(message) return self.version = str(row[0][:1]) self.dlg = DrawProfile() utils_giswater.setDialog(self.dlg) self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint) self.set_icon(self.dlg.btn_add_start_point, "111") self.set_icon(self.dlg.btn_add_end_point, "111") self.set_icon(self.dlg.btn_add_arc, "111") self.set_icon(self.dlg.btn_delete_arc, "112") self.dlg.findChild(QPushButton, "btn_add_start_point").clicked.connect( self.activate_snapping_node1) self.dlg.findChild(QPushButton, "btn_add_end_point").clicked.connect( self.activate_snapping_node2) self.btn_save_profile = self.dlg.findChild(QPushButton, "btn_save_profile") self.btn_save_profile.clicked.connect(self.save_profile) self.btn_load_profile = self.dlg.findChild(QPushButton, "btn_load_profile") self.btn_load_profile.clicked.connect(self.load_profile) self.profile_id = self.dlg.findChild(QLineEdit, "profile_id") self.widget_start_point = self.dlg.findChild(QLineEdit, "start_point") self.widget_end_point = self.dlg.findChild(QLineEdit, "end_point") self.group_pointers_node = [] self.group_layers_node = [ "Junction", "Valve", "Reduction", "Tank", "Meter", "Manhole", "Source", "Hydrant", "Pump", "Filter", "Waterwell", "Register", "Netwjoin" ] for layername in self.group_layers_node: layer = QgsMapLayerRegistry.instance().mapLayersByName(layername) if layer: self.group_pointers_node.append(layer[0]) self.group_pointers_arc = [] self.group_layers_arc = ["Conduit", "Siphon", "Varc", "Waccel"] for layername in self.group_layers_arc: layer = QgsMapLayerRegistry.instance().mapLayersByName(layername) if layer: self.group_pointers_arc.append(layer[0]) self.nodes = [] self.list_of_selected_nodes = [] self.dlg.open()
def sector_selection(self, tableleft, tableright, field_id_left, field_id_right): """ Load the tables in the selection form """ dlg_psector_sel = Multirow_selector() utils_giswater.setDialog(dlg_psector_sel) self.load_settings(dlg_psector_sel) dlg_psector_sel.btn_ok.pressed.connect(dlg_psector_sel.close) dlg_psector_sel.setWindowTitle("Selector") self.multi_row_selector(dlg_psector_sel, tableleft, tableright, field_id_left, field_id_right) dlg_psector_sel.exec_()
def mg_mincut_management(self): """ Button 27: Mincut management """ self.action = "mg_mincut_management" # Create the dialog and signals self.dlg_min_edit = Mincut_edit() utils_giswater.setDialog(self.dlg_min_edit) self.tbl_mincut_edit = self.dlg_min_edit.findChild( QTableView, "tbl_mincut_edit") self.txt_mincut_id = self.dlg_min_edit.findChild( QLineEdit, "txt_mincut_id") self.tbl_mincut_edit.setSelectionBehavior(QAbstractItemView.SelectRows) # Adding auto-completion to a QLineEdit self.completer = QCompleter() self.txt_mincut_id.setCompleter(self.completer) model = QStringListModel() sql = "SELECT DISTINCT(id) FROM " + self.schema_name + ".anl_mincut_result_cat " rows = self.controller.get_rows(sql) values = [] for row in rows: values.append(str(row[0])) model.setStringList(values) self.completer.setModel(model) self.txt_mincut_id.textChanged.connect( partial(self.filter_by_id, self.tbl_mincut_edit, self.txt_mincut_id, "anl_mincut_result_cat")) self.dlg_min_edit.btn_accept.pressed.connect(self.open_mincut) self.dlg_min_edit.btn_cancel.pressed.connect(self.dlg_min_edit.close) self.dlg_min_edit.btn_delete.clicked.connect( partial(self.delete_mincut_management, self.tbl_mincut_edit, "anl_mincut_result_cat", "id")) # Fill ComboBox state sql = ("SELECT id" " FROM " + self.schema_name + ".anl_mincut_cat_state" " ORDER BY id") rows = self.controller.get_rows(sql) utils_giswater.fillComboBox("state_edit", rows) self.dlg_min_edit.state_edit.activated.connect( partial(self.filter_by_state, self.tbl_mincut_edit, self.dlg_min_edit.state_edit, "anl_mincut_result_cat")) # Set a model with selected filter. Attach that model to selected table self.fill_table_mincut_management( self.tbl_mincut_edit, self.schema_name + ".anl_mincut_result_cat") self.mincut.set_table_columns(self.tbl_mincut_edit, "anl_mincut_result_cat") self.dlg_min_edit.show()
def open_catalog_form(self, wsoftware, geom_type, node_type=None): """ Set dialog depending water software """ node_type = utils_giswater.getWidgetText("node_node_type_new") if wsoftware == 'ws': self.dlg_cat = WScatalog() self.field2 = 'pnom' self.field3 = 'dnom' elif wsoftware == 'ud': self.dlg_cat = UDcatalog() self.field2 = 'shape' self.field3 = 'geom1' utils_giswater.setDialog(self.dlg_cat) self.node_type_text = None if wsoftware == 'ws' and geom_type == 'node': self.node_type_text = node_type sql = "SELECT DISTINCT(matcat_id) as matcat_id " sql += " FROM " + self.schema_name + ".cat_" + geom_type if wsoftware == 'ws' and geom_type == 'node': sql += " WHERE " + geom_type + "type_id = '" + self.node_type_text + "'" sql += " ORDER BY matcat_id" rows = self.controller.get_rows(sql) utils_giswater.fillComboBox(self.dlg_cat.matcat_id, rows) sql = "SELECT DISTINCT(" + self.field2 + ")" sql += " FROM " + self.schema_name + ".cat_" + geom_type if wsoftware == 'ws' and geom_type == 'node': sql += " WHERE " + geom_type + "type_id = '" + self.node_type_text + "'" sql += " ORDER BY " + self.field2 rows = self.controller.get_rows(sql) utils_giswater.fillComboBox(self.dlg_cat.filter2, rows) self.fill_filter3(wsoftware, geom_type) # Set signals and open dialog self.dlg_cat.btn_ok.pressed.connect( partial(self.fill_geomcat_id, geom_type)) self.dlg_cat.btn_cancel.pressed.connect( partial(self.close_dialog, self.dlg_cat)) self.dlg_cat.matcat_id.currentIndexChanged.connect( partial(self.fill_catalog_id, wsoftware, geom_type)) self.dlg_cat.matcat_id.currentIndexChanged.connect( partial(self.fill_filter2, wsoftware, geom_type)) self.dlg_cat.matcat_id.currentIndexChanged.connect( partial(self.fill_filter3, wsoftware, geom_type)) self.dlg_cat.filter2.currentIndexChanged.connect( partial(self.fill_catalog_id, wsoftware, geom_type)) self.dlg_cat.filter2.currentIndexChanged.connect( partial(self.fill_filter3, wsoftware, geom_type)) self.dlg_cat.filter3.currentIndexChanged.connect( partial(self.fill_catalog_id, wsoftware, geom_type)) self.dlg_cat.open()
def ud_times(self): """ Dialog ud_times.ui """ dlg_udtimes = UDtimes() utils_giswater.setDialog(dlg_udtimes) self.load_settings(dlg_udtimes) dlg_udtimes.dry_days.setValidator(QIntValidator()) dlg_udtimes.btn_accept.pressed.connect(partial(self.update_table, 'inp_options', dlg_udtimes)) dlg_udtimes.btn_cancel.pressed.connect(dlg_udtimes.close) self.go2epa_options_get_data('inp_options') dlg_udtimes.exec_()
def insert_records (self): # Create the dialog and signals self.dlg_sum = Add_sum() utils_giswater.setDialog(self.dlg_sum) # Set signals self.dlg_sum.findChild(QPushButton, "btn_accept").clicked.connect(self.btn_accept_dae) self.dlg_sum.findChild(QPushButton, "btn_close").clicked.connect(self.btn_close_dae) # Open the dialog self.dlg_sum.exec_()
def manage_rejected(self): """Do all action when closed the dialog with Cancel or X. e.g. all necessary rollbacks and cleanings.""" # set the previous dialog utils_giswater.setDialog(self.previous_dialog) # removed current working visit. This should cascade removing of all related records if hasattr(self, 'it_is_new_visit') and self.it_is_new_visit: self.current_visit.delete() # Remove all previous selections self.remove_selection()
def ud_options(self): """ Dialog ud_options.ui """ # Create dialog dlg_udoptions = UDoptions() utils_giswater.setDialog(dlg_udoptions) dlg_udoptions.min_slope.setValidator(QDoubleValidator()) dlg_udoptions.lengthening_step.setValidator(QDoubleValidator()) dlg_udoptions.max_trials.setValidator(QIntValidator()) dlg_udoptions.sys_flow_tol.setValidator(QIntValidator()) dlg_udoptions.variable_step.setValidator(QIntValidator()) dlg_udoptions.min_surfarea.setValidator(QIntValidator()) dlg_udoptions.head_tolerance.setValidator(QDoubleValidator()) dlg_udoptions.lat_flow_tol.setValidator(QIntValidator()) # Set values from widgets of type QComboBox sql = "SELECT DISTINCT(id) FROM " + self.schema_name + ".inp_value_options_fu ORDER BY id" rows = self.dao.get_rows(sql) utils_giswater.fillComboBox("flow_units", rows, False) sql = "SELECT DISTINCT(id) FROM " + self.schema_name + ".inp_value_options_fr ORDER BY id" rows = self.dao.get_rows(sql) utils_giswater.fillComboBox("flow_routing", rows, False) sql = "SELECT DISTINCT(id) FROM " + self.schema_name + ".inp_value_options_lo ORDER BY id" rows = self.dao.get_rows(sql) utils_giswater.fillComboBox("link_offsets", rows, False) sql = "SELECT DISTINCT(id) FROM " + self.schema_name + ".inp_value_options_fme ORDER BY id" rows = self.dao.get_rows(sql) utils_giswater.fillComboBox("force_main_equation", rows, False) sql = "SELECT DISTINCT(id) FROM " + self.schema_name + ".inp_value_options_nfl ORDER BY id" rows = self.dao.get_rows(sql) utils_giswater.fillComboBox("normal_flow_limited", rows, False) sql = "SELECT DISTINCT(id) FROM " + self.schema_name + ".inp_value_options_id ORDER BY id" rows = self.dao.get_rows(sql) utils_giswater.fillComboBox("inertial_damping", rows, False) sql = "SELECT DISTINCT(id) FROM " + self.schema_name + ".value_yesno ORDER BY id" rows = self.dao.get_rows(sql) utils_giswater.fillComboBox("allow_ponding", rows, False) utils_giswater.fillComboBox("skip_steady_state", rows, False) utils_giswater.fillComboBox("ignore_rainfall", rows, False) utils_giswater.fillComboBox("ignore_snowmelt", rows, False) utils_giswater.fillComboBox("ignore_groundwater", rows, False) utils_giswater.fillComboBox("ignore_routing", rows, False) utils_giswater.fillComboBox("ignore_quality", rows, False) update = True dlg_udoptions.btn_accept.pressed.connect( partial(self.insert_or_update, update, 'inp_options', dlg_udoptions)) dlg_udoptions.btn_cancel.pressed.connect(dlg_udoptions.close) self.go2epa_options_get_data('inp_options') dlg_udoptions.exec_()
def ws_times(self): """ Open dialog ws_times.ui""" dlg_wstimes = WStimes() utils_giswater.setDialog(dlg_wstimes) dlg_wstimes.duration.setValidator(QIntValidator()) sql = "SELECT id FROM " + self.schema_name + ".inp_value_times ORDER BY id" rows = self.controller.get_rows(sql) utils_giswater.fillComboBox("statistic", rows, False) dlg_wstimes.btn_accept.pressed.connect( partial(self.insert_or_update, True, 'inp_times', dlg_wstimes)) dlg_wstimes.btn_cancel.pressed.connect(dlg_wstimes.close) self.go2epa_options_get_data('inp_times') dlg_wstimes.exec_()
def zoom_img(self, i, visit_id, event_id): handeler_index = i self.dlg_gallery_zoom = GalleryZoom() utils_giswater.setDialog(self.dlg_gallery_zoom) self.load_settings(self.dlg_gallery_zoom) self.lbl_img = self.dlg_gallery_zoom.findChild(QLabel, "lbl_img_zoom") # Parse a URL into components url = urlparse.urlsplit(str(self.img_path_list[self.start_indx][i])) # Check if path is URL if url.scheme == "http" or url.scheme == "https": url = str(self.img_path_list[self.start_indx][i]) data = urllib2.urlopen(url).read() pixmap = QPixmap() pixmap.loadFromData(data) else: pixmap = QPixmap(str(self.img_path_list[self.start_indx][i])) self.lbl_img.setPixmap(pixmap) # lbl_img.show() zoom_visit_id = self.dlg_gallery_zoom.findChild(QLineEdit, "visit_id") zoom_event_id = self.dlg_gallery_zoom.findChild(QLineEdit, "event_id") zoom_visit_id.setText(str(visit_id)) zoom_event_id.setText(str(event_id)) self.btn_slidePrevious = self.dlg_gallery_zoom.findChild( QPushButton, "btn_slidePrevious") self.btn_slideNext = self.dlg_gallery_zoom.findChild( QPushButton, "btn_slideNext") self.set_icon(self.btn_slidePrevious, "109") self.set_icon(self.btn_slideNext, "108") self.dlg_gallery_zoom.rejected.connect( partial(self.close_dialog, self.dlg_gallery_zoom)) self.i = i self.btn_slidePrevious.clicked.connect(self.slide_previous) self.btn_slideNext.clicked.connect(self.slide_next) # Open dialog self.open_dialog(self.dlg_gallery_zoom, maximize_button=False) # Controling start index if handeler_index != i: self.start_indx = self.start_indx + 1
def mg_change_elem_type(self): ''' Button 28: User select one node. A form is opened showing current node_type.type Combo to select new node_type.type Combo to select new node_type.id Combo to select new cat_node.id TODO: Trigger 'gw_trg_edit_node' has to be disabled temporarily ''' # Check if at least one node is checked layer = self.iface.activeLayer() count = layer.selectedFeatureCount() if count == 0: message = "You have to select at least one feature!" self.controller.show_info(message, context_name='ui_message' ) return elif count > 1: message = "More than one feature selected. Only the first one will be processed!" self.controller.show_info(message, context_name='ui_message' ) # Get selected features (nodes) features = layer.selectedFeatures() feature = features[0] # Get node_id form current node self.node_id = feature.attribute('node_id') # Get node_type from current node node_type = feature.attribute('node_type') # Create the dialog, fill node_type and define its signals self.dlg = ChangeNodeType() self.dlg.node_node_type.setText(node_type) self.dlg.node_type_type_new.currentIndexChanged.connect(self.mg_change_elem_type_get_value) self.dlg.node_node_type_new.currentIndexChanged.connect(self.mg_change_elem_type_get_value_2) self.dlg.node_nodecat_id.currentIndexChanged.connect(self.mg_change_elem_type_get_value_3) self.dlg.btn_accept.pressed.connect(self.mg_change_elem_type_accept) self.dlg.btn_cancel.pressed.connect(self.close_dialog) # Fill 1st combo boxes-new system node type sql = "SELECT DISTINCT(type) FROM "+self.schema_name+".node_type ORDER BY type" rows = self.dao.get_rows(sql) utils_giswater.setDialog(self.dlg) utils_giswater.fillComboBox("node_type_type_new", rows) # Manage i18n of the form and open it self.controller.translate_form(self.dlg, 'change_node_type') self.dlg.exec_()
def ed_add_element(self): ''' Button 33. Add element ''' # Create the dialog and signals self.dlg = Add_element() utils_giswater.setDialog(self.dlg) self.dlg.btn_accept.pressed.connect(self.ed_add_element_accept) self.dlg.btn_cancel.pressed.connect(self.close_dialog) # Manage i18n of the form self.controller.translate_form(self.dlg, 'element') # Check if we have at least one feature selected if not self.ed_check(): return # Fill combo boxes self.populate_combo("elementcat_id", "cat_element") self.populate_combo("state", "value_state") self.populate_combo("location_type", "man_type_location") self.populate_combo("workcat_id", "cat_work") self.populate_combo("buildercat_id", "cat_builder") self.populate_combo("elementcat_id", "cat_element") self.populate_combo("ownercat_id", "cat_owner") self.populate_combo("verified", "value_verified") # Adding auto-completion to a QLineEdit self.edit = self.dlg.findChild(QLineEdit, "element_id") self.completer = QCompleter() self.edit.setCompleter(self.completer) model = QStringListModel() sql = "SELECT DISTINCT(element_id) FROM "+self.schema_name+".element " row = self.dao.get_rows(sql) for i in range(0,len(row)): aux = row[i] row[i] = str(aux[0]) model.setStringList(row) self.completer.setModel(model) # Set signal to reach selected value from QCompleter self.completer.activated.connect(self.ed_add_el_autocomplete) # Open the dialog self.dlg.exec_()
def ed_add_file(self): ''' Button 34. Add file ''' # Create the dialog and signals self.dlg = Add_file() utils_giswater.setDialog(self.dlg) self.dlg.btn_accept.pressed.connect(self.ed_add_file_accept) self.dlg.btn_cancel.pressed.connect(self.close_dialog) # Manage i18n of the form self.controller.translate_form(self.dlg, 'file') # Check if we have at least one feature selected if not self.ed_check(): return # Fill combo boxes self.populate_combo("doc_type", "doc_type") self.populate_combo("tagcat_id", "cat_tag") # Adding auto-completion to a QLineEdit self.edit = self.dlg.findChild(QLineEdit, "doc_id") self.completer = QCompleter() self.edit.setCompleter(self.completer) model = QStringListModel() sql = "SELECT DISTINCT(id) FROM "+self.schema_name+".doc " row = self.dao.get_rows(sql) for i in range(0,len(row)): aux = row[i] row[i] = str(aux[0]) model.setStringList(row) self.completer.setModel(model) # Set signal to reach selected value from QCompleter self.completer.activated.connect(self.ed_add_file_autocomplete) # Open the dialog self.dlg.exec_()
def mg_config(self): ''' Button 99 - Open a dialog showing data from table "config" User can changge its values ''' # Create the dialog and signals self.dlg = Config() utils_giswater.setDialog(self.dlg) self.dlg.btn_accept.pressed.connect(self.mg_config_accept) self.dlg.btn_cancel.pressed.connect(self.close_dialog) # Set values from widgets of type QComboBox sql = "SELECT DISTINCT(type) FROM "+self.schema_name+".node_type ORDER BY type" rows = self.dao.get_rows(sql) utils_giswater.fillComboBox("nodeinsert_catalog_vdefault", rows) # Get data from tables: 'config', 'config_search_plus' and 'config_extract_raster_value' self.generic_columns = self.mg_config_get_data('config') self.search_plus_columns = self.mg_config_get_data('config_search_plus') self.raster_columns = self.mg_config_get_data('config_extract_raster_value') # Manage i18n of the form and open it self.controller.translate_form(self.dlg, 'config') self.dlg.exec_()