Skip to content

Commit cfc2a48

Browse files
committedNov 14, 2013
Restore advanced layer effects, labeling in composer.
Also fixes DpiY setting in composer + workaround for QPicture DPI issues
1 parent cf3d86c commit cfc2a48

10 files changed

+84
-138
lines changed
 

‎src/app/qgslabelengineconfigdialog.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ QgsLabelEngineConfigDialog::QgsLabelEngineConfigDialog( QgsPalLabeling* lbl, QWi
4242
chkShowAllLabels->setChecked( mLBL->isShowingAllLabels() );
4343
mShadowDebugRectChkBox->setChecked( mLBL->isShowingShadowRectangles() );
4444

45-
mSaveWithProjectChkBox->setChecked( mLBL->isStoredWithProject() );
46-
4745
chkShowPartialsLabels->setChecked( mLBL-> isShowingPartialsLabels() );
4846
}
4947

@@ -62,14 +60,8 @@ void QgsLabelEngineConfigDialog::onOK()
6260
mLBL->setShowingAllLabels( chkShowAllLabels->isChecked() );
6361
mLBL->setShowingPartialsLabels( chkShowPartialsLabels->isChecked() );
6462

65-
if ( mSaveWithProjectChkBox->isChecked() )
66-
{
67-
mLBL->saveEngineSettings();
68-
}
69-
else if ( mLBL->isStoredWithProject() )
70-
{
71-
mLBL->clearEngineSettings();
72-
}
63+
mLBL->saveEngineSettings();
64+
7365
accept();
7466
}
7567

‎src/core/composer/qgscomposermap.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@ void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const
160160
jobMapSettings.setExtent( extent );
161161
jobMapSettings.setOutputSize( size.toSize() );
162162
jobMapSettings.setOutputDpi( dpi );
163-
/* TODO: if ( mMapRenderer->labelingEngine() )
164-
theMapRenderer.setLabelingEngine( mMapRenderer->labelingEngine()->clone() );*/
163+
164+
QgsPalLabeling labeling;
165+
labeling.loadEngineSettings();
165166

166167
//use stored layer set or read current set from main canvas
167168
jobMapSettings.setLayers( mKeepLayerSet ? mLayerSet : ms.layers() );
@@ -176,6 +177,7 @@ void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const
176177

177178
// render
178179
QgsMapRendererCustomPainterJob job( jobMapSettings, painter );
180+
job.setLabelingEngine( &labeling );
179181
job.start();
180182
job.waitForFinished();
181183

@@ -225,7 +227,7 @@ void QgsComposerMap::cache( void )
225227

226228
// set DPI of the image
227229
mCacheImage.setDotsPerMeterX( 1000 * w / widthMM );
228-
mCacheImage.setDotsPerMeterX( 1000 * h / heightMM );
230+
mCacheImage.setDotsPerMeterY( 1000 * h / heightMM );
229231

230232
if ( hasBackground() )
231233
{

‎src/core/qgsmaprendererjob.cpp

Lines changed: 46 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ void QgsMapRendererCustomPainterJob::startRender()
223223

224224
// Store the painter in case we need to swap it out for the
225225
// cache painter
226-
//QPainter * mypContextPainter = mRenderContext.painter();
226+
QPainter * mypContextPainter = mRenderContext.painter();
227227
// Flattened image for drawing when a blending mode is set
228-
//QImage * mypFlattenedImage = 0;
228+
QImage * mypFlattenedImage = 0;
229229

230230
QString layerId = li.previous();
231231

@@ -248,12 +248,12 @@ void QgsMapRendererCustomPainterJob::startRender()
248248
.arg( ml->blendMode() )
249249
);
250250

251-
/*if ( mRenderContext.useAdvancedEffects() )
251+
if ( mRenderContext.useAdvancedEffects() )
252252
{
253253
// Set the QPainter composition mode so that this layer is rendered using
254254
// the desired blending mode
255255
mypContextPainter->setCompositionMode( ml->blendMode() );
256-
}*/
256+
}
257257

258258
if ( !ml->hasScaleBasedVisibility() || ( ml->minimumScale() <= mSettings.scale() && mSettings.scale() < ml->maximumScale() ) ) //|| mOverview )
259259
{
@@ -284,56 +284,14 @@ void QgsMapRendererCustomPainterJob::startRender()
284284

285285
mRenderContext.setCoordinateTransform( ct );
286286

287-
/*QSettings mySettings;
288-
bool useRenderCaching = false;
289-
if ( ! split )//render caching does not yet cater for split extents
290-
{
291-
if ( mySettings.value( "/qgis/enable_render_caching", false ).toBool() )
292-
{
293-
useRenderCaching = true;
294-
if ( !mySameAsLastFlag || ml->cacheImage() == 0 )
295-
{
296-
QgsDebugMsg( "Caching enabled but layer redraw forced by extent change or empty cache" );
297-
QImage * mypImage = new QImage( mRenderContext.painter()->device()->width(),
298-
mRenderContext.painter()->device()->height(), QImage::Format_ARGB32 );
299-
if ( mypImage->isNull() )
300-
{
301-
QgsDebugMsg( "insufficient memory for image " + QString::number( mRenderContext.painter()->device()->width() ) + "x" + QString::number( mRenderContext.painter()->device()->height() ) );
302-
emit drawError( ml );
303-
painter->end(); // drawError is not caught by anyone, so we end painting to notify caller
304-
return;
305-
}
306-
mypImage->fill( 0 );
307-
ml->setCacheImage( mypImage ); //no need to delete the old one, maplayer does it for you
308-
QPainter * mypPainter = new QPainter( ml->cacheImage() );
309-
// Changed to enable anti aliasing by default in QGIS 1.7
310-
if ( mySettings.value( "/qgis/enable_anti_aliasing", true ).toBool() )
311-
{
312-
mypPainter->setRenderHint( QPainter::Antialiasing );
313-
}
314-
mRenderContext.setPainter( mypPainter );
315-
}
316-
else if ( mySameAsLastFlag )
317-
{
318-
//draw from cached image
319-
QgsDebugMsg( "Caching enabled --- drawing layer from cached image" );
320-
mypContextPainter->drawImage( 0, 0, *( ml->cacheImage() ) );
321-
//short circuit as there is nothing else to do...
322-
continue;
323-
}
324-
}
325-
}*/
326-
327287
// If we are drawing with an alternative blending mode then we need to render to a separate image
328288
// before compositing this on the map. This effectively flattens the layer and prevents
329289
// blending occuring between objects on the layer
330-
// (this is not required for raster layers or when layer caching is enabled, since that has the same effect)
331-
/*bool flattenedLayer = false;
290+
bool flattenedLayer = false;
332291
if (( mRenderContext.useAdvancedEffects() ) && ( ml->type() == QgsMapLayer::VectorLayer ) )
333292
{
334293
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
335-
if (( !useRenderCaching )
336-
&& (( vl->blendMode() != QPainter::CompositionMode_SourceOver )
294+
if ( (( vl->blendMode() != QPainter::CompositionMode_SourceOver )
337295
|| ( vl->featureBlendMode() != QPainter::CompositionMode_SourceOver )
338296
|| ( vl->layerTransparency() != 0 ) ) )
339297
{
@@ -343,23 +301,22 @@ void QgsMapRendererCustomPainterJob::startRender()
343301
if ( mypFlattenedImage->isNull() )
344302
{
345303
QgsDebugMsg( "insufficient memory for image " + QString::number( mRenderContext.painter()->device()->width() ) + "x" + QString::number( mRenderContext.painter()->device()->height() ) );
346-
emit drawError( ml );
347-
painter->end(); // drawError is not caught by anyone, so we end painting to notify caller
304+
// TODO emit drawError( ml );
305+
mPainter->end(); // drawError is not caught by anyone, so we end painting to notify caller
348306
return;
349307
}
350308
mypFlattenedImage->fill( 0 );
351309
QPainter * mypPainter = new QPainter( mypFlattenedImage );
352-
if ( mySettings.value( "/qgis/enable_anti_aliasing", true ).toBool() )
310+
if ( mSettings.testFlag( QgsMapSettings::Antialiasing ) )
353311
{
354312
mypPainter->setRenderHint( QPainter::Antialiasing );
355313
}
356-
mypPainter->scale( rasterScaleFactor, rasterScaleFactor );
357314
mRenderContext.setPainter( mypPainter );
358315
}
359-
}*/
316+
}
360317

361318
// Per feature blending mode
362-
/*if (( mRenderContext.useAdvancedEffects() ) && ( ml->type() == QgsMapLayer::VectorLayer ) )
319+
if (( mRenderContext.useAdvancedEffects() ) && ( ml->type() == QgsMapLayer::VectorLayer ) )
363320
{
364321
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
365322
if ( vl->featureBlendMode() != QPainter::CompositionMode_SourceOver )
@@ -368,7 +325,7 @@ void QgsMapRendererCustomPainterJob::startRender()
368325
// on this layer will interact and blend with each other
369326
mRenderContext.painter()->setCompositionMode( vl->featureBlendMode() );
370327
}
371-
}*/
328+
}
372329

373330
if ( !ml->draw( mRenderContext ) )
374331
{
@@ -389,7 +346,7 @@ void QgsMapRendererCustomPainterJob::startRender()
389346
}
390347

391348
//apply layer transparency for vector layers
392-
/*if (( mRenderContext.useAdvancedEffects() ) && ( ml->type() == QgsMapLayer::VectorLayer ) )
349+
if (( mRenderContext.useAdvancedEffects() ) && ( ml->type() == QgsMapLayer::VectorLayer ) )
393350
{
394351
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
395352
if ( vl->layerTransparency() != 0 )
@@ -402,30 +359,17 @@ void QgsMapRendererCustomPainterJob::startRender()
402359
mRenderContext.painter()->fillRect( 0, 0, mRenderContext.painter()->device()->width(),
403360
mRenderContext.painter()->device()->height(), transparentFillColor );
404361
}
405-
}*/
406-
407-
/*if ( useRenderCaching )
408-
{
409-
// composite the cached image into our view and then clean up from caching
410-
// by reinstating the painter as it was swapped out for caching renders
411-
delete mRenderContext.painter();
412-
mRenderContext.setPainter( mypContextPainter );
413-
//draw from cached image that we created further up
414-
if ( ml->cacheImage() )
415-
mypContextPainter->drawImage( 0, 0, *( ml->cacheImage() ) );
416362
}
417-
else if ( flattenedLayer )
363+
364+
if ( flattenedLayer )
418365
{
419366
// If we flattened this layer for alternate blend modes, composite it now
420367
delete mRenderContext.painter();
421368
mRenderContext.setPainter( mypContextPainter );
422-
mypContextPainter->save();
423-
mypContextPainter->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
424369
mypContextPainter->drawImage( 0, 0, *( mypFlattenedImage ) );
425-
mypContextPainter->restore();
426370
delete mypFlattenedImage;
427371
mypFlattenedImage = 0;
428-
}*/
372+
}
429373

430374
}
431375
else // layer not visible due to scale
@@ -441,7 +385,8 @@ void QgsMapRendererCustomPainterJob::startRender()
441385
// Reset the composition mode before rendering the labels
442386
mRenderContext.painter()->setCompositionMode( QPainter::CompositionMode_SourceOver );
443387

444-
/*if ( !mOverview )
388+
// old labeling - to be removed at some point...
389+
if ( mSettings.testFlag( QgsMapSettings::DrawLabeling ) )
445390
{
446391
// render all labels for vector layers in the stack, starting at the base
447392
li.toBack();
@@ -456,40 +401,40 @@ void QgsMapRendererCustomPainterJob::startRender()
456401

457402
QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
458403

459-
if ( ml && ( ml->type() != QgsMapLayer::RasterLayer ) )
460-
{
461-
// only make labels if the layer is visible
462-
// after scale dep viewing settings are checked
463-
if ( !ml->hasScaleBasedVisibility() || ( ml->minimumScale() < mScale && mScale < ml->maximumScale() ) )
464-
{
465-
bool split = false;
404+
if ( !ml || ( ml->type() != QgsMapLayer::VectorLayer ) )
405+
continue;
466406

467-
if ( hasCrsTransformEnabled() )
468-
{
469-
QgsRectangle r1 = mExtent;
470-
split = splitLayersExtent( ml, r1, r2 );
471-
ct = new QgsCoordinateTransform( ml->crs(), *mDestCRS );
472-
mRenderContext.setExtent( r1 );
473-
}
474-
else
475-
{
476-
ct = NULL;
477-
}
407+
// only make labels if the layer is visible
408+
// after scale dep viewing settings are checked
409+
if ( ml->hasScaleBasedVisibility() && ( mSettings.scale() < ml->minimumScale() || mSettings.scale() > ml->maximumScale() ) )
410+
continue;
478411

479-
mRenderContext.setCoordinateTransform( ct );
412+
bool split = false;
480413

481-
ml->drawLabels( mRenderContext );
482-
if ( split )
483-
{
484-
mRenderContext.setExtent( r2 );
485-
ml->drawLabels( mRenderContext );
486-
}
487-
}
414+
if ( mSettings.hasCrsTransformEnabled() )
415+
{
416+
QgsRectangle r1 = mSettings.visibleExtent();
417+
ct = QgsCoordinateTransformCache::instance()->transform( ml->crs().authid(), mSettings.destinationCrs().authid() );
418+
split = reprojectToLayerExtent( ct, ml->crs().geographicFlag(), r1, r2 );
419+
mRenderContext.setExtent( r1 );
420+
}
421+
else
422+
{
423+
ct = NULL;
424+
}
425+
426+
mRenderContext.setCoordinateTransform( ct );
427+
428+
ml->drawLabels( mRenderContext );
429+
if ( split )
430+
{
431+
mRenderContext.setExtent( r2 );
432+
ml->drawLabels( mRenderContext );
488433
}
489434
}
490-
} // if (!mOverview)*/
435+
}
491436

492-
if ( mLabelingEngine )
437+
if ( mSettings.testFlag( QgsMapSettings::DrawLabeling ) && mLabelingEngine )
493438
{
494439
// set correct extent
495440
mRenderContext.setExtent( mSettings.visibleExtent() );

‎src/core/qgsmapsettings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ QgsMapSettings::QgsMapSettings()
2020
, mDestCRS( GEOCRS_ID, QgsCoordinateReferenceSystem::InternalCrsId ) // WGS 84
2121
, mBackgroundColor( Qt::white )
2222
, mSelectionColor( Qt::yellow )
23-
, mFlags( Antialiasing )
23+
, mFlags( Antialiasing | UseAdvancedEffects | DrawLabeling )
2424
{
2525
updateDerived();
2626

‎src/core/qgsmapsettings.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ class QgsMapSettings
5959
Antialiasing = 0x01,
6060
DrawEditingInfo = 0x02,
6161
ForceVectorOutput = 0x04,
62-
UseAdvancedEffects = 0x08
63-
// TODO: no labeling, ignore scale-based visibiity (overview)
62+
UseAdvancedEffects = 0x08,
63+
DrawLabeling = 0x10
64+
// TODO: ignore scale-based visibiity (overview)
6465
};
6566
Q_DECLARE_FLAGS(Flags, Flag)
6667

‎src/core/qgspallabeling.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@
5757
#include "qgssymbollayerv2utils.h"
5858
#include <QMessageBox>
5959

60+
61+
Q_GUI_EXPORT extern int qt_defaultDpiX();
62+
Q_GUI_EXPORT extern int qt_defaultDpiY();
63+
64+
static void _fixQPictureDPI( QPainter* p )
65+
{
66+
// QPicture makes an assumption that we drawing to it with system DPI.
67+
// Then when being drawn, it scales the painter. The following call
68+
// negates the effect. There is no way of setting QPicture's DPI.
69+
// See QTBUG-20361
70+
p->scale( (double)qt_defaultDpiX() / p->device()->logicalDpiX(),
71+
(double)qt_defaultDpiY() / p->device()->logicalDpiY() );
72+
}
73+
74+
6075
using namespace pal;
6176

6277

@@ -4286,6 +4301,7 @@ void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QgsRenderContext& con
42864301

42874302
// scale for any print output or image saving @ specific dpi
42884303
painter->scale( component.dpiRatio(), component.dpiRatio() );
4304+
_fixQPictureDPI( painter );
42894305
painter->drawPicture( 0, 0, textPict );
42904306

42914307
// regular text draw, for testing optimization
@@ -4353,6 +4369,7 @@ void QgsPalLabeling::drawLabelBuffer( QgsRenderContext& context,
43534369

43544370
// scale for any print output or image saving @ specific dpi
43554371
p->scale( component.dpiRatio(), component.dpiRatio() );
4372+
_fixQPictureDPI( p );
43564373
p->drawPicture( 0, 0, buffPict );
43574374
p->restore();
43584375
}
@@ -4648,6 +4665,7 @@ void QgsPalLabeling::drawLabelBackground( QgsRenderContext& context,
46484665

46494666
// scale for any print output or image saving @ specific dpi
46504667
p->scale( component.dpiRatio(), component.dpiRatio() );
4668+
_fixQPictureDPI( p );
46514669
p->drawPicture( 0, 0, shapePict );
46524670
p->restore();
46534671
}
@@ -4822,7 +4840,6 @@ void QgsPalLabeling::loadEngineSettings()
48224840
"PAL", "/ShowingAllLabels", false, &saved );
48234841
mShowingPartialsLabels = QgsProject::instance()->readBoolEntry(
48244842
"PAL", "/ShowingPartialsLabels", p.getShowPartial(), &saved );
4825-
mSavedWithProject = saved;
48264843
}
48274844

48284845
void QgsPalLabeling::saveEngineSettings()
@@ -4835,7 +4852,6 @@ void QgsPalLabeling::saveEngineSettings()
48354852
QgsProject::instance()->writeEntry( "PAL", "/ShowingShadowRects", mShowingShadowRects );
48364853
QgsProject::instance()->writeEntry( "PAL", "/ShowingAllLabels", mShowingAllLabels );
48374854
QgsProject::instance()->writeEntry( "PAL", "/ShowingPartialsLabels", mShowingPartialsLabels );
4838-
mSavedWithProject = true;
48394855
}
48404856

48414857
void QgsPalLabeling::clearEngineSettings()
@@ -4848,7 +4864,6 @@ void QgsPalLabeling::clearEngineSettings()
48484864
QgsProject::instance()->removeEntry( "PAL", "/ShowingShadowRects" );
48494865
QgsProject::instance()->removeEntry( "PAL", "/ShowingAllLabels" );
48504866
QgsProject::instance()->removeEntry( "PAL", "/ShowingPartialsLabels" );
4851-
mSavedWithProject = false;
48524867
}
48534868

48544869
QgsLabelingEngineInterface* QgsPalLabeling::clone()

‎src/core/qgspallabeling.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,10 @@ class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface
747747
void loadEngineSettings();
748748
void saveEngineSettings();
749749
void clearEngineSettings();
750-
bool isStoredWithProject() const { return mSavedWithProject; }
751-
void setStoredWithProject( bool store ) { mSavedWithProject = store; }
750+
//! @deprecated since 2.1 - settings are always stored in project
751+
Q_DECL_DEPRECATED bool isStoredWithProject() const { return true; }
752+
//! @deprecated since 2.1 - settings are always stored in project
753+
Q_DECL_DEPRECATED void setStoredWithProject( bool store ) { Q_UNUSED( store ); }
752754

753755
protected:
754756
// update temporary QgsPalLayerSettings with any data defined text style values
@@ -787,7 +789,6 @@ class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface
787789
QList<QgsLabelCandidate> mCandidates;
788790
bool mShowingCandidates;
789791
bool mShowingAllLabels; // whether to avoid collisions or not
790-
bool mSavedWithProject; // whether engine settings have been read from project file
791792
bool mShowingShadowRects; // whether to show debugging rectangles for drop shadows
792793
bool mShowingPartialsLabels; // whether to avoid partials labels or not
793794

‎src/gui/qgsmapoverviewcanvas.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ QgsMapOverviewCanvas::QgsMapOverviewCanvas( QWidget * parent, QgsMapCanvas* mapC
7676
mPanningWidget = new QgsPanningWidget( this );
7777

7878
setBackgroundColor( palette().window().color() );
79+
80+
mSettings.setFlag( QgsMapSettings::DrawLabeling, false );
7981
}
8082

8183
QgsMapOverviewCanvas::~QgsMapOverviewCanvas()

‎src/ui/qgsengineconfigdialog.ui

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>336</width>
10-
<height>367</height>
10+
<height>430</height>
1111
</rect>
1212
</property>
1313
<property name="minimumSize">
@@ -244,19 +244,6 @@
244244
</property>
245245
</widget>
246246
</item>
247-
<item row="5" column="0" colspan="3">
248-
<widget class="QCheckBox" name="mSaveWithProjectChkBox">
249-
<property name="layoutDirection">
250-
<enum>Qt::LeftToRight</enum>
251-
</property>
252-
<property name="text">
253-
<string>Save settings with project</string>
254-
</property>
255-
<property name="checked">
256-
<bool>false</bool>
257-
</property>
258-
</widget>
259-
</item>
260247
<item row="3" column="0" colspan="3">
261248
<widget class="QCheckBox" name="chkShowCandidates">
262249
<property name="text">

‎tests/src/core/testqgsdiagram.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
//qgis test includes
4343
#include "qgsrenderchecker.h"
4444
#include "qgspallabeling.h"
45+
#include "qgsproject.h"
4546

4647
/** \ingroup UnitTests
4748
* This is a unit test for the vector layer class.
@@ -159,7 +160,7 @@ class TestQgsDiagram: public QObject
159160
dls.placement = QgsDiagramLayerSettings::OverPoint;
160161
dls.renderer = dr;
161162

162-
// TODO dynamic_cast<QgsPalLabeling*>( mMapRenderer->labelingEngine() )->setShowingAllLabels( true );
163+
QgsProject::instance()->writeEntry( "PAL", "/ShowingAllLabels", true );
163164

164165
mPointsLayer->setDiagramLayerSettings( dls );
165166

0 commit comments

Comments
 (0)
Please sign in to comment.