void TestPageCommands::testInsertPageCommand() // move of frames { KWDocument document; KWPageInsertCommand command1(&document, 0); QCOMPARE(document.pageCount(), 0); QCOMPARE(document.frameSetCount(), 0); command1.redo(); QCOMPARE(document.pageCount(), 1); QCOMPARE(document.frameSetCount(), 0); KWFrameSet *fs = new KWFrameSet(); MockShape *shape = new MockShape(); KWFrame *frame = new KWFrame(shape, fs); Q_UNUSED(frame); document.addFrameSet(fs); QPointF startPos = shape->position(); KWPageInsertCommand command2(&document, 0); QCOMPARE(document.pageCount(), 1); QCOMPARE(document.frameSetCount(), 1); command2.redo(); QCOMPARE(document.pageCount(), 2); QCOMPARE(document.frameSetCount(), 1); QCOMPARE(fs->frameCount(), 1); QCOMPARE(command2.page().pageNumber(), 1); QCOMPARE(command1.page().pageNumber(), 2); QPointF newPos = shape->position(); QCOMPARE(newPos, QPointF(0, command2.page().height()) + startPos); // it moved ;) KWPageInsertCommand command3(&document, 2); command3.redo(); QCOMPARE(document.pageCount(), 3); QCOMPARE(document.frameSetCount(), 1); QCOMPARE(fs->frameCount(), 1); QCOMPARE(newPos, shape->position()); // it has not moved from page 2 command3.undo(); QCOMPARE(document.pageCount(), 2); QCOMPARE(document.frameSetCount(), 1); QCOMPARE(fs->frameCount(), 1); QCOMPARE(newPos, shape->position()); // it has not moved from page 2 QCOMPARE(command2.page().pageNumber(), 1); QCOMPARE(command1.page().pageNumber(), 2); command2.undo(); QCOMPARE(document.pageCount(), 1); QCOMPARE(document.frameSetCount(), 1); QCOMPARE(fs->frameCount(), 1); QCOMPARE(command1.page().pageNumber(), 1); QCOMPARE(startPos, shape->position()); // it has been moved back command2.redo(); QCOMPARE(document.pageCount(), 2); QCOMPARE(document.frameSetCount(), 1); QCOMPARE(fs->frameCount(), 1); QCOMPARE(command2.page().pageNumber(), 1); QCOMPARE(command1.page().pageNumber(), 2); QCOMPARE(QPointF(0, command2.page().height()) + startPos, newPos); // it moved again ;) }
void KWDocStructRootItem::setupTextFrameSets() { // Delete Empty item from list. QListViewItem* lvItem = firstChild(); if (lvItem && (lvItem->text(0) == i18n("Empty"))) delete lvItem; // Build a list of framesets ordered by their screen position (top left corner). KWDocument* dok = doc(); QValueList<KWOrderedFrameSet> orderedFrameSets; for ( int i = dok->frameSetCount() - 1; i >= 0; i-- ) { KWFrameSet* frameset = dok->frameSet(i); if ( frameset->type() == FT_TEXT && frameset->frameSetInfo() == KWFrameSet::FI_BODY && !frameset->groupmanager() && frameset->frameCount()>0) orderedFrameSets.append(KWOrderedFrameSet(frameset)); } qHeapSort(orderedFrameSets); // Build a list of frameset pointers from the sorted list. QPtrList<KWTextFrameSet> frameSetPtrs; frameSetPtrs.setAutoDelete(false); for ( uint i = 0; i < orderedFrameSets.count(); i++ ) frameSetPtrs.append(dynamic_cast<KWTextFrameSet *>(orderedFrameSets[i].frameSet())); // Remove deleted framesets from the listview. KWDocStructTextFrameSetItem* item = dynamic_cast<KWDocStructTextFrameSetItem *>(firstChild()); KWDocStructTextFrameSetItem* delItem; while (item) { delItem = item; item = dynamic_cast<KWDocStructTextFrameSetItem *>(item->nextSibling()); if (frameSetPtrs.containsRef(delItem->frameSet()) == 0) delete delItem; } // Add new framesets to the list or update existing ones. KWDocStructTextFrameSetItem* after = 0L; for ( uint i = 0; i < orderedFrameSets.count(); i++ ) { KWTextFrameSet* textFrameset = dynamic_cast<KWTextFrameSet *>(orderedFrameSets[i].frameSet()); item = findTextFrameSetItem(textFrameset); if (item) item->setText(0, textFrameset->name()); else { if (after) item = new KWDocStructTextFrameSetItem( this, after, textFrameset->name(), textFrameset); else item = new KWDocStructTextFrameSetItem(this, textFrameset->name(), textFrameset); } after = item; item->setupTextFrames(); } if ( childCount() == 0 ) ( void )new KListViewItem( this, i18n( "Empty" ) ); }
void KWDocStructRootItem::setupArrangement() { deleteAllChildren(); QIntDict<KWDocStructParagItem> parags; parags.setAutoDelete( false ); KWFrameSet* frameset = 0L; KWTextParag* parag = 0L; KoTextDocument* textdoc = 0L; KWDocument* dok = doc(); KWDocStructTextFrameSetItem *item = 0L; QString _name; for ( int i = dok->frameSetCount() - 1; i >= 0; i-- ) { frameset = dok->frameSet( i ); if ( frameset->type() == FT_TEXT && frameset->frameSetInfo() == KWFrameSet::FI_BODY && !frameset->groupmanager() && frameset->frameCount()>0) { KWTextFrameSet *tmpParag = dynamic_cast<KWTextFrameSet*> (frameset) ; item = new KWDocStructTextFrameSetItem( this, frameset->name(), tmpParag); textdoc= tmpParag->textDocument(); parag = static_cast<KWTextParag *>(textdoc->firstParag()); while ( parag ) { KoParagCounter *tmpCounter = parag->counter(); if (tmpCounter !=0 && (tmpCounter->style() != KoParagCounter::STYLE_NONE) && (tmpCounter->numbering() == KoParagCounter::NUM_CHAPTER) ) { int _depth = tmpCounter->depth(); if ( _depth == 0 ) { if ( item->childCount() == 0 ) parags.replace( _depth, new KWDocStructParagItem( item,QString( tmpCounter->text(parag) + " " +parag->string()->toString().mid( 0, parag->string()->length() ) ),parag) ); else parags.replace( _depth, new KWDocStructParagItem( item, parags[ _depth ],QString( tmpCounter->text(parag) + " " +parag->string()->toString().mid( 0, parag->string()->length() ) ),parag) ); } else { if (parags[ _depth - 1 ]==0) parags.replace( _depth, new KWDocStructParagItem( item,QString( tmpCounter->text(parag) + " " +parag->string()->toString().mid( 0, parag->string()->length() ) ), parag) ); else if ( parags[ _depth - 1 ]->childCount() == 0 ) parags.replace( _depth, new KWDocStructParagItem( parags[ _depth - 1 ],QString( tmpCounter->text(parag) + " " +parag->string()->toString().mid( 0, parag->string()->length() ) ), parag) ); else parags.replace( _depth, new KWDocStructParagItem( parags[ _depth - 1 ], parags[ _depth ],QString( tmpCounter->text(parag) + " " +parag->string()->toString().mid( 0, parag->string()->length() ) ), parag) ); } } parag = static_cast<KWTextParag *>(parag->next()); } } } if ( childCount() == 0 ) ( void )new KListViewItem( this, i18n( "Empty" ) ); }
void TestPageCommands::testRemovePageCommand4() // auto remove of frames { KWDocument document; KWPageInsertCommand insertCommand(&document, 0); insertCommand.redo(); KWFrameSet *fs = new KWFrameSet(); document.addFrameSet(fs); MockShape *shape1 = new MockShape(); new KWFrame(shape1, fs); KWTextFrameSet *tfs = new KWTextFrameSet(&document, Words::MainTextFrameSet); document.addFrameSet(tfs); MockShape *shape2 = new MockShape(); shape2->setUserData(new KoTextShapeData()); new KWTextFrame(shape2, tfs); KWTextFrameSet *header = new KWTextFrameSet(&document, Words::EvenPagesHeaderTextFrameSet); document.addFrameSet(header); MockShape *shape3 = new MockShape(); shape3->setUserData(new KoTextShapeData()); new KWTextFrame(shape3, header); KWPageRemoveCommand command(&document, insertCommand.page()); QCOMPARE(document.frameSetCount(), 3); command.redo(); QCOMPARE(document.frameSetCount(), 2); // only the main&header framesets are left QVERIFY(document.frameSets().contains(tfs)); QVERIFY(document.frameSets().contains(header)); QCOMPARE(fs->frameCount(), 0); QCOMPARE(tfs->frameCount(), 0); QCOMPARE(header->frameCount(), 0); command.undo(); QCOMPARE(document.frameSetCount(), 3); QCOMPARE(fs->frameCount(), 1); QCOMPARE(tfs->frameCount(), 0); // doesn't get auto-added QCOMPARE(header->frameCount(), 0); // doesn't get auto-added }
void TestPageCommands::testInsertPageCommand2() // auto remove of frames { KWDocument document; KWFrameSet *fs = new KWFrameSet(); document.addFrameSet(fs); KWTextFrameSet *tfs = new KWTextFrameSet(&document, Words::MainTextFrameSet); document.addFrameSet(tfs); KWPageInsertCommand command1(&document, 0); command1.redo(); MockShape *shape1 = new MockShape(); new KWFrame(shape1, fs); MockShape *shape2 = new MockShape(); shape2->setUserData(new KoTextShapeData()); new KWTextFrame(shape2, tfs); KWPageInsertCommand command2(&document, 1); // append a page command2.redo(); QCOMPARE(document.pageCount(), 2); QCOMPARE(document.frameSetCount(), 2); QCOMPARE(fs->frameCount(), 1); QCOMPARE(tfs->frameCount(), 1); // add a new frame for the page we just created. MockShape *shape3 = new MockShape(); QPointF position(30, command2.page().offsetInDocument()); shape3->setPosition(position); new KWTextFrame(shape3, tfs); QCOMPARE(tfs->frameCount(), 2); command2.undo(); // remove the page again. QCOMPARE(document.pageCount(), 1); QCOMPARE(document.frameSetCount(), 2); QCOMPARE(fs->frameCount(), 1); QCOMPARE(tfs->frameCount(), 1); // the text frame is an auto-generated one, so it should be removed. }
void TestPageCommands::testRemovePageCommand2() // auto remove of frames { // In contrary to the insert command the remove command will remove frames // of all types and reinsert only non-auto-generated ones. // lets make sure we it does that. KWDocument document; KWFrameSet *fs = new KWFrameSet(); document.addFrameSet(fs); KWTextFrameSet *tfs = new KWTextFrameSet(&document, Words::MainTextFrameSet); document.addFrameSet(tfs); KWPageInsertCommand insertCommand(&document, 0); insertCommand.redo(); MockShape *shape1 = new MockShape(); new KWFrame(shape1, fs); MockShape *shape2 = new MockShape(); shape2->setUserData(new KoTextShapeData()); new KWTextFrame(shape2, tfs); KWPageRemoveCommand command(&document, insertCommand.page()); QCOMPARE(document.frameSetCount(), 2); command.redo(); QCOMPARE(document.frameSetCount(), 1); // only the main frameset is left QCOMPARE(document.frameSets().first(), tfs); QCOMPARE(fs->frameCount(), 0); QCOMPARE(tfs->frameCount(), 0); command.undo(); QCOMPARE(document.frameSetCount(), 2); QCOMPARE(fs->frameCount(), 1); QCOMPARE(tfs->frameCount(), 0); // doesn't get auto-added }
void KWDocStructRootItem::setupEmbedded() { deleteAllChildren(); KWFrameSet* frameset = 0L; QString _name; KWDocStructPartItem* child; KWDocument* dok = doc(); for ( int i = dok->frameSetCount() - 1; i >= 0; i-- ) { frameset = dok->frameSet( i ); if ( frameset->type() == FT_PART && frameset->frameCount()>0) { // Use the name of the frameset as the entry for the object. _name=frameset->name(); child = new KWDocStructPartItem(this, _name, dynamic_cast<KWPartFrameSet*>( frameset )); } } if ( childCount() == 0 ) ( void )new KListViewItem( this, i18n( "Empty" ) ); }
void KWDocStructRootItem::setupPictures() { deleteAllChildren(); KWFrameSet* frameset = 0L; QString _name; KWDocStructPictureItem* child; KWDocument* dok = doc(); int j = 0; for ( int i = dok->frameSetCount() - 1; i >= 0; i-- ) { frameset = dok->frameSet( i ); if ( frameset->type() == FT_PICTURE && frameset->frameCount()>0) { _name=i18n("Picture (%1) %2").arg(dynamic_cast<KWPictureFrameSet*>( frameset )->key().filename()).arg(++j); child = new KWDocStructPictureItem(this, _name, dynamic_cast<KWPictureFrameSet*>( frameset )); } } if ( childCount() == 0 ) ( void )new KListViewItem( this, i18n( "Empty" ) ); }
void KWDocStructRootItem::setupFormulaFrames() { deleteAllChildren(); KWFrameSet* frameset = 0L; QString _name; KWDocStructFormulaItem* child; KWDocument* dok = doc(); for ( int i = dok->frameSetCount() - 1; i >= 0; i-- ) { frameset = dok->frameSet( i ); if ( frameset->type() == FT_FORMULA && frameset->frameCount()>0 ) { _name=i18n("Formula Frame %1").arg(QString::number(i+1)); child = new KWDocStructFormulaItem(this, _name, dynamic_cast<KWFormulaFrameSet*>( frameset )); } } if ( childCount() == 0 ) ( void )new KListViewItem( this, i18n( "Empty" ) ); }
void TestPageCommands::testRemovePageCommand() // move of frames { KWDocument document; KWPageInsertCommand insertCommand(&document, 0); insertCommand.redo(); KWFrameSet *fs = new KWFrameSet(); MockShape *shape = new MockShape(); KWFrame *frame = new KWFrame(shape, fs); Q_UNUSED(frame); document.addFrameSet(fs); KWPageInsertCommand insertCommand2(&document, 1); insertCommand2.redo(); MockShape *shape2 = new MockShape(); QPointF pos = QPointF(20, insertCommand2.page().offsetInDocument() + 10); shape2->setPosition(pos); KWFrame *frame2 = new KWFrame(shape2, fs); Q_UNUSED(frame2); QCOMPARE(document.pageCount(), 2); QCOMPARE(document.frameSetCount(), 1); QCOMPARE(fs->frameCount(), 2); // remove page2 KWPageRemoveCommand command1(&document, insertCommand2.page()); command1.redo(); QCOMPARE(insertCommand.page().pageNumber(), 1); QCOMPARE(insertCommand2.page().isValid(), false); QCOMPARE(document.pageCount(), 1); QCOMPARE(document.frameSetCount(), 1); QCOMPARE(fs->frameCount(), 1); QCOMPARE(shape2->position(), pos); // shapes are not deleted, just removed from the document command1.undo(); QCOMPARE(insertCommand.page().pageNumber(), 1); QCOMPARE(document.pageCount(), 2); QCOMPARE(document.frameSetCount(), 1); QCOMPARE(fs->frameCount(), 2); QCOMPARE(shape2->position(), pos); // not moved. // remove page 1 KWPageRemoveCommand command2(&document, insertCommand.page()); command2.redo(); QCOMPARE(insertCommand.page().isValid(), false); QCOMPARE(document.pageCount(), 1); QCOMPARE(document.frameSetCount(), 1); QCOMPARE(fs->frameCount(), 1); QCOMPARE(shape->position(), QPointF(0,0)); QCOMPARE(shape2->position(), QPointF(20, 10)); // moved! command2.undo(); QCOMPARE(document.pageCount(), 2); QCOMPARE(document.frameSetCount(), 1); QCOMPARE(fs->frameCount(), 2); QCOMPARE(shape->position(), QPointF(0,0)); QCOMPARE(shape2->position(), pos); // moved back! }