예제 #1
0
void KWFrameSet::removeFrame(KWFrame *frame, KoShape *shape)
{
    Q_ASSERT(frame);
    if (frame->isCopy()) {
        KWCopyShape* copyShape = dynamic_cast<KWCopyShape*>(frame->shape());
        if (copyShape && copyShape->original()) {
            KWFrame *originalFrame = dynamic_cast<KWFrame*>(copyShape->original()->applicationData());
            if (originalFrame) {
                originalFrame->removeCopy(frame);
            }
        }
    } else {
        //TODO use the copyFrame-list the KWFrame's remembers now
        // Loop over all frames to see if there is a copy frame that references the removed
        // frame; if it does, then delete the copy too.
        for(int i = frames().count() - 1; i >= 0; --i) {
            KWFrame *frame = frames()[i];
            if (KWCopyShape *cs = dynamic_cast<KWCopyShape*>(frame->shape())) {
                if (cs->original() == shape) {
                    Q_ASSERT(frame->frameSet() == this);
                    frame->cleanupShape(cs);
                    removeFrame(frame, cs);
                    delete cs;
                }
            }
        }
    }

    if (m_frames.removeAll(frame)) {
        frame->setFrameSet(0);
        emit frameRemoved(frame);
    }
}
예제 #2
0
void KWFrameSet::addFrame(KWFrame *frame)
{
    Q_ASSERT(frame);
    kDebug(32001) << "frame=" << frame << "frameSet=" << frame->frameSet();
    Q_ASSERT(!m_frames.contains(frame));
    m_frames.append(frame); // this one first, so we don't enter the addFrame twice.
    frame->setFrameSet(this);
    setupFrame(frame);
    if (frame->isCopy()) {
        KWCopyShape* copyShape = dynamic_cast<KWCopyShape*>(frame->shape());
        if (copyShape && copyShape->original()) {
            KWFrame *originalFrame = dynamic_cast<KWFrame*>(copyShape->original()->applicationData());
            if (originalFrame) {
                originalFrame->addCopy(frame);
            }
        }
    }
    emit frameAdded(frame);
}
예제 #3
0
파일: TestFrames.cpp 프로젝트: KDE/koffice
void TestFrames::testCopyShapes()
{
    KWTextFrameSet *fs = new KWTextFrameSet(0, KWord::OddPagesHeaderTextFrameSet);
    MockShape *orig = new MockShape();
    orig->setUserData(new KTextShapeData());
    KWTextFrame *tf = new KWTextFrame(orig, fs);
    orig->setPosition(QPointF(10, 10));

    KWCopyShape *copy = new KWCopyShape(orig);
    new KWFrame(copy, fs);
    copy->setPosition(QPointF(20, 100));
    QCOMPARE(fs->frameCount(), 2);

    delete tf->shape(); // causes the first frame to be deleted.
    QCOMPARE(fs->frameCount(), 1);

    // the deletion of the orig should have caused the copy shape to be disconnected
    QVERIFY(copy->original() == 0);

    // please don't crash..
    copy->outline();
}