From kde-commits Sat Jan 31 20:50:01 2015 From: C. Boemann Date: Sat, 31 Jan 2015 20:50:01 +0000 To: kde-commits Subject: [calligra/calligra/2.9] words/part: Move copies() and cleanupShape to the frameset Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=142273741023544 Git commit 62a556dfaa7e29793eda865580392321e4d24ddd by C. Boemann. Committed on 31/01/2015 at 20:49. Pushed by boemann into branch 'calligra/2.9'. Move copies() and cleanupShape to the frameset M +7 -6 words/part/KWRootAreaProvider.cpp M +3 -6 words/part/KWRootAreaProviderBase.cpp M +3 -6 words/part/KWRootAreaProviderTextBox.cpp M +2 -48 words/part/frames/KWFrame.cpp M +0 -12 words/part/frames/KWFrame.h M +18 -11 words/part/frames/KWFrameSet.cpp M +17 -0 words/part/frames/KWFrameSet.h M +20 -0 words/part/frames/KWTextFrameSet.cpp M +1 -0 words/part/frames/KWTextFrameSet.h http://commits.kde.org/calligra/62a556dfaa7e29793eda865580392321e4d24ddd diff --git a/words/part/KWRootAreaProvider.cpp b/words/part/KWRootAreaProvi= der.cpp index 8a58c47..c1180f7 100644 --- a/words/part/KWRootAreaProvider.cpp +++ b/words/part/KWRootAreaProvider.cpp @@ -24,6 +24,7 @@ #include "KWDocument.h" #include "KWView.h" #include "KWPage.h" +#include "frames/KWCopyShape.h" #include "frames/KWTextFrameSet.h" #include "frames/KWFrameLayout.h" = @@ -501,12 +502,8 @@ void KWRootAreaProvider::doPostLayout(KoTextLayoutRoot= Area *rootArea, bool isNew rootArea->associatedShape()->setSize(newSize); = // transfer the new size to the copy-shapes - if (KWFrame *frame =3D dynamic_cast(rootArea->associated= Shape()->applicationData())) { - foreach(KWFrame* f, frame->copies()) { - if (f->shape()) { - f->shape()->setSize(newSize); - } - } + foreach(KWCopyShape *cs, frameSet()->copyShapes()) { + cs->setSize(newSize); } = if (isHeaderFooter) { @@ -516,6 +513,10 @@ void KWRootAreaProvider::doPostLayout(KoTextLayoutRoot= Area *rootArea, bool isNew if (frame->minimumFrameHeight() !=3D newSize.height()) { frame->setMinimumFrameHeight(newSize.height()); = + // transfer the new minimumFrameHeight to the copy-shapes = too + foreach(KWCopyShape *cs, frameSet()->copyShapes()) { + cs->setMinimumFrameHeight(newSize.height()); + } // cause the header/footer's height changed we have to rel= ayout the whole page frameSet()->wordsDocument()->frameLayout()->layoutFramesOn= Page(page.pageNumber()); } diff --git a/words/part/KWRootAreaProviderBase.cpp b/words/part/KWRootAreaP= roviderBase.cpp index 841f402..1b35cbf 100644 --- a/words/part/KWRootAreaProviderBase.cpp +++ b/words/part/KWRootAreaProviderBase.cpp @@ -24,6 +24,7 @@ #include "KWDocument.h" #include "KWView.h" #include "frames/KWTextFrameSet.h" +#include "frames/KWCopyShape.h" = #include #include @@ -91,12 +92,8 @@ void KWRootAreaProviderBase::doPostLayout(KoTextLayoutRo= otArea *rootArea, bool / rootArea->associatedShape()->setSize(newSize); = // transfer the new size to the copy-shapes - if (KWFrame *frame =3D dynamic_cast(rootArea->associated= Shape()->applicationData())) { - foreach(KWFrame* f, frame->copies()) { - if (f->shape()) { - f->shape()->setSize(newSize); - } - } + foreach(KWCopyShape *cs, frameSet()->copyShapes()) { + cs->setSize(newSize); } } = diff --git a/words/part/KWRootAreaProviderTextBox.cpp b/words/part/KWRootAr= eaProviderTextBox.cpp index fb7567e..73392d3 100644 --- a/words/part/KWRootAreaProviderTextBox.cpp +++ b/words/part/KWRootAreaProviderTextBox.cpp @@ -24,6 +24,7 @@ #include "KWPageManager.h" #include "KWDocument.h" #include "frames/KWTextFrameSet.h" +#include "frames/KWCopyShape.h" #include "frames/KWFrameLayout.h" = #include @@ -182,12 +183,8 @@ void KWRootAreaProviderTextBox::doPostLayout(KoTextLay= outRootArea *rootArea, boo rootArea->associatedShape()->setSize(newSize); = // transfer the new size to the copy-shapes - if (KWFrame *frame =3D dynamic_cast(rootArea->associated= Shape()->applicationData())) { - foreach(KWFrame* f, frame->copies()) { - if (f->shape()) { - f->shape()->setSize(newSize); - } - } + foreach(KWCopyShape *cs, frameSet()->copyShapes()) { + cs->setSize(newSize); } } = diff --git a/words/part/frames/KWFrame.cpp b/words/part/frames/KWFrame.cpp index bc99bcb..1c5a446 100644 --- a/words/part/frames/KWFrame.cpp +++ b/words/part/frames/KWFrame.cpp @@ -84,7 +84,7 @@ KWFrame::~KWFrame() m_shape =3D 0; // no delete is needed as the shape deletes us. = if (m_frameSet) { - cleanupShape(ourShape); + m_frameSet->cleanupShape(ourShape); = bool justMe =3D m_frameSet->shapeCount() =3D=3D 1; m_frameSet->removeFrame(this, ourShape); // first remove me so we = won't get double @@ -111,36 +111,6 @@ void KWFrame::setMinimumFrameHeight(qreal minimumFrame= Height) if (m_minimumFrameHeight =3D=3D minimumFrameHeight) return; m_minimumFrameHeight =3D minimumFrameHeight; - - // transfer the minimumFrameHeight to the copy-shapes - foreach(KWFrame* copyFrame, m_copyShapes) { - copyFrame->setMinimumFrameHeight(m_minimumFrameHeight); - } -} - -void KWFrame::cleanupShape(KoShape* shape) -{ - Q_ASSERT(m_frameSet); - KWTextFrameSet *tfs =3D dynamic_cast(m_frameSet); - if (tfs) { - KWRootAreaProviderBase *rootAreaProvider =3D tfs->rootAreaProvider= (); - // it is no longer set when document is destroyed - if (rootAreaProvider) { - KoTextDocumentLayout *lay =3D dynamic_cast(tfs->document()->documentLayout()); - Q_ASSERT(lay); - QList layoutRootAreas =3D lay->rootAre= as(); - for(int i =3D 0; i < layoutRootAreas.count(); ++i) { - KoTextLayoutRootArea *rootArea =3D layoutRootAreas[i]; - if (rootArea->associatedShape() =3D=3D shape) { - KoTextLayoutRootArea *prevRootArea =3D i >=3D 1 ? layo= utRootAreas[i - 1] : 0; - rootAreaProvider->releaseAllAfter(prevRootArea); - lay->removeRootArea(prevRootArea); - rootArea->setAssociatedShape(0); - break; - } - } - } - } } = void KWFrame::setFrameSetxx(KWFrameSet *fs) @@ -150,7 +120,7 @@ void KWFrame::setFrameSetxx(KWFrameSet *fs) Q_ASSERT_X(!fs || !m_frameSet, __FUNCTION__, "Changing the FrameSet af= terwards needs to invalidate lots of stuff including whatever is done in th= e KWRootAreaProvider. The better way would be to not allow this."); if (m_frameSet) { if (m_shape) - cleanupShape(m_shape); + m_frameSet->cleanupShape(m_shape); m_frameSet->removeFrame(this); } m_frameSet =3D fs; @@ -158,22 +128,6 @@ void KWFrame::setFrameSetxx(KWFrameSet *fs) fs->addFrame(this); } = -QList KWFrame::copies() const -{ - return m_copyShapes; -} - -void KWFrame::addCopy(KWFrame* frame) -{ - if (!m_copyShapes.contains(frame)) - m_copyShapes.append(frame); -} - -void KWFrame::removeCopy(KWFrame* frame) -{ - m_copyShapes.removeAll(frame); -} - void KWFrame::saveOdf(KoShapeSavingContext &context, const KWPage &page, i= nt /*pageZIndexOffset*/) const { if (minimumFrameHeight() > 1) { diff --git a/words/part/frames/KWFrame.h b/words/part/frames/KWFrame.h index 5440cbe..68c5e5b 100644 --- a/words/part/frames/KWFrame.h +++ b/words/part/frames/KWFrame.h @@ -88,8 +88,6 @@ public: */ virtual void setFrameSetxx(KWFrameSet *newFrameSet); = - void cleanupShape(KoShape* shape); - qreal anchoredFrameOffset() const { return m_anchoredFrameOffset; } @@ -98,15 +96,6 @@ public: } = /** - * Returns the list of copy-shapes, see @a KWCopyShape , that - * are copies of this KWFrame. - */ - QList copies() const; - - void addCopy(KWFrame* frame); - void removeCopy(KWFrame* frame); - - /** * Save the frame as ODF * @param context the context for saving. */ @@ -117,7 +106,6 @@ private: qreal m_anchoredFrameOffset; KWFrameSet *m_frameSet; qreal m_minimumFrameHeight; - QList m_copyShapes; }; = #endif diff --git a/words/part/frames/KWFrameSet.cpp b/words/part/frames/KWFrameSe= t.cpp index a960d3b..e059700 100644 --- a/words/part/frames/KWFrameSet.cpp +++ b/words/part/frames/KWFrameSet.cpp @@ -65,10 +65,7 @@ void KWFrameSet::addFrame(KWFrame *frame) KWCopyShape* copyShape =3D dynamic_cast(frame->shape()); if (copyShape) { if (copyShape->original()) { - KWFrame *originalFrame =3D dynamic_cast(copyShape->o= riginal()->applicationData()); - if (originalFrame) { - originalFrame->addCopy(frame); - } + addCopy(copyShape); } } emit frameAdded(frame); @@ -79,12 +76,7 @@ void KWFrameSet::removeFrame(KWFrame *frame, KoShape *sh= ape) Q_ASSERT(frame); KWCopyShape* copyShape =3D dynamic_cast(frame->shape()); if (copyShape) { - if (copyShape->original()) { - KWFrame *originalFrame =3D dynamic_cast(copyShape->o= riginal()->applicationData()); - if (originalFrame) { - originalFrame->removeCopy(frame); - } - } + removeCopy(copyShape); } else { //TODO use the copyFrame-list the KWFrame's remembers now // Loop over all frames to see if there is a copy frame that refer= ences the removed @@ -94,7 +86,7 @@ void KWFrameSet::removeFrame(KWFrame *frame, KoShape *sha= pe) if (KWCopyShape *cs =3D dynamic_cast(frame->shap= e())) { if (cs->original() =3D=3D shape) { Q_ASSERT(frame->frameSetxx() =3D=3D this); - frame->cleanupShape(cs); + cleanupShape(cs); removeFrame(frame, cs); delete cs; } @@ -108,3 +100,18 @@ void KWFrameSet::removeFrame(KWFrame *frame, KoShape *= shape) } } = +QList KWFrameSet::copyShapes() const +{ + return m_copyShapes; +} + +void KWFrameSet::addCopy(KWCopyShape *copyShape) +{ + if (!m_copyShapes.contains(copyShape)) + m_copyShapes.append(copyShape); +} + +void KWFrameSet::removeCopy(KWCopyShape *copyShape) +{ + m_copyShapes.removeAll(copyShape); +} diff --git a/words/part/frames/KWFrameSet.h b/words/part/frames/KWFrameSet.h index 87d6a25..f2786600 100644 --- a/words/part/frames/KWFrameSet.h +++ b/words/part/frames/KWFrameSet.h @@ -29,6 +29,7 @@ = #include = +class KWCopyShape; = /** * A frameSet holds a number of frames (zero or more) and a frameSet holds= the @@ -116,6 +117,14 @@ public: return m_type; } = + /** + * Returns the list of copy-shapes, see @a KWCopyShape + */ + QList copyShapes() const; + + void addCopy(KWCopyShape *copyShape); + void removeCopy(KWCopyShape *copyShape); + signals: /** * emitted whenever a frame is added @@ -140,6 +149,13 @@ protected: Q_UNUSED(frame); } = + /** + * @param frame the frame that has just been added + */ + virtual void cleanupShape(KoShape *shape) { + Q_UNUSED(shape); + } + void cleanupFrames(); = private: @@ -149,6 +165,7 @@ private: Words::FrameSetType m_type; /// The name of the frameset. QString m_name; + QList m_copyShapes; }; = #endif diff --git a/words/part/frames/KWTextFrameSet.cpp b/words/part/frames/KWTex= tFrameSet.cpp index 9eb207c..56bc11c 100644 --- a/words/part/frames/KWTextFrameSet.cpp +++ b/words/part/frames/KWTextFrameSet.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include = @@ -126,6 +127,25 @@ void KWTextFrameSet::setupFrame(KWFrame *frame) #endif } = +void KWTextFrameSet::cleanupShape(KoShape *shape) { + // it is no longer set when document is destroyed + if (rootAreaProvider()) { + KoTextDocumentLayout *lay =3D dynamic_cast(= document()->documentLayout()); + Q_ASSERT(lay); + QList layoutRootAreas =3D lay->rootAreas(); + for(int i =3D 0; i < layoutRootAreas.count(); ++i) { + KoTextLayoutRootArea *rootArea =3D layoutRootAreas[i]; + if (rootArea->associatedShape() =3D=3D shape) { + KoTextLayoutRootArea *prevRootArea =3D i >=3D 1 ? layoutRo= otAreas[i - 1] : 0; + rootAreaProvider()->releaseAllAfter(prevRootArea); + lay->removeRootArea(prevRootArea); + rootArea->setAssociatedShape(0); + break; + } + } + } +} + void KWTextFrameSet::setupDocument() { m_document->setUseDesignMetrics(true); diff --git a/words/part/frames/KWTextFrameSet.h b/words/part/frames/KWTextF= rameSet.h index 092784f..ca5a6dc 100644 --- a/words/part/frames/KWTextFrameSet.h +++ b/words/part/frames/KWTextFrameSet.h @@ -79,6 +79,7 @@ protected: friend class TestTextFrameManagement; = virtual void setupFrame(KWFrame *frame); + virtual void cleanupShape(KoShape *shape); = private: void setupDocument();