Skip to content
Permalink
Browse files

[FEATURE]: Multipage compositions

  • Loading branch information
mhugent committed Jul 13, 2012
1 parent b70a0c6 commit f70e716495a697547d9afbc9a59da2709d7ad789
@@ -41,6 +41,8 @@ QgsCompositionWidget::QgsCompositionWidget( QWidget* parent, QgsComposition* c )

if ( mComposition )
{
mNumPagesSpinBox->setValue( mComposition->numPages() );

//read printout resolution from composition
mResolutionSpinBox->setValue( mComposition->printResolution() );

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

void QgsCompositionWidget::on_mNumPagesSpinBox_valueChanged( int value )
{
if ( !mComposition )
{
return;
}
mComposition->setNumPages( value );
}

void QgsCompositionWidget::displayCompositionWidthHeight()
{
if ( !mComposition )
@@ -519,6 +530,7 @@ void QgsCompositionWidget::blockSignals( bool block )
mPaperUnitsComboBox->blockSignals( block );
mPaperWidthDoubleSpinBox->blockSignals( block );
mPaperHeightDoubleSpinBox->blockSignals( block );
mNumPagesSpinBox->blockSignals( block );
mPaperOrientationComboBox->blockSignals( block );
mResolutionSpinBox->blockSignals( block );
mPrintAsRasterCheckBox->blockSignals( block );
@@ -45,6 +45,7 @@ class QgsCompositionWidget: public QWidget, private Ui::QgsCompositionWidgetBase
void on_mPaperOrientationComboBox_currentIndexChanged( const QString& text );
void on_mPaperWidthDoubleSpinBox_editingFinished();
void on_mPaperHeightDoubleSpinBox_editingFinished();
void on_mNumPagesSpinBox_valueChanged( int value );
void on_mResolutionSpinBox_valueChanged( const int value );
void on_mPrintAsRasterCheckBox_stateChanged( int state );

@@ -33,30 +33,29 @@
#include <QSettings>

QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer ):
QGraphicsScene( 0 ), mMapRenderer( mapRenderer ), mPlotStyle( QgsComposition::Preview ), mPaperItem( 0 ), mPrintAsRaster( false ), mSelectionTolerance( 0.0 ),
QGraphicsScene( 0 ), mMapRenderer( mapRenderer ), mPlotStyle( QgsComposition::Preview ), mPageWidth( 297 ), mPageHeight( 210 ), mPrintAsRaster( false ), mSelectionTolerance( 0.0 ),
mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveCommand( 0 )
{
setBackgroundBrush( Qt::gray );
addPaperItem();

//set paper item
mPaperItem = new QgsPaperItem( 0, 0, 297, 210, this ); //default size A4
mPaperItem->setBrush( Qt::white );
addItem( mPaperItem );
mPaperItem->setZValue( 0 );
mPrintResolution = 300; //hardcoded default
loadSettings();
}

QgsComposition::QgsComposition():
QGraphicsScene( 0 ), mMapRenderer( 0 ), mPlotStyle( QgsComposition::Preview ), mPaperItem( 0 ), mPrintAsRaster( false ),
QGraphicsScene( 0 ), mMapRenderer( 0 ), mPlotStyle( QgsComposition::Preview ), mPageWidth( 297 ), mPageHeight( 210 ), mPrintAsRaster( false ),
mSelectionTolerance( 0.0 ), mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveCommand( 0 )
{
loadSettings();
}

QgsComposition::~QgsComposition()
{
delete mPaperItem;
for ( int i = 0; i < mPages.size(); ++i )
{
delete mPages.at( i );
}

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

void QgsComposition::setPaperSize( double width, double height )
{
if ( mPaperItem )
for ( int i = 0; i < mPages.size(); ++i )
{
mPaperItem->setRect( QRectF( 0, 0, width, height ) );
emit paperSizeChanged();
mPages.at( i )->setRect( QRectF( 0, 0, width, height ) );
}
}

double QgsComposition::paperHeight() const
{
return mPaperItem->rect().height();
return mPageHeight;
}

double QgsComposition::paperWidth() const
{
return mPaperItem->rect().width();
return mPageWidth;
}

void QgsComposition::setNumPages( int pages )
{
int currentPages = numPages();
int diff = pages - currentPages;
if ( diff >= 0 )
{
for ( int i = 0; i < diff; ++i )
{
addPaperItem();
}
}
else
{
diff = -diff;
for ( int i = 0; i < diff; ++i )
{
delete mPages.last();
mPages.removeLast();
}
}
}

int QgsComposition::numPages() const
{
return mPages.size();
}

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

QDomElement compositionElem = doc.createElement( "Composition" );
#if 0
if ( mPaperItem )
{
compositionElem.setAttribute( "paperWidth", QString::number( mPaperItem->rect().width() ) );
compositionElem.setAttribute( "paperHeight", QString::number( mPaperItem->rect().height() ) );
}
#endif //0

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

if ( widthConversionOk && heightConversionOk )
{
#if 0
delete mPaperItem;
mPaperItem = new QgsPaperItem( 0, 0, paperWidth, paperHeight, this );
mPaperItem->setBrush( Qt::white );
addItem( mPaperItem );
mPaperItem->setZValue( 0 );
#endif //0
}

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

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

#if 0
if ( mPaperItem )
{
mPaperItem->update();
}
#endif //0

return true;
}
@@ -824,60 +856,72 @@ int QgsComposition::boundingRectOfSelectedItems( QRectF& bRect )
void QgsComposition::setSnapToGridEnabled( bool b )
{
mSnapToGrid = b;
#if 0
if ( mPaperItem )
{
mPaperItem->update();
}
#endif //0
saveSettings();
}

void QgsComposition::setSnapGridResolution( double r )
{
mSnapGridResolution = r;
#if 0
if ( mPaperItem )
{
mPaperItem->update();
}
#endif //0
saveSettings();
}

void QgsComposition::setSnapGridOffsetX( double offset )
{
mSnapGridOffsetX = offset;
#if 0
if ( mPaperItem )
{
mPaperItem->update();
}
#endif //0
saveSettings();
}

void QgsComposition::setSnapGridOffsetY( double offset )
{
mSnapGridOffsetY = offset;
#if 0
if ( mPaperItem )
{
mPaperItem->update();
}
#endif //0
saveSettings();
}

void QgsComposition::setGridPen( const QPen& p )
{
mGridPen = p;
#if 0
if ( mPaperItem )
{
mPaperItem->update();
}
#endif //0
saveSettings();
}

void QgsComposition::setGridStyle( GridStyle s )
{
mGridStyle = s;
#if 0
if ( mPaperItem )
{
mPaperItem->update();
}
#endif //0
saveSettings();
}

@@ -1197,3 +1241,15 @@ void QgsComposition::sendItemAddedSignal( QgsComposerItem* item )
return;
}
}

void QgsComposition::addPaperItem()
{
double paperHeight = this->paperHeight();
double paperWidth = this->paperWidth();
double currentY = paperHeight * mPages.size();
QgsPaperItem* paperItem = new QgsPaperItem( 0, currentY, paperWidth, paperHeight, this ); //default size A4
paperItem->setBrush( Qt::white );
addItem( paperItem );
paperItem->setZValue( 0 );
mPages.push_back( paperItem );
}
@@ -79,6 +79,9 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
/**Returns width of paper item*/
double paperWidth() const;

void setNumPages( int pages );
int numPages() const;

void setSnapToGridEnabled( bool b );
bool snapToGridEnabled() const {return mSnapToGrid;}

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

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

void connectAddRemoveCommandSignals( QgsAddRemoveItemCommand* c );

void addPaperItem();

signals:
void paperSizeChanged();

@@ -152,7 +152,7 @@
</item>
</layout>
</item>
<item row="2" column="0">
<item row="4" column="0">
<widget class="QLabel" name="textLabel7">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
@@ -171,7 +171,7 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="4" column="1">
<widget class="QComboBox" name="mPaperOrientationComboBox">
<property name="enabled">
<bool>true</bool>
@@ -184,7 +184,7 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="5" column="0">
<widget class="QCheckBox" name="mPrintAsRasterCheckBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@@ -197,7 +197,7 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="5" column="1">
<widget class="QSpinBox" name="mResolutionSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@@ -216,6 +216,16 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="mNumPagesSpinBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mNumPagesLabel">
<property name="text">
<string>Number of pages</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

0 comments on commit f70e716

Please sign in to comment.
You can’t perform that action at this time.