def loadReportSettings(self,file): #Helper for restoring previously saved report settings #Deserialize report settings rptSerializer = ReportSerializer(file) rptValid, rptConf = rptSerializer.deserialize() #Validate if the object is an STDM Report Settings file if rptValid: #Check if the table exists tabExists = self._tableExists(rptConf.table) #QMessageBox.information(self, "List of tables", str(rptConf.table)) if tabExists: self.showhideProgressDialog(QApplication.translate("ReportBuilder","Restoring Report Settings...")) #friendlyTabName = self.tabNames[rptConf.table] friendlyTabName = rptConf.table #Force builder reset even if the loaded report refers to the previously loaded table if rptConf.table == self.tabName: self.tabChanged(friendlyTabName) else: self.tabName = rptConf.table #QMessageBox.information(self, "table name name", str(self.tabName)) #Set focus to report table in the drop down menu setComboCurrentIndexWithItemData(self.comboBox, friendlyTabName) #Validate the fields validTabFields = table_column_names(rptConf.table) validRptFields, invalidRptFields = compareLists(validTabFields, rptConf.fields) #Configure supporting controls self.loadSettings_activateControls(validRptFields) #Set filter statement self.txtSqlParser.setText(rptConf.filter) #Group order container gpInfoCollection =[] #Sort info container sortInfoCollection =[] #Iterate report elements for r in rptConf.reportElementCollection: if r.parent != "Groups": #Get corresponding widget and load the settings rptWidg = self.__displayGetStWidget(r.name) if not rptWidg == None: rptWidg.loadSettings(r.dialogSettings) #Set grouping and sorting configuration if r.parent == "Fields": gpInfo = r.uiConfiguration.groupingInfo if gpInfo != None: gpInfo.field = r.name gpInfoCollection.append(gpInfo) fieldSort = r.uiConfiguration.sortInfo if fieldSort.direction != SortDir.Null: fieldSort.field = r.name sortInfoCollection.append(fieldSort) #Sort GROUPINFO items using the order attribute then add fields to the report builder controls gpInfoCollection.sort(key=lambda g: g.order) for g in gpInfoCollection: groupDlg = self.grouping_addFieldByName(g.field) groupDlg.loadSettings(g.dialogSettings) #Order SORTINFO items using the order attribute then add fields to the report builder controls sortInfoCollection.sort(key=lambda s: s.order) for s in sortInfoCollection: sortItem = self.sorting_getFieldItem(s.field) if sortItem is not None: rowIndex = sortItem.row() dirCombo = self.tbSortFields.cellWidget(rowIndex,1) if s.direction == SortDir.Ascending: setComboCurrentIndexWithText(dirCombo, "Ascending") elif s.direction == SortDir.Descending: setComboCurrentIndexWithText(dirCombo, "Descending") #Show message of invalid fields if len(invalidRptFields) > 0: fieldsStr = ",".join(invalidRptFields) msg = QApplication.translate("ReportBuilder"," columns do not exist in the current table definition." "\nThey will not be included in the report") self.ErrorInfoMessage(fieldsStr + msg) else: self.showhideProgressDialog("", False) msg = QApplication.translate("ReportBuilder"," table or view does not exist in the database") self.ErrorInfoMessage(rptConf.table + msg) else: self.showhideProgressDialog("", False) fileName = str(file.section("/",-1)) msg = QApplication.translate("ReportBuilder"," is not a valid STDM Report Settings file.\n " "Please validate the source of the file") self.ErrorInfoMessage(fileName +msg ) self.showhideProgressDialog("", False)