def setDB(self): self.database_connection = con_.con_1() table_name = "tbl_gado" filtro = None lstVal2Real = [None,['id ', 'nome']] lstRelTblName = [None,'tbl_categorias'] """ Setting up Models """ """ This is the model for the table that will be displayed:: tbl_gado """ _, self.model = mixedModel.setViewModel(tblName= table_name, filtro=None, lstVal2Rel = lstVal2Real, lstRelTblName=lstRelTblName) self.tableView.setModel(self.model) self.tableView.setSelectionMode(QAbstractItemView.SingleSelection) self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows) """THis is the model for the table that won't be displayed but it will be necessary for mapping the widgets """ self.second_model = SimpleModel(self.database_connection, tblName='tbl_log') self.second_model.setModel() self.second_model.model.sort(2, Qt.AscendingOrder) '''Need to sort the tableView according to the id_gado so the values from the first model can correspond to the values of the second model''' self.index_gado_in_log = [] for x in range(int(self.second_model.model.rowCount())): self.index_gado_in_log.append(self.second_model.model.record(x).value(2)) self.index_gado_in_log.sort()
def setDB(self): self.dbConnection = con_.con_1() table_name = 'tbl_gado' list_of_values_tRelate = [None, ['id', 'nome']] list_of_tableNames = [None, 'tbl_categorias'] list_of_new_names = [ 'id', 'Categoria', 'sexo', 'Data de Nascimento', 'Total' ] _, self.model = mx.setViewModel(tblName=table_name, lstVal2Rel=list_of_values_tRelate, lstRelTblName=list_of_tableNames, lstNewNames=list_of_new_names) self.tableView.setModel(self.model) self.tableView.setSelectionMode(QAbstractItemView.SingleSelection) self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows)
def setDB(self): self.dbConnection = con_.con_1() query = '''select id_gado, data_acontecimento, descricao from tbl_log where id_acontecimento = 2; ''' list_of_newNames = ['ID Gado', 'Data da Morte', 'Descricao'] self.model = mx.setQueryModel(query=query, lstNewNames=list_of_newNames) self.tableView.setModel(self.model) self.tableView.setSelectionMode(QAbstractItemView.SingleSelection) self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows) mx.setModel4CombBox(tblName='tbl_log', lstNames='id_gado', widg=self.idComboBox, namePos=0)
def setDB(self): self.dbConnection = con_.con_1()