예제 #1
0
파일: rdf_test.cpp 프로젝트: KDE/calligra
void RdfTest::testFindMarkers()
{
    QObject parent;

    // the rdf storage. In calligra, it's part of the KoDocument.
    KoDocumentRdf rdfDoc;

    // create a document
    QTextDocument doc;

    KoTextRangeManager rangeManager(&parent);
    KoTextDocument textDoc(&doc);
    textDoc.setTextRangeManager(&rangeManager);

    KoTextEditor editor(&doc);
    textDoc.setTextEditor(&editor);

    // insert some lorem ipsum
    editor.insertText(lorem);

    // insert a table and set a bookmark on it
    QStringList idList;
    QString newId = insertTableWithSemItem(editor, rdfDoc, "test item1");
    idList << newId;

    editor.setPosition(0);

    // now use soprano to find the tables
    QList<hTestSemanticItem> semItems = TestSemanticItem::allObjects(&rdfDoc);
    Q_ASSERT(semItems.length() == 1);

    foreach(hTestSemanticItem semItem, semItems) {
        QStringList xmlidlist = semItem->xmlIdList();

        Q_ASSERT(xmlidlist.length() == 1);
        foreach(const QString xmlid, xmlidlist) {
            Q_ASSERT(idList.contains(xmlid));
            QPair<int, int> position = rdfDoc.findExtent(xmlid);

            QCOMPARE(position.first, lorem.length() + 1);
            QCOMPARE(position.second, lorem.length() + 1 + TABLESIZE - 1);

            editor.setPosition(position.first + 2);
            const QTextTable *table = editor.currentTable();
            QVERIFY(table);
            Q_UNUSED(table);
        }
예제 #2
0
void TestKoTextEditor::testRemoveSelectedText()
{
    QObject parent;

    // create a document
    QTextDocument doc;

    KoTextRangeManager rangeManager(&parent);
    KoTextDocument textDoc(&doc);
    textDoc.setTextRangeManager(&rangeManager);

    KoTextEditor editor(&doc);
    textDoc.setTextEditor(&editor);

    // enter some lorem ipsum
    editor.insertText(lorem);

    QTextCursor cur(&doc);
    cur.setPosition(editor.position());
    KoBookmark *bookmark = new KoBookmark(cur);
    bookmark->setName("start!");
    bookmark->setPositionOnlyMode(false); // we want it to be several chars long
    rangeManager.insert(bookmark);

    editor.insertText(lorem);

    bookmark->setRangeEnd(editor.position());

    QCOMPARE(bookmark->rangeStart(), lorem.length());
    QCOMPARE(bookmark->rangeEnd(), lorem.length() * 2);
    Q_ASSERT(rangeManager.textRanges().length() == 1);

    // select all text
    editor.setPosition(0, QTextCursor::MoveAnchor);
    editor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);

    Q_ASSERT(editor.hasSelection());

    // remove the text + the bookmark from the document
    editor.deleteChar();

    // check whether the bookmark has gone.
    Q_ASSERT(rangeManager.textRanges().length() == 0);
}
예제 #3
0
파일: rdf_test.cpp 프로젝트: KDE/calligra
void RdfTest::testCreateMarkers()
{
    QObject parent;

    // the rdf storage. In calligra, it's part of the KoDocument.
    KoDocumentRdf rdfDoc;

    // create a document
    QTextDocument doc;

    KoTextRangeManager rangeManager(&parent);
    KoTextDocument textDoc(&doc);
    textDoc.setTextRangeManager(&rangeManager);

    KoTextEditor editor(&doc);
    textDoc.setTextEditor(&editor);

    // insert some lorem ipsum
    editor.insertText(lorem);

    // insert a table and set a bookmark on it with semantics
    QString newId = insertTableWithSemItem(editor, rdfDoc, "test item1");

    // insert some more lorem before the table
    editor.insertText(lorem);

    // verify that the bookmark marks the table and only that
    QPair<int,int> position = rdfDoc.findExtent(newId);
    QCOMPARE(position.first, 2*(lorem.length()+1));
    QCOMPARE(position.second, 2*(lorem.length()+1)+TABLESIZE-1);

    editor.setPosition(position.first + 1);
    QPair<int,int> position2 = rdfDoc.findExtent(&editor);
    qDebug()<<position<<position2;
    QCOMPARE(position, position2);

    // check that the id is like we expext
    QCOMPARE(rdfDoc.findXmlId(&editor), newId);
}