Skip to content
Permalink
Browse files

Add option to turn on / off printing of canvas item in composer map (…

…ticket #2734)

git-svn-id: http://svn.osgeo.org/qgis/trunk@14549 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Nov 12, 2010
1 parent 873b94a commit 66d24374d76aac1c9e3e0da8bc5918e3935b1a88
@@ -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() )
{
@@ -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()
@@ -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 )
@@ -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();
@@ -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();
@@ -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;
@@ -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() );
@@ -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;
@@ -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;
}
@@ -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*/
@@ -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 );
@@ -34,7 +34,7 @@
<x>0</x>
<y>0</y>
<width>377</width>
<height>455</height>
<height>414</height>
</rect>
</property>
<attribute name="label">
@@ -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>
@@ -202,7 +209,7 @@
<x>0</x>
<y>0</y>
<width>394</width>
<height>347</height>
<height>356</height>
</rect>
</property>
<attribute name="label">
@@ -319,7 +326,7 @@
<x>0</x>
<y>0</y>
<width>377</width>
<height>789</height>
<height>720</height>
</rect>
</property>
<attribute name="label">

0 comments on commit 66d2437

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