simplify string operations.
authorBarış Metin <Talip-Baris.Metin@sophia.inria.fr>
Wed, 15 Sep 2010 10:44:04 +0000 (12:44 +0200)
committerBarış Metin <Talip-Baris.Metin@sophia.inria.fr>
Wed, 15 Sep 2010 10:44:04 +0000 (12:44 +0200)
expand only first level in rspecscreen

sface/screens/rspecscreen.py

index 772f4cb..e7edb47 100644 (file)
@@ -30,8 +30,7 @@ class DomModel(QAbstractItemModel):
         childList = document.childNodes()
         for i in range(childList.count()):
             currElem = childList.item(i)
-            if (currElem.nodeType() ==
-                QDomNode.ProcessingInstructionNode):
+            if (currElem.nodeType() == QDomNode.ProcessingInstructionNode):
                 document.removeChild(currElem)
                 break
         self.rootItem = DomItem(document, 0);
@@ -50,16 +49,9 @@ class DomModel(QAbstractItemModel):
                 qslist = QStringList()
                 for i in range(attributeMap.count()):
                     attr = attributeMap.item(i)
-                    elem = (attr.nodeName()
-                            .append(QString('="'))
-                            .append(attr.nodeValue())
-                            .append(QString('"')))
+                    elem = '%s="%s"' % (attr.nodeName(), attr.nodeValue())
                     qslist.append(elem)
-                return (QString('<').
-                        append(node.nodeName()).
-                        append(' ').
-                        append(qslist.join(' ')).
-                        append('>'))
+                return QString("<%s %s>" % (node.nodeName(), qslist.join(' ')))
             elif node.nodeType() == QDomNode.AttributeNode:
                 return QString('Whozat?!')
             elif node.nodeType() == QDomNode.TextNode:
@@ -95,14 +87,13 @@ class DomModel(QAbstractItemModel):
     def flags(self, index):
         if not index.isValid():
             return Qt.ItemIsEnabled
-        # does this `|` thing hold?
         return Qt.ItemIsEnabled | Qt.ItemIsSelectable
         
     def headerData(self, section, orientation, role):
         return QVariant()
 
-    def index(self, row, column, parent):
-        if not parent.isValid():
+    def index(self, row, column, parent=None):
+        if not parent or not parent.isValid():
             parentItem = self.rootItem
         else:
             parentItem = parent.internalPointer()
@@ -133,16 +124,14 @@ class DomModel(QAbstractItemModel):
         return parentItem.node().childNodes().count()
 
     def columnCount(self, parent):
-        # just one column
-        # we'll print tag name (and attributes)
-        # or the tag content
+        # just one column we'll print tag name (and attributes) or the
+        # tag content
         return 1
 
 
 class DomItem:
-    # wrapper around PyQt4.QtXml.QDomNode
-    # it keeps an hash of childrens for
-    # performance reasons
+    # wrapper around PyQt4.QtXml.QDomNode it keeps an hash of
+    # childrens for performance reasons
 
     def __init__(self, node, row, parent = 0):
         # node is of type PyQt4.QtXml.QDomNode
@@ -171,7 +160,6 @@ class DomItem:
         return self.rowNumber
     
 
-
 class RSpecWidget(QWidget):
     def __init__(self, parent=None):
         QWidget.__init__(self, parent)
@@ -179,7 +167,6 @@ class RSpecWidget(QWidget):
         self.view = RSpecView(self)
         self.updateView()
         
-
     def updateView(self):
         document = QDomDocument("RSpec")
         rspec_file = config.getSliceRSpecFile()
@@ -191,8 +178,7 @@ class RSpecWidget(QWidget):
 
         view = RSpecView(self)
         view.setModel(model)
-# too slow!
-#        view.expandAll()
+        view.expand(model.index(0, 0)) #expand first level only
 
         layout = QVBoxLayout()
         layout.addWidget(view)