Skip to content

Commit

Permalink
Display name of layers in need of rasterization when saving as PDF (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed May 12, 2017
1 parent ad5054b commit 4180846
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
4 changes: 2 additions & 2 deletions python/core/qgsmapsettingsutils.sip
Expand Up @@ -22,11 +22,11 @@ class QgsMapSettingsUtils
%End
public:

static bool containsAdvancedEffects( const QgsMapSettings &mapSettings );
static const QStringList containsAdvancedEffects( const QgsMapSettings &mapSettings );
%Docstring
Checks whether any of the layers attached to a map settings object contain advanced effects
\param mapSettings map settings
:rtype: bool
:rtype: list of str
%End

static QString worldFileContent( const QgsMapSettings &mapSettings );
Expand Down
18 changes: 17 additions & 1 deletion src/app/qgsmapsavedialog.cpp
Expand Up @@ -66,7 +66,23 @@ QgsMapSaveDialog::QgsMapSaveDialog( QWidget *parent, QgsMapCanvas *mapCanvas, co
{
mSaveWorldFile->setVisible( false );

mSaveAsRaster->setChecked( QgsMapSettingsUtils::containsAdvancedEffects( mapCanvas->mapSettings() ) );
QStringList layers = QgsMapSettingsUtils::containsAdvancedEffects( mapCanvas->mapSettings() );
if ( !layers.isEmpty() )
{
// Limit number of items to avoid extreme dialog height
if ( layers.count() >= 10 )
{
layers = layers.mid( 0, 9 );
layers << QChar( 0x2026 );
}
mInfo->setText( tr( "The following layer(s) use advanced effects:\n%1\nRasterizing map is recommended for proper rendering." ).arg(
QChar( 0x2022 ) + QString( " " ) + layers.join( QString( "\n" ) + QChar( 0x2022 ) + QString( " " ) ) ) );
mSaveAsRaster->setChecked( true );
}
else
{
mSaveAsRaster->setChecked( false );
}
mSaveAsRaster->setVisible( true );

this->setWindowTitle( tr( "Save map as PDF" ) );
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposermap.cpp
Expand Up @@ -1082,7 +1082,7 @@ bool QgsComposerMap::containsAdvancedEffects() const

QgsMapSettings ms;
ms.setLayers( layersToRender() );
return QgsMapSettingsUtils::containsAdvancedEffects( ms );
return ( !QgsMapSettingsUtils::containsAdvancedEffects( ms ).isEmpty() );
}

void QgsComposerMap::connectUpdateSlot()
Expand Down
17 changes: 11 additions & 6 deletions src/core/qgsmapsettingsutils.cpp
Expand Up @@ -23,41 +23,46 @@

#include <QString>

bool QgsMapSettingsUtils::containsAdvancedEffects( const QgsMapSettings &mapSettings )
const QStringList QgsMapSettingsUtils::containsAdvancedEffects( const QgsMapSettings &mapSettings )
{
QSet< QString > layers;

QgsTextFormat layerFormat;
Q_FOREACH ( QgsMapLayer *layer, mapSettings.layers() )
{
if ( layer )
{
if ( layer->blendMode() != QPainter::CompositionMode_SourceOver )
{
return true;
layers << layer->name();
}
// if vector layer, check labels and feature blend mode
QgsVectorLayer *currentVectorLayer = qobject_cast<QgsVectorLayer *>( layer );
if ( currentVectorLayer )
{
if ( currentVectorLayer->layerTransparency() != 0 )
{
return true;
layers << layer->name();
}
if ( currentVectorLayer->featureBlendMode() != QPainter::CompositionMode_SourceOver )
{
return true;
layers << layer->name();
}
// check label blend modes
if ( QgsPalLabeling::staticWillUseLayer( currentVectorLayer ) )
{
// Check all label blending properties
layerFormat.readFromLayer( currentVectorLayer );
if ( layerFormat.containsAdvancedEffects() )
return true;
{
layers << layer->name();
}
}
}
}
}
return false;

return layers.toList();
}

QString QgsMapSettingsUtils::worldFileContent( const QgsMapSettings &mapSettings )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsmapsettingsutils.h
Expand Up @@ -35,7 +35,7 @@ class CORE_EXPORT QgsMapSettingsUtils
/** Checks whether any of the layers attached to a map settings object contain advanced effects
* \param mapSettings map settings
*/
static bool containsAdvancedEffects( const QgsMapSettings &mapSettings );
static const QStringList containsAdvancedEffects( const QgsMapSettings &mapSettings );

/** Creates the content of a world file.
* \param mapSettings map settings
Expand Down
7 changes: 7 additions & 0 deletions src/ui/qgsmapsavedialog.ui
Expand Up @@ -16,6 +16,13 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="9" column="0" colspan="2">
<widget class="QLabel" name="mInfo">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="mSaveAsRaster">
<property name="text">
Expand Down

0 comments on commit 4180846

Please sign in to comment.