Beispiel #1
0
    def _initPersonFilter(self):
        '''
        Initializes person filter settings
        '''

        cols=table_searchable_cols('party')
        if len(cols)>0:
            for col in cols:
                self.cboPersonFilterCols.addItem(str(QApplication.translate("newSTRWiz",col.replace('_',' ').title())), col)
Beispiel #2
0
    def _initializeData(self):
        """
        Set table model and load data into it.
        """
        if not self._dbmodel is None:
            display_mapping = self._dbmodel.displayMapping()
            headers = display_mapping.values()
            modelAttrs = display_mapping.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.critical(
                        self, QApplication.translate("EntityBrowser", "Loading Entity"), unicode(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
            class_name = entity.__class__.__name__.replace(" ", "_").lower()
            if table_searchable_cols(class_name):
                self.cboFilterColumn.addItems(table_searchable_cols(class_name))

            # Use sortfilter proxy model for the view
            self._proxyModel = VerticalHeaderSortFilterProxyModel()
            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.Interactive)

            # Connect signals
            self.connect(self.cboFilterColumn, SIGNAL("currentIndexChanged (int)"), self.onFilterColumnChanged)
            self.connect(self.txtFilterPattern, SIGNAL("textChanged(const QString&)"), self.onFilterRegExpChanged)