Skip to content

Commit

Permalink
Fix #7549 (selection color is now stored in QgsRendererContext)
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Apr 11, 2013
1 parent 94639ee commit 1a723b4
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 39 deletions.
5 changes: 5 additions & 0 deletions python/core/qgsrendercontext.sip
Expand Up @@ -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*/
Expand All @@ -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 );
};
3 changes: 0 additions & 3 deletions python/core/symbology-ng/qgssymbolv2.sip
Expand Up @@ -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;

Expand Down
2 changes: 0 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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" );
Expand Down
1 change: 0 additions & 1 deletion src/app/qgsprojectproperties.cpp
Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions src/core/qgsmaprenderer.cpp
Expand Up @@ -29,6 +29,7 @@
#include "qgscentralpointpositionmanager.h"
#include "qgsoverlayobjectpositionmanager.h"
#include "qgspalobjectpositionmanager.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgsvectoroverlay.h"

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgsrendercontext.h
Expand Up @@ -18,6 +18,8 @@
#ifndef QGSRENDERCONTEXT_H
#define QGSRENDERCONTEXT_H

#include <QColor>

#include "qgscoordinatetransform.h"
#include "qgsmaptopixel.h"
#include "qgsrectangle.h"
Expand Down Expand Up @@ -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*/
Expand All @@ -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:

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.cpp
Expand Up @@ -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 );
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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() );
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgslinesymbollayerv2.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 ) );
Expand Down
8 changes: 4 additions & 4 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 );
Expand Down
13 changes: 0 additions & 13 deletions src/core/symbology-ng/qgssymbolv2.cpp
Expand Up @@ -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 )
Expand All @@ -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
{
Expand Down
9 changes: 0 additions & 9 deletions src/core/symbology-ng/qgssymbolv2.h
Expand Up @@ -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;

Expand All @@ -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;
};


Expand Down
2 changes: 0 additions & 2 deletions src/mapserver/qgswmsserver.cpp
Expand Up @@ -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;
}

Expand Down

0 comments on commit 1a723b4

Please sign in to comment.