예제 #1
0
    def testSplitLines(self):
        doc = QgsTextDocument.fromHtml(['abc def'])
        self.assertEqual(len(doc), 1)
        self.assertEqual(len(doc[0]), 1)
        self.assertEqual(doc[0][0].text(), 'abc def')
        doc.splitLines(' ')
        self.assertEqual(len(doc), 2)
        self.assertEqual(len(doc[0]), 1)
        self.assertEqual(doc[0][0].text(), 'abc')
        self.assertEqual(len(doc[1]), 1)
        self.assertEqual(doc[1][0].text(), 'def')

        doc = QgsTextDocument.fromHtml(['<span style="color: red">R_ED</span> not <div>red</div>'])
        self.assertEqual(len(doc), 2)
        self.assertEqual(len(doc[0]), 2)
        self.assertEqual(doc[0][0].text(), 'R_ED')
        self.assertEqual(doc[0][1].text(), ' not ')
        self.assertEqual(len(doc[1]), 1)
        self.assertEqual(doc[1][0].text(), 'red')
        doc.splitLines(' ')
        self.assertEqual(len(doc), 4)
        self.assertEqual(len(doc[0]), 1)
        self.assertEqual(doc[0][0].text(), 'R_ED')
        self.assertEqual(len(doc[1]), 1)
        self.assertEqual(doc[1][0].text(), 'not')
        self.assertEqual(len(doc[2]), 1)
        self.assertEqual(doc[2][0].text(), '')
        self.assertEqual(len(doc[3]), 1)
        self.assertEqual(doc[3][0].text(), 'red')

        doc = QgsTextDocument.fromHtml(['<span style="color: red">R_ED</span> not <div>red</div>'])
        doc.splitLines('_')
        self.assertEqual(len(doc), 3)
        self.assertEqual(len(doc[0]), 1)
        self.assertEqual(doc[0][0].text(), 'R')
        self.assertEqual(len(doc[1]), 2)
        self.assertEqual(doc[1][0].text(), 'ED')
        self.assertEqual(doc[1][1].text(), ' not ')
        self.assertEqual(len(doc[2]), 1)
        self.assertEqual(doc[2][0].text(), 'red')
예제 #2
0
 def testFromHtml(self):
     doc = QgsTextDocument.fromHtml(['abc<div style="color: red"><b style="text-decoration: underline">def</b> ghi<div>jkl</div></div>', 'b c d', 'e'])
     self.assertEqual(len(doc), 5)
     self.assertEqual(len(doc[0]), 1)
     self.assertEqual(doc[0][0].text(), 'abc')
     self.assertEqual(doc[0][0].characterFormat().underline(), QgsTextCharacterFormat.BooleanValue.NotSet)
     self.assertFalse(doc[0][0].characterFormat().textColor().isValid())
     self.assertEqual(len(doc[1]), 2)
     self.assertEqual(doc[1][0].text(), 'def')
     self.assertEqual(doc[1][0].characterFormat().underline(), QgsTextCharacterFormat.BooleanValue.SetTrue)
     self.assertEqual(doc[1][0].characterFormat().textColor().name(), '#ff0000')
     self.assertEqual(doc[1][1].text(), ' ghi')
     self.assertEqual(doc[1][1].characterFormat().underline(), QgsTextCharacterFormat.BooleanValue.NotSet)
     self.assertEqual(doc[1][1].characterFormat().textColor().name(), '#ff0000')
     self.assertEqual(len(doc[2]), 1)
     self.assertEqual(doc[2][0].text(), 'jkl')
     self.assertEqual(len(doc[3]), 1)
     self.assertEqual(doc[3][0].text(), 'b c d')
     self.assertEqual(len(doc[4]), 1)
     self.assertEqual(doc[4][0].text(), 'e')
예제 #3
0
 def testToPlainText(self):
     self.assertEqual(QgsTextDocument.fromHtml(['']).toPlainText(), [])
     self.assertEqual(QgsTextDocument.fromHtml(['abc']).toPlainText(), ['abc'])
     self.assertEqual(QgsTextDocument.fromHtml(['abc\ndef']).toPlainText(), ['abc def'])
     self.assertEqual(QgsTextDocument.fromHtml(['abc<b>def</b>']).toPlainText(), ['abcdef'])
     self.assertEqual(QgsTextDocument.fromHtml(['abc<div><b>def</b><div>ghi</div></div>']).toPlainText(), ['abc', 'def', 'ghi'])