예제 #1
0
    def test_data_name_attr_true(self):
        fun = sys._getframe().f_code.co_name
        print "Run: %s.%s() " % (self.__class__.__name__, fun)

        doc = QDomDocument()
        nname = "definition"
        qdn = doc.createElement(nname)
        doc.appendChild(qdn)
        nkids = self.__rnd.randint(1, 10)
        kds = []
        tkds = []
        for n in range(nkids):
            kds.append(doc.createElement("kid%s" % n))
            kds[-1].setAttribute("name", "myname%s" % n)
            kds[-1].setAttribute("type", "mytype%s" % n)
            kds[-1].setAttribute("units", "myunits%s" % n)
            qdn.appendChild(kds[-1])
            tkds.append(doc.createTextNode("\nText\n %s\n" % n))
            kds[-1].appendChild(tkds[-1])

#        print doc.toString()

        allAttr = True
        cm = ComponentModel(doc, allAttr)
        self.assertTrue(isinstance(cm, QAbstractItemModel))
        self.assertTrue(isinstance(cm.rootIndex, QModelIndex))
        cd = cm.rootIndex.internalPointer()
        self.assertTrue(isinstance(cd, ComponentItem))
        self.assertEqual(cm.rootIndex.row(), 0)
        self.assertEqual(cm.rootIndex.column(), 0)
        self.assertEqual(cm.headerData(0, Qt.Vertical), None)

        ri = cm.rootIndex
        di = cm.index(0, 0, ri)
        ci = cd.child(0)
        for n in range(nkids):
            kd = ci.child(n)

            ki0 = cm.index(n, 0, di)
            dt = cm.data(ki0)
            self.assertTrue(isinstance(dt, QVariant))
            self.assertEqual(dt.toString(), 'kid%s: myname%s' % (n, n))

            ki1 = cm.index(n, 1, di)
            dt = cm.data(ki1)
            self.assertTrue(isinstance(dt, QVariant))
            self.assertEqual(
                str(dt.toString()).strip(),
                'units="myunits%s" type="mytype%s" name="myname%s"' %
                (n, n, n))

            ki2 = cm.index(n, 2, di)
            dt = cm.data(ki2)
            self.assertTrue(isinstance(dt, QVariant))
            self.assertEqual(str(dt.toString()).strip(), '')
예제 #2
0
    def test_data(self):
        fun = sys._getframe().f_code.co_name
        print "Run: %s.%s() " % (self.__class__.__name__, fun)

        doc = QDomDocument()
        nname = "definition"
        qdn = doc.createElement(nname)
        doc.appendChild(qdn)
        nkids = self.__rnd.randint(1, 10)
        kds = []
        for n in range(nkids):
            kds.append(doc.createElement("kid%s" % n))
            qdn.appendChild(kds[-1])

        allAttr = False
        cm = ComponentModel(doc, allAttr)
        self.assertTrue(isinstance(cm, QAbstractItemModel))
        self.assertTrue(isinstance(cm.rootIndex, QModelIndex))
        cd = cm.rootIndex.internalPointer()
        self.assertTrue(isinstance(cd, ComponentItem))
        self.assertEqual(cm.rootIndex.row(), 0)
        self.assertEqual(cm.rootIndex.column(), 0)
        self.assertEqual(cm.headerData(0, Qt.Vertical), None)

        dt = cm.data(QModelIndex())
        self.assertTrue(isinstance(dt, QVariant))
        self.assertEqual(dt.toString(), '')

        for role in range(1, 5):
            dt = cm.data(cm.rootIndex, role)
            self.assertTrue(isinstance(dt, QVariant))
            self.assertEqual(dt.toString(), '')

        dt = cm.data(cm.rootIndex)
        self.assertTrue(isinstance(dt, QVariant))
        self.assertEqual(dt.toString(), '#document')

        dt = cm.data(cm.rootIndex, Qt.DisplayRole)
        self.assertTrue(isinstance(dt, QVariant))
        self.assertEqual(dt.toString(), '#document')
예제 #3
0
    def test_headerData(self):
        fun = sys._getframe().f_code.co_name
        print "Run: %s.%s() " % (self.__class__.__name__, fun)

        doc = QDomDocument()
        nname = "definition"
        qdn = doc.createElement(nname)
        doc.appendChild(qdn)
        nkids = self.__rnd.randint(1, 10)
        kds = []
        for n in range(nkids):
            kds.append(doc.createElement("kid%s" % n))
            qdn.appendChild(kds[-1])

        allAttr = False
        cm = ComponentModel(doc, allAttr)
        self.assertTrue(isinstance(cm, QAbstractItemModel))
        self.assertTrue(isinstance(cm.rootIndex, QModelIndex))
        cd = cm.rootIndex.internalPointer()
        self.assertTrue(isinstance(cd, ComponentItem))
        self.assertEqual(cm.rootIndex.row(), 0)
        self.assertEqual(cm.rootIndex.column(), 0)
        self.assertEqual(cm.headerData(0, Qt.Vertical), None)

        hd = cm.headerData(0, Qt.Horizontal)
        self.assertTrue(isinstance(hd, QVariant))
        self.assertEqual(hd.toString(), 'Name')
        hd = cm.headerData(0, Qt.Horizontal, Qt.DisplayRole)
        self.assertTrue(isinstance(hd, QVariant))
        self.assertEqual(hd.toString(), 'Name')

        hd = cm.headerData(1, Qt.Horizontal)
        self.assertTrue(isinstance(hd, QVariant))
        self.assertEqual(hd.toString(), 'Type')
        hd = cm.headerData(1, Qt.Horizontal, Qt.DisplayRole)
        self.assertTrue(isinstance(hd, QVariant))
        self.assertEqual(hd.toString(), 'Type')

        hd = cm.headerData(2, Qt.Horizontal)
        self.assertTrue(isinstance(hd, QVariant))
        self.assertEqual(hd.toString(), 'Value')
        hd = cm.headerData(2, Qt.Horizontal, Qt.DisplayRole)
        self.assertTrue(isinstance(hd, QVariant))
        self.assertEqual(hd.toString(), 'Value')

        hd = cm.headerData(3, Qt.Horizontal)
        self.assertTrue(isinstance(hd, QVariant))
        self.assertEqual(hd.toString(), '')
        hd = cm.headerData(3, Qt.Horizontal, Qt.DisplayRole)
        self.assertTrue(isinstance(hd, QVariant))
        self.assertEqual(hd.toString(), '')

        hd = cm.headerData(-1, Qt.Horizontal)
        self.assertTrue(isinstance(hd, QVariant))
        self.assertEqual(hd.toString(), '')
        hd = cm.headerData(-1, Qt.Horizontal, Qt.DisplayRole)
        self.assertTrue(isinstance(hd, QVariant))
        self.assertEqual(hd.toString(), '')

        cm.setAttributeView(True)

        hd = cm.headerData(1, Qt.Horizontal)
        self.assertTrue(isinstance(hd, QVariant))
        self.assertEqual(hd.toString(), 'Attributes')
        hd = cm.headerData(1, Qt.Horizontal, Qt.DisplayRole)
        self.assertTrue(isinstance(hd, QVariant))
        self.assertEqual(hd.toString(), 'Attributes')

        cm.setAttributeView(False)

        hd = cm.headerData(1, Qt.Horizontal)
        self.assertTrue(isinstance(hd, QVariant))
        self.assertEqual(hd.toString(), 'Type')
        hd = cm.headerData(1, Qt.Horizontal, Qt.DisplayRole)
        self.assertTrue(isinstance(hd, QVariant))
        self.assertEqual(hd.toString(), 'Type')

        allAttr = True
        cm = ComponentModel(doc, allAttr)
        hd = cm.headerData(1, Qt.Horizontal)
        self.assertTrue(isinstance(hd, QVariant))
        self.assertEqual(hd.toString(), 'Attributes')
        hd = cm.headerData(1, Qt.Horizontal, Qt.DisplayRole)
        self.assertTrue(isinstance(hd, QVariant))
        self.assertEqual(hd.toString(), 'Attributes')