def test_split_cells(self): doc = Doc(Config()) doc.text.setPlainText("1 row\n 2 row\n3 row") doc.insert_table({"padding": 0, "space": 0, "rows": 4, "cols": 3}) def in_table(): c = QTextCursor(doc.text) c.movePosition(QTextCursor.Start) while c.movePosition(QTextCursor.NextCharacter, QTextCursor.KeepAnchor): if doc.in_table(): cc = doc.table().cellAt(2, 2) cc.firstCursorPosition().insertText("Hello1") cc = doc.table().cellAt(2, 1) cc.firstCursorPosition().insertText("Hello") c.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor) break in_table() doc.table().mergeCells(0, 0, 2, 2) doc.split_cells() self.assertFalse("colspan" in doc.text.toHtml())
def test_table(self): doc = Doc(Config()) doc.text.setPlainText("1 row\n 2 row\n3 row") self.assertEqual(doc.table(), None) doc.insert_table({"padding": 0, "space": 0, "rows": 3, "cols": 2}) def in_table(): c = QTextCursor(doc.text) c.movePosition(QTextCursor.Start) while c.movePosition(QTextCursor.NextCharacter, QTextCursor.KeepAnchor): if doc.in_table(): break in_table() self.assertTrue("QTextTable" in str(type(doc.table())))
def test_ins_col(self): doc = Doc(Config()) doc.text.setPlainText("1 row\n 2 row\n3 row") doc.insert_table({"padding": 0, "space": 0, "rows": 3, "cols": 2}) def in_table(): c = QTextCursor(doc.text) c.movePosition(QTextCursor.Start) while c.movePosition(QTextCursor.NextCharacter, QTextCursor.KeepAnchor): if doc.in_table(): break in_table() self.assertEqual(doc.table().rows(), 3) self.assertEqual(doc.table().columns(), 2) doc.ins_col() self.assertEqual(doc.table().rows(), 3) self.assertEqual(doc.table().columns(), 3)
def test_del_col(self): doc = Doc(Config()) doc.text.setPlainText("1 row\n 2 row\n3 row") doc.insert_table({"padding": 0, "space": 0, "rows": 3, "cols": 2}) def in_table(): c = QTextCursor(doc.text) c.movePosition(QTextCursor.Start) while c.movePosition(QTextCursor.NextCharacter, QTextCursor.KeepAnchor): if doc.in_table(): cc = doc.table().cellAt(2, 1) cc.firstCursorPosition().insertText("Hello") doc.change(cc.firstCursorPosition()) in_table() self.assertEqual(doc.table().rows(), 3) self.assertEqual(doc.table().columns(), 2) doc.del_col() self.assertEqual(doc.table().rows(), 3) self.assertEqual(doc.table().columns(), 1)