void TestStyleManager::testAddRemoveParagraphStyle() { // Add paragraph style. KoParagraphStyle paragraphStyle; paragraphStyle.setName("Test Paragraph Style"); QSignalSpy addSignalSpy(m_styleManager, SIGNAL(styleAdded(KoParagraphStyle*))); m_styleManager->beginEdit(); m_styleManager->add(¶graphStyle); m_styleManager->endEdit(); QVERIFY(paragraphStyle.styleId() > 0); QVERIFY(!m_styleManager->usedParagraphStyles().contains(paragraphStyle.styleId())); QCOMPARE(m_styleManager->paragraphStyles().count(¶graphStyle), 1); QCOMPARE(m_styleManager->paragraphStyle(paragraphStyle.styleId()), ¶graphStyle); QCOMPARE(m_styleManager->paragraphStyle("Test Paragraph Style"), ¶graphStyle); QCOMPARE(addSignalSpy.count(), 1); QCOMPARE(addSignalSpy.at(0).at(0).value<KoParagraphStyle *>(), ¶graphStyle); // Remove paragraph style. QSignalSpy removeSignalSpy(m_styleManager, SIGNAL(styleRemoved(KoParagraphStyle*))); m_styleManager->beginEdit(); m_styleManager->remove(¶graphStyle); m_styleManager->endEdit(); QVERIFY(!m_styleManager->paragraphStyles().contains(¶graphStyle)); QVERIFY(!m_styleManager->paragraphStyle(paragraphStyle.styleId())); QVERIFY(!m_styleManager->paragraphStyle("Test Paragraph Style")); QCOMPARE(removeSignalSpy.count(), 1); QCOMPARE(removeSignalSpy.at(0).at(0).value<KoParagraphStyle *>(), ¶graphStyle); }
void NewStyleWidget::createButtonPressed() { if (widget.character->isChecked()) { KoCharacterStyle *style = new KoCharacterStyle(); style->setName(widget.name->text()); emit newCharacterStyle(style); } else { KoParagraphStyle *style = new KoParagraphStyle(); style->setName(widget.name->text()); emit newParagraphStyle(style); } }
void TestStyles::testApplyParagraphStyle() { KoParagraphStyle style; style.setStyleId(1001); QTextBlockFormat format; QCOMPARE(format.properties().count(), 0); style.applyStyle(format); QCOMPARE(format.properties().count(), 2); // the styleId and nextStyleId QCOMPARE(format.property(KoParagraphStyle::StyleId).toInt(), 1001); QCOMPARE(format.property(KoParagraphStyle::NextStyle).toInt(), 1001); style.setName("name"); style.setAlignment(Qt::AlignRight); style.applyStyle(format); QCOMPARE(format.properties().count(), 3); QCOMPARE(format.alignment(), Qt::AlignRight); }