当前位置: 首页>>代码示例>>C++>>正文


C++ KWDocument::initEmpty方法代码示例

本文整理汇总了C++中KWDocument::initEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ KWDocument::initEmpty方法的具体用法?C++ KWDocument::initEmpty怎么用?C++ KWDocument::initEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在KWDocument的用法示例。


在下文中一共展示了KWDocument::initEmpty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testRoundtrip

void TestKoBookmark::testRoundtrip()
{
    const QString lorem(
                "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor"
                "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud"
                "exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n"
                "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla"
                "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia"
                "deserunt mollit anim id est laborum.\n"
                );
    {
        // Get the words part and create a document
        KWDocument *doc = new KWDocument(new KWPart(0));
        Q_ASSERT(doc);
        doc->setAutoSave(0);
        doc->initEmpty();

        // get the main text frame
        KWTextFrameSet *mainFrameSet = doc->mainFrameSet();
        Q_ASSERT(mainFrameSet);

        QTextDocument *textDocument = mainFrameSet->document();
        Q_ASSERT(textDocument);

        // Insert some text a bookmark pair
        KoTextDocument koTextDocument(textDocument);
        KoTextEditor *editor = koTextDocument.textEditor();
        editor->insertText(lorem);

        KoTextRangeManager *rangeManager = koTextDocument.textRangeManager();
        QTextCursor cursor(editor->document());
        KoBookmark *mark = new KoBookmark(cursor);
        mark->setName("TESTMARK");
        rangeManager->insert(mark);

        editor->insertTable(5,10);
        const QTextTable *table = editor->currentTable();
        Q_ASSERT(table);

        editor->setPosition(table->lastPosition());
        mark->setRangeEnd(editor->position());

        editor->insertText(lorem);

        // Save the document
        KUrl url(QString(FILES_OUTPUT_DIR) + "/bookmark_roundtrip.odt");
        doc->documentPart()->saveAs(url);

        // check the number of bookmarks
        QCOMPARE(rangeManager->bookmarkManager()->bookmarkNameList().length(), 1);
        QCOMPARE(rangeManager->textRanges().length(), 1);

        delete doc;
    }
    {
        // Load the document
        KWDocument *doc = new KWDocument(new KWPart(0));
        Q_ASSERT(doc);
        doc->setAutoSave(0);
        KUrl url(QString(FILES_OUTPUT_DIR) + "/bookmark_roundtrip.odt");
        // this also creates a view...
        bool result = doc->openUrl(url);
        Q_ASSERT(result);
        // get the main text frame
        KWTextFrameSet *mainFrameSet = doc->mainFrameSet();
        Q_ASSERT(mainFrameSet);

        QTextDocument *textDocument = mainFrameSet->document();
        Q_ASSERT(textDocument);

        KoTextDocument koTextDocument(textDocument);

        // check the number of bookmarks
        KoTextRangeManager *rangeManager = koTextDocument.textRangeManager();
        QCOMPARE(rangeManager->bookmarkManager()->bookmarkNameList().length(), 1);
        QCOMPARE(rangeManager->textRanges().length(), 1);

        delete doc;
    }

}
开发者ID:abhishekmurthy,项目名称:Calligra,代码行数:81,代码来源:TestKoBookmark.cpp


注:本文中的KWDocument::initEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。