def applyConfigDialogFormats(self, addUndo=True): """Replace the formats with the duplicates and signal for view update. Also updates all nodes for changed type and field names. """ if addUndo: undo.FormatUndo(self.undoList, self.treeFormats, self.configDialogFormats) self.treeFormats.copySettings(self.configDialogFormats) self.treeFormats.updateDerivedRefs() self.treeFormats.updateMathFieldRefs() if self.configDialogFormats.fieldRenameDict: for node in self.nodeDict.values(): fieldRenameDict = (self.configDialogFormats.fieldRenameDict. get(node.formatRef.name, {})) tmpDataDict = {} for oldName, newName in fieldRenameDict.items(): if oldName in node.data: tmpDataDict[newName] = node.data[oldName] del node.data[oldName] node.data.update(tmpDataDict) self.configDialogFormats.fieldRenameDict = {} if self.treeFormats.emptiedMathDict: for node in self.nodeDict.values(): for fieldName in self.treeFormats.emptiedMathDict.get(node. formatRef. name, set()): node.data.pop(fieldName, None) self.formats.emptiedMathDict = {}
def retrieveRules(self): """Show a menu to retrieve stored rules. """ modelRef = globalref.mainControl.activeControl.model nodeFormats = modelRef.formats savedRules = nodeFormats.savedConditions() ruleNames = sorted(list(savedRules.keys())) dlg = RuleRetrieveDialog(ruleNames, self) if dlg.exec_() == QtGui.QDialog.Accepted: if dlg.selectedRule: conditional = savedRules[dlg.selectedRule] self.setCondition(conditional, conditional.origNodeFormatName) if dlg.removedRules: undo.FormatUndo(modelRef.undoList, nodeFormats, treeformats.TreeFormats()) for ruleName in dlg.removedRules: conditional = savedRules[ruleName] if conditional.origNodeFormatName: typeFormat = nodeFormats[ conditional.origNodeFormatName] del typeFormat.savedConditionText[ruleName] else: del nodeFormats.savedConditionText[ruleName] self.retrieveButton.setEnabled( len(nodeFormats.savedConditions()) > 0) globalref.mainControl.activeControl.setModified()
def applyConfigDialogFormats(self, addUndo=True): """Replace the formats with the duplicates and signal for view update. Also updates all nodes for changed type and field names. """ self.configDialogFormats.updateMathFieldRefs() if addUndo: undo.FormatUndo(self.undoList, self.formats, self.configDialogFormats) self.formats = self.configDialogFormats self.getConfigDialogFormats(True) if self.formats.typeRenameDict or self.formats.fieldRenameDict: for node in self.root.descendantGen(): node.formatName = (self.formats.typeRenameDict.get( node.formatName, node.formatName)) fieldRenameDict = (self.formats.fieldRenameDict.get( node.formatName, {})) for oldName, newName in fieldRenameDict.items(): if oldName in node.data: node.data[newName] = node.data[oldName] del node.data[oldName] self.formats.typeRenameDict = {} self.formats.fieldRenameDict = {} if self.formats.changedIdFieldTypes: for node in self.root.descendantGen(): if node.nodeFormat() in self.formats.changedIdFieldTypes: node.updateUniqueId() self.formats.changedIdFieldTypes = set() if self.formats.emptiedMathDict: for node in self.root.descendantGen(): for fieldName in self.formats.emptiedMathDict.get( node.formatName, set()): node.data.pop(fieldName, None) self.formats.emptiedMathDict = {} self.allModified.emit()
def deleteRule(self): """Remove the current saved rule. """ treeStructure = globalref.mainControl.activeControl.structure nodeFormats = treeStructure.treeFormats undo.FormatUndo(treeStructure.undoList, nodeFormats, treeformats.TreeFormats()) savedRules = nodeFormats.savedConditions() ruleName = self.saveListBox.currentItem().text() conditional = savedRules[ruleName] if conditional.origNodeFormatName: typeFormat = nodeFormats[conditional.origNodeFormatName] del typeFormat.savedConditionText[ruleName] else: del nodeFormats.savedConditionText[ruleName] self.loadSavedNames(True) globalref.mainControl.activeControl.setModified()
def saveRule(self): """Save the current rule settings. """ name = self.saveNameEdit.text() self.saveNameEdit.setText('') treeStructure = globalref.mainControl.activeControl.structure undo.FormatUndo(treeStructure.undoList, treeStructure.treeFormats, treeformats.TreeFormats()) typeName = self.typeCombo.currentText() if typeName == _allTypeEntry: nodeFormat = treeStructure.treeFormats else: nodeFormat = treeStructure.treeFormats[typeName] nodeFormat.savedConditionText[name] = ( self.conditional().conditionStr()) self.loadSavedNames(True) self.saveListBox.setCurrentItem( self.saveListBox.findItems(name, Qt.MatchExactly)[0]) globalref.mainControl.activeControl.setModified()
def saveRules(self): """Prompt for a name for storing these rules. """ modelRef = globalref.mainControl.activeControl.model nodeFormats = modelRef.formats usedNames = set(nodeFormats.savedConditions().keys()) dlg = configdialog.NameEntryDialog(_('Save Rules'), _('Enter a descriptive name'), '', '', usedNames, self) if dlg.exec_() == QtGui.QDialog.Accepted: undo.FormatUndo(modelRef.undoList, nodeFormats, treeformats.TreeFormats()) typeName = self.typeCombo.currentText() if typeName == _allTypeEntry: nodeFormat = nodeFormats else: nodeFormat = nodeFormats[typeName] nodeFormat.savedConditionText[dlg.text] = ( self.conditional().conditionStr()) self.retrieveButton.setEnabled(True) globalref.mainControl.activeControl.setModified()