def fill_table_psector(self, widget, table_name, column_id):
        """ Set a model with selected filter.
        Attach that model to selected table """

        # Set model
        self.model = QSqlTableModel()
        self.model.setTable(self.schema_name + "." + table_name)
        self.model.setEditStrategy(QSqlTableModel.OnManualSubmit)
        self.model.setSort(0, 0)
        self.model.select()

        # Check for errors
        if self.model.lastError().isValid():
            self.controller.show_warning(self.model.lastError().text())
        # Attach model to table view
        widget.setModel(self.model)
        # put combobox in qtableview
        sql = "SELECT * FROM " + self.schema_name + "." + table_name + " ORDER BY " + column_id
        rows = self.controller.get_rows(sql)
        for x in range(len(rows)):
            combo = QComboBox()
            sql = "SELECT DISTINCT(priority) FROM " + self.schema_name + "." + table_name
            row = self.controller.get_rows(sql)
            utils_giswater.fillComboBox(combo, row, False)
            row = rows[x]
            priority = row[4]
            utils_giswater.setSelectedItem(combo, str(priority))
            i = widget.model().index(x, 4)
            widget.setIndexWidget(i, combo)
            #combo.setStyleSheet("background:#F2F2F2")
            combo.setStyleSheet("background:#E6E6E6")
            combo.currentIndexChanged.connect(
                partial(self.update_combobox_values, widget, combo, x))
    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_result_selector(self):
        """ Button 29: Epa result selector """

        # Create the dialog and signals
        self.dlg_go2epa_result = EpaResultCompareSelector()
        self.load_settings(self.dlg_go2epa_result)

        self.dlg_go2epa_result.btn_accept.clicked.connect(self.result_selector_accept)
        self.dlg_go2epa_result.btn_cancel.clicked.connect(partial(self.close_dialog, self.dlg_go2epa_result))
        self.dlg_go2epa_result.rejected.connect(partial(self.close_dialog, self.dlg_go2epa_result))

        # Set values from widgets of type QComboBox
        sql = "SELECT DISTINCT(result_id) FROM " + self.schema_name + ".v_ui_rpt_cat_result ORDER BY result_id"
        rows = self.controller.get_rows(sql)
        utils_giswater.fillComboBox(self.dlg_go2epa_result, self.dlg_go2epa_result.rpt_selector_result_id, rows)
        utils_giswater.fillComboBox(self.dlg_go2epa_result, self.dlg_go2epa_result.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.controller.get_row(sql)
        if row:
            utils_giswater.setWidgetText(self.dlg_go2epa_result, self.dlg_go2epa_result.rpt_selector_result_id, row["result_id"])
        sql = "SELECT result_id FROM " + self.schema_name + ".rpt_selector_compare"
        row = self.controller.get_row(sql)
        if row:
            utils_giswater.setWidgetText(self.dlg_go2epa_result, self.dlg_go2epa_result.rpt_selector_compare_id, row["result_id"])

        # Open the dialog
        self.dlg_go2epa_result.setWindowFlags(Qt.WindowStaysOnTopHint)
        self.dlg_go2epa_result.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 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 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 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)             
Example #8
0
 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_()            
Example #9
0
    def fill_fields(self):
        """ Fill dates and combo cat_work """

        sql = (
            "SELECT value FROM " + self.controller.schema_name +
            ".config_param_user "
            " WHERE parameter = 'enddate_vdefault' and cur_user = current_user"
        )
        row = self.controller.get_row(sql, log_info=False)
        if row:
            enddate = QDate.fromString(row[0], 'yyyy-MM-dd')
        else:
            enddate = QDate.currentDate()
        utils_giswater.setCalendarDate(self.dlg_work_end, "enddate", enddate)

        sql = ("SELECT id FROM " + self.controller.schema_name + ".cat_work")
        rows = self.controller.get_rows(sql)
        utils_giswater.fillComboBox(self.dlg_work_end,
                                    self.dlg_work_end.workcat_id_end,
                                    rows,
                                    allow_nulls=False)
        utils_giswater.set_autocompleter(self.dlg_work_end.workcat_id_end)
        sql = (
            "SELECT value FROM " + self.controller.schema_name +
            ".config_param_user "
            " WHERE parameter = 'workcat_vdefault' and cur_user = current_user"
        )
        row = self.controller.get_row(sql, log_info=False)
        if row:
            utils_giswater.setWidgetText(self.dlg_work_end,
                                         self.dlg_work_end.workcat_id_end,
                                         row[0])
    def fill_filter2(self, wsoftware, geom_type):

        # Get values from filters
        mats = utils_giswater.getWidgetText(self.dlg_cat.matcat_id)

        # Set SQL query
        sql_where = ""
        sql = ("SELECT DISTINCT(" + self.field2 + ")"
               " FROM " + self.schema_name + ".cat_" + geom_type)

        # Build SQL filter
        if mats != "null":
            if sql_where == "":
                sql_where = " WHERE"
            sql_where += " matcat_id = '" + mats + "'"
        if wsoftware == 'ws' and self.node_type_text is not None:
            if sql_where == "":
                sql_where = " WHERE"
            else:
                sql_where += " AND"
            sql_where += " " + geom_type + "type_id = '" + self.node_type_text + "'"
        sql += sql_where + " ORDER BY " + self.field2

        rows = self.controller.get_rows(sql)
        utils_giswater.fillComboBox(self.dlg_cat.filter2, rows)
        self.fill_filter3(wsoftware, geom_type)
Example #11
0
 def populate_combo(self, widget, table_name, field_name="id"): 
     ''' Executes query and fill combo box ''' 
     sql = "SELECT "+field_name+" FROM "+self.schema_name+"."+table_name+" ORDER BY "+field_name
     rows = self.dao.get_rows(sql)
     utils_giswater.fillComboBox(widget, rows)
     if len(rows) > 0:  
         utils_giswater.setCurrentIndex(widget, 1);             
Example #12
0
 def filter_cbx_by_text(self, tablename, widgettxt, widgetcbx):
     sql = "SELECT DISTINCT(name) FROM " + self.schema_name + "." + str(
         tablename)
     sql += " WHERE name LIKE '%" + str(widgettxt.text()) + "%'"
     sql += " ORDER BY name "
     rows = self.dao.get_rows(sql)
     utils_giswater.fillComboBox(widgetcbx, rows, False)
     self.update_labels()
Example #13
0
 def filter_elementcat_id(self):
     """ Filter QComboBox @elementcat_id according QComboBox @elementtype_id """
     
     sql = ("SELECT DISTINCT(id) FROM " + self.schema_name + ".cat_element"
            " WHERE elementtype_id = '" + utils_giswater.getWidgetText(self.dlg_add_element, "element_type") + "'"
            " ORDER BY id")
     rows = self.controller.get_rows(sql)
     utils_giswater.fillComboBox(self.dlg_add_element, "elementcat_id", rows, False)
 def fill_arc_type(self):
     ''' Define and execute query to populate combo 'cat_arctype_id' '''
     cat_arctype_id = utils_giswater.getWidgetText("cat_arctype_id", False)     
     sql = "SELECT id, man_table, epa_table FROM "+self.schema_name+".arc_type"
     sql+= " WHERE epa_default = '"+self.epa_type+"' ORDER BY id"
     rows = self.dao.get_rows(sql)       
     utils_giswater.fillComboBox("cat_arctype_id", rows)
     utils_giswater.setWidgetText("cat_arctype_id", cat_arctype_id)
Example #15
0
 def fill_arc_type(self):
     ''' Define and execute query to populate combo 'cat_arctype_id' '''
     cat_arctype_id = utils_giswater.getWidgetText("cat_arctype_id", False)
     sql = "SELECT id, man_table, epa_table FROM " + self.schema_name + ".arc_type"
     sql += " WHERE epa_default = '" + self.epa_type + "' ORDER BY id"
     rows = self.dao.get_rows(sql)
     utils_giswater.fillComboBox("cat_arctype_id", rows)
     utils_giswater.setWidgetText("cat_arctype_id", cat_arctype_id)
 def change_arc_type(self):
     ''' Define and execute query to populate combo 'arccat_id_dummy' '''
     cat_arctype_id = utils_giswater.getWidgetText("cat_arctype_id", True)    
     sql = "SELECT id FROM "+self.schema_name+".cat_arc"
     sql+= " WHERE arctype_id = "+cat_arctype_id+" ORDER BY id"   
     rows = self.dao.get_rows(sql)
     utils_giswater.fillComboBox("arccat_id_dummy", rows, False) 
     # Select first item by default         
     self.change_arc_cat()       
 def fill_connec_type_id(self):
     ''' Define and execute query to populate combo 'cat_connectype_id_dummy' '''
     
     sql = "SELECT connec_type.id"
     sql+= " FROM "+self.schema_name+".connec_type INNER JOIN "+self.schema_name+".cat_connec ON connec_type.id = cat_connec.type"
     sql+= " GROUP BY connec_type.id ORDER BY connec_type.id"
     rows = self.dao.get_rows(sql)           
     utils_giswater.fillComboBox("cat_connectype_id_dummy", rows, False)
     utils_giswater.setWidgetText("cat_connectype_id_dummy", self.connec_type)
 def fillNodeType(self):
     """ Define and execute query to populate combo 'cat_nodetype_id' """
     cat_nodetype_id = utils_giswater.getSelectedItem("cat_nodetype_id")     
     sql = "SELECT id, man_table, epa_table FROM "+self.schema_name+".arc_type WHERE epa_default = '"+self.epa_type+"' UNION "
     sql+= "SELECT id, man_table, epa_table FROM "+self.schema_name+".node_type WHERE epa_default = '"+self.epa_type+"' ORDER BY id"
     rows = self.dao.get_rows(sql)     
     self.cbo_cat_nodetype_id = self.dialog.findChild(QComboBox, "cat_nodetype_id")    
     utils_giswater.fillComboBox(self.cbo_cat_nodetype_id, rows)
     utils_giswater.setSelectedItem('cat_nodetype_id', cat_nodetype_id)
Example #19
0
    def populate_combo(self, widget, table_name, field_name="id"):
        """ Executes query and fill combo box """

        sql = "SELECT " + field_name
        sql += " FROM " + self.schema_name + "." + table_name + " ORDER BY " + field_name
        rows = self.dao.get_rows(sql)
        utils_giswater.fillComboBox(widget, rows)
        if len(rows) > 0:
            utils_giswater.setCurrentIndex(widget, 1)
 def changeNodeType(self, index):
     """ Define and execute query to populate combo 'nodecat_id_dummy' """
     cat_nodetype_id = utils_giswater.getSelectedItem("cat_nodetype_id")     
     sql = "SELECT id FROM "+self.schema_name+".cat_arc WHERE arctype_id = '"+cat_nodetype_id+"' UNION "
     sql+= "SELECT id FROM "+self.schema_name+".cat_node WHERE nodetype_id = '"+cat_nodetype_id+"' ORDER BY id"   
     rows = self.dao.get_rows(sql)
     self.cbo_nodecat_id = self.dialog.findChild(QComboBox, "nodecat_id_dummy")
     utils_giswater.fillComboBox(self.cbo_nodecat_id, rows, False)  
     self.changeNodeCat(0)       
Example #21
0
 def change_arc_type(self):
     ''' Define and execute query to populate combo 'arccat_id_dummy' '''
     cat_arctype_id = utils_giswater.getWidgetText("cat_arctype_id", True)
     sql = "SELECT id FROM " + self.schema_name + ".cat_arc"
     sql += " WHERE arctype_id = " + cat_arctype_id + " ORDER BY id"
     rows = self.dao.get_rows(sql)
     utils_giswater.fillComboBox("arccat_id_dummy", rows, False)
     # Select first item by default
     self.change_arc_cat()
Example #22
0
 def set_parameter_id_combo(self):
     """set parameter_id combo basing on current selections."""
     sql = ("SELECT id"
            " FROM " + self.schema_name + ".om_visit_parameter"
            " WHERE UPPER (parameter_type) = '" + self.parameter_type_id.currentText().upper() + "'"
            " AND UPPER (feature_type) = '" + self.feature_type.currentText().upper() + "'"
            " ORDER BY id")
     rows = self.controller.get_rows(sql, commit=self.autocommit)
     utils_giswater.fillComboBox("parameter_id", rows, allow_nulls=False)
Example #23
0
 def update_location_cmb(self):
     element_type = utils_giswater.getWidgetText(self.dlg_add_element, self.dlg_add_element.element_type)
     sql = ("SELECT location_type FROM " + self.schema_name + ".man_type_location"
            " WHERE feature_type = 'ELEMENT' "
            " AND (featurecat_id = '"+str(element_type)+"' OR featurecat_id is null)"
            " ORDER BY location_type")
     rows = self.controller.get_rows(sql, log_sql=True, commit=self.autocommit)
     utils_giswater.fillComboBox(self.dlg_add_element, "location_type", rows)
     if rows:
         utils_giswater.setCurrentIndex(self.dlg_add_element, "location_type", 0)
Example #24
0
 def fillNodeType(self):
     """ Define and execute query to populate combo 'cat_nodetype_id' """
     cat_nodetype_id = utils_giswater.getSelectedItem("cat_nodetype_id")
     sql = "SELECT id, man_table, epa_table FROM " + self.schema_name + ".arc_type WHERE epa_default = '" + self.epa_type + "' UNION "
     sql += "SELECT id, man_table, epa_table FROM " + self.schema_name + ".node_type WHERE epa_default = '" + self.epa_type + "' ORDER BY id"
     rows = self.dao.get_rows(sql)
     self.cbo_cat_nodetype_id = self.dialog.findChild(
         QComboBox, "cat_nodetype_id")
     utils_giswater.fillComboBox(self.cbo_cat_nodetype_id, rows)
     utils_giswater.setSelectedItem('cat_nodetype_id', cat_nodetype_id)
Example #25
0
    def populate_combo(self, dialog, widget, table_name, field_name="id"):
        """ Executes query and fill combo box """

        sql = ("SELECT " + field_name + ""
               " FROM " + self.schema_name + "." + table_name + ""
               " ORDER BY " + field_name)
        rows = self.controller.get_rows(sql, commit=self.autocommit)
        utils_giswater.fillComboBox(dialog, widget, rows)
        if rows:
            utils_giswater.setCurrentIndex(dialog, widget, 0)
Example #26
0
 def changeNodeType(self, index):
     """ Define and execute query to populate combo 'nodecat_id_dummy' """
     cat_nodetype_id = utils_giswater.getSelectedItem("cat_nodetype_id")
     sql = "SELECT id FROM " + self.schema_name + ".cat_arc WHERE arctype_id = '" + cat_nodetype_id + "' UNION "
     sql += "SELECT id FROM " + self.schema_name + ".cat_node WHERE nodetype_id = '" + cat_nodetype_id + "' ORDER BY id"
     rows = self.dao.get_rows(sql)
     self.cbo_nodecat_id = self.dialog.findChild(QComboBox,
                                                 "nodecat_id_dummy")
     utils_giswater.fillComboBox(self.cbo_nodecat_id, rows, False)
     self.changeNodeCat(0)
Example #27
0
    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()
Example #28
0
    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()
Example #29
0
 def change_node_type_id(self, index):
     ''' Define and execute query to populate combo 'cat_nodetype_id' '''
     node_type_id = utils_giswater.getWidgetText("node_type_dummy", False)    
     if node_type_id:        
         utils_giswater.setWidgetText("node_type", node_type_id)    
         sql = "SELECT id FROM "+self.schema_name+".cat_node"
         sql+= " WHERE nodetype_id = '"+node_type_id+"' ORDER BY id"
         rows = self.dao.get_rows(sql)    
         utils_giswater.fillComboBox("nodecat_id_dummy", rows, False)    
         if index == -1:  
             utils_giswater.setWidgetText("nodecat_id_dummy", self.nodecat_id)    
         self.change_node_cat()
    def open_catalog_form(self, wsoftware, geom_type):
        """ Set dialog depending water software """

        node_type = utils_giswater.getWidgetText(self.dlg_chg_node_type, "node_node_type_new")
        if node_type == 'null':
            message = "Select a Custom node Type"
            self.controller.show_warning(message)
            return

        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'
        self.load_settings(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 "
               " 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, self.dlg_cat.matcat_id, rows)

        sql = ("SELECT DISTINCT(" + self.field2 + ")"
               " 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, self.dlg_cat.filter2, rows)

        self.fill_filter3(wsoftware, geom_type)

        # Set signals and open dialog
        self.dlg_cat.btn_ok.clicked.connect(self.fill_geomcat_id)
        self.dlg_cat.btn_cancel.clicked.connect(partial(self.close_dialog, self.dlg_cat))
        self.dlg_cat.rejected.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.open_dialog(self.dlg_cat)
    def change_arc_type_id(self, index):
        ''' Define and execute query to populate combo 'cat_arctype_id' '''

        arc_type_id = utils_giswater.getWidgetText("cat_arctype_id", False)    
        if arc_type_id:        
            utils_giswater.setWidgetText("cat_arctype_id", arc_type_id)    
            sql = "SELECT id FROM "+self.schema_name+".cat_arc"
            sql+= " WHERE arctype_id = '"+arc_type_id+"' ORDER BY id"
            rows = self.dao.get_rows(sql)    
            utils_giswater.fillComboBox("arccat_id_dummy", rows, False)    
            if index == -1:  
                utils_giswater.setWidgetText("arccat_id_dummy", self.arccat_id)    
            self.change_arc_cat()     
Example #32
0
 def mg_change_elem_type_get_value(self, index):   #@UnusedVariable
     ''' Just select item to 'real' combo 'nodecat_id' (that is hidden) ''' 
     
     # Get selected value from 1st combobox
     self.value_combo1 = utils_giswater.getWidgetText("node_type_type_new")   
     
     # When value is selected, enabled 2nd combo box
     if self.value_combo1 != 'null':
         self.dlg.node_node_type_new.setEnabled(True)  
         # Fill 2nd combo_box-custom node type
         sql = "SELECT DISTINCT(id) FROM "+self.schema_name+".node_type WHERE type='"+self.value_combo1+"'"
         rows = self.dao.get_rows(sql)
         utils_giswater.fillComboBox("node_node_type_new", rows)
Example #33
0
    def canvasReleaseEvent(self, event):

        if event.button() == Qt.RightButton:
            self.cancel_map_tool()
            return

        # Get the click
        x = event.pos().x()
        y = event.pos().y()
        event_point = QPoint(x, y)
        snapped_feat = None

        # Snapping
        (retval,
         result) = self.snapper.snapToCurrentLayer(event_point,
                                                   2)  # @UnusedVariable

        # That's the snapped features
        if result:
            # Get the first feature
            snapped_feat = result[0]
            point = QgsPoint(snapped_feat.snappedVertex)  #@UnusedVariable
            snapped_feat = next(
                snapped_feat.layer.getFeatures(
                    QgsFeatureRequest().setFilterFid(
                        snapped_feat.snappedAtGeometry)))

        if snapped_feat:
            self.node_id = snapped_feat.attribute('node_id')
            self.dlg_fusion = ArcFusion()
            self.load_settings(self.dlg_fusion)

            # Fill ComboBox workcat_id_end
            sql = ("SELECT id FROM " + self.schema_name +
                   ".cat_work ORDER BY id")
            rows = self.controller.get_rows(sql)
            utils_giswater.fillComboBox(self.dlg_fusion, "workcat_id_end",
                                        rows, False)

            # Set QDateEdit to current date
            current_date = QDate.currentDate()
            utils_giswater.setCalendarDate(self.dlg_fusion, "enddate",
                                           current_date)

            # Set signals
            self.dlg_fusion.btn_accept.clicked.connect(self.exec_fusion)
            self.dlg_fusion.btn_cancel.clicked.connect(
                partial(self.close_dialog, self.dlg_fusion))

            self.dlg_fusion.setWindowFlags(Qt.WindowStaysOnTopHint)
            self.dlg_fusion.open()
Example #34
0
    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 ppoint_field_zone(self):
     ''' Executed when field_zone is activated '''
     
     # Filter combo 'ppoint_number' with value selected in combo 'ppoint_field_zone'
     text = utils_giswater.getSelectedItem(self.dlg.ppoint_field_zone) 
     sql = "SELECT DISTINCT("+self.params['ppoint_field_number']+"::int4)"
     sql+= " FROM "+self.controller.schema_name+"."+self.params['ppoint_layer']
     if text != 'null':
         sql+= " WHERE "+self.params['ppoint_field_zone']+" = '"+str(text)+"'"
     sql+= " ORDER BY "+self.params['ppoint_field_number']
     rows = self.controller.dao.get_rows(sql)
     utils_giswater.fillComboBox(self.dlg.ppoint_number, rows)
     
     # Make zoom to selected elements
     self.ppoint_zoom()   
 def urban_field_zone(self):
     ''' Executed when 'urban_propierties_field_pzone' is activated '''
     
     # Filter combo 'urban_properties_block' with value selected in combo 'urban_properties_zone'
     text = utils_giswater.getSelectedItem(self.dlg.urban_properties_zone)
     sql = "SELECT DISTINCT("+self.params['urban_propierties_field_block']+"::int4)"
     sql+= " FROM "+self.controller.schema_name+"."+self.params['urban_propierties_layer']
     if text != 'null':
         sql+= " WHERE "+self.params['urban_propierties_field_pzone']+" = '"+str(text)+"'"
     sql+= " ORDER BY "+self.params['urban_propierties_field_block']
     print sql
     rows = self.controller.dao.get_rows(sql)
     utils_giswater.fillComboBox(self.dlg.urban_properties_block, rows)
     
     # Make zoom to selected elements
     self.urban_zoom()   
 def fill_arc_type_id(self):
     ''' Define and execute query to populate combo 'node_type_dummy' '''
     
     # Get node_type.type from node_type.id
     sql = "SELECT type FROM "+self.schema_name+".arc_type"
     if self.arc_type:
         sql+= " WHERE id = '"+self.arc_type+"'"
     row = self.dao.get_row(sql)
     if row: 
         arc_type_type = row[0]
         sql = "SELECT arc_type.id"
         sql+= " FROM "+self.schema_name+".arc_type INNER JOIN "+self.schema_name+".cat_arc ON arc_type.id = cat_arc.arctype_id"
         sql+= " WHERE type = '"+arc_type_type+"' GROUP BY arc_type.id ORDER BY arc_type.id"
         rows = self.dao.get_rows(sql)             
         utils_giswater.fillComboBox("cat_arctype_id_dummy", rows, False)
         utils_giswater.setWidgetText("cat_arctype_id_dummy", self.arc_type)
Example #38
0
 def fill_node_type_id(self):
     ''' Define and execute query to populate combo 'node_type_dummy' '''
     # Get node_type.type from node_type.id
     sql = "SELECT type FROM "+self.schema_name+".node_type"
     sql+= " WHERE id = '"+self.node_type+"'"
     row = self.dao.get_row(sql)
     if row: 
         node_type_type = row[0]
         sql = "SELECT id FROM "+self.schema_name+".node_type"
         sql+= " WHERE type = '"+node_type_type+"' ORDER BY id"
         sql = "SELECT node_type.id"
         sql+= " FROM "+self.schema_name+".node_type INNER JOIN "+self.schema_name+".cat_node ON node_type.id = cat_node.nodetype_id"
         sql+= " WHERE type = '"+node_type_type+"' GROUP BY node_type.id ORDER BY node_type.id"
         rows = self.dao.get_rows(sql)              
         utils_giswater.fillComboBox("node_type_dummy", rows, False)
         utils_giswater.setWidgetText("node_type_dummy", self.node_type)
Example #39
0
    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_()    
Example #40
0
    def edit_change_elem_type_get_value(self, index):
        """ Just select item to 'real' combo 'nodecat_id' (that is hidden) """

        if index == -1:
            return

        # Get selected value from 2nd combobox
        node_node_type_new = utils_giswater.getWidgetText("node_node_type_new")

        # When value is selected, enabled 3rd combo box
        if node_node_type_new != 'null':
            # Fill 3rd combo_box-catalog_id
            utils_giswater.setWidgetEnabled(self.dlg.node_nodecat_id, True)
            sql = ("SELECT DISTINCT(id)"
                   " FROM " + self.schema_name + ".cat_node"
                   " WHERE nodetype_id = '" + str(node_node_type_new) + "'")
            rows = self.controller.get_rows(sql)
            utils_giswater.fillComboBox(self.dlg.node_nodecat_id, rows)
    def load_tab_analysis(self):
        """ Load data from tab 'Analysis' """

        if self.epa_type == "JUNCTION":
            # Load combo 'pattern_id'
            combo = self.epa_table + "_pattern_id"
            table_name = "inp_pattern"
            sql = "SELECT pattern_id FROM " + self.schema_name + "." + table_name + " ORDER BY pattern_id"
            rows = self.dao.get_rows(sql)
            utils_giswater.fillComboBox(combo, rows)

            self.fields_junction = ["demand", "pattern_id"]
            sql = "SELECT "
            for i in range(len(self.fields_junction)):
                sql += self.fields_junction[i] + ", "
            sql = sql[:-2]
            sql += " FROM " + self.schema_name + "." + self.epa_table + " WHERE node_id = '" + self.id + "'"
            row = self.dao.get_row(sql)
            if row:
                for i in range(len(self.fields_junction)):
                    widget_name = self.epa_table + "_" + self.fields_junction[i]
                    utils_giswater.setWidgetText(widget_name, str(row[i]))

        elif self.epa_type == "TANK":
            # Load combo 'curve_id'
            combo = self.epa_table + "_curve_id"
            table_name = "inp_curve_id"
            sql = "SELECT id FROM " + self.schema_name + ".inp_curve_id ORDER BY id"
            rows = self.dao.get_rows(sql)
            utils_giswater.fillComboBox(combo, rows)

            self.fields_tank = ["initlevel", "minlevel", "maxlevel", "diameter", "minvol", "curve_id"]
            sql = "SELECT "
            for i in range(len(self.fields_tank)):
                sql += self.fields_tank[i] + ", "
            sql = sql[:-2]
            sql += (
                " FROM " + self.schema_name + "." + self.epa_table + " WHERE " + self.field_id + " = '" + self.id + "'"
            )
            row = self.dao.get_row(sql)
            if row:
                for i in range(len(self.fields_tank)):
                    widget_name = self.epa_table + "_" + self.fields_tank[i]
                    utils_giswater.setWidgetText(widget_name, str(row[i]))
Example #42
0
    def mg_change_elem_type_get_value_2(self, index):    
        ''' Just select item to 'real' combo 'nodecat_id' (that is hidden) ''' 

        if index == -1:
            return
        
        # Get selected value from 2nd combobox
        self.value_combo2 = utils_giswater.getWidgetText("node_node_type_new")         
        
        # When value is selected, enabled 3rd combo box
        if self.value_combo2 != 'null':
            # Get selected value from 2nd combobox
            self.dlg.node_nodecat_id.setEnabled(True)
            # Fill 3rd combo_box-catalog_id
            sql = "SELECT DISTINCT(id)"
            sql+= " FROM "+self.schema_name+".cat_node"
            sql+= " WHERE nodetype_id='"+self.value_combo2+"'"
            rows = self.dao.get_rows(sql)
            utils_giswater.fillComboBox("node_nodecat_id", rows)     
    def fill_filter3(self, wsoftware, geom_type):

        # Get values from filters
        mats = utils_giswater.getWidgetText(self.dlg_cat.matcat_id)
        filter2 = utils_giswater.getWidgetText(self.dlg_cat.filter2)

        # Set SQL query
        sql_where = ""
        if wsoftware == 'ws' and geom_type != 'connec':
            sql = "SELECT " + self.field3
            sql += " FROM (SELECT DISTINCT(regexp_replace(trim(' nm' FROM " + self.field3 + "),'-','', 'g')) as x, " + self.field3
        elif wsoftware == 'ws' and geom_type == 'connec':
            sql = "SELECT DISTINCT(TRIM(TRAILING ' ' from " + self.field3 + ")) as " + self.field3
        else:
            sql = "SELECT DISTINCT(" + self.field3 + ")"
        sql += " FROM " + self.schema_name + ".cat_" + geom_type

        # Build SQL filter
        if wsoftware == 'ws' and self.node_type_text is not None:
            sql_where = " WHERE " + geom_type + "type_id = '" + self.node_type_text + "'"
            
        if mats != "null":
            if sql_where == "":
                sql_where = " WHERE"
            else:
                sql_where += " AND"
            sql_where += " matcat_id = '" + mats + "'"
            
        if filter2 != "null":
            if sql_where == "":
                sql_where = " WHERE"
            else:
                sql_where += " AND"
            sql_where += " " + self.field2 + " = '" + filter2 + "'"
        if wsoftware == 'ws' and geom_type != 'connec':
            sql += sql_where + " ORDER BY x) AS " + self.field3
        else:
            sql += sql_where + " ORDER BY " + self.field3

        rows = self.controller.get_rows(sql)
        utils_giswater.fillComboBox(self.dlg_cat.filter3, rows)
        
        self.fill_catalog_id(wsoftware, geom_type)        
Example #44
0
 def workcat_populate(self, combo):
     """ Fill @combo """
     
     sql = ("SELECT DISTINCT(workcat_id) FROM " + self.controller.schema_name + ".arc"
            " WHERE workcat_id LIKE '%%' or workcat_id is NULL"
            " UNION"
            " SELECT DISTINCT(workcat_id) FROM " + self.controller.schema_name + ".connec"
            " WHERE workcat_id LIKE '%%' or workcat_id is NULL"
            " UNION"
            " SELECT DISTINCT(workcat_id) FROM " + self.controller.schema_name + ".node"
            " WHERE workcat_id LIKE '%%' or workcat_id is NULL")
     if self.project_type == 'ud':
         sql += (" UNION"
                 " SELECT DISTINCT(workcat_id) FROM " + self.controller.schema_name + ".gully"
                 " WHERE workcat_id LIKE '%%' or workcat_id is NULL")
     rows = self.controller.get_rows(sql)
     utils_giswater.fillComboBox(combo, rows)
     
     return rows
Example #45
0
 def load_tab_analysis(self):
     ''' Load data from tab 'Analysis' '''
     
     if self.epa_type == 'JUNCTION':                           
         # Load combo 'pattern_id'
         combo = self.epa_table+"_pattern_id"
         table_name = "inp_pattern"
         sql = "SELECT pattern_id FROM "+self.schema_name+"."+table_name+" ORDER BY pattern_id"
         rows = self.dao.get_rows(sql)
         utils_giswater.fillComboBox(combo, rows)
         
         self.fields_junction = ['demand', 'pattern_id']               
         sql = "SELECT "
         for i in range(len(self.fields_junction)):
             sql+= self.fields_junction[i]+", "
         sql = sql[:-2]
         sql+= " FROM "+self.schema_name+"."+self.epa_table+" WHERE node_id = '"+self.id+"'"
         row = self.dao.get_row(sql)
         if row:
             for i in range(len(self.fields_junction)):
                 widget_name = self.epa_table+"_"+self.fields_junction[i]
                 utils_giswater.setWidgetText(widget_name, str(row[i]))                
                 
     elif self.epa_type == 'TANK':
         # Load combo 'curve_id'
         combo = self.epa_table+"_curve_id"
         table_name = "inp_curve_id"            
         sql = "SELECT id FROM "+self.schema_name+".inp_curve_id ORDER BY id"
         rows = self.dao.get_rows(sql)
         utils_giswater.fillComboBox(combo, rows)
                     
         self.fields_tank = ['initlevel', 'minlevel', 'maxlevel', 'diameter', 'minvol', 'curve_id']            
         sql = "SELECT "
         for i in range(len(self.fields_tank)):
             sql+= self.fields_tank[i]+", "
         sql = sql[:-2]
         sql+= " FROM "+self.schema_name+"."+self.epa_table+" WHERE "+self.field_id+" = '"+self.id+"'"
         row = self.dao.get_row(sql)      
         if row:
             for i in range(len(self.fields_tank)):
                 widget_name = self.epa_table+"_"+self.fields_tank[i]
                 utils_giswater.setWidgetText(widget_name, str(row[i]))
Example #46
0
 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_()        
    def change_node_type_id(self, index):
        """ Define and execute query to populate combo 'cat_nodetype_id' """

        node_type_id = utils_giswater.getWidgetText("node_type_dummy", False)
        if node_type_id:
            utils_giswater.setWidgetText("node_type", node_type_id)
            sql = "SELECT id FROM " + self.schema_name + ".cat_node"
            sql += " WHERE nodetype_id = '" + node_type_id + "' ORDER BY id"
            rows = self.dao.get_rows(sql)
            utils_giswater.fillComboBox("nodecat_id_dummy", rows, False)
            if index == -1:
                utils_giswater.setWidgetText("nodecat_id_dummy", self.nodecat_id)
            self.change_node_cat()

            if self.loaded:
                sql = "SELECT epa_default FROM " + self.schema_name + ".node_type"
                sql += " WHERE id = '" + node_type_id + "'"
                rows = self.dao.get_rows(sql)
                utils_giswater.setWidgetText("epa_type", rows[0][0])
                utils_giswater.setSelectedItem("epa_type", rows[0][0])
                self.change_epa_type(-1)

            else:
                self.loaded = True
    def fill_tbl_document(self, widget, table_name, filter_):
        ''' Fill the table control to show documents'''
        
        # Get widgets
        doc_user = self.dialog.findChild(QComboBox, "doc_user")
        doc_type = self.dialog.findChild(QComboBox, "doc_type")
        doc_tag = self.dialog.findChild(QComboBox, "doc_tag")
        self.date_document_to = self.dialog.findChild(QDateEdit, "date_document_to")
        self.date_document_from = self.dialog.findChild(QDateEdit, "date_document_from")

        # Set signals
        doc_user.activated.connect(partial(self.set_filter_table, widget))
        doc_type.activated.connect(partial(self.set_filter_table, widget))
        doc_tag.activated.connect(partial(self.set_filter_table, widget))
        self.date_document_to.dateChanged.connect(partial(self.set_filter_table, widget))
        self.date_document_from.dateChanged.connect(partial(self.set_filter_table, widget))
        self.tbl_document.doubleClicked.connect(self.open_selected_document)

        # Fill ComboBox tagcat_id
        sql = "SELECT DISTINCT(tagcat_id)"
        sql+= " FROM "+table_name
        sql+= " ORDER BY tagcat_id"
        rows = self.dao.get_rows(sql)
        utils_giswater.fillComboBox("doc_tag", rows)

        # Fill ComboBox doccat_id
        sql = "SELECT DISTINCT(doc_type)"
        sql+= " FROM "+table_name
        sql+= " ORDER BY doc_type"
        rows = self.dao.get_rows(sql)
        utils_giswater.fillComboBox("doc_type", rows)

        # Fill ComboBox doc_user
        sql = "SELECT DISTINCT(user_name)"
        sql+= " FROM "+table_name
        sql+= " ORDER BY user_name"
        rows = self.dao.get_rows(sql)
        utils_giswater.fillComboBox("doc_user", rows)

        # Set model of selected widget
        self.set_model_to_table(widget, table_name, filter_)