16
16
#include " qgscomposermultiframe.h"
17
17
#include " qgscomposerframe.h"
18
18
19
- QgsComposerMultiFrame::QgsComposerMultiFrame ( QgsComposition* c ): mComposition( c )
19
+ QgsComposerMultiFrame::QgsComposerMultiFrame ( QgsComposition* c ): mComposition( c ), mResizeMode( UseExistingFrames )
20
20
{
21
+ // debug
22
+ mResizeMode = ExtendToNextPage;
21
23
}
22
24
23
- QgsComposerMultiFrame::QgsComposerMultiFrame (): mComposition( 0 )
25
+ QgsComposerMultiFrame::QgsComposerMultiFrame (): mComposition( 0 ), mResizeMode( UseExistingFrames )
24
26
{
25
27
}
26
28
@@ -30,12 +32,65 @@ QgsComposerMultiFrame::~QgsComposerMultiFrame()
30
32
31
33
void QgsComposerMultiFrame::recalculateFrameSizes ()
32
34
{
35
+ if ( mFrameItems .size () < 1 )
36
+ {
37
+ return ;
38
+ }
39
+
40
+ QSizeF size = totalSize ();
41
+ double totalHeight = size.height ();
42
+ double currentY = 0 ;
43
+ double currentHeight = 0 ;
44
+ QgsComposerFrame* currentItem = 0 ;
45
+
46
+ QList<QgsComposerFrame*>::iterator frameIt = mFrameItems .begin ();
47
+ for ( ; frameIt != mFrameItems .end (); ++frameIt )
48
+ {
49
+ if ( currentY >= totalHeight )
50
+ {
51
+ return ;
52
+ }
53
+ currentItem = *frameIt;
54
+ currentHeight = currentItem->rect ().height ();
55
+ currentItem->setContentSection ( QRectF ( 0 , currentY, currentItem->rect ().width (), currentHeight ) );
56
+ currentItem->update ();
57
+ currentY += currentHeight;
58
+ }
59
+
60
+ // at end of frames but there is still content left. Add other pages if ResizeMode ==
61
+ if ( mResizeMode == ExtendToNextPage )
62
+ {
63
+ while ( currentY < totalHeight )
64
+ {
65
+ // find out on which page the lower left point of the last frame is
66
+ int page = currentItem->transform ().dy () / ( mComposition ->paperHeight () + mComposition ->spaceBetweenPages () );
67
+ // double offset = currentItem->transform().dy() - page * ( mComposition->paperHeight() + mComposition->spaceBetweenPages() );
68
+
69
+ // e.v. add a new page
70
+ if ( mComposition ->numPages () < ( page + 2 ) )
71
+ {
72
+ mComposition ->setNumPages ( page + 2 );
73
+ }
74
+
75
+ // copy last frame
76
+ QgsComposerFrame* newFrame = new QgsComposerFrame ( mComposition , this , 0 , currentItem->transform ().dy () + mComposition ->paperHeight () + mComposition ->spaceBetweenPages (),
77
+ currentItem->rect ().width (), currentItem->rect ().height () );
78
+ newFrame->setContentSection ( QRectF ( 0 , currentY, newFrame->rect ().width (), newFrame->rect ().height () ) );
79
+ currentY += newFrame->rect ().height ();
80
+ currentItem = newFrame;
81
+ addFrame ( newFrame );
82
+ mComposition ->addItem ( newFrame );
83
+ }
84
+ }
85
+
86
+ #if 0
33
87
if ( mFrameItems.size() > 0 )
34
88
{
35
89
QSizeF size = totalSize();
36
90
QgsComposerFrame* item = mFrameItems[0];
37
91
item->setContentSection( QRectF( 0, 0, item->rect().width(), item->rect().height() ) );
38
92
}
93
+ #endif // 0
39
94
}
40
95
41
96
void QgsComposerMultiFrame::addFrame ( QgsComposerFrame* frame )
0 commit comments