ignore qvariants when painting and computing size; fix duplicate treeview in rspec...
[sface.git] / sface / xmlwidget.py
index a2d3ec2..a803868 100644 (file)
@@ -85,7 +85,7 @@ class DomModel(QAbstractItemModel):
         if not index.isValid():
             return Qt.ItemIsEnabled
         return Qt.ItemIsEnabled | Qt.ItemIsSelectable
-        
+
     def headerData(self, section, orientation, role):
         return QVariant()
 
@@ -176,7 +176,7 @@ class XmlWindow(QDialog):
         self.model = None
         self.title = title
 
-        self.view = XmlView(self)
+        self.view = self.initView()
         self.delegate = XmlDelegate(self)
         self.view.setItemDelegate(self.delegate)
         self.delegate.insertNodeDelegate('element', ElemNodeDelegate())
@@ -188,6 +188,9 @@ class XmlWindow(QDialog):
 
         self.updateView()
 
+    def initView(self):
+        return XmlView(self)
+
     def show(self):
         self.updateView()
         QDialog.show(self)
@@ -228,6 +231,8 @@ class XmlDelegate(QItemDelegate):
             del self.delegates[nodeType]
     
     def paint(self, painter, option, index):
+        if isinstance(index.model().data(index),QVariant):
+            return
         nodeType = index.model().data(index).property('nodeType')
         delegate = self.delegates.get(str(nodeType.toString()))
         #print "TYPE:", str(type(str(nodeType.toString())))
@@ -244,6 +249,8 @@ class XmlDelegate(QItemDelegate):
 
     def sizeHint(self, option, index):
         fm = option.fontMetrics
+        if isinstance(index.model().data(index),QVariant):
+            return QSize(0, 0)
         text = index.model().data(index).property('content').toString()
         document = QTextDocument()
         document.setDefaultFont(option.font)
@@ -263,9 +270,9 @@ class ElemNodeDelegate(QAbstractItemDelegate):
         highGlobPattern = '&lt;<b>%s</b>%s&gt;'
         highAttPattern = ' <b>%s</b>="%s"'
         def getHtmlText(plainText, globPattern, attPattern):
-            print "PLAIN TEXT:", plainText
+#            print "PLAIN TEXT:", plainText
             tmp = plainText.split(' ', 1)
-            print "TMP:", tmp
+#            print "TMP:", tmp
             elemName = tmp[0]
             AttListHtml = ''
             if len(tmp) > 1:
@@ -281,7 +288,7 @@ class ElemNodeDelegate(QAbstractItemDelegate):
         def colorize(color, text):
             return '<font color=' + color + '>' + text + '</font>'
         text = str(index.model().data(index).property('content').toString())
-        print "TEXT:", text
+#        print "TEXT:", text
         if option.state & QStyle.State_Selected:
             htmlText = colorize(palette.highlightedText().color().name(),
                                 getHtmlText(text, highGlobPattern, highAttPattern))
@@ -293,7 +300,7 @@ class ElemNodeDelegate(QAbstractItemDelegate):
             if option.state & QStyle.State_Selected \
             else palette.base().color()
         painter.save()
-        print "COLOR:", color.name()
+#        print "COLOR:", color.name()
         # voodoo: if not highlighted, filling the rect
         # with the base color makes no difference
         painter.fillRect(option.rect, color)