@@ -156,13 +156,15 @@ void QgsMapRendererCustomPainterJob::startRender()
156
156
157
157
mPainter ->setRenderHint ( QPainter::Antialiasing, mSettings .isAntiAliasingEnabled () );
158
158
159
+ QPaintDevice* thePaintDevice = mPainter ->device ();
160
+
159
161
#ifdef QGISDEBUG
160
162
QgsDebugMsg ( " Starting to render layer stack." );
161
163
QTime renderTime;
162
164
renderTime.start ();
163
165
#endif
164
166
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() ) );
166
168
mRenderContext .setExtent ( mSettings .visibleExtent () );
167
169
168
170
mRenderContext .setDrawEditingInformation ( false );
@@ -173,19 +175,15 @@ void QgsMapRendererCustomPainterJob::startRender()
173
175
mRenderContext .setRenderingStopped ( false );
174
176
175
177
// 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 () );
182
179
183
180
// calculate scale factor
184
181
// use the specified dpi and not those from the paint device
185
182
// 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 ();
187
185
double scaleFactor = 1.0 ;
188
- if ( mOutputUnits == QgsMapRenderer ::Millimeters )
186
+ if ( mSettings . outputUnits () == QgsMapSettings ::Millimeters )
189
187
{
190
188
if ( forceWidthScale )
191
189
{
@@ -197,44 +195,14 @@ void QgsMapRendererCustomPainterJob::startRender()
197
195
}
198
196
}
199
197
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 () );
221
201
222
- mRenderContext.setLabelingEngine( mLabelingEngine );
202
+ /* mRenderContext.setLabelingEngine( mLabelingEngine );
223
203
if ( mLabelingEngine )
224
204
mLabelingEngine->init( this );*/
225
205
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
-
238
206
// render all layers in the stack, starting at the base
239
207
QListIterator<QString> li ( mSettings .layers () );
240
208
li.toBack ();
@@ -251,22 +219,14 @@ void QgsMapRendererCustomPainterJob::startRender()
251
219
252
220
// Store the painter in case we need to swap it out for the
253
221
// cache painter
254
- QPainter * mypContextPainter = mRenderContext .painter ();
222
+ // QPainter * mypContextPainter = mRenderContext.painter();
255
223
// Flattened image for drawing when a blending mode is set
256
224
// QImage * mypFlattenedImage = 0;
257
225
258
226
QString layerId = li.previous ();
259
227
260
228
QgsDebugMsg ( " Rendering at layer item " + layerId );
261
229
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
-
270
230
QgsMapLayer *ml = QgsMapLayerRegistry::instance ()->mapLayer ( layerId );
271
231
272
232
if ( !ml )
@@ -284,12 +244,12 @@ void QgsMapRendererCustomPainterJob::startRender()
284
244
.arg ( ml->blendMode () )
285
245
);
286
246
287
- if ( mRenderContext .useAdvancedEffects () )
247
+ /* if ( mRenderContext.useAdvancedEffects() )
288
248
{
289
249
// Set the QPainter composition mode so that this layer is rendered using
290
250
// the desired blending mode
291
251
mypContextPainter->setCompositionMode( ml->blendMode() );
292
- }
252
+ }*/
293
253
294
254
if ( !ml->hasScaleBasedVisibility () || ( ml->minimumScale () <= mSettings .scale () && mSettings .scale () < ml->maximumScale () ) ) // || mOverview )
295
255
{
@@ -322,26 +282,14 @@ void QgsMapRendererCustomPainterJob::startRender()
322
282
323
283
// decide if we have to scale the raster
324
284
// this is necessary in case QGraphicsScene is used
325
- /* bool scaleRaster = false;
285
+ bool scaleRaster = false ;
326
286
QgsMapToPixel rasterMapToPixel;
327
287
QgsMapToPixel bk_mapToPixel;
328
288
329
289
if ( ml->type () == QgsMapLayer::RasterLayer && qAbs ( rasterScaleFactor - 1.0 ) > 0.000001 )
330
290
{
331
291
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
+ }
345
293
346
294
/* QSettings mySettings;
347
295
bool useRenderCaching = false;
@@ -429,16 +377,16 @@ void QgsMapRendererCustomPainterJob::startRender()
429
377
}
430
378
}*/
431
379
432
- /* if ( scaleRaster )
380
+ if ( scaleRaster )
433
381
{
434
382
bk_mapToPixel = mRenderContext .mapToPixel ();
435
383
rasterMapToPixel = mRenderContext .mapToPixel ();
436
384
rasterMapToPixel.setMapUnitsPerPixel ( mRenderContext .mapToPixel ().mapUnitsPerPixel () / rasterScaleFactor );
437
- rasterMapToPixel.setYMaximum( mSize .height() * rasterScaleFactor );
385
+ rasterMapToPixel.setYMaximum ( mSettings . outputSize () .height () * rasterScaleFactor );
438
386
mRenderContext .setMapToPixel ( rasterMapToPixel );
439
387
mRenderContext .painter ()->save ();
440
388
mRenderContext .painter ()->scale ( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
441
- }*/
389
+ }
442
390
443
391
if ( !ml->draw ( mRenderContext ) )
444
392
{
@@ -458,11 +406,11 @@ void QgsMapRendererCustomPainterJob::startRender()
458
406
}
459
407
}
460
408
461
- /* if ( scaleRaster )
409
+ if ( scaleRaster )
462
410
{
463
411
mRenderContext .setMapToPixel ( bk_mapToPixel );
464
412
mRenderContext .painter ()->restore ();
465
- }*/
413
+ }
466
414
467
415
// apply layer transparency for vector layers
468
416
/* if (( mRenderContext.useAdvancedEffects() ) && ( ml->type() == QgsMapLayer::VectorLayer ) )
0 commit comments