Skip to content

Commit 241f54a

Browse files
author
mhugent
committedNov 12, 2010
Add option to turn on / off printing of canvas item in composer map (ticket #2734)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14549 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

5 files changed

+67
-7
lines changed

5 files changed

+67
-7
lines changed
 

‎src/app/composer/qgscomposermapwidget.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,16 @@ void QgsComposerMapWidget::updateGuiElements()
292292
mKeepLayerListCheckBox->setCheckState( Qt::Unchecked );
293293
}
294294

295+
//draw canvas items
296+
if ( mComposerMap->drawCanvasItems() )
297+
{
298+
mDrawCanvasItemsCheckBox->setCheckState( Qt::Checked );
299+
}
300+
else
301+
{
302+
mDrawCanvasItemsCheckBox->setCheckState( Qt::Unchecked );
303+
}
304+
295305
//grid
296306
if ( mComposerMap->gridEnabled() )
297307
{
@@ -418,6 +428,7 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
418428
mDistanceToMapFrameSpinBox->blockSignals( b );
419429
mAnnotationDirectionComboBox->blockSignals( b );
420430
mCoordinatePrecisionSpinBox->blockSignals( b );
431+
mDrawCanvasItemsCheckBox->blockSignals( b );
421432
}
422433

423434
void QgsComposerMapWidget::on_mUpdatePreviewButton_clicked()
@@ -461,6 +472,21 @@ void QgsComposerMapWidget::on_mKeepLayerListCheckBox_stateChanged( int state )
461472
}
462473
}
463474

475+
void QgsComposerMapWidget::on_mDrawCanvasItemsCheckBox_stateChanged( int state )
476+
{
477+
if ( !mComposerMap )
478+
{
479+
return;
480+
}
481+
482+
mComposerMap->setDrawCanvasItems( state == Qt::Checked );
483+
mUpdatePreviewButton->setEnabled( false ); //prevent crashes because of many button clicks
484+
mComposerMap->setCacheUpdated( false );
485+
mComposerMap->cache();
486+
mComposerMap->update();
487+
mUpdatePreviewButton->setEnabled( true );
488+
}
489+
464490
void QgsComposerMapWidget::on_mGridCheckBox_toggled( bool state )
465491
{
466492
if ( !mComposerMap )

‎src/app/composer/qgscomposermapwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
4343
void on_mSetToMapCanvasExtentButton_clicked();
4444
void on_mUpdatePreviewButton_clicked();
4545
void on_mKeepLayerListCheckBox_stateChanged( int state );
46+
void on_mDrawCanvasItemsCheckBox_stateChanged( int state );
4647

4748
void on_mXMinLineEdit_editingFinished();
4849
void on_mXMaxLineEdit_editingFinished();

‎src/core/composer/qgscomposermap.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height )
4444
: QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ), \
4545
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), \
46-
mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ), mCrossLength( 3 ), mMapCanvas( 0 )
46+
mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ),
47+
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true )
4748
{
4849
mComposition = composition;
4950
mId = mComposition->composerMapItems().size();
@@ -74,7 +75,8 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
7475
QgsComposerMap::QgsComposerMap( QgsComposition *composition )
7576
: QgsComposerItem( 0, 0, 10, 10, composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ), \
7677
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), \
77-
mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ), mCrossLength( 3 ), mMapCanvas( 0 )
78+
mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ), mCrossLength( 3 ),
79+
mMapCanvas( 0 ), mDrawCanvasItems( true )
7880
{
7981
//Offset
8082
mXOffset = 0.0;
@@ -604,6 +606,15 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
604606
composerMapElem.setAttribute( "keepLayerSet", "false" );
605607
}
606608

609+
if ( mDrawCanvasItems )
610+
{
611+
composerMapElem.setAttribute( "drawCanvasItems", "true" );
612+
}
613+
else
614+
{
615+
composerMapElem.setAttribute( "drawCanvasItems", "false" );
616+
}
617+
607618
//extent
608619
QDomElement extentElem = doc.createElement( "Extent" );
609620
extentElem.setAttribute( "xmin", mExtent.xMinimum() );
@@ -708,6 +719,16 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
708719
mKeepLayerSet = false;
709720
}
710721

722+
QString drawCanvasItemsFlag = itemElem.attribute( "drawCanvasItems" );
723+
if ( drawCanvasItemsFlag.compare( "true", Qt::CaseInsensitive ) == 0 )
724+
{
725+
mDrawCanvasItems = true;
726+
}
727+
else
728+
{
729+
mDrawCanvasItems = false;
730+
}
731+
711732
//mLayerSet
712733
QDomNodeList layerSetNodeList = itemElem.elementsByTagName( "LayerSet" );
713734
QStringList layerSet;
@@ -1410,7 +1431,7 @@ QgsComposerMap::Border QgsComposerMap::borderForLineCoord( const QPointF& p ) co
14101431

14111432
void QgsComposerMap::drawCanvasItems( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle )
14121433
{
1413-
if ( !mMapCanvas )
1434+
if ( !mMapCanvas || !mDrawCanvasItems )
14141435
{
14151436
return;
14161437
}

‎src/core/composer/qgscomposermap.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
254254
/**Sets canvas pointer (necessary to query and draw map canvas items)*/
255255
void setMapCanvas( QGraphicsView* canvas ) { mMapCanvas = canvas; }
256256

257+
void setDrawCanvasItems( bool b ) { mDrawCanvasItems = b; }
258+
bool drawCanvasItems() const { return mDrawCanvasItems; }
259+
257260
public slots:
258261

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

355360
/**Draws the map grid*/
356361
void drawGrid( QPainter* p );

‎src/ui/qgscomposermapwidgetbase.ui

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<x>0</x>
3535
<y>0</y>
3636
<width>377</width>
37-
<height>455</height>
37+
<height>414</height>
3838
</rect>
3939
</property>
4040
<attribute name="label">
@@ -178,7 +178,14 @@
178178
</item>
179179
</layout>
180180
</item>
181-
<item row="10" column="0">
181+
<item row="10" column="0" colspan="2">
182+
<widget class="QCheckBox" name="mDrawCanvasItemsCheckBox">
183+
<property name="text">
184+
<string>Draw map canvas items</string>
185+
</property>
186+
</widget>
187+
</item>
188+
<item row="11" column="0">
182189
<spacer name="verticalSpacer">
183190
<property name="orientation">
184191
<enum>Qt::Vertical</enum>
@@ -202,7 +209,7 @@
202209
<x>0</x>
203210
<y>0</y>
204211
<width>394</width>
205-
<height>347</height>
212+
<height>356</height>
206213
</rect>
207214
</property>
208215
<attribute name="label">
@@ -319,7 +326,7 @@
319326
<x>0</x>
320327
<y>0</y>
321328
<width>377</width>
322-
<height>789</height>
329+
<height>720</height>
323330
</rect>
324331
</property>
325332
<attribute name="label">

0 commit comments

Comments
 (0)
Please sign in to comment.