Esempio n. 1
0
 def saveReportSettings(self,file):
     #Helper for saving user report settings to file
     self.showhideProgressDialog(QApplication.translate("ReportBuilder","Saving Report Settings..."))
     
     #Create report config object
     rptConfig = STDMReportConfig(self.tabName)
     #Loop through all report elements' settings
     for i in range(self.stackedWidget.count()):
         w = self.stackedWidget.widget(i)
         
         #Get report element 
         rptEl = w.getSettings()
         
         #Group dialog settings are not added directly to the collection but through the DBField proxy
         if not rptEl.parent == "Groups":               
             #Check if it is a definition for database fields
             if rptEl.parent == "Fields":
                 df = DbField()   
                                
                 #copy attributes from ReportElement base to DbField object
                 copyattrs(rptEl,df,["dialogSettings","parent","name"])   
                                                              
                 #Set field configuration
                 fc = FieldConfig()
                 fc.sortInfo = self.sorting_getFieldConfig(rptEl.name)
                 
                 #Set grouping information
                 gi = self.grouping_getFieldConfig(rptEl.name)
                 if not gi == None:
                     gpDialog = self.__displayGetStWidget("gp_" + rptEl.name)
                     if gpDialog != None:                          
                         gi.dialogSettings = gpDialog.getSettings().dialogSettings
                         fc.groupingInfo = gi
                         
                 #Get field index
                 fc.reportOrder = self.rptFields.index(rptEl.name)
                 df.uiConfiguration = fc              
                 rptEl = df
             rptConfig.addElement(rptEl)   
                    
     rptConfig.setFilter(str(self.txtSqlParser.toPlainText()))
     rptConfig.setVersion(1.1)
     
     #Serialize to file 
     rptSerializer = ReportSerializer(file) 
     rptSerializer.serialize(rptConfig)
     self.showhideProgressDialog("",False)
Esempio n. 2
0
    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)