From c4fc02cbcfff975712e977dc08f859fba71ba0ad Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Mon, 9 Jul 2018 11:49:26 -0300 Subject: [PATCH] Arch: fixed bug in non-GUI mode --- src/Mod/Arch/ArchComponent.py | 166 +++++++++++++++++----------------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/src/Mod/Arch/ArchComponent.py b/src/Mod/Arch/ArchComponent.py index 21dec51bbd..c633804be3 100644 --- a/src/Mod/Arch/ArchComponent.py +++ b/src/Mod/Arch/ArchComponent.py @@ -1350,94 +1350,94 @@ class ComponentTaskPanel: pset = self.ifcModel.itemFromIndex(sel[0].parent()) pset.takeRow(sel[0].row()) +if FreeCAD.GuiUp: - -class IfcEditorDelegate(QtGui.QStyledItemDelegate): - - - def __init__(self, parent=None, dialog=None, ptypes=[], plabels=[], *args): - - self.dialog = dialog - QtGui.QStyledItemDelegate.__init__(self, parent, *args) - self.ptypes = ptypes - self.plabels = plabels - - def createEditor(self,parent,option,index): - - if index.column() == 0: # property name - editor = QtGui.QLineEdit(parent) - elif index.column() == 1: # property type - editor = QtGui.QComboBox(parent) - else: # property value - ptype = index.sibling(index.row(),1).data() - if "Integer" in ptype: - editor = QtGui.QSpinBox(parent) - elif "Real" in ptype: - editor = QtGui.QDoubleSpinBox(parent) - editor.setDecimals(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").GetInt("Decimals",2)) - elif ("Boolean" in ptype) or ("Logical" in ptype): - editor = QtGui.QComboBox(parent) - editor.addItems(["True","False"]) - elif "Measure" in ptype: - editor = FreeCADGui.UiLoader().createWidget("Gui::InputField") - editor.setParent(parent) - else: + class IfcEditorDelegate(QtGui.QStyledItemDelegate): + + + def __init__(self, parent=None, dialog=None, ptypes=[], plabels=[], *args): + + self.dialog = dialog + QtGui.QStyledItemDelegate.__init__(self, parent, *args) + self.ptypes = ptypes + self.plabels = plabels + + def createEditor(self,parent,option,index): + + if index.column() == 0: # property name editor = QtGui.QLineEdit(parent) - editor.setObjectName("editor_"+ptype) - return editor - - def setEditorData(self, editor, index): - - if index.column() == 0: - editor.setText(index.data()) - elif index.column() == 1: - editor.addItems(self.plabels) - if index.data() in self.plabels: - idx = self.plabels.index(index.data()) - editor.setCurrentIndex(idx) - else: - if "Integer" in editor.objectName(): - try: - editor.setValue(int(index.data())) - except: - editor.setValue(0) - elif "Real" in editor.objectName(): - try: - editor.setValue(float(index.data())) - except: - editor.setValue(0) - elif ("Boolean" in editor.objectName()) or ("Logical" in editor.objectName()): - try: - editor.setCurrentIndex(["true","false"].index(index.data().lower())) - except: - editor.setCurrentIndex(1) - elif "Measure" in editor.objectName(): - try: - editor.setText(index.data()) - except: - editor.setValue(0) - else: + elif index.column() == 1: # property type + editor = QtGui.QComboBox(parent) + else: # property value + ptype = index.sibling(index.row(),1).data() + if "Integer" in ptype: + editor = QtGui.QSpinBox(parent) + elif "Real" in ptype: + editor = QtGui.QDoubleSpinBox(parent) + editor.setDecimals(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").GetInt("Decimals",2)) + elif ("Boolean" in ptype) or ("Logical" in ptype): + editor = QtGui.QComboBox(parent) + editor.addItems(["True","False"]) + elif "Measure" in ptype: + editor = FreeCADGui.UiLoader().createWidget("Gui::InputField") + editor.setParent(parent) + else: + editor = QtGui.QLineEdit(parent) + editor.setObjectName("editor_"+ptype) + return editor + + def setEditorData(self, editor, index): + + if index.column() == 0: editor.setText(index.data()) - - def setModelData(self, editor, model, index): - - if index.column() == 0: - model.setData(index,editor.text()) - elif index.column() == 1: - if editor.currentIndex() > -1: - idx = editor.currentIndex() - data = self.plabels[idx] - model.setData(index,data) - else: - if ("Integer" in editor.objectName()) or ("Real" in editor.objectName()): - model.setData(index,str(editor.value())) - elif ("Boolean" in editor.objectName()) or ("Logical" in editor.objectName()): - model.setData(index,editor.currentText()) - elif "Measure" in editor.objectName(): - model.setData(index,editor.property("text")) + elif index.column() == 1: + editor.addItems(self.plabels) + if index.data() in self.plabels: + idx = self.plabels.index(index.data()) + editor.setCurrentIndex(idx) else: + if "Integer" in editor.objectName(): + try: + editor.setValue(int(index.data())) + except: + editor.setValue(0) + elif "Real" in editor.objectName(): + try: + editor.setValue(float(index.data())) + except: + editor.setValue(0) + elif ("Boolean" in editor.objectName()) or ("Logical" in editor.objectName()): + try: + editor.setCurrentIndex(["true","false"].index(index.data().lower())) + except: + editor.setCurrentIndex(1) + elif "Measure" in editor.objectName(): + try: + editor.setText(index.data()) + except: + editor.setValue(0) + else: + editor.setText(index.data()) + + def setModelData(self, editor, model, index): + + if index.column() == 0: model.setData(index,editor.text()) - self.dialog.update() + elif index.column() == 1: + if editor.currentIndex() > -1: + idx = editor.currentIndex() + data = self.plabels[idx] + model.setData(index,data) + else: + if ("Integer" in editor.objectName()) or ("Real" in editor.objectName()): + model.setData(index,str(editor.value())) + elif ("Boolean" in editor.objectName()) or ("Logical" in editor.objectName()): + model.setData(index,editor.currentText()) + elif "Measure" in editor.objectName(): + model.setData(index,editor.property("text")) + else: + model.setData(index,editor.text()) + self.dialog.update()