コード例 #1
0
 def addModelToView(self,modelObj):
     '''
     Convenience method for adding model info into the view.
     '''
     insertPosition = self._tableModel.rowCount()
     self._tableModel.insertRows(insertPosition,1)
     
     for i,attr in enumerate(self._dbmodel.displayMapping().keys()):
         propIndex = self._tableModel.index(insertPosition,i)
         attrVal = getattr(modelObj,attr)
         
         #Check if there re display formatters and apply if one exists for the given attribute
         if attr in self._cellFormatters:
             attrVal = self._cellFormatters[attr](attrVal)
         if not attr in self._cellFormatters and isinstance(attrVal,date):
                     attrVal = dateFormatter(attrVal)
                     
         self._tableModel.setData(propIndex, attrVal)
コード例 #2
0
ファイル: entity_browser.py プロジェクト: 7o9/stdm-plugin
    def addModelToView(self,modelObj):
        '''
        Convenience method for adding model info into the view.
        '''
        try:
            insertPosition = self._tableModel.rowCount()
            self._tableModel.insertRows(insertPosition,1)

            for i,attr in enumerate(self._dbmodel.displayMapping().keys()):
                propIndex = self._tableModel.index(insertPosition, i)
                if hasattr(modelObj, attr):
                    attrVal = getattr(modelObj, attr)
                #QMessageBox.information(self, 'model',"propertyindex;{0}\nattributeVal;{1}".format(str(propIndex), str(attrVal)))
                #Check if there re display formatters and apply if one exists for the given attribute
                if attr in self._cellFormatters:
                    attrVal = self._cellFormatters[attr](attrVal)
                if not attr in self._cellFormatters and isinstance(attrVal, date):
                    attrVal = dateFormatter(attrVal)

                self._tableModel.setData(propIndex, attrVal)
        except Exception as ex:
            QMessageBox.information(self, QApplication.translate("EntityBrowser", "Updating row"), str(ex.message))
            return
コード例 #3
0
ファイル: entity_browser.py プロジェクト: 7o9/stdm-plugin
    def _initializeData(self):
        '''
        Set table model and load data into it.
        '''
        if self._dbmodel != None:
            headers = self._dbmodel.displayMapping().values()
            modelAttrs = self._dbmodel.displayMapping().keys()
            
            '''
            Load entity data. There might be a better way in future in order to ensure that
            there is a balance between user data discovery experience and performance.
            '''
            numRecords = self.recomputeRecordCount()
                        
            #Load progress dialog
            progressLabel = QApplication.translate("EntityBrowser", "Fetching Records...")
            progressDialog = QProgressDialog(progressLabel,"",0,numRecords,self)
            
            entity = self._dbmodel()
            entityRecords = entity.queryObject().filter().all()
            #entityRecordsList = [[getattr(er,attr)for attr in modelAttrs]for er in entityRecords]
            
            #Add records to nested list for enumeration in table model
            entityRecordsList = []
            for i,er in enumerate(entityRecords):
                entityRowInfo = []
                progressDialog.setValue(i)
                try:
                    for attr in modelAttrs:
                        attrVal = getattr(er,attr)

                        #Check if there are display formatters and apply if one exists for the given attribute
                        if attr in self._cellFormatters:
                            attrVal = self._cellFormatters[attr](attrVal)

                        if not attr in self._cellFormatters and isinstance(attrVal,date):
                            attrVal = dateFormatter(attrVal)

                        entityRowInfo.append(attrVal)
                except Exception as ex:
                    QMessageBox.information(None, QApplication.translate("EntityBrowser", "Loading dialog"), str(ex.message) )
                    return

                entityRecordsList.append(entityRowInfo)
                
            #Set maximum value of the progress dialog
            progressDialog.setValue(numRecords)
        
            self._tableModel = BaseSTDMTableModel(entityRecordsList,headers,self)
            
            #Add filter columns
            self.cboFilterColumn.addItems(headers)
            
            #Use sortfilter proxy model for the view
            self._proxyModel = QSortFilterProxyModel()
            self._proxyModel.setDynamicSortFilter(True)
            self._proxyModel.setSourceModel(self._tableModel)
            self._proxyModel.setSortCaseSensitivity(Qt.CaseInsensitive)
            self._proxyModel.setFilterKeyColumn(1) 
            
            self.tbEntity.setModel(self._proxyModel)
            self.tbEntity.setSortingEnabled(True)
            self.tbEntity.sortByColumn(1,Qt.AscendingOrder)
            
            #First (ID) column will always be hidden
            self.tbEntity.hideColumn(0)
            self.cboFilterColumn.removeItem(0)
            
            self.tbEntity.horizontalHeader().setResizeMode(QHeaderView.Stretch)
            
            #Connect signals
            self.connect(self.cboFilterColumn, SIGNAL("currentIndexChanged (int)"),self.onFilterColumnChanged)
            self.connect(self.txtFilterPattern, SIGNAL("textChanged(const QString&)"),self.onFilterRegExpChanged)