Skip to content

Commit d1985a1

Browse files
committed
Introduce flags for boolean settings in map settings.
Also revived drawEditingInformation setting in render context
1 parent 735fab1 commit d1985a1

File tree

8 files changed

+58
-38
lines changed

8 files changed

+58
-38
lines changed

src/core/composer/qgscomposermap.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,12 @@ void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const
167167
jobMapSettings.setLayers( mKeepLayerSet ? mLayerSet : ms.layers() );
168168
jobMapSettings.setDestinationCrs( ms.destinationCrs() );
169169
jobMapSettings.setProjectionsEnabled( ms.hasCrsTransformEnabled() );
170-
jobMapSettings.setAntiAliasingEnabled( ms.isAntiAliasingEnabled() );
171-
jobMapSettings.setDrawEditingInformation( false );
170+
jobMapSettings.setFlags( ms.flags() );
172171

173-
// force vector output (no caching of marker images etc.)
174-
jobMapSettings.setForceVectorOutput( true );
175-
176-
// make the renderer respect the composition's useAdvancedEffects flag
177-
jobMapSettings.setUseAdvancedEffects( mComposition->useAdvancedEffects() );
172+
// composer-specific overrides of flags
173+
jobMapSettings.setFlag( QgsMapSettings::ForceVectorOutput ); // force vector output (no caching of marker images etc.)
174+
jobMapSettings.setFlag( QgsMapSettings::DrawEditingInfo, false );
175+
jobMapSettings.setFlag( QgsMapSettings::UseAdvancedEffects, mComposition->useAdvancedEffects() ); // respect the composition's useAdvancedEffects flag
178176

179177
// render
180178
QgsMapRendererCustomPainterJob job( jobMapSettings, painter );

src/core/qgsmaprendererjob.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void QgsMapRendererCustomPainterJob::startRender()
188188
// clear the background
189189
mPainter->fillRect( 0, 0, mSettings.outputSize().width(), mSettings.outputSize().height(), mSettings.backgroundColor() );
190190

191-
mPainter->setRenderHint( QPainter::Antialiasing, mSettings.isAntiAliasingEnabled() );
191+
mPainter->setRenderHint( QPainter::Antialiasing, mSettings.testFlag( QgsMapSettings::Antialiasing ) );
192192

193193
QPaintDevice* thePaintDevice = mPainter->device();
194194

@@ -202,7 +202,9 @@ void QgsMapRendererCustomPainterJob::startRender()
202202

203203
mRenderContext.setMapToPixel( mSettings.mapToPixel() );
204204
mRenderContext.setExtent( mSettings.visibleExtent() );
205-
mRenderContext.setDrawEditingInformation( false );
205+
mRenderContext.setDrawEditingInformation( mSettings.testFlag( QgsMapSettings::DrawEditingInfo ) );
206+
mRenderContext.setForceVectorOutput( mSettings.testFlag( QgsMapSettings::ForceVectorOutput ) );
207+
mRenderContext.setUseAdvancedEffects( mSettings.testFlag( QgsMapSettings::UseAdvancedEffects ) );
206208
mRenderContext.setPainter( mPainter );
207209
mRenderContext.setCoordinateTransform( 0 );
208210
mRenderContext.setSelectionColor( mSettings.selectionColor() );

src/core/qgsmapsettings.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,6 @@
1111
#include "qgsmaplayer.h"
1212
#include "qgsmaplayerregistry.h"
1313

14-
/*
15-
16-
usage in QgsMapCanvas - upon pan / zoom - in QgsMapCanvasMap:
17-
- stop rendering if active
18-
- update QgsMapRendererV2 settings
19-
- start rendering
20-
- start update timer
21-
- [on timeout/finished] show rendered image
22-
23-
usage in QgsComposer
24-
- create QgsMapRendererV2
25-
- setup, start with QPainter
26-
- wait until it finishes
27-
28-
*/
2914

3015
QgsMapSettings::QgsMapSettings()
3116
: mDpi( 96 ) // what to set?
@@ -35,7 +20,7 @@ QgsMapSettings::QgsMapSettings()
3520
, mDestCRS( GEOCRS_ID, QgsCoordinateReferenceSystem::InternalCrsId ) // WGS 84
3621
, mBackgroundColor( Qt::white )
3722
, mSelectionColor( Qt::yellow )
38-
, mAntiAliasing( true )
23+
, mFlags( Antialiasing )
3924
{
4025
updateDerived();
4126

@@ -214,6 +199,29 @@ void QgsMapSettings::setMapUnits( QGis::UnitType u )
214199
updateDerived();
215200
}
216201

202+
void QgsMapSettings::setFlags( QgsMapSettings::Flags flags )
203+
{
204+
mFlags = flags;
205+
}
206+
207+
void QgsMapSettings::setFlag( QgsMapSettings::Flag flag, bool on )
208+
{
209+
if ( on )
210+
mFlags |= flag;
211+
else
212+
mFlags &= ~flag;
213+
}
214+
215+
QgsMapSettings::Flags QgsMapSettings::flags() const
216+
{
217+
return mFlags;
218+
}
219+
220+
bool QgsMapSettings::testFlag( QgsMapSettings::Flag flag ) const
221+
{
222+
return mFlags.testFlag( flag );
223+
}
224+
217225
QGis::UnitType QgsMapSettings::mapUnits() const
218226
{
219227
return mScaleCalculator.mapUnits();

src/core/qgsmapsettings.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,20 @@ class QgsMapSettings
5454
void setSelectionColor( const QColor& color ) { mSelectionColor = color; }
5555
QColor selectionColor() const { return mSelectionColor; }
5656

57-
void setAntiAliasingEnabled( bool enabled ) { mAntiAliasing = enabled; }
58-
bool isAntiAliasingEnabled() const { return mAntiAliasing; }
59-
60-
// TODO: implement
61-
void setDrawEditingInformation( bool enabled ) { Q_UNUSED(enabled); }
62-
void setForceVectorOutput( bool enabled ) { Q_UNUSED(enabled); }
63-
void setUseAdvancedEffects( bool enabled ) { Q_UNUSED(enabled); }
57+
enum Flag
58+
{
59+
Antialiasing = 0x01,
60+
DrawEditingInfo = 0x02,
61+
ForceVectorOutput = 0x04,
62+
UseAdvancedEffects = 0x08
63+
// TODO: no labeling, ignore scale-based visibiity (overview)
64+
};
65+
Q_DECLARE_FLAGS(Flags, Flag)
66+
67+
void setFlags( Flags flags );
68+
void setFlag( Flag flag, bool on = true );
69+
Flags flags() const;
70+
bool testFlag( Flag flag ) const;
6471

6572
bool hasValidSettings() const;
6673
QgsRectangle visibleExtent() const;
@@ -134,7 +141,8 @@ class QgsMapSettings
134141

135142
QColor mBackgroundColor;
136143
QColor mSelectionColor;
137-
bool mAntiAliasing;
144+
145+
Flags mFlags;
138146

139147
// derived properties
140148
bool mValid; //!< whether the actual settings are valid (set in updateDerived())
@@ -153,5 +161,7 @@ class QgsMapSettings
153161
const QgsCoordinateTransform* coordTransform( QgsMapLayer *layer ) const;
154162
};
155163

164+
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
165+
156166

157167
#endif // QGSMAPSETTINGS_H

src/core/qgsvectorlayer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ void QgsVectorLayer::drawRendererV2( QgsFeatureIterator &fit, QgsRenderContext&
408408
}
409409

410410
bool sel = mSelectedFeatureIds.contains( fet.id() );
411-
bool drawMarker = ( mEditBuffer && ( !vertexMarkerOnlyForSelection || sel ) );
411+
bool drawMarker = ( mEditBuffer && rendererContext.drawEditingInformation() && ( !vertexMarkerOnlyForSelection || sel ) );
412412

413413
// render feature
414414
bool rendered = mRendererV2->renderFeature( fet, rendererContext, -1, sel, drawMarker );
@@ -552,7 +552,7 @@ void QgsVectorLayer::drawRendererV2Levels( QgsFeatureIterator &fit, QgsRenderCon
552552

553553
bool sel = mSelectedFeatureIds.contains( fit->id() );
554554
// maybe vertex markers should be drawn only during the last pass...
555-
bool drawMarker = ( mEditBuffer && ( !vertexMarkerOnlyForSelection || sel ) );
555+
bool drawMarker = ( mEditBuffer && rendererContext.drawEditingInformation() && ( !vertexMarkerOnlyForSelection || sel ) );
556556

557557
try
558558
{

src/gui/qgsmapcanvas.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
126126
connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ),
127127
this, SLOT( writeProject( QDomDocument & ) ) );
128128

129+
mSettings.setFlag( QgsMapSettings::DrawEditingInfo );
130+
129131
mSettings.setOutputSize( size() );
130132
mMap->resize( size() );
131133
setSceneRect( 0, 0, size().width(), size().height() );
@@ -175,7 +177,7 @@ QgsMapCanvas::~QgsMapCanvas()
175177

176178
void QgsMapCanvas::enableAntiAliasing( bool theFlag )
177179
{
178-
mSettings.setAntiAliasingEnabled( theFlag );
180+
mSettings.setFlag( QgsMapSettings::Antialiasing, theFlag );
179181

180182
if ( mMapOverview )
181183
mMapOverview->enableAntiAliasing( theFlag );

src/gui/qgsmapcanvas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
275275
void enableAntiAliasing( bool theFlag );
276276

277277
//! true if antialising is enabled
278-
bool antiAliasingEnabled() const { return mSettings.isAntiAliasingEnabled(); }
278+
bool antiAliasingEnabled() const { return mSettings.testFlag( QgsMapSettings::Antialiasing ); }
279279

280280
//! Select which Qt class to render with
281281
void useImageToRender( bool theFlag );

src/gui/qgsmapoverviewcanvas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class GUI_EXPORT QgsMapOverviewCanvas : public QWidget
6060

6161
QStringList layerSet() const;
6262

63-
void enableAntiAliasing( bool flag ) { mSettings.setAntiAliasingEnabled( flag ); }
63+
void enableAntiAliasing( bool flag ) { mSettings.setFlag( QgsMapSettings::Antialiasing, flag ); }
6464

6565
void updateFullExtent();
6666

0 commit comments

Comments
 (0)