Skip to content

Commit f70e716

Browse files
committed
[FEATURE]: Multipage compositions
1 parent b70a0c6 commit f70e716

File tree

5 files changed

+105
-19
lines changed

5 files changed

+105
-19
lines changed

src/app/composer/qgscompositionwidget.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ QgsCompositionWidget::QgsCompositionWidget( QWidget* parent, QgsComposition* c )
4141

4242
if ( mComposition )
4343
{
44+
mNumPagesSpinBox->setValue( mComposition->numPages() );
45+
4446
//read printout resolution from composition
4547
mResolutionSpinBox->setValue( mComposition->printResolution() );
4648

@@ -328,6 +330,15 @@ void QgsCompositionWidget::on_mPaperHeightDoubleSpinBox_editingFinished()
328330
applyWidthHeight();
329331
}
330332

333+
void QgsCompositionWidget::on_mNumPagesSpinBox_valueChanged( int value )
334+
{
335+
if ( !mComposition )
336+
{
337+
return;
338+
}
339+
mComposition->setNumPages( value );
340+
}
341+
331342
void QgsCompositionWidget::displayCompositionWidthHeight()
332343
{
333344
if ( !mComposition )
@@ -519,6 +530,7 @@ void QgsCompositionWidget::blockSignals( bool block )
519530
mPaperUnitsComboBox->blockSignals( block );
520531
mPaperWidthDoubleSpinBox->blockSignals( block );
521532
mPaperHeightDoubleSpinBox->blockSignals( block );
533+
mNumPagesSpinBox->blockSignals( block );
522534
mPaperOrientationComboBox->blockSignals( block );
523535
mResolutionSpinBox->blockSignals( block );
524536
mPrintAsRasterCheckBox->blockSignals( block );

src/app/composer/qgscompositionwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class QgsCompositionWidget: public QWidget, private Ui::QgsCompositionWidgetBase
4545
void on_mPaperOrientationComboBox_currentIndexChanged( const QString& text );
4646
void on_mPaperWidthDoubleSpinBox_editingFinished();
4747
void on_mPaperHeightDoubleSpinBox_editingFinished();
48+
void on_mNumPagesSpinBox_valueChanged( int value );
4849
void on_mResolutionSpinBox_valueChanged( const int value );
4950
void on_mPrintAsRasterCheckBox_stateChanged( int state );
5051

src/core/composer/qgscomposition.cpp

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,29 @@
3333
#include <QSettings>
3434

3535
QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer ):
36-
QGraphicsScene( 0 ), mMapRenderer( mapRenderer ), mPlotStyle( QgsComposition::Preview ), mPaperItem( 0 ), mPrintAsRaster( false ), mSelectionTolerance( 0.0 ),
36+
QGraphicsScene( 0 ), mMapRenderer( mapRenderer ), mPlotStyle( QgsComposition::Preview ), mPageWidth( 297 ), mPageHeight( 210 ), mPrintAsRaster( false ), mSelectionTolerance( 0.0 ),
3737
mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveCommand( 0 )
3838
{
3939
setBackgroundBrush( Qt::gray );
40+
addPaperItem();
4041

41-
//set paper item
42-
mPaperItem = new QgsPaperItem( 0, 0, 297, 210, this ); //default size A4
43-
mPaperItem->setBrush( Qt::white );
44-
addItem( mPaperItem );
45-
mPaperItem->setZValue( 0 );
4642
mPrintResolution = 300; //hardcoded default
4743
loadSettings();
4844
}
4945

5046
QgsComposition::QgsComposition():
51-
QGraphicsScene( 0 ), mMapRenderer( 0 ), mPlotStyle( QgsComposition::Preview ), mPaperItem( 0 ), mPrintAsRaster( false ),
47+
QGraphicsScene( 0 ), mMapRenderer( 0 ), mPlotStyle( QgsComposition::Preview ), mPageWidth( 297 ), mPageHeight( 210 ), mPrintAsRaster( false ),
5248
mSelectionTolerance( 0.0 ), mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveCommand( 0 )
5349
{
5450
loadSettings();
5551
}
5652

5753
QgsComposition::~QgsComposition()
5854
{
59-
delete mPaperItem;
55+
for ( int i = 0; i < mPages.size(); ++i )
56+
{
57+
delete mPages.at( i );
58+
}
6059

6160
// make sure that all composer items are removed before
6261
// this class is deconstructed - to avoid segfaults
@@ -66,21 +65,47 @@ QgsComposition::~QgsComposition()
6665

6766
void QgsComposition::setPaperSize( double width, double height )
6867
{
69-
if ( mPaperItem )
68+
for ( int i = 0; i < mPages.size(); ++i )
7069
{
71-
mPaperItem->setRect( QRectF( 0, 0, width, height ) );
72-
emit paperSizeChanged();
70+
mPages.at( i )->setRect( QRectF( 0, 0, width, height ) );
7371
}
7472
}
7573

7674
double QgsComposition::paperHeight() const
7775
{
78-
return mPaperItem->rect().height();
76+
return mPageHeight;
7977
}
8078

8179
double QgsComposition::paperWidth() const
8280
{
83-
return mPaperItem->rect().width();
81+
return mPageWidth;
82+
}
83+
84+
void QgsComposition::setNumPages( int pages )
85+
{
86+
int currentPages = numPages();
87+
int diff = pages - currentPages;
88+
if ( diff >= 0 )
89+
{
90+
for ( int i = 0; i < diff; ++i )
91+
{
92+
addPaperItem();
93+
}
94+
}
95+
else
96+
{
97+
diff = -diff;
98+
for ( int i = 0; i < diff; ++i )
99+
{
100+
delete mPages.last();
101+
mPages.removeLast();
102+
}
103+
}
104+
}
105+
106+
int QgsComposition::numPages() const
107+
{
108+
return mPages.size();
84109
}
85110

86111
QgsComposerItem* QgsComposition::composerItemAt( const QPointF & position )
@@ -100,7 +125,8 @@ QgsComposerItem* QgsComposition::composerItemAt( const QPointF & position )
100125
for ( ; itemIt != itemList.end(); ++itemIt )
101126
{
102127
QgsComposerItem* composerItem = dynamic_cast<QgsComposerItem *>( *itemIt );
103-
if ( composerItem && composerItem != mPaperItem )
128+
QgsPaperItem* paperItem = dynamic_cast<QgsPaperItem*>( *itemIt );
129+
if ( composerItem && !paperItem )
104130
{
105131
return composerItem;
106132
}
@@ -187,11 +213,13 @@ bool QgsComposition::writeXML( QDomElement& composerElem, QDomDocument& doc )
187213
}
188214

189215
QDomElement compositionElem = doc.createElement( "Composition" );
216+
#if 0
190217
if ( mPaperItem )
191218
{
192219
compositionElem.setAttribute( "paperWidth", QString::number( mPaperItem->rect().width() ) );
193220
compositionElem.setAttribute( "paperHeight", QString::number( mPaperItem->rect().height() ) );
194221
}
222+
#endif //0
195223

196224
//snapping
197225
if ( mSnapToGrid )
@@ -229,11 +257,13 @@ bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocu
229257

230258
if ( widthConversionOk && heightConversionOk )
231259
{
260+
#if 0
232261
delete mPaperItem;
233262
mPaperItem = new QgsPaperItem( 0, 0, paperWidth, paperHeight, this );
234263
mPaperItem->setBrush( Qt::white );
235264
addItem( mPaperItem );
236265
mPaperItem->setZValue( 0 );
266+
#endif //0
237267
}
238268

239269
//snapping
@@ -252,10 +282,12 @@ bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocu
252282

253283
mPrintResolution = compositionElem.attribute( "printResolution", "300" ).toInt();
254284

285+
#if 0
255286
if ( mPaperItem )
256287
{
257288
mPaperItem->update();
258289
}
290+
#endif //0
259291

260292
return true;
261293
}
@@ -824,60 +856,72 @@ int QgsComposition::boundingRectOfSelectedItems( QRectF& bRect )
824856
void QgsComposition::setSnapToGridEnabled( bool b )
825857
{
826858
mSnapToGrid = b;
859+
#if 0
827860
if ( mPaperItem )
828861
{
829862
mPaperItem->update();
830863
}
864+
#endif //0
831865
saveSettings();
832866
}
833867

834868
void QgsComposition::setSnapGridResolution( double r )
835869
{
836870
mSnapGridResolution = r;
871+
#if 0
837872
if ( mPaperItem )
838873
{
839874
mPaperItem->update();
840875
}
876+
#endif //0
841877
saveSettings();
842878
}
843879

844880
void QgsComposition::setSnapGridOffsetX( double offset )
845881
{
846882
mSnapGridOffsetX = offset;
883+
#if 0
847884
if ( mPaperItem )
848885
{
849886
mPaperItem->update();
850887
}
888+
#endif //0
851889
saveSettings();
852890
}
853891

854892
void QgsComposition::setSnapGridOffsetY( double offset )
855893
{
856894
mSnapGridOffsetY = offset;
895+
#if 0
857896
if ( mPaperItem )
858897
{
859898
mPaperItem->update();
860899
}
900+
#endif //0
861901
saveSettings();
862902
}
863903

864904
void QgsComposition::setGridPen( const QPen& p )
865905
{
866906
mGridPen = p;
907+
#if 0
867908
if ( mPaperItem )
868909
{
869910
mPaperItem->update();
870911
}
912+
#endif //0
871913
saveSettings();
872914
}
873915

874916
void QgsComposition::setGridStyle( GridStyle s )
875917
{
876918
mGridStyle = s;
919+
#if 0
877920
if ( mPaperItem )
878921
{
879922
mPaperItem->update();
880923
}
924+
#endif //0
881925
saveSettings();
882926
}
883927

@@ -1197,3 +1241,15 @@ void QgsComposition::sendItemAddedSignal( QgsComposerItem* item )
11971241
return;
11981242
}
11991243
}
1244+
1245+
void QgsComposition::addPaperItem()
1246+
{
1247+
double paperHeight = this->paperHeight();
1248+
double paperWidth = this->paperWidth();
1249+
double currentY = paperHeight * mPages.size();
1250+
QgsPaperItem* paperItem = new QgsPaperItem( 0, currentY, paperWidth, paperHeight, this ); //default size A4
1251+
paperItem->setBrush( Qt::white );
1252+
addItem( paperItem );
1253+
paperItem->setZValue( 0 );
1254+
mPages.push_back( paperItem );
1255+
}

src/core/composer/qgscomposition.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
7979
/**Returns width of paper item*/
8080
double paperWidth() const;
8181

82+
void setNumPages( int pages );
83+
int numPages() const;
84+
8285
void setSnapToGridEnabled( bool b );
8386
bool snapToGridEnabled() const {return mSnapToGrid;}
8487

@@ -222,7 +225,9 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
222225
/**Pointer to map renderer of QGIS main map*/
223226
QgsMapRenderer* mMapRenderer;
224227
QgsComposition::PlotStyle mPlotStyle;
225-
QgsPaperItem* mPaperItem;
228+
double mPageWidth;
229+
double mPageHeight;
230+
QList< QgsPaperItem* > mPages;
226231

227232
/**Maintains z-Order of items. Starts with item at position 1 (position 0 is always paper item)*/
228233
QLinkedList<QgsComposerItem*> mItemZList;
@@ -262,6 +267,8 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
262267

263268
void connectAddRemoveCommandSignals( QgsAddRemoveItemCommand* c );
264269

270+
void addPaperItem();
271+
265272
signals:
266273
void paperSizeChanged();
267274

src/ui/qgscompositionwidgetbase.ui

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
</item>
153153
</layout>
154154
</item>
155-
<item row="2" column="0">
155+
<item row="4" column="0">
156156
<widget class="QLabel" name="textLabel7">
157157
<property name="sizePolicy">
158158
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
@@ -171,7 +171,7 @@
171171
</property>
172172
</widget>
173173
</item>
174-
<item row="2" column="1">
174+
<item row="4" column="1">
175175
<widget class="QComboBox" name="mPaperOrientationComboBox">
176176
<property name="enabled">
177177
<bool>true</bool>
@@ -184,7 +184,7 @@
184184
</property>
185185
</widget>
186186
</item>
187-
<item row="3" column="0">
187+
<item row="5" column="0">
188188
<widget class="QCheckBox" name="mPrintAsRasterCheckBox">
189189
<property name="sizePolicy">
190190
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@@ -197,7 +197,7 @@
197197
</property>
198198
</widget>
199199
</item>
200-
<item row="3" column="1">
200+
<item row="5" column="1">
201201
<widget class="QSpinBox" name="mResolutionSpinBox">
202202
<property name="sizePolicy">
203203
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@@ -216,6 +216,16 @@
216216
</property>
217217
</widget>
218218
</item>
219+
<item row="2" column="1">
220+
<widget class="QSpinBox" name="mNumPagesSpinBox"/>
221+
</item>
222+
<item row="2" column="0">
223+
<widget class="QLabel" name="mNumPagesLabel">
224+
<property name="text">
225+
<string>Number of pages</string>
226+
</property>
227+
</widget>
228+
</item>
219229
</layout>
220230
</widget>
221231
</item>

0 commit comments

Comments
 (0)