Skip to content

Commit abc15ab

Browse files
committed
Handling of selection color in QgsMapSettings
1 parent 016f39e commit abc15ab

7 files changed

+38
-80
lines changed

src/app/qgisapp.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -3243,6 +3243,7 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
32433243
prj->writeEntry( "Gui", "/SelectionColorGreenPart", myGreen );
32443244
prj->writeEntry( "Gui", "/SelectionColorBluePart", myBlue );
32453245
prj->writeEntry( "Gui", "/SelectionColorAlphaPart", myAlpha );
3246+
mMapCanvas->setSelectionColor( QColor( myRed, myGreen, myBlue ) );
32463247

32473248
//set the canvas to the default background color
32483249
//the default can be set in qgisoptions

src/app/qgsprojectproperties.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ void QgsProjectProperties::apply()
602602
QgsProject::instance()->writeEntry( "Gui", "/SelectionColorGreenPart", myColor.green() );
603603
QgsProject::instance()->writeEntry( "Gui", "/SelectionColorBluePart", myColor.blue() );
604604
QgsProject::instance()->writeEntry( "Gui", "/SelectionColorAlphaPart", myColor.alpha() );
605+
mMapCanvas->setSelectionColor( myColor );
605606

606607
//set the color for canvas
607608
myColor = pbnCanvasColor->color();

src/core/qgsmaprendererjob.cpp

+21-73
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,15 @@ void QgsMapRendererCustomPainterJob::startRender()
156156

157157
mPainter->setRenderHint( QPainter::Antialiasing, mSettings.isAntiAliasingEnabled() );
158158

159+
QPaintDevice* thePaintDevice = mPainter->device();
160+
159161
#ifdef QGISDEBUG
160162
QgsDebugMsg( "Starting to render layer stack." );
161163
QTime renderTime;
162164
renderTime.start();
163165
#endif
164166

165-
mRenderContext.setMapToPixel( QgsMapToPixel( mSettings.mapUnitsPerPixel(), mSettings.outputSize().height(), mSettings.visibleExtent().yMinimum(), mSettings.visibleExtent().xMinimum() ) );
167+
mRenderContext.setMapToPixel( mSettings.mapToPixel() ); // QgsMapToPixel( mSettings.mapUnitsPerPixel(), mSettings.outputSize().height(), mSettings.visibleExtent().yMinimum(), mSettings.visibleExtent().xMinimum() ) );
166168
mRenderContext.setExtent( mSettings.visibleExtent() );
167169

168170
mRenderContext.setDrawEditingInformation( false );
@@ -173,19 +175,15 @@ void QgsMapRendererCustomPainterJob::startRender()
173175
mRenderContext.setRenderingStopped( false );
174176

175177
// set selection color
176-
/* TODO QgsProject* prj = QgsProject::instance();
177-
int myRed = prj->readNumEntry( "Gui", "/SelectionColorRedPart", 255 );
178-
int myGreen = prj->readNumEntry( "Gui", "/SelectionColorGreenPart", 255 );
179-
int myBlue = prj->readNumEntry( "Gui", "/SelectionColorBluePart", 0 );
180-
int myAlpha = prj->readNumEntry( "Gui", "/SelectionColorAlphaPart", 255 );*/
181-
mRenderContext.setSelectionColor( mSettings.selectionColor() ); // TODO QColor( myRed, myGreen, myBlue, myAlpha ) );
178+
mRenderContext.setSelectionColor( mSettings.selectionColor() );
182179

183180
//calculate scale factor
184181
//use the specified dpi and not those from the paint device
185182
//because sometimes QPainter units are in a local coord sys (e.g. in case of QGraphicsScene)
186-
/* TODO double sceneDpi = mScaleCalculator->dpi();
183+
double* forceWidthScale = 0; // TODO: may point to a value (composer)
184+
double sceneDpi = mSettings.outputDpi();
187185
double scaleFactor = 1.0;
188-
if ( mOutputUnits == QgsMapRenderer::Millimeters )
186+
if ( mSettings.outputUnits() == QgsMapSettings::Millimeters )
189187
{
190188
if ( forceWidthScale )
191189
{
@@ -197,44 +195,14 @@ void QgsMapRendererCustomPainterJob::startRender()
197195
}
198196
}
199197
double rasterScaleFactor = ( thePaintDevice->logicalDpiX() + thePaintDevice->logicalDpiY() ) / 2.0 / sceneDpi;
200-
if ( mRenderContext.rasterScaleFactor() != rasterScaleFactor )
201-
{
202-
mRenderContext.setRasterScaleFactor( rasterScaleFactor );
203-
mySameAsLastFlag = false;
204-
}
205-
if ( mRenderContext.scaleFactor() != scaleFactor )
206-
{
207-
mRenderContext.setScaleFactor( scaleFactor );
208-
mySameAsLastFlag = false;
209-
}
210-
if ( mRenderContext.rendererScale() != mScale )
211-
{
212-
//add map scale to render context
213-
mRenderContext.setRendererScale( mScale );
214-
mySameAsLastFlag = false;
215-
}
216-
if ( mLastExtent != mExtent )
217-
{
218-
mLastExtent = mExtent;
219-
mySameAsLastFlag = false;
220-
}
198+
mRenderContext.setRasterScaleFactor( rasterScaleFactor );
199+
mRenderContext.setScaleFactor( scaleFactor );
200+
mRenderContext.setRendererScale( mSettings.scale() );
221201

222-
mRenderContext.setLabelingEngine( mLabelingEngine );
202+
/*mRenderContext.setLabelingEngine( mLabelingEngine );
223203
if ( mLabelingEngine )
224204
mLabelingEngine->init( this );*/
225205

226-
// know we know if this render is just a repeat of the last time, we
227-
// can clear caches if it has changed
228-
/*if ( !mySameAsLastFlag )
229-
{
230-
//clear the cache pixmap if we changed resolution / extent
231-
QSettings mySettings;
232-
if ( mySettings.value( "/qgis/enable_render_caching", false ).toBool() )
233-
{
234-
QgsMapLayerRegistry::instance()->clearAllLayerCaches();
235-
}
236-
}*/
237-
238206
// render all layers in the stack, starting at the base
239207
QListIterator<QString> li( mSettings.layers() );
240208
li.toBack();
@@ -251,22 +219,14 @@ void QgsMapRendererCustomPainterJob::startRender()
251219

252220
// Store the painter in case we need to swap it out for the
253221
// cache painter
254-
QPainter * mypContextPainter = mRenderContext.painter();
222+
//QPainter * mypContextPainter = mRenderContext.painter();
255223
// Flattened image for drawing when a blending mode is set
256224
//QImage * mypFlattenedImage = 0;
257225

258226
QString layerId = li.previous();
259227

260228
QgsDebugMsg( "Rendering at layer item " + layerId );
261229

262-
// This call is supposed to cause the progress bar to
263-
// advance. However, it seems that updating the progress bar is
264-
// incompatible with having a QPainter active (the one that is
265-
// passed into this function), as Qt produces a number of errors
266-
// when try to do so. I'm (Gavin) not sure how to fix this, but
267-
// added these comments and debug statement to help others...
268-
QgsDebugMsg( "If there is a QPaintEngine error here, it is caused by an emit call" );
269-
270230
QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
271231

272232
if ( !ml )
@@ -284,12 +244,12 @@ void QgsMapRendererCustomPainterJob::startRender()
284244
.arg( ml->blendMode() )
285245
);
286246

287-
if ( mRenderContext.useAdvancedEffects() )
247+
/*if ( mRenderContext.useAdvancedEffects() )
288248
{
289249
// Set the QPainter composition mode so that this layer is rendered using
290250
// the desired blending mode
291251
mypContextPainter->setCompositionMode( ml->blendMode() );
292-
}
252+
}*/
293253

294254
if ( !ml->hasScaleBasedVisibility() || ( ml->minimumScale() <= mSettings.scale() && mSettings.scale() < ml->maximumScale() ) ) //|| mOverview )
295255
{
@@ -322,26 +282,14 @@ void QgsMapRendererCustomPainterJob::startRender()
322282

323283
//decide if we have to scale the raster
324284
//this is necessary in case QGraphicsScene is used
325-
/*bool scaleRaster = false;
285+
bool scaleRaster = false;
326286
QgsMapToPixel rasterMapToPixel;
327287
QgsMapToPixel bk_mapToPixel;
328288

329289
if ( ml->type() == QgsMapLayer::RasterLayer && qAbs( rasterScaleFactor - 1.0 ) > 0.000001 )
330290
{
331291
scaleRaster = true;
332-
}*/
333-
334-
// Force render of layers that are being edited
335-
// or if there's a labeling engine that needs the layer to register features
336-
/*if ( ml->type() == QgsMapLayer::VectorLayer )
337-
{
338-
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
339-
if ( vl->isEditable() ||
340-
( mRenderContext.labelingEngine() && mRenderContext.labelingEngine()->willUseLayer( vl ) ) )
341-
{
342-
ml->setCacheImage( 0 );
343-
}
344-
}*/
292+
}
345293

346294
/*QSettings mySettings;
347295
bool useRenderCaching = false;
@@ -429,16 +377,16 @@ void QgsMapRendererCustomPainterJob::startRender()
429377
}
430378
}*/
431379

432-
/*if ( scaleRaster )
380+
if ( scaleRaster )
433381
{
434382
bk_mapToPixel = mRenderContext.mapToPixel();
435383
rasterMapToPixel = mRenderContext.mapToPixel();
436384
rasterMapToPixel.setMapUnitsPerPixel( mRenderContext.mapToPixel().mapUnitsPerPixel() / rasterScaleFactor );
437-
rasterMapToPixel.setYMaximum( mSize.height() * rasterScaleFactor );
385+
rasterMapToPixel.setYMaximum( mSettings.outputSize().height() * rasterScaleFactor );
438386
mRenderContext.setMapToPixel( rasterMapToPixel );
439387
mRenderContext.painter()->save();
440388
mRenderContext.painter()->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
441-
}*/
389+
}
442390

443391
if ( !ml->draw( mRenderContext ) )
444392
{
@@ -458,11 +406,11 @@ void QgsMapRendererCustomPainterJob::startRender()
458406
}
459407
}
460408

461-
/*if ( scaleRaster )
409+
if ( scaleRaster )
462410
{
463411
mRenderContext.setMapToPixel( bk_mapToPixel );
464412
mRenderContext.painter()->restore();
465-
}*/
413+
}
466414

467415
//apply layer transparency for vector layers
468416
/*if (( mRenderContext.useAdvancedEffects() ) && ( ml->type() == QgsMapLayer::VectorLayer ) )

src/core/qgsmapsettings.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ usage in QgsComposer
2828
*/
2929

3030
QgsMapSettings::QgsMapSettings()
31-
: mDpi( 120 ) // what to set?
31+
: mDpi( 96 ) // what to set?
3232
, mSize( QSize( 0, 0 ) )
3333
, mExtent()
3434
, mProjectionsEnabled( false )

src/gui/qgsmapcanvas.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,11 @@ QColor QgsMapCanvas::canvasColor() const
12021202
return mScene->backgroundBrush().color();
12031203
}
12041204

1205+
void QgsMapCanvas::setSelectionColor( const QColor& color )
1206+
{
1207+
mSettings.setSelectionColor( color );
1208+
}
1209+
12051210
int QgsMapCanvas::layerCount() const
12061211
{
12071212
return mapSettings().layers().size();

src/gui/qgsmapcanvas.h

+3
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
197197
/** Read property of QColor bgColor. */
198198
virtual QColor canvasColor() const;
199199

200+
/** Set color of selected vector features */
201+
void setSelectionColor( const QColor& color );
202+
200203
/** Emits signal scaleChanged to update scale in main window */
201204
void updateScale();
202205

src/gui/qgsmapcanvasmap.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,26 @@ class GUI_EXPORT QgsMapCanvasMap : public QObject, public QGraphicsRectItem
4848
void resize( QSize size );
4949

5050
//! @deprecated in 2.1 - does nothing. Kept for API compatibility
51-
void enableAntiAliasing( bool flag );
51+
Q_DECL_DEPRECATED void enableAntiAliasing( bool flag );
5252

5353
//! @deprecated in 2.1 - does nothing. Kept for API compatibility
54-
void render() {}
54+
Q_DECL_DEPRECATED void render() {}
5555

5656
//! @deprecated in 2.1 - does nothing. Kept for API compatibility
57-
void setBackgroundColor( const QColor& color ) {}
57+
Q_DECL_DEPRECATED void setBackgroundColor( const QColor& color ) { Q_UNUSED( color ); }
5858

5959
//! @deprecated in 2.1 - not called by QgsMapCanvas anymore
60-
Q_DECL_DEPRECATED void setPanningOffset( const QPoint& point ) {}
60+
Q_DECL_DEPRECATED void setPanningOffset( const QPoint& point ) { Q_UNUSED( point ); }
6161

6262
//! @deprecated in 2.1
63-
QPaintDevice& paintDevice();
63+
Q_DECL_DEPRECATED QPaintDevice& paintDevice();
6464

6565
void paint( QPainter* p, const QStyleOptionGraphicsItem*, QWidget* );
6666

6767
QRectF boundingRect() const;
6868

6969
//! @deprecated in 2.1 - does nothing. Kept for API compatibility
70-
void updateContents() {}
70+
Q_DECL_DEPRECATED void updateContents() {}
7171

7272
const QgsMapSettings& settings() const;
7373

0 commit comments

Comments
 (0)