Example #1
0
    def mg_table_wizard_import_csv(self):

        # Get selected table, delimiter, and header
        alias = utils_giswater.getWidgetText(self.dlg.cbo_table)  
        table_name = self.table_dict[alias]
        delimiter = utils_giswater.getWidgetText(self.dlg.cbo_delimiter)  
        header_status = self.dlg.chk_header.checkState()             
        
        # Get CSV file. Check if file exists
        self.file_path = self.dlg.txt_file_path.toPlainText()
        if not os.path.exists(self.file_path):
            message = "Selected file not found: "+self.file_path
            self.controller.show_warning(message, context_name='ui_message' )
            return False      
              
        # Open CSV file for read and copy into database
        rf = open(self.file_path)
        sql = "COPY "+self.schema_name+"."+table_name+" FROM STDIN WITH CSV"
        if (header_status == Qt.Checked):
            sql+= " HEADER"
        sql+= " DELIMITER AS '"+delimiter+"'"
        status = self.dao.copy_expert(sql, rf)
        if status:
            self.dao.rollback()
            msg = "Cannot import CSV into table "+table_name+". Reason:\n"+str(status).decode('utf-8')
            QMessageBox.warning(None, "Import CSV", self.controller.tr(msg))
            return False
        else:
            self.dao.commit()
            message = "Selected CSV has been imported successfully"
            self.controller.show_info(message, context_name='ui_message' )
   def set_filter_table(self, widget):
       ''' Get values selected by the user and sets a new filter for its table model '''
       
       # Get selected dates
       date_from = self.date_document_from.date().toString('yyyyMMdd') 
       date_to = self.date_document_to.date().toString('yyyyMMdd') 
       if (date_from > date_to):
           message = "Selected date interval is not valid"
           self.controller.show_warning(message, context_name='ui_message')                   
           return
       
       # Set filter
       expr = self.field_id+" = '"+self.id+"'"
       expr+= " AND date >= '"+date_from+"' AND date <= '"+date_to+"'"
       
       # Get selected values in Comboboxes        
       doc_type_value = utils_giswater.getWidgetText("doc_type")
       if doc_type_value != 'null': 
           expr+= " AND doc_type = '"+doc_type_value+"'"
       doc_tag_value = utils_giswater.getWidgetText("doc_tag")
       if doc_tag_value != 'null': 
           expr+= " AND tagcat_id = '"+doc_tag_value+"'"
       doc_user_value = utils_giswater.getWidgetText("doc_user")
       if doc_user_value != 'null':
           expr+= " AND user_name = '"+doc_user_value+"'"
 
       # Refresh model with selected filter
       widget.model().setFilter(expr)
       widget.model().select()   
 def init_config_arc(self):
     ''' Custom form initial configuration for 'Arc' '''
     
     # Define class variables
     self.field_id = "arc_id"
     self.id = utils_giswater.getWidgetText(self.field_id, False)
     self.epa_type = utils_giswater.getWidgetText("epa_type", False)    
     if self.epa_type == 'PIPE':
         self.epa_table = 'inp_pipe'
     
     # Get widget controls
     self.tab_analysis = self.dialog.findChild(QTabWidget, "tab_analysis")            
     self.tab_event = self.dialog.findChild(QTabWidget, "tab_event")   
     self.tab_main = self.dialog.findChild(QTabWidget, "tab_main")                   
          
     # Manage tab visibility
     self.set_tabs_visibility()
     
     # Manage i18n
     self.translate_form('ws_arc')        
     
     # Fill combo 'arc type' from 'epa_type'
     self.fill_arc_type()
     
     # Load data from related tables
     self.load_data()
     
     # Set layer in editing mode
     self.layer.startEditing()
 def init_config_node(self):
     ''' Custom form initial configuration for 'Node' '''
     
     # Define class variables
     self.field_id = "node_id"        
     self.id = utils_giswater.getWidgetText(self.field_id, False)  
     self.node_type = utils_giswater.getWidgetText("node_type", False)        
     self.nodecat_id = utils_giswater.getWidgetText("nodecat_id", False)        
     self.epa_type = utils_giswater.getWidgetText("epa_type", False)      
     
     # Get widget controls
     self.tab_analysis = self.dialog.findChild(QTabWidget, "tab_analysis")            
     self.tab_event = self.dialog.findChild(QTabWidget, "tab_event")         
     self.tab_main = self.dialog.findChild(QTabWidget, "tab_main")            
          
     # Manage tab visibility
     self.set_tabs_visibility()
     
     # Manage i18n
     self.translate_form('ws_node')        
     
     # Define and execute query to populate combo 'node_type_dummy'
     self.fill_node_type_id()
     
     # Load data from related tables
     self.load_data()
     
     # Set layer in editing mode
     self.layer.startEditing()
    def save_tab_analysis(self):
        """ Save tab from tab 'Analysis' """

        # super(NodeDialog, self).save_tab_analysis()
        if self.epa_type == "JUNCTION":
            values = []
            sql = "UPDATE " + self.schema_name + "." + self.epa_table + " SET "
            for i in range(len(self.fields_junction)):
                widget_name = self.epa_table + "_" + self.fields_junction[i]
                value = utils_giswater.getWidgetText(widget_name, True)
                values.append(value)
                sql += self.fields_junction[i] + " = " + str(values[i]) + ", "
            sql = sql[:-2]
            sql += " WHERE node_id = '" + self.id + "'"
            self.dao.execute_sql(sql)

        if self.epa_type == "TANK":
            values = []
            sql = "UPDATE " + self.schema_name + "." + self.epa_table + " SET "
            for i in range(len(self.fields_tank)):
                widget_name = self.epa_table + "_" + self.fields_tank[i]
                value = utils_giswater.getWidgetText(widget_name, True)
                values.append(value)
                sql += self.fields_tank[i] + " = " + str(values[i]) + ", "
            sql = sql[:-2]
            sql += " WHERE node_id = '" + self.id + "'"
            self.dao.execute_sql(sql)
    def init_config_form(self):
        ''' Custom form initial configuration '''
        
        # Define local variables
        context_name = "ws_arc"            
        table_element = "v_ui_element_x_arc"           
        table_document = "v_ui_doc_x_arc"
        
        # Define class variables
        self.field_id = "arc_id" 
        self.id = utils_giswater.getWidgetText(self.field_id, False)  
        self.filter = self.field_id+" = '"+str(self.id)+"'"                    
        self.arc_type = utils_giswater.getWidgetText("cat_arctype_id", False)        
        self.arccat_id = utils_giswater.getWidgetText("arccat_id", False)        
        self.epa_type = utils_giswater.getWidgetText("epa_type", False) 
        self.tab_analysis = self.dialog.findChild(QTabWidget, "tab_analysis")            
        self.tab_event = self.dialog.findChild(QTabWidget, "tab_event")  
        self.tab_event_2 = self.dialog.findChild(QTabWidget, "tab_event_2")        
        self.tab_main = self.dialog.findChild(QTabWidget, "tab_main")      
        self.tbl_info = self.dialog.findChild(QTableView, "tbl_info")    
        self.tbl_document = self.dialog.findChild(QTableView, "tbl_document") 
        self.tbl_rtc = self.dialog.findChild(QTableView, "tbl_rtc")             
             
        # Manage tab visibility
        self.set_tabs_visibility()
        
        # Manage i18n
        self.translate_form(context_name)        
        
        # Define and execute query to populate combo 'cat_arctype_id_dummy'
        self.fill_arc_type_id()        
      
        # Load data from related tables
        self.load_data()
        
        # Set layer in editing mode
        self.layer.startEditing()
        
        # Fill the info table
        self.fill_table(self.tbl_info, self.schema_name+"."+table_element, self.filter)
        
        # Configuration of  info table
        self.set_configuration(self.tbl_info, table_element)
        
        # Fill the tab Document
        self.fill_tbl_document(self.tbl_document, self.schema_name+"."+table_document, self.filter)
        
        # Configuration of table document
        self.set_configuration(self.tbl_document, table_document)

        # Set signals    
        btn_element_delete = self.dialog.findChild(QPushButton, "btn_element_delete")
        btn_doc_delete = self.dialog.findChild(QPushButton, "btn_doc_delete")
        if btn_element_delete:             
            btn_element_delete.clicked.connect(partial(self.delete_records, self.tbl_info, table_element))  
        if btn_doc_delete:               
            btn_doc_delete.clicked.connect(partial(self.delete_records, self.tbl_document, table_document))   
    def save_tab_add_info(self):
        """ Save tab from tab 'Add. info' """

        if self.epa_type == "TANK":
            vmax = utils_giswater.getWidgetText("man_tank_vmax", False)
            area = utils_giswater.getWidgetText("man_tank_area", False)
            sql = " UPDATE " + self.schema_name + ".man_tank SET"
            sql += " vmax = " + str(vmax) + ", area = " + str(area)
            sql += " WHERE node_id = '" + self.id + "';"
            self.dao.execute_sql(sql)
            total = self.dao.get_rowcount()
            # Perform an INSERT if any record has been updated
            # TODO: If trigger was working correctly this wouldn't be necessary!
            if total == 0:
                sql = "INSERT INTO " + self.schema_name + ".man_tank (node_id, vmax, area) VALUES"
                sql += " ('" + self.id + "', " + str(vmax) + ", " + str(area) + ");"
                self.dao.execute_sql(sql)
 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 init_config():
     
    feature_dialog.dialog.findChild(QComboBox, "connecat_id").setVisible(False)         
    connecat_id = utils_giswater.getWidgetText("connecat_id", False)
    
    # TODO: Define slots
    
    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 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 init_config():
    
    # Manage visibility     
    feature_dialog.dialog.findChild(QComboBox, "connecat_id").setVisible(False)    
    feature_dialog.dialog.findChild(QComboBox, "cat_connectype_id").setVisible(False)    
    
    # Manage 'connecat_id'
    connecat_id = utils_giswater.getWidgetText("connecat_id")
    feature_dialog.dialog.findChild(QComboBox, "connecat_id_dummy").activated.connect(feature_dialog.change_connec_cat)          
    utils_giswater.setSelectedItem("connecat_id_dummy", connecat_id)   
    utils_giswater.setSelectedItem("connecat_id", connecat_id)   
    
    # Manage 'connec_type'
    cat_connectype_id = utils_giswater.getWidgetText("cat_connectype_id")
    utils_giswater.setSelectedItem("cat_connectype_id_dummy", cat_connectype_id)  
    feature_dialog.dialog.findChild(QComboBox, "cat_connectype_id_dummy").activated.connect(feature_dialog.change_connec_type_id)  
    feature_dialog.change_connec_type_id(-1)      
    
    # Set button signals      
    feature_dialog.dialog.findChild(QPushButton, "btn_accept").clicked.connect(feature_dialog.update_sum)            
    feature_dialog.dialog.findChild(QPushButton, "btn_close").clicked.connect(feature_dialog.close)      
Example #13
0
    def mg_result_selector_accept(self):
        ''' Update current values to the table '''
           
        # Get new values from widgets of type QComboBox
        rpt_selector_result_id = utils_giswater.getWidgetText("rpt_selector_result_id")
        rpt_selector_compare_id = utils_giswater.getWidgetText("rpt_selector_compare_id")

        # Delete previous values
        # Set new values to tables 'rpt_selector_result' and 'rpt_selector_compare'
        sql= "DELETE FROM "+self.schema_name+".rpt_selector_result" 
        self.dao.execute_sql(sql)
        sql= "DELETE FROM "+self.schema_name+".rpt_selector_compare" 
        self.dao.execute_sql(sql)
        sql= "INSERT INTO "+self.schema_name+".rpt_selector_result VALUES ('"+rpt_selector_result_id+"');"
        self.dao.execute_sql(sql)
        sql= "INSERT INTO "+self.schema_name+".rpt_selector_compare VALUES ('"+rpt_selector_compare_id+"');"
        self.dao.execute_sql(sql)

        # Show message to user
        message = "Values has been updated"
        self.controller.show_info(message, context_name='ui_message') 
        self.close_dialog(self.dlg) 
def init_config():
     
    feature_dialog.dialog.findChild(QComboBox, "arccat_id").setVisible(False)         
    arccat_id = utils_giswater.getWidgetText("arccat_id", False)
    feature_dialog.change_arc_type()  
    feature_dialog.dialog.findChild(QComboBox, "cat_arctype_id").activated.connect(feature_dialog.change_arc_type)    
    feature_dialog.dialog.findChild(QComboBox, "arccat_id_dummy").activated.connect(feature_dialog.change_arc_cat)          
    utils_giswater.setSelectedItem("arccat_id_dummy", arccat_id)            
    utils_giswater.setSelectedItem("arccat_id", arccat_id)            
    
    feature_dialog.dialog.findChild(QComboBox, "epa_type").activated.connect(feature_dialog.change_epa_type)    
    feature_dialog.dialog.findChild(QPushButton, "btn_accept").clicked.connect(feature_dialog.save)            
    feature_dialog.dialog.findChild(QPushButton, "btn_close").clicked.connect(feature_dialog.close)        
Example #15
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)
    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()     
def init_config():
    
    # Manage visibility 
    feature_dialog.dialog.findChild(QComboBox, "cat_arctype_id").setVisible(False)    
    feature_dialog.dialog.findChild(QComboBox, "arccat_id").setVisible(False)    
    
    # Manage 'arccat_id'
    nodecat_id = utils_giswater.getWidgetText("arccat_id")
    feature_dialog.dialog.findChild(QComboBox, "arccat_id_dummy").activated.connect(feature_dialog.change_arc_cat)          
    utils_giswater.setSelectedItem("arcccat_id_dummy", nodecat_id)   
    utils_giswater.setSelectedItem("nodecat_id", nodecat_id)   
    
    # Manage 'cat_arctype_id'
    arc_type_id = utils_giswater.getWidgetText("cat_arctype_id")
    utils_giswater.setSelectedItem("cat_arctype_id_dummy", arc_type_id)    
    feature_dialog.dialog.findChild(QComboBox, "cat_arctype_id_dummy").activated.connect(feature_dialog.change_arc_type_id)  
    feature_dialog.change_arc_type_id(-1)      
      
    # Set 'epa_type' and button signals      
    feature_dialog.dialog.findChild(QComboBox, "epa_type").activated.connect(feature_dialog.change_epa_type)  
    feature_dialog.dialog.findChild(QPushButton, "btn_accept").clicked.connect(feature_dialog.save)            
    feature_dialog.dialog.findChild(QPushButton, "btn_close").clicked.connect(feature_dialog.close)      
Example #18
0
 def ed_add_file_accept(self): 
     ''' Insert or update document. Add document to selected feature '''  
     
     # Get values from dialog
     doc_id = utils_giswater.getWidgetText("doc_id") 
     doc_type = utils_giswater.getWidgetText("doc_type")   
     tagcat_id = utils_giswater.getWidgetText("tagcat_id")  
     observ = utils_giswater.getWidgetText("observ")
     path = utils_giswater.getWidgetText("path")
     
     # Check if this document already exists
     sql = "SELECT DISTINCT(id) FROM "+self.schema_name+".doc WHERE id = '"+doc_id+"'" 
     row = self.dao.get_row(sql)
     if row:
         answer = self.controller.ask_question("Are you sure you want change the data?")
         if answer:
             sql = "UPDATE "+self.schema_name+".doc "
             sql+= " SET doc_type = '"+doc_type+"', tagcat_id= '"+tagcat_id+"',observ = '"+observ+"', path = '"+path+"'"
             sql+= " WHERE id = '"+doc_id+"'" 
             self.dao.execute_sql(sql) 
         else:
             self.close_dialog(self.dlg) 
     else:
         sql = "INSERT INTO "+self.schema_name+".doc (id, doc_type, path, observ, tagcat_id) "
         sql+= " VALUES ('"+doc_id+"', '"+doc_type+"', '"+path+"', '"+observ+"', '"+tagcat_id+"')"
         status = self.controller.execute_sql(sql) 
         if not status:
             message = "Error inserting element in table, you need to review data"
             self.controller.show_warning(message, context_name='ui_message')
             return
     
     # Add document to selected feature
     self.ed_add_to_feature("doc", doc_id)
        
     # Show message to user
     message = "Values has been updated"
     self.controller.show_info(message, context_name='ui_message')
     self.close_dialog()  
 def save_tab_analysis(self):
     ''' Save tab from tab 'Analysis' '''   
                  
     #super(ArcDialog, self).save_tab_analysis()
     if self.epa_type == 'PIPE':
         values = []            
         sql = "UPDATE "+self.schema_name+"."+self.epa_table+" SET "
         for i in range(len(self.fields_pipe)):
             widget_name = self.epa_table+"_"+self.fields_pipe[i]     
             value = utils_giswater.getWidgetText(widget_name, True)     
             values.append(value)
             sql+= self.fields_pipe[i]+" = "+str(values[i])+", "
         sql = sql[:-2]      
         sql+= " WHERE "+self.field_id+" = '"+self.id+"'"        
         self.dao.execute_sql(sql)        
    def init_config_form(self):
        """ Custom form initial configuration """

        # Define local variables
        context_name = "ud_arc"
        table_element = "v_ui_element_x_arc"
        table_document = "v_ui_doc_x_arc"

        # Define class variables
        self.field_id = "arc_id"
        self.id = utils_giswater.getWidgetText(self.field_id, False)
        self.filter = self.field_id + " = '" + str(self.id) + "'"
        self.tab_main = self.dialog.findChild(QTabWidget, "tab_main")
        self.tbl_element = self.dialog.findChild(QTableView, "tbl_element")
        self.tbl_document = self.dialog.findChild(QTableView, "tbl_document")

        # Manage tab visibility
        self.set_tabs_visibility()

        # Manage i18n
        self.translate_form(context_name)

        # Load data from related tables
        # self.load_data()

        # Set layer in editing mode
        self.layer.startEditing()

        # Fill the element table
        self.fill_table(self.tbl_element, self.schema_name + "." + table_element, self.filter)

        # Configuration of element table
        self.set_configuration(self.tbl_element, table_element)

        # Fill the tab Document
        self.fill_tbl_document(self.tbl_document, self.schema_name + "." + table_document, self.filter)

        # Configuration of document table
        self.set_configuration(self.tbl_document, table_document)

        # Set signals
        btn_element_delete = self.dialog.findChild(QPushButton, "btn_element_delete")
        btn_doc_delete = self.dialog.findChild(QPushButton, "btn_doc_delete")
        if btn_element_delete:
            btn_element_delete.clicked.connect(partial(self.delete_records, self.tbl_element, table_element))
        if btn_doc_delete:
            btn_doc_delete.clicked.connect(partial(self.delete_records, self.tbl_document, table_document))
Example #21
0
    def ed_add_file_autocomplete(self): 
        ''' Once we select 'element_id' using autocomplete, fill widgets with current values '''

        self.dlg.doc_id.setCompleter(self.completer)
        doc_id = utils_giswater.getWidgetText("doc_id") 
        
        # Get values from database           
        sql = "SELECT doc_type, tagcat_id, observ, path"
        sql+= " FROM "+self.schema_name+".doc" 
        sql+= " WHERE id = '"+doc_id+"'"
        row = self.dao.get_row(sql)
        
        # Fill widgets
        columns_length = self.dao.get_columns_length()
        for i in range(0, columns_length):
            column_name = self.dao.get_column_name(i)
            utils_giswater.setWidgetText(column_name, row[column_name])       
Example #22
0
    def ed_add_el_autocomplete(self):    
        ''' Once we select 'element_id' using autocomplete, fill widgets with current values '''

        self.dlg.element_id.setCompleter(self.completer)
        element_id = utils_giswater.getWidgetText("element_id") 
        
        # Get values from database       
        sql = "SELECT elementcat_id, location_type, ownercat_id, state, workcat_id," 
        sql+= " buildercat_id, annotation, observ, comment, link, verified, rotation"
        sql+= " FROM "+self.schema_name+".element" 
        sql+= " WHERE element_id = '"+element_id+"'"
        row = self.dao.get_row(sql)
        
        # Fill widgets
        columns_length = self.dao.get_columns_length()
        for i in range(0, columns_length):
            column_name = self.dao.get_column_name(i)
            utils_giswater.setWidgetText(column_name, row[column_name]) 
Example #23
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)     
Example #24
0
 def mg_config_accept_table(self, tablename, columns):
     ''' Update values of selected 'tablename' with the content of 'columns' '''
     
     if columns is not None:       
         sql = "UPDATE "+self.schema_name+"."+tablename+" SET "         
         for column_name in columns:
             if column_name != 'id':
                 widget_type = utils_giswater.getWidgetType(column_name)
                 if widget_type is QCheckBox:
                     value = utils_giswater.isChecked(column_name)                      
                 else:
                     value = utils_giswater.getWidgetText(column_name)
                 if value is None or value == 'null':
                     sql+= column_name+" = null, "     
                 else:
                     if type(value) is not bool:
                         value = value.replace(",", ".")
                     sql+= column_name+" = '"+str(value)+"', "           
         
         sql = sql[:-2]
         self.dao.execute_sql(sql)
                     
             
 def init_config_connec(self):
     ''' Custom form initial configuration for 'Connec' '''
     
     # Define class variables
     self.field_id = "connec_id"
     self.id = utils_giswater.getWidgetText(self.field_id, False)     
     
     # Get widget controls
     self.tab_analysis = self.dialog.findChild(QTabWidget, "tab_analysis")            
     self.tab_event = self.dialog.findChild(QTabWidget, "tab_event")         
     self.tab_main = self.dialog.findChild(QTabWidget, "tab_main")     
     
     # Manage tab visibility
     self.set_tabs_visibility()                
     
     # Manage i18n
     self.translate_form('ws_connec')        
     
     # Load data from related tables
     self.load_data()
     
     # Set layer in editing mode
     self.layer.startEditing()
    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 change_arc_cat(self):
     ''' Just select item to 'real' combo 'arccat_id' (that is hidden) '''
     arccat_id_dummy = utils_giswater.getWidgetText("arccat_id_dummy")
     utils_giswater.setWidgetText("arccat_id", arccat_id_dummy)           
    def init_config_form(self):
        ''' Custom form initial configuration '''

        # Define local variables
        context_name = "ws_connec"    
        table_element = "v_ui_element_x_connec" 
        table_document = "v_ui_doc_x_connec"   
        table_hydrometer = "v_rtc_hydrometer"   
        table_hydrometer_epanet = "v_edit_rtc_hydro_data_x_connec"                     
        
        # Define class variables
        self.field_id = "connec_id"        
        self.id = utils_giswater.getWidgetText(self.field_id, False)  
        self.filter = self.field_id+" = '"+str(self.id)+"'"                    
        self.connec_type = utils_giswater.getWidgetText("cat_connectype_id", False)        
        self.connecat_id = utils_giswater.getWidgetText("connecat_id", False)      
        
        # Get widget controls
        self.tab_analysis = self.dialog.findChild(QTabWidget, "tab_analysis")            
        self.tab_event = self.dialog.findChild(QTabWidget, "tab_event")  
        self.tab_event_2 = self.dialog.findChild(QTabWidget, "tab_event_2")        
        self.tab_main = self.dialog.findChild(QTabWidget, "tab_main")      
        self.tbl_info = self.dialog.findChild(QTableView, "tbl_info")    
        self.tbl_document = self.dialog.findChild(QTableView, "tbl_connec")             
        self.tbl_dae = self.dialog.findChild(QTableView, "tbl_dae")   
        self.tbl_dae_2 = self.dialog.findChild(QTableView, "tbl_dae_2")    
             
        # Manage tab visibility
        self.set_tabs_visibility()
        
        # Manage i18n
        self.translate_form(context_name)        
        
        # Define and execute query to populate combo 'cat_connectype_id_dummy' 
        self.fill_connec_type_id()
        
        # Load data from related tables
        self.load_data()
        
        # Set layer in editing mode
        self.layer.startEditing()
        
        # Fill the info table
        self.fill_table(self.tbl_info, self.schema_name+"."+table_element, self.filter)
        
        # Configuration of info table
        self.set_configuration(self.tbl_info, table_element)
        
        # Fill the tab Document
        self.fill_tbl_document(self.tbl_document, self.schema_name+"."+table_document, self.filter)
        
        # Configuration of table Document
        self.set_configuration(self.tbl_document, table_document)
        
        # Fill tab Hydrometer | feature
        self.fill_tbl_hydrometer(self.tbl_dae, self.schema_name+"."+table_hydrometer, self.filter)
        
        # Configuration of table Hydrometer | feature
        self.set_configuration(self.tbl_dae, table_hydrometer)
        
        # Fill tab Hydrometer | epanet
        self.fill_tbl_hydrometer_epanet(self.tbl_dae_2, self.schema_name+"."+table_hydrometer_epanet, self.filter)

        # Configuration of table Hydrometer | epanet
        self.set_configuration(self.tbl_dae_2, table_hydrometer_epanet)
        
        # Set signals                  
        self.dialog.findChild(QPushButton, "delete_row_info").clicked.connect(partial(self.delete_records, self.tbl_info, table_element))                 
        self.dialog.findChild(QPushButton, "delete_row_doc").clicked.connect(partial(self.delete_records, self.tbl_document, table_document))    
        self.dialog.findChild(QPushButton, "btn_delete_hydrometer").clicked.connect(partial(self.delete_records_dae, self.tbl_dae, table_hydrometer))               
        self.dialog.findChild(QPushButton, "btn_add_hydrometer").clicked.connect(self.insert_records)
 def change_node_cat(self):
     """ Just select item to 'real' combo 'nodecat_id' (that is hidden) """
     nodecat_id_dummy = utils_giswater.getWidgetText("nodecat_id_dummy")
     utils_giswater.setWidgetText("nodecat_id", nodecat_id_dummy)
Example #30
0
    def ed_add_element_accept(self):
           
        # Get values from dialog
        element_id = utils_giswater.getWidgetText("element_id")
        elementcat_id = utils_giswater.getWidgetText("elementcat_id")  
        state = utils_giswater.getWidgetText("state")   
        annotation = utils_giswater.getWidgetText("annotation")
        observ = utils_giswater.getWidgetText("observ")
        comment = utils_giswater.getWidgetText("comment")
        location_type = utils_giswater.getWidgetText("location_type")
        workcat_id = utils_giswater.getWidgetText("workcat_id")
        buildercat_id = utils_giswater.getWidgetText("buildercat_id")
        ownercat_id = utils_giswater.getWidgetText("ownercat_id")
        rotation = utils_giswater.getWidgetText("rotation")
        link = utils_giswater.getWidgetText("link")
        verified = utils_giswater.getWidgetText("verified")

        # Check if we already have data with selected element_id
        sql = "SELECT DISTINCT(element_id) FROM "+self.schema_name+".element WHERE element_id = '"+element_id+"'"    
        row = self.dao.get_row(sql)
        if row:
            answer = self.controller.ask_question("Are you sure you want change the data?")
            if answer:
                sql = "UPDATE "+self.schema_name+".element"
                sql+= " SET element_id = '"+element_id+"', elementcat_id= '"+elementcat_id+"',state = '"+state+"', location_type = '"+location_type+"'"
                sql+= ", workcat_id= '"+workcat_id+"',buildercat_id = '"+buildercat_id+"', ownercat_id = '"+ownercat_id+"'"
                sql+= ", rotation= '"+rotation+"',comment = '"+comment+"', annotation = '"+annotation+"', observ= '"+observ+"',link = '"+link+"', verified = '"+verified+"'"
                sql+= " WHERE element_id = '"+element_id+"'" 
                self.dao.execute_sql(sql)  
            else:
                self.close_dialog(self.dlg)
        else:
            sql = "INSERT INTO "+self.schema_name+".element (element_id, elementcat_id, state, location_type"
            sql+= ", workcat_id, buildercat_id, ownercat_id, rotation, comment, annotation, observ, link, verified) "
            sql+= " VALUES ('"+element_id+"', '"+elementcat_id+"', '"+state+"', '"+location_type+"', '"
            sql+= workcat_id+"', '"+buildercat_id+"', '"+ownercat_id+"', '"+rotation+"', '"+comment+"', '"
            sql+= annotation+"','"+observ+"','"+link+"','"+verified+"')"
            status = self.controller.execute_sql(sql) 
            if not status:
                message = "Error inserting element in table, you need to review data"
                self.controller.show_warning(message, context_name='ui_message') 
                return
        
        # Add document to selected feature
        self.ed_add_to_feature("element", element_id)
                
        # Show message to user
        message = "Values has been updated"
        self.controller.show_info(message, context_name='ui_message')
        self.close_dialog()