[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [calligra/calligra/2.9] words/part: Move copies() and cleanupShape to the frameset
From:       C. Boemann <cbo () boemann ! dk>
Date:       2015-01-31 20:50:01
Message-ID: E1YHezR-0006CG-OV () scm ! kde ! org
[Download RAW message or body]

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/KWRootAreaProvider.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(KoTextLayoutRootArea \
*rootArea, bool isNew  rootArea->associatedShape()->setSize(newSize);
 
         // transfer the new size to the copy-shapes
-        if (KWFrame *frame = \
                dynamic_cast<KWFrame*>(rootArea->associatedShape()->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(KoTextLayoutRootArea \
*rootArea, bool isNew  if (frame->minimumFrameHeight() != 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 relayout the \
                whole page
                 frameSet()->wordsDocument()->frameLayout()->layoutFramesOnPage(page.pageNumber());
  }
diff --git a/words/part/KWRootAreaProviderBase.cpp \
b/words/part/KWRootAreaProviderBase.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 <KoTextLayoutRootArea.h>
 #include <KoShape.h>
@@ -91,12 +92,8 @@ void KWRootAreaProviderBase::doPostLayout(KoTextLayoutRootArea \
*rootArea, bool /  rootArea->associatedShape()->setSize(newSize);
 
         // transfer the new size to the copy-shapes
-        if (KWFrame *frame = \
                dynamic_cast<KWFrame*>(rootArea->associatedShape()->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/KWRootAreaProviderTextBox.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 <KoTextLayoutRootArea.h>
@@ -182,12 +183,8 @@ void \
KWRootAreaProviderTextBox::doPostLayout(KoTextLayoutRootArea *rootArea, boo  \
rootArea->associatedShape()->setSize(newSize);  
         // transfer the new size to the copy-shapes
-        if (KWFrame *frame = \
                dynamic_cast<KWFrame*>(rootArea->associatedShape()->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 = 0; // no delete is needed as the shape deletes us.
 
     if (m_frameSet) {
-        cleanupShape(ourShape);
+        m_frameSet->cleanupShape(ourShape);
 
         bool justMe = m_frameSet->shapeCount() == 1;
         m_frameSet->removeFrame(this, ourShape); // first remove me so we won't get \
double @@ -111,36 +111,6 @@ void KWFrame::setMinimumFrameHeight(qreal \
minimumFrameHeight)  if (m_minimumFrameHeight == minimumFrameHeight)
         return;
     m_minimumFrameHeight = 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 = dynamic_cast<KWTextFrameSet*>(m_frameSet);
-    if (tfs) {
-        KWRootAreaProviderBase *rootAreaProvider = tfs->rootAreaProvider();
-        // it is no longer set when document is destroyed
-        if (rootAreaProvider) {
-            KoTextDocumentLayout *lay = \
                dynamic_cast<KoTextDocumentLayout*>(tfs->document()->documentLayout());
                
-            Q_ASSERT(lay);
-            QList<KoTextLayoutRootArea *> layoutRootAreas = lay->rootAreas();
-            for(int i = 0; i < layoutRootAreas.count(); ++i) {
-                KoTextLayoutRootArea *rootArea = layoutRootAreas[i];
-                if (rootArea->associatedShape() == shape) {
-                    KoTextLayoutRootArea *prevRootArea = i >= 1 ? layoutRootAreas[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 afterwards \
needs to invalidate lots of stuff including whatever is done in the \
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 = fs;
@@ -158,22 +128,6 @@ void KWFrame::setFrameSetxx(KWFrameSet *fs)
         fs->addFrame(this);
 }
 
-QList<KWFrame*> 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, int \
/*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<KWFrame*> 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<KWFrame*> m_copyShapes;
 };
 
 #endif
diff --git a/words/part/frames/KWFrameSet.cpp b/words/part/frames/KWFrameSet.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 = dynamic_cast<KWCopyShape*>(frame->shape());
     if (copyShape) {
         if (copyShape->original()) {
-            KWFrame *originalFrame = \
                dynamic_cast<KWFrame*>(copyShape->original()->applicationData());
-            if (originalFrame) {
-                originalFrame->addCopy(frame);
-            }
+            addCopy(copyShape);
         }
     }
     emit frameAdded(frame);
@@ -79,12 +76,7 @@ void KWFrameSet::removeFrame(KWFrame *frame, KoShape *shape)
     Q_ASSERT(frame);
     KWCopyShape* copyShape = dynamic_cast<KWCopyShape*>(frame->shape());
     if (copyShape) {
-        if (copyShape->original()) {
-            KWFrame *originalFrame = \
                dynamic_cast<KWFrame*>(copyShape->original()->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 references the \
removed @@ -94,7 +86,7 @@ void KWFrameSet::removeFrame(KWFrame *frame, KoShape \
                *shape)
             if (KWCopyShape *cs = dynamic_cast<KWCopyShape*>(frame->shape())) {
                 if (cs->original() == shape) {
                     Q_ASSERT(frame->frameSetxx() == this);
-                    frame->cleanupShape(cs);
+                    cleanupShape(cs);
                     removeFrame(frame, cs);
                     delete cs;
                 }
@@ -108,3 +100,18 @@ void KWFrameSet::removeFrame(KWFrame *frame, KoShape *shape)
     }
 }
 
+QList<KWCopyShape *> 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 <QObject>
 
+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<KWCopyShape *> 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<KWCopyShape *> m_copyShapes;
 };
 
 #endif
diff --git a/words/part/frames/KWTextFrameSet.cpp \
b/words/part/frames/KWTextFrameSet.cpp index 9eb207c..56bc11c 100644
--- a/words/part/frames/KWTextFrameSet.cpp
+++ b/words/part/frames/KWTextFrameSet.cpp
@@ -35,6 +35,7 @@
 #include <KoTextDocument.h>
 #include <KoTextEditor.h>
 #include <KoTextDocumentLayout.h>
+#include <KoTextLayoutRootArea.h>
 #include <KoShapeFactoryBase.h>
 #include <KoAnnotationLayoutManager.h>
 
@@ -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 = \
dynamic_cast<KoTextDocumentLayout*>(document()->documentLayout()); +        \
Q_ASSERT(lay); +        QList<KoTextLayoutRootArea *> layoutRootAreas = \
lay->rootAreas(); +        for(int i = 0; i < layoutRootAreas.count(); ++i) {
+            KoTextLayoutRootArea *rootArea = layoutRootAreas[i];
+            if (rootArea->associatedShape() == shape) {
+                KoTextLayoutRootArea *prevRootArea = i >= 1 ? layoutRootAreas[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/KWTextFrameSet.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();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic