def load_locales_por_ciudad(self, index): """función que carga los locales por ciudad al apretar el combobox""" id_ciudad = self.ui.combo.itemData(self.ui.combo.currentIndex()) if id_ciudad == -1: ciudad = controller_local.get_locales() else: ciudad = c.obtener_locales_por_ciudad(id_ciudad) self.load_datos(ciudad)
def load_datos(self, locales=None): """función que carga todos los locales en la ventana principal""" if locales is None: locales = controller_local.get_locales() self.model = QtGui.QStandardItemModel(len(locales), 7) self.model.setHorizontalHeaderItem(0, QtGui.QStandardItem(u"id_local")) self.model.setHorizontalHeaderItem(1, QtGui.QStandardItem(u"Nombre")) self.model.setHorizontalHeaderItem(2, QtGui.QStandardItem(u"Direccion")) self.model.setHorizontalHeaderItem(3, QtGui.QStandardItem(u"Ciudad")) self.model.setHorizontalHeaderItem(4, QtGui.QStandardItem(u"N° empleados")) self.model.setHorizontalHeaderItem(5, QtGui.QStandardItem(u"hombres")) self.model.setHorizontalHeaderItem(6, QtGui.QStandardItem(u"mujeres")) r = 0 for row in locales: index = self.model.index(r, 0, QtCore.QModelIndex()); self.model.setData(index, row['id_local']) index = self.model.index(r, 1, QtCore.QModelIndex()); self.model.setData(index, row['nombre']) index = self.model.index(r, 2, QtCore.QModelIndex()); self.model.setData(index, row['direccion']) index = self.model.index(r, 3, QtCore.QModelIndex()); self.model.setData(index, row['ciudad']) index = self.model.index(r, 4, QtCore.QModelIndex()); empleados = c.obtener_empleados_por_local(row['id_local']) self.model.setData(index, len(empleados)); index = self.model.index(r, 5, QtCore.QModelIndex()); self.model.setData(index, c.obtener_hombres(row['id_local'])) index = self.model.index(r, 6, QtCore.QModelIndex()); self.model.setData(index, c.obtener_mujeres(row['id_local'])) r = r+1 self.ui.table_win.setModel(self.model) self.ui.table_win.setColumnWidth(1, 200) self.ui.table_win.setColumnWidth(2, 300) self.ui.table_win.setColumnWidth(3, 140) self.ui.table_win.setColumnWidth(4, 100) self.ui.table_win.setColumnWidth(5, 80) self.ui.table_win.setColumnWidth(6, 80) self.ui.table_win.hideColumn(0) self.update_search()