class withWidgets(): ''' Todos Metodos aqui sao para o auxilio caso queria trabalhar com model com Mappers ''' def setMapper(self, model=None, fldToMap=None): """ Metodo para configurar o mapper ao modelo modelo = Modelo fldToMap = Campos para mappear """ self.mapper = QDataWidgetMapper()# cria objecto Mapper self.mapper.setModel(model) #Define modelo ao mapper for cidx, field in enumerate(fldToMap):#Para cada campo if field is not None: #Verdicacao self.mapper.addMapping(field, cidx)#Atribuimos ao mapping self.mapper.toFirst()#e movemos para o primeiro(obrigatorio) def mapperToNext(self): self.mapper.toNext()#Proxima linha def mapperToPerv(self): self.mapper.toPrevious()#Linha previa def getCurrentIndex(self): cIdx = self.mapper.currentIndex()#Get Current Index return cIdx def getValueFromMapper(self, pos=0): try: val = self.mapper.model().record(self.mapper.currentIndex()).value(0) #Get the value from the mapper row = self.mapper.currentIndex() #Get the current row or index except Exception: row = None val = None return val, row def sychClickWithMap(self,indexModel=None): self.mapper.setCurrentModelIndex(indexModel) #Scncy clicked object with mapper def setMapperToIdx(self, idx): self.mapper.setCurrentIndex(idx)#Set Current index to row or index
class withWidgets(): def setMapper(self, model=None, fldToMap=None): """ Metodo para configurar o mapper. """ self.mapper = QDataWidgetMapper() self.mapper.setModel(model) for cidx, field in enumerate(fldToMap): if field is not None: self.mapper.addMapping(field, cidx) self.mapper.toFirst() def mapperToNext(self): self.mapper.toNext() def mapperToPerv(self): self.mapper.toPrevious() def getCurrentIndex(self): cIdx = self.mapper.currentIndex() return cIdx def getValueFromMapper(self, pos=0): try: val = self.mapper.model().record( self.mapper.currentIndex()).value(0) row = self.mapper.currentIndex() except Exception: row = None val = None return val, row def sychClickWithMap(self, indexModel=None): self.mapper.setCurrentModelIndex(indexModel) def setMapperToIdx(self, idx): self.mapper.setCurrentIndex(idx)