From: Giovanni Gherdovich Date: Thu, 14 Oct 2010 16:41:46 +0000 (+0200) Subject: rspecview: html is now in now in the delegate for good. TODO: get rid of the up-left... X-Git-Url: http://git.onelab.eu/?p=sface.git;a=commitdiff_plain;h=fb132fb2d33c908789e05d5364283172f7db0d32 rspecview: html is now in now in the delegate for good. TODO: get rid of the up-left widget, highlight colouring right --- diff --git a/sface/xmlwidget.py b/sface/xmlwidget.py index 34578df..a6c36b3 100644 --- a/sface/xmlwidget.py +++ b/sface/xmlwidget.py @@ -8,6 +8,19 @@ from PyQt4.QtXml import * from sface.config import config from sface.screens.sfascreen import SfaScreen +def QVarMapAccess(qv, key): + # helper function. qv is a dict wrapped into a QVariant + print 10*'=' + print "DICT:", qv.toMap() + if len(qv.toMap().keys()) == 0: + print "EMPTY!" + import traceback + traceback.print_stack() + return None + else: + return qv.toMap()[QString(key)].toString() + + class DomModel(QAbstractItemModel): def __init__(self, document, parent = 0): QAbstractItemModel.__init__(self, parent) @@ -40,42 +53,58 @@ class DomModel(QAbstractItemModel): elem = ' %s="%s"' % (attr.nodeName(), attr.nodeValue()) qslist.append(elem) ElemNameAndAtts = '%s%s'% (node.nodeName(), qslist.join(' ')) + print "1" return QVariant( - {QString('nodeType'):QVariant(QString('element')), - QString('content'):ElemNameAndAtts}) + {'nodeType':QVariant(QString('element')), + 'content':ElemNameAndAtts}) elif node.nodeType() == QDomNode.AttributeNode: + print "2" return QVariant() elif node.nodeType() == QDomNode.TextNode: + print "3" return QVariant( - {QString('nodeType'):QVariant(QString('text')), - QString('content'):node.nodeValue()}) + {'nodeType':QVariant(QString('text')), + 'content':node.nodeValue()}) elif node.nodeType() == QDomNode.CDATASectionNode: + print "4" return QString('unsupported node type') elif node.nodeType() == QDomNode.EntityReferenceNode: + print "5" return QString('unsupported node type') elif node.nodeType() == QDomNode.EntityNode: + print "6" return QString('unsupported node type') elif node.nodeType() == QDomNode.ProcessingInstructionNode: + print "7" return QVariant() elif node.nodeType() == QDomNode.CommentNode: + print "8" return QVariant( - {QString('nodeType'):QVariant(QString('comment')), - QString('content'):node.nodeValue()}) + {'nodeType':QVariant(QString('comment')), + 'content':node.nodeValue()}) elif node.nodeType() == QDomNode.DocumentNode: + print "9" return QString('unsupported node type') elif node.nodeType() == QDomNode.DocumentTypeNode: + print "10" return QString('unsupported node type') elif node.nodeType() == QDomNode.DocumentFragmentNode: + print "12" return QString('unsupported node type') elif node.nodeType() == QDomNode.NotationNode: + print "13" return QString('unsupported node type') elif node.nodeType() == QDomNode.BaseNode: + print "14" return QString('unsupported node type') elif node.nodeType() == QDomNode.CharacterDataNode: + print "15" return QString('unsupported node type') else: + print "16" return QVariant() else: + print "17" return QVariant() def flags(self, index): @@ -225,12 +254,11 @@ class XmlDelegate(QItemDelegate): del self.delegates[nodeType] def paint(self, painter, option, index): - QVarMapAccess = lambda qv, key: qv.toMap()[QString(key)].toString() + print "ASKING FOR DATA" dataAsQVarMap = index.model().data(index) + print "GOT DATA" nodeType = str(QVarMapAccess(dataAsQVarMap, 'nodeType')) delegate = self.delegates.get(nodeType) - print "WTF IS THIS TYPE:", type(index.model().data(index)) - print "NODE TYPE:", nodeType #print "DELEGS DICT:", self.delegates #print "NODETYPE:", nodeType.toString() if delegate is not None: @@ -239,7 +267,7 @@ class XmlDelegate(QItemDelegate): else: #print "ELSE BRANCH" # not sure this will ever work. this delegate - # doesn't know about my QObject strategy. + # doesn't know about my QMap strategy. QItemDelegate.paint(self, painter, option, index) # def sizeHint(self, option, index): @@ -287,7 +315,6 @@ class ElemNodeDelegate(QAbstractItemDelegate): return html def colorize(color, text): return '' + text + '' - QVarMapAccess = lambda qv, key: qv.toMap()[QString(key)].toString() dataAsQVarMap = index.model().data(index) text = str(QVarMapAccess(dataAsQVarMap, 'content')) if option.state & QStyle.State_Selected: @@ -318,7 +345,6 @@ class TextNodeDelegate(QAbstractItemDelegate): return '
' + text + '' + text + ''
-        QVarMapAccess = lambda qv, key: qv.toMap()[QString(key)].toString()
         dataAsQVarMap = index.model().data(index)
         text = str(QVarMapAccess(dataAsQVarMap, 'content'))
         if option.state & QStyle.State_Selected: