예제 #1
0
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(&paragraphStyle);
    m_styleManager->endEdit();
    QVERIFY(paragraphStyle.styleId() > 0);
    QVERIFY(!m_styleManager->usedParagraphStyles().contains(paragraphStyle.styleId()));
    QCOMPARE(m_styleManager->paragraphStyles().count(&paragraphStyle), 1);
    QCOMPARE(m_styleManager->paragraphStyle(paragraphStyle.styleId()), &paragraphStyle);
    QCOMPARE(m_styleManager->paragraphStyle("Test Paragraph Style"), &paragraphStyle);
    QCOMPARE(addSignalSpy.count(), 1);
    QCOMPARE(addSignalSpy.at(0).at(0).value<KoParagraphStyle *>(), &paragraphStyle);

    // Remove paragraph style.
    QSignalSpy removeSignalSpy(m_styleManager, SIGNAL(styleRemoved(KoParagraphStyle*)));
    m_styleManager->beginEdit();
    m_styleManager->remove(&paragraphStyle);
    m_styleManager->endEdit();
    QVERIFY(!m_styleManager->paragraphStyles().contains(&paragraphStyle));
    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 *>(), &paragraphStyle);
}
예제 #2
0
int KoBibliographyInfo::styleNameToStyleId(KoTextSharedLoadingData *sharedLoadingData, const QString &styleName)
{
    KoParagraphStyle * style = sharedLoadingData->paragraphStyle(styleName, true);
    if (style) {
        return style->styleId();
    }

    return 0;
}
예제 #3
0
void TestStyleManager::testAddAppliedParagraphStyle()
{
    // Create style, apply it, then add it to the manager.
    KoParagraphStyle paragraphStyle;
    QTextBlock block = m_doc->begin();
    paragraphStyle.applyStyle(block);

    m_styleManager->beginEdit();
    m_styleManager->add(&paragraphStyle);
    m_styleManager->endEdit();

    // Check that style is marked as used.
    QVERIFY(m_styleManager->usedParagraphStyles().contains(paragraphStyle.styleId()));
}
예제 #4
0
void ValidParentStylesProxyModel::createMapping()
{

    if (!m_styleManager || !m_sourceModel) {
        return;
    }
    m_sourceToProxy.clear();
    m_proxyToSource.clear();

    for(int i = 0; i < m_sourceModel->rowCount(QModelIndex()); ++i) {
        QModelIndex index = m_sourceModel->index(i, 0, QModelIndex());
        int id = (int)index.internalId();
        KoParagraphStyle *paragraphStyle = m_styleManager->paragraphStyle(id);
        if (paragraphStyle) {
            bool ok = true;
            KoParagraphStyle *testStyle = paragraphStyle;
            while (testStyle && ok) {
                ok = testStyle->styleId() != m_currentChildStyleId;
                testStyle = testStyle->parentStyle();
            }
            if (!ok) {
                continue; //we cannot inherit ourself even indirectly through the parent chain
            }
            m_proxyToSource.append(i); //the style is ok for parenting
        }
        else {
            KoCharacterStyle *characterStyle = m_styleManager->characterStyle(id);
            if (characterStyle) {
                bool ok = true;
                KoCharacterStyle *testStyle = characterStyle;
                while (testStyle && ok) {
                    ok = testStyle->styleId() != m_currentChildStyleId;
                    testStyle = testStyle->parentStyle();
                }
                if (!ok) {
                    continue; //we cannot inherit ourself even indirectly through the parent chain
                }
                m_proxyToSource.append(i); //the style is ok for parenting
            }
        }
    }
    m_sourceToProxy.fill(-1, m_sourceModel->rowCount(QModelIndex()));
    for(int i = 0; i < m_proxyToSource.count(); ++i) {
        m_sourceToProxy[m_proxyToSource.at(i)] = i;
    }
}
예제 #5
0
void TestStyleManager::testApplyAddedParagraphStyle()
{
    QSignalSpy appliedSignalSpy(m_styleManager, SIGNAL(styleApplied(const KoParagraphStyle*)));

    // Create style, add it to the manager, then apply it.
    KoParagraphStyle paragraphStyle;

    m_styleManager->beginEdit();
    m_styleManager->add(&paragraphStyle);
    m_styleManager->endEdit();

    QTextBlock block = m_doc->begin();
    paragraphStyle.applyStyle(block);

    // Check that style is marked as used and that the correct signal was emitted.
    QVERIFY(m_styleManager->usedParagraphStyles().contains(paragraphStyle.styleId()));
    QCOMPARE(appliedSignalSpy.count(), 1);
    QCOMPARE(appliedSignalSpy.at(0).at(0).value<const KoParagraphStyle *>(), &paragraphStyle);
}
int KoTableOfContentsGeneratorInfo::styleNameToStyleId(KoTextSharedLoadingData *sharedLoadingData, QString styleName)
{
    //find styleId of a style based on its style:name property
    KoParagraphStyle * style = sharedLoadingData->paragraphStyle(styleName, true);
    if (style) {
        return style->styleId();
    }

    //if the previous way of finding styles fails fall back on using style:display-name property of a style
    QList<KoParagraphStyle *> paragraphStyles = sharedLoadingData->paragraphStyles(true);
    QList<KoParagraphStyle *>::const_iterator iter = paragraphStyles.constBegin();

    for (; iter != paragraphStyles.constEnd(); ++iter) {
        if ((*iter)->name() == styleName) {
            return (*iter)->styleId();
        }
    }

    return 0;
}