Skip to content
Permalink
Browse files

Introduce flags for boolean settings in map settings.

Also revived drawEditingInformation setting in render context
  • Loading branch information
wonder-sk committed Nov 13, 2013
1 parent 735fab1 commit d1985a16a3d2bb2b878bcb55631ab70729f37786
@@ -167,14 +167,12 @@ void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const
jobMapSettings.setLayers( mKeepLayerSet ? mLayerSet : ms.layers() );
jobMapSettings.setDestinationCrs( ms.destinationCrs() );
jobMapSettings.setProjectionsEnabled( ms.hasCrsTransformEnabled() );
jobMapSettings.setAntiAliasingEnabled( ms.isAntiAliasingEnabled() );
jobMapSettings.setDrawEditingInformation( false );
jobMapSettings.setFlags( ms.flags() );

// force vector output (no caching of marker images etc.)
jobMapSettings.setForceVectorOutput( true );

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

// render
QgsMapRendererCustomPainterJob job( jobMapSettings, painter );
@@ -188,7 +188,7 @@ void QgsMapRendererCustomPainterJob::startRender()
// clear the background
mPainter->fillRect( 0, 0, mSettings.outputSize().width(), mSettings.outputSize().height(), mSettings.backgroundColor() );

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

QPaintDevice* thePaintDevice = mPainter->device();

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

mRenderContext.setMapToPixel( mSettings.mapToPixel() );
mRenderContext.setExtent( mSettings.visibleExtent() );
mRenderContext.setDrawEditingInformation( false );
mRenderContext.setDrawEditingInformation( mSettings.testFlag( QgsMapSettings::DrawEditingInfo ) );
mRenderContext.setForceVectorOutput( mSettings.testFlag( QgsMapSettings::ForceVectorOutput ) );
mRenderContext.setUseAdvancedEffects( mSettings.testFlag( QgsMapSettings::UseAdvancedEffects ) );
mRenderContext.setPainter( mPainter );
mRenderContext.setCoordinateTransform( 0 );
mRenderContext.setSelectionColor( mSettings.selectionColor() );
@@ -11,21 +11,6 @@
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"

/*

usage in QgsMapCanvas - upon pan / zoom - in QgsMapCanvasMap:
- stop rendering if active
- update QgsMapRendererV2 settings
- start rendering
- start update timer
- [on timeout/finished] show rendered image

usage in QgsComposer
- create QgsMapRendererV2
- setup, start with QPainter
- wait until it finishes

*/

QgsMapSettings::QgsMapSettings()
: mDpi( 96 ) // what to set?
@@ -35,7 +20,7 @@ QgsMapSettings::QgsMapSettings()
, mDestCRS( GEOCRS_ID, QgsCoordinateReferenceSystem::InternalCrsId ) // WGS 84
, mBackgroundColor( Qt::white )
, mSelectionColor( Qt::yellow )
, mAntiAliasing( true )
, mFlags( Antialiasing )
{
updateDerived();

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

void QgsMapSettings::setFlags( QgsMapSettings::Flags flags )
{
mFlags = flags;
}

void QgsMapSettings::setFlag( QgsMapSettings::Flag flag, bool on )
{
if ( on )
mFlags |= flag;
else
mFlags &= ~flag;
}

QgsMapSettings::Flags QgsMapSettings::flags() const
{
return mFlags;
}

bool QgsMapSettings::testFlag( QgsMapSettings::Flag flag ) const
{
return mFlags.testFlag( flag );
}

QGis::UnitType QgsMapSettings::mapUnits() const
{
return mScaleCalculator.mapUnits();
@@ -54,13 +54,20 @@ class QgsMapSettings
void setSelectionColor( const QColor& color ) { mSelectionColor = color; }
QColor selectionColor() const { return mSelectionColor; }

void setAntiAliasingEnabled( bool enabled ) { mAntiAliasing = enabled; }
bool isAntiAliasingEnabled() const { return mAntiAliasing; }

// TODO: implement
void setDrawEditingInformation( bool enabled ) { Q_UNUSED(enabled); }
void setForceVectorOutput( bool enabled ) { Q_UNUSED(enabled); }
void setUseAdvancedEffects( bool enabled ) { Q_UNUSED(enabled); }
enum Flag
{
Antialiasing = 0x01,
DrawEditingInfo = 0x02,
ForceVectorOutput = 0x04,
UseAdvancedEffects = 0x08
// TODO: no labeling, ignore scale-based visibiity (overview)
};
Q_DECLARE_FLAGS(Flags, Flag)

void setFlags( Flags flags );
void setFlag( Flag flag, bool on = true );
Flags flags() const;
bool testFlag( Flag flag ) const;

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

QColor mBackgroundColor;
QColor mSelectionColor;
bool mAntiAliasing;

Flags mFlags;

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

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )


#endif // QGSMAPSETTINGS_H
@@ -408,7 +408,7 @@ void QgsVectorLayer::drawRendererV2( QgsFeatureIterator &fit, QgsRenderContext&
}

bool sel = mSelectedFeatureIds.contains( fet.id() );
bool drawMarker = ( mEditBuffer && ( !vertexMarkerOnlyForSelection || sel ) );
bool drawMarker = ( mEditBuffer && rendererContext.drawEditingInformation() && ( !vertexMarkerOnlyForSelection || sel ) );

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

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

try
{
@@ -126,6 +126,8 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ),
this, SLOT( writeProject( QDomDocument & ) ) );

mSettings.setFlag( QgsMapSettings::DrawEditingInfo );

mSettings.setOutputSize( size() );
mMap->resize( size() );
setSceneRect( 0, 0, size().width(), size().height() );
@@ -175,7 +177,7 @@ QgsMapCanvas::~QgsMapCanvas()

void QgsMapCanvas::enableAntiAliasing( bool theFlag )
{
mSettings.setAntiAliasingEnabled( theFlag );
mSettings.setFlag( QgsMapSettings::Antialiasing, theFlag );

if ( mMapOverview )
mMapOverview->enableAntiAliasing( theFlag );
@@ -275,7 +275,7 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
void enableAntiAliasing( bool theFlag );

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

//! Select which Qt class to render with
void useImageToRender( bool theFlag );
@@ -60,7 +60,7 @@ class GUI_EXPORT QgsMapOverviewCanvas : public QWidget

QStringList layerSet() const;

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

void updateFullExtent();

0 comments on commit d1985a1

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