Exemplo n.º 1
0
QString RdfTest::insertTableWithSemItem(KoTextEditor &editor,
                               KoDocumentRdf &rdfDoc,
                               const QString name)
{
    editor.insertTable(5,10);
#define TABLESIZE (5*10)
    const QTextTable *table = editor.currentTable();

    QTextCursor cur(editor.document());
    cur.setPosition(table->firstPosition());
    KoBookmark *bookmark = new KoBookmark(cur);
    bookmark->setPositionOnlyMode(false); // we want it to be several chars long

    KoTextInlineRdf *inlineRdf(new KoTextInlineRdf(editor.document(), bookmark));
    QString newId = inlineRdf->createXmlId();
    inlineRdf->setXmlId(newId);

    bookmark->setName(newId);
    bookmark->setInlineRdf(inlineRdf);
    KoTextDocument(editor.document()).textRangeManager()->insert(bookmark);

    editor.setPosition(table->firstPosition());
    editor.movePosition(QTextCursor::PreviousCharacter);

    hTestSemanticItem testItem(new TestSemanticItem(0, &rdfDoc));
    testItem->setName(name);
    Soprano::Statement st(
                testItem->linkingSubject(), // subject
                Soprano::Node::createResourceNode(QUrl("http://docs.oasis-open.org/ns/office/1.2/meta/pkg#idref")), // predicate
                Soprano::Node::createLiteralNode(newId), // object
                rdfDoc.manifestRdfNode()); // manifest datastore
    rdfDoc.model()->addStatement(st);
    rdfDoc.rememberNewInlineRdfObject(inlineRdf);

    Q_ASSERT(rdfDoc.model()->statementCount() > 0);

    bookmark->setRangeEnd(table->lastPosition());

    return newId;
}
Exemplo n.º 2
0
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;
    }

}