Fix #7549 (selection color is now stored in QgsRendererContext)

This commit is contained in:
Martin Dobias 2013-04-12 00:35:21 +02:00
parent 94639ee61e
commit 1a723b4c38
13 changed files with 33 additions and 39 deletions

View File

@ -36,6 +36,9 @@ class QgsRenderContext
//! Added in QGIS v1.4
QgsLabelingEngineInterface* labelingEngine();
//! Added in QGIS v2.0
QColor selectionColor() const;
//setters
/**Sets coordinate transformation. QgsRenderContext does not take ownership*/
@ -52,4 +55,6 @@ class QgsRenderContext
void setForceVectorOutput( bool force );
//! Added in QGIS v1.4
void setLabelingEngine(QgsLabelingEngineInterface* iface);
//! Added in QGIS v2.0
void setSelectionColor( const QColor& color );
};

View File

@ -152,9 +152,6 @@ class QgsSymbolV2RenderContext
void setLayer( const QgsVectorLayer* layer );
const QgsVectorLayer* layer() const;
// Color used for selections
static QColor selectionColor();
double outputLineWidth( double width ) const;
double outputPixelSize( double size ) const;

View File

@ -3159,7 +3159,6 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
prj->writeEntry( "Gui", "/SelectionColorGreenPart", myGreen );
prj->writeEntry( "Gui", "/SelectionColorBluePart", myBlue );
prj->writeEntry( "Gui", "/SelectionColorAlphaPart", myAlpha );
QgsSymbolV2RenderContext::setSelectionColor( QColor( myRed, myGreen, myBlue, myAlpha ) );
//set the canvas to the default background color
//the default can be set in qgisoptions
@ -3543,7 +3542,6 @@ bool QgisApp::addProject( QString projectFile )
int myGreen = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorGreenPart", defaultGreen );
int myBlue = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorBluePart", defaultBlue );
int myAlpha = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorAlphaPart", defaultAlpha );
QgsSymbolV2RenderContext::setSelectionColor( QColor( myRed, myGreen, myBlue, myAlpha ) );
//load project scales
bool projectScales = QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" );

View File

@ -583,7 +583,6 @@ void QgsProjectProperties::apply()
QgsProject::instance()->writeEntry( "Gui", "/SelectionColorGreenPart", myColor.green() );
QgsProject::instance()->writeEntry( "Gui", "/SelectionColorBluePart", myColor.blue() );
QgsProject::instance()->writeEntry( "Gui", "/SelectionColorAlphaPart", myColor.alpha() );
QgsSymbolV2RenderContext::setSelectionColor( myColor );
//set the color for canvas
myColor = pbnCanvasColor->color();

View File

@ -29,6 +29,7 @@
#include "qgscentralpointpositionmanager.h"
#include "qgsoverlayobjectpositionmanager.h"
#include "qgspalobjectpositionmanager.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgsvectoroverlay.h"
@ -281,6 +282,14 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
//so must be false at every new render operation
mRenderContext.setRenderingStopped( false );
// set selection color
QgsProject* prj = QgsProject::instance();
int myRed = prj->readNumEntry( "Gui", "/SelectionColorRedPart", 255 );
int myGreen = prj->readNumEntry( "Gui", "/SelectionColorGreenPart", 255 );
int myBlue = prj->readNumEntry( "Gui", "/SelectionColorBluePart", 0 );
int myAlpha = prj->readNumEntry( "Gui", "/SelectionColorAlphaPart", 255 );
mRenderContext.setSelectionColor( QColor( myRed, myGreen, myBlue, myAlpha ) );
//calculate scale factor
//use the specified dpi and not those from the paint device
//because sometimes QPainter units are in a local coord sys (e.g. in case of QGraphicsScene)

View File

@ -18,6 +18,8 @@
#ifndef QGSRENDERCONTEXT_H
#define QGSRENDERCONTEXT_H
#include <QColor>
#include "qgscoordinatetransform.h"
#include "qgsmaptopixel.h"
#include "qgsrectangle.h"
@ -64,6 +66,9 @@ class CORE_EXPORT QgsRenderContext
//! Added in QGIS v1.4
QgsLabelingEngineInterface* labelingEngine() const { return mLabelingEngine; }
//! Added in QGIS v2.0
QColor selectionColor() const { return mSelectionColor; }
//setters
/**Sets coordinate transformation. QgsRenderContext does not take ownership*/
@ -80,6 +85,8 @@ class CORE_EXPORT QgsRenderContext
void setForceVectorOutput( bool force ) {mForceVectorOutput = force;}
//! Added in QGIS v1.4
void setLabelingEngine( QgsLabelingEngineInterface* iface ) { mLabelingEngine = iface; }
//! Added in QGIS v2.0
void setSelectionColor( const QColor& color ) { mSelectionColor = color; }
private:
@ -113,6 +120,9 @@ class CORE_EXPORT QgsRenderContext
/**Labeling engine (can be NULL)*/
QgsLabelingEngineInterface* mLabelingEngine;
/** Color used for features that are marked as selected */
QColor mSelectionColor;
};
#endif

View File

@ -467,7 +467,7 @@ void QgsVectorLayer::drawRendererV2Levels( QgsFeatureIterator &fit, QgsRenderCon
if ( !mSelectedFeatureIds.isEmpty() )
{
selRenderer = new QgsSingleSymbolRendererV2( QgsSymbolV2::defaultSymbol( geometryType() ) );
selRenderer->symbol()->setColor( QgsSymbolV2RenderContext::selectionColor() );
selRenderer->symbol()->setColor( rendererContext.selectionColor() );
selRenderer->setVertexMarkerAppearance( currentVertexMarkerType(), currentVertexMarkerSize() );
selRenderer->startRender( rendererContext, this );
}

View File

@ -233,7 +233,7 @@ void QgsSimpleFillSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context
mBrush.setMatrix( QMatrix().scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor ) );
}
QColor selColor = context.selectionColor();
QColor selColor = context.renderContext().selectionColor();
QColor selPenColor = selColor == mColor ? selColor : mBorderColor;
if ( ! selectionIsOpaque ) selColor.setAlphaF( context.alpha() );
mSelBrush = QBrush( selColor );
@ -426,7 +426,7 @@ void QgsImageFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPol
p->setPen( QPen( Qt::NoPen ) );
if ( context.selected() )
{
QColor selColor = context.selectionColor();
QColor selColor = context.renderContext().selectionColor();
// Alister - this doesn't seem to work here
//if ( ! selectionIsOpaque )
// selColor.setAlphaF( context.alpha() );

View File

@ -282,7 +282,7 @@ void QgsSimpleLineSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context
mPen.setCapStyle( mPenCapStyle );
mSelPen = mPen;
QColor selColor = context.selectionColor();
QColor selColor = context.renderContext().selectionColor();
if ( ! selectionIsOpaque )
selColor.setAlphaF( context.alpha() );
mSelPen.setColor( selColor );
@ -1396,7 +1396,7 @@ void QgsLineDecorationSymbolLayerV2::startRender( QgsSymbolV2RenderContext& cont
double width = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit );
mPen.setWidth( context.outputLineWidth( width ) );
mPen.setColor( penColor );
QColor selColor = context.selectionColor();
QColor selColor = context.renderContext().selectionColor();
if ( ! selectionIsOpaque )
selColor.setAlphaF( context.alpha() );
mSelPen.setWidth( context.outputLineWidth( width ) );

View File

@ -151,7 +151,7 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex
mPen = QPen( penColor );
mPen.setWidthF( mOutlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit ) );
QColor selBrushColor = context.selectionColor();
QColor selBrushColor = context.renderContext().selectionColor();
QColor selPenColor = selBrushColor == mColor ? selBrushColor : mBorderColor;
if ( context.alpha() < 1 )
{
@ -251,7 +251,7 @@ void QgsSimpleMarkerSymbolLayerV2::prepareCache( QgsSymbolV2RenderContext& conte
// Construct the selected version of the Cache
QColor selColor = context.selectionColor();
QColor selColor = context.renderContext().selectionColor();
mSelCache = QImage( QSize( imageSize, imageSize ), QImage::Format_ARGB32_Premultiplied );
mSelCache.fill( 0 );
@ -1195,7 +1195,7 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re
if ( context.selected() )
{
QPen pen( context.selectionColor() );
QPen pen( context.renderContext().selectionColor() );
double penWidth = QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), QgsSymbolV2::MM );
if ( penWidth > size / 20 )
{
@ -1620,7 +1620,7 @@ void QgsFontMarkerSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
void QgsFontMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context )
{
QPainter* p = context.renderContext().painter();
QColor penColor = context.selected() ? context.selectionColor() : mColor;
QColor penColor = context.selected() ? context.renderContext().selectionColor() : mColor;
penColor.setAlphaF( mColor.alphaF() * context.alpha() );
p->setPen( penColor );
p->setFont( mFont );

View File

@ -374,8 +374,6 @@ QSet<QString> QgsSymbolV2::usedAttributes() const
////////////////////
QColor QgsSymbolV2RenderContext::mSelectionColor = QColor( 0, 0, 0 );
QgsSymbolV2RenderContext::QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u, qreal alpha, bool selected, int renderHints, const QgsFeature* f )
: mRenderContext( c ), mOutputUnit( u ), mAlpha( alpha ), mSelected( selected ), mRenderHints( renderHints ), mFeature( f ), mLayer( 0 )
@ -388,17 +386,6 @@ QgsSymbolV2RenderContext::~QgsSymbolV2RenderContext()
}
QColor QgsSymbolV2RenderContext::selectionColor()
{
return mSelectionColor;
}
void QgsSymbolV2RenderContext::setSelectionColor( const QColor& color )
{
mSelectionColor = color;
}
double QgsSymbolV2RenderContext::outputLineWidth( double width ) const
{

View File

@ -181,11 +181,6 @@ class CORE_EXPORT QgsSymbolV2RenderContext
void setLayer( const QgsVectorLayer* layer ) { mLayer = layer; }
const QgsVectorLayer* layer() const { return mLayer; }
// Color used for selections
static QColor selectionColor();
//! @note added in 2.0
static void setSelectionColor( const QColor& color );
double outputLineWidth( double width ) const;
double outputPixelSize( double size ) const;
@ -200,10 +195,6 @@ class CORE_EXPORT QgsSymbolV2RenderContext
int mRenderHints;
const QgsFeature* mFeature; //current feature
const QgsVectorLayer* mLayer; //current vectorlayer
/**Color to draw selected features - static so we can change it in proj props and automatically
all renderers are updated*/
static QColor mSelectionColor;
};

View File

@ -969,8 +969,6 @@ QImage* QgsWMSServer::initializeRendering( QStringList& layersList, QStringList&
#endif
mMapRenderer->setLayerSet( layerIdList );
//set selection color prior to each render to avoid problems with caching (selection color is a global property of QgsSymbolV2RenderContext)
QgsSymbolV2RenderContext::setSelectionColor( mConfigParser->selectionColor() );
return theImage;
}