Skip to content

Commit

Permalink
Add option to turn on / off printing of canvas item in composer map (…
Browse files Browse the repository at this point in the history
…ticket #2734)

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14549 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 12, 2010
1 parent a71881e commit 241f54a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 7 deletions.
26 changes: 26 additions & 0 deletions src/app/composer/qgscomposermapwidget.cpp
Expand Up @@ -292,6 +292,16 @@ void QgsComposerMapWidget::updateGuiElements()
mKeepLayerListCheckBox->setCheckState( Qt::Unchecked );
}

//draw canvas items
if ( mComposerMap->drawCanvasItems() )
{
mDrawCanvasItemsCheckBox->setCheckState( Qt::Checked );
}
else
{
mDrawCanvasItemsCheckBox->setCheckState( Qt::Unchecked );
}

//grid
if ( mComposerMap->gridEnabled() )
{
Expand Down Expand Up @@ -418,6 +428,7 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
mDistanceToMapFrameSpinBox->blockSignals( b );
mAnnotationDirectionComboBox->blockSignals( b );
mCoordinatePrecisionSpinBox->blockSignals( b );
mDrawCanvasItemsCheckBox->blockSignals( b );
}

void QgsComposerMapWidget::on_mUpdatePreviewButton_clicked()
Expand Down Expand Up @@ -461,6 +472,21 @@ void QgsComposerMapWidget::on_mKeepLayerListCheckBox_stateChanged( int state )
}
}

void QgsComposerMapWidget::on_mDrawCanvasItemsCheckBox_stateChanged( int state )
{
if ( !mComposerMap )
{
return;
}

mComposerMap->setDrawCanvasItems( state == Qt::Checked );
mUpdatePreviewButton->setEnabled( false ); //prevent crashes because of many button clicks
mComposerMap->setCacheUpdated( false );
mComposerMap->cache();
mComposerMap->update();
mUpdatePreviewButton->setEnabled( true );
}

void QgsComposerMapWidget::on_mGridCheckBox_toggled( bool state )
{
if ( !mComposerMap )
Expand Down
1 change: 1 addition & 0 deletions src/app/composer/qgscomposermapwidget.h
Expand Up @@ -43,6 +43,7 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
void on_mSetToMapCanvasExtentButton_clicked();
void on_mUpdatePreviewButton_clicked();
void on_mKeepLayerListCheckBox_stateChanged( int state );
void on_mDrawCanvasItemsCheckBox_stateChanged( int state );

void on_mXMinLineEdit_editingFinished();
void on_mXMaxLineEdit_editingFinished();
Expand Down
27 changes: 24 additions & 3 deletions src/core/composer/qgscomposermap.cpp
Expand Up @@ -43,7 +43,8 @@
QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height )
: QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ), \
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), \
mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ), mCrossLength( 3 ), mMapCanvas( 0 )
mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ),
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true )
{
mComposition = composition;
mId = mComposition->composerMapItems().size();
Expand Down Expand Up @@ -74,7 +75,8 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
QgsComposerMap::QgsComposerMap( QgsComposition *composition )
: QgsComposerItem( 0, 0, 10, 10, composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ), \
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), \
mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ), mCrossLength( 3 ), mMapCanvas( 0 )
mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ), mCrossLength( 3 ),
mMapCanvas( 0 ), mDrawCanvasItems( true )
{
//Offset
mXOffset = 0.0;
Expand Down Expand Up @@ -604,6 +606,15 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
composerMapElem.setAttribute( "keepLayerSet", "false" );
}

if ( mDrawCanvasItems )
{
composerMapElem.setAttribute( "drawCanvasItems", "true" );
}
else
{
composerMapElem.setAttribute( "drawCanvasItems", "false" );
}

//extent
QDomElement extentElem = doc.createElement( "Extent" );
extentElem.setAttribute( "xmin", mExtent.xMinimum() );
Expand Down Expand Up @@ -708,6 +719,16 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
mKeepLayerSet = false;
}

QString drawCanvasItemsFlag = itemElem.attribute( "drawCanvasItems" );
if ( drawCanvasItemsFlag.compare( "true", Qt::CaseInsensitive ) == 0 )
{
mDrawCanvasItems = true;
}
else
{
mDrawCanvasItems = false;
}

//mLayerSet
QDomNodeList layerSetNodeList = itemElem.elementsByTagName( "LayerSet" );
QStringList layerSet;
Expand Down Expand Up @@ -1410,7 +1431,7 @@ QgsComposerMap::Border QgsComposerMap::borderForLineCoord( const QPointF& p ) co

void QgsComposerMap::drawCanvasItems( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle )
{
if ( !mMapCanvas )
if ( !mMapCanvas || !mDrawCanvasItems )
{
return;
}
Expand Down
5 changes: 5 additions & 0 deletions src/core/composer/qgscomposermap.h
Expand Up @@ -254,6 +254,9 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
/**Sets canvas pointer (necessary to query and draw map canvas items)*/
void setMapCanvas( QGraphicsView* canvas ) { mMapCanvas = canvas; }

void setDrawCanvasItems( bool b ) { mDrawCanvasItems = b; }
bool drawCanvasItems() const { return mDrawCanvasItems; }

public slots:

/**Called if map canvas has changed*/
Expand Down Expand Up @@ -351,6 +354,8 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
/**The length of the cross sides for mGridStyle Cross*/
double mCrossLength;
QGraphicsView* mMapCanvas;
/**True if annotation items, rubber band, etc. from the main canvas should be displayed*/
bool mDrawCanvasItems;

/**Draws the map grid*/
void drawGrid( QPainter* p );
Expand Down
15 changes: 11 additions & 4 deletions src/ui/qgscomposermapwidgetbase.ui
Expand Up @@ -34,7 +34,7 @@
<x>0</x>
<y>0</y>
<width>377</width>
<height>455</height>
<height>414</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -178,7 +178,14 @@
</item>
</layout>
</item>
<item row="10" column="0">
<item row="10" column="0" colspan="2">
<widget class="QCheckBox" name="mDrawCanvasItemsCheckBox">
<property name="text">
<string>Draw map canvas items</string>
</property>
</widget>
</item>
<item row="11" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -202,7 +209,7 @@
<x>0</x>
<y>0</y>
<width>394</width>
<height>347</height>
<height>356</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -319,7 +326,7 @@
<x>0</x>
<y>0</y>
<width>377</width>
<height>789</height>
<height>720</height>
</rect>
</property>
<attribute name="label">
Expand Down

0 comments on commit 241f54a

Please sign in to comment.