Skip to content

Commit 4180846

Browse files
authored
Display name of layers in need of rasterization when saving as PDF (#4539)
1 parent ad5054b commit 4180846

File tree

6 files changed

+39
-11
lines changed

6 files changed

+39
-11
lines changed

python/core/qgsmapsettingsutils.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ class QgsMapSettingsUtils
2222
%End
2323
public:
2424

25-
static bool containsAdvancedEffects( const QgsMapSettings &mapSettings );
25+
static const QStringList containsAdvancedEffects( const QgsMapSettings &mapSettings );
2626
%Docstring
2727
Checks whether any of the layers attached to a map settings object contain advanced effects
2828
\param mapSettings map settings
29-
:rtype: bool
29+
:rtype: list of str
3030
%End
3131

3232
static QString worldFileContent( const QgsMapSettings &mapSettings );

src/app/qgsmapsavedialog.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,23 @@ QgsMapSaveDialog::QgsMapSaveDialog( QWidget *parent, QgsMapCanvas *mapCanvas, co
6666
{
6767
mSaveWorldFile->setVisible( false );
6868

69-
mSaveAsRaster->setChecked( QgsMapSettingsUtils::containsAdvancedEffects( mapCanvas->mapSettings() ) );
69+
QStringList layers = QgsMapSettingsUtils::containsAdvancedEffects( mapCanvas->mapSettings() );
70+
if ( !layers.isEmpty() )
71+
{
72+
// Limit number of items to avoid extreme dialog height
73+
if ( layers.count() >= 10 )
74+
{
75+
layers = layers.mid( 0, 9 );
76+
layers << QChar( 0x2026 );
77+
}
78+
mInfo->setText( tr( "The following layer(s) use advanced effects:\n%1\nRasterizing map is recommended for proper rendering." ).arg(
79+
QChar( 0x2022 ) + QString( " " ) + layers.join( QString( "\n" ) + QChar( 0x2022 ) + QString( " " ) ) ) );
80+
mSaveAsRaster->setChecked( true );
81+
}
82+
else
83+
{
84+
mSaveAsRaster->setChecked( false );
85+
}
7086
mSaveAsRaster->setVisible( true );
7187

7288
this->setWindowTitle( tr( "Save map as PDF" ) );

src/core/composer/qgscomposermap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ bool QgsComposerMap::containsAdvancedEffects() const
10821082

10831083
QgsMapSettings ms;
10841084
ms.setLayers( layersToRender() );
1085-
return QgsMapSettingsUtils::containsAdvancedEffects( ms );
1085+
return ( !QgsMapSettingsUtils::containsAdvancedEffects( ms ).isEmpty() );
10861086
}
10871087

10881088
void QgsComposerMap::connectUpdateSlot()

src/core/qgsmapsettingsutils.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,46 @@
2323

2424
#include <QString>
2525

26-
bool QgsMapSettingsUtils::containsAdvancedEffects( const QgsMapSettings &mapSettings )
26+
const QStringList QgsMapSettingsUtils::containsAdvancedEffects( const QgsMapSettings &mapSettings )
2727
{
28+
QSet< QString > layers;
29+
2830
QgsTextFormat layerFormat;
2931
Q_FOREACH ( QgsMapLayer *layer, mapSettings.layers() )
3032
{
3133
if ( layer )
3234
{
3335
if ( layer->blendMode() != QPainter::CompositionMode_SourceOver )
3436
{
35-
return true;
37+
layers << layer->name();
3638
}
3739
// if vector layer, check labels and feature blend mode
3840
QgsVectorLayer *currentVectorLayer = qobject_cast<QgsVectorLayer *>( layer );
3941
if ( currentVectorLayer )
4042
{
4143
if ( currentVectorLayer->layerTransparency() != 0 )
4244
{
43-
return true;
45+
layers << layer->name();
4446
}
4547
if ( currentVectorLayer->featureBlendMode() != QPainter::CompositionMode_SourceOver )
4648
{
47-
return true;
49+
layers << layer->name();
4850
}
4951
// check label blend modes
5052
if ( QgsPalLabeling::staticWillUseLayer( currentVectorLayer ) )
5153
{
5254
// Check all label blending properties
5355
layerFormat.readFromLayer( currentVectorLayer );
5456
if ( layerFormat.containsAdvancedEffects() )
55-
return true;
57+
{
58+
layers << layer->name();
59+
}
5660
}
5761
}
5862
}
5963
}
60-
return false;
64+
65+
return layers.toList();
6166
}
6267

6368
QString QgsMapSettingsUtils::worldFileContent( const QgsMapSettings &mapSettings )

src/core/qgsmapsettingsutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CORE_EXPORT QgsMapSettingsUtils
3535
/** Checks whether any of the layers attached to a map settings object contain advanced effects
3636
* \param mapSettings map settings
3737
*/
38-
static bool containsAdvancedEffects( const QgsMapSettings &mapSettings );
38+
static const QStringList containsAdvancedEffects( const QgsMapSettings &mapSettings );
3939

4040
/** Creates the content of a world file.
4141
* \param mapSettings map settings

src/ui/qgsmapsavedialog.ui

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
<layout class="QVBoxLayout" name="verticalLayout">
1717
<item>
1818
<layout class="QGridLayout" name="gridLayout">
19+
<item row="9" column="0" colspan="2">
20+
<widget class="QLabel" name="mInfo">
21+
<property name="enabled">
22+
<bool>false</bool>
23+
</property>
24+
</widget>
25+
</item>
1926
<item row="8" column="0" colspan="2">
2027
<widget class="QCheckBox" name="mSaveAsRaster">
2128
<property name="text">

0 commit comments

Comments
 (0)