Skip to content
Permalink
Browse files

Minor refactoring, more tests

  • Loading branch information
nyalldawson committed Jun 7, 2020
1 parent d5d7280 commit 0a9d61a0b3b27dd95b1a2ebf75b47d33c59560cc
Showing with 117 additions and 46 deletions.
  1. +72 −46 src/core/qgsabstractgeopdfexporter.cpp
  2. +13 −0 src/core/qgsabstractgeopdfexporter.h
  3. +32 −0 tests/src/core/testqgsgeopdfexport.cpp
@@ -136,6 +136,29 @@ QString QgsAbstractGeoPdfExporter::generateTemporaryFilepath( const QString &fil
return mTemporaryDir.filePath( filename );
}

bool QgsAbstractGeoPdfExporter::compositionModeSupported( QPainter::CompositionMode mode )
{
switch ( mode )
{
case QPainter::CompositionMode_SourceOver:
case QPainter::CompositionMode_Multiply:
case QPainter::CompositionMode_Screen:
case QPainter::CompositionMode_Overlay:
case QPainter::CompositionMode_Darken:
case QPainter::CompositionMode_Lighten:
case QPainter::CompositionMode_ColorDodge:
case QPainter::CompositionMode_ColorBurn:
case QPainter::CompositionMode_HardLight:
case QPainter::CompositionMode_SoftLight:
case QPainter::CompositionMode_Difference:
case QPainter::CompositionMode_Exclusion:
return true;

default:
return false;
}
return false;
}

void QgsAbstractGeoPdfExporter::pushRenderedFeature( const QString &layerId, const QgsAbstractGeoPdfExporter::RenderedFeature &feature, const QString &group )
{
@@ -479,52 +502,7 @@ QString QgsAbstractGeoPdfExporter::createCompositionXml( const QList<ComponentLa
{
QDomElement blendingElement = doc.createElement( QStringLiteral( "Blending" ) );
blendingElement.setAttribute( QStringLiteral( "opacity" ), component.opacity );
QString function;
switch ( component.compositionMode )
{
case QPainter::CompositionMode_SourceOver:
function = QStringLiteral( "Normal" );
break;
case QPainter::CompositionMode_Multiply:
function = QStringLiteral( "Multiply" );
break;
case QPainter::CompositionMode_Screen:
function = QStringLiteral( "Screen" );
break;
case QPainter::CompositionMode_Overlay:
function = QStringLiteral( "Overlay" );
break;
case QPainter::CompositionMode_Darken:
function = QStringLiteral( "Darken" );
break;
case QPainter::CompositionMode_Lighten:
function = QStringLiteral( "Lighten" );
break;
case QPainter::CompositionMode_ColorDodge:
function = QStringLiteral( "ColorDodge" );
break;
case QPainter::CompositionMode_ColorBurn:
function = QStringLiteral( "ColorBurn" );
break;
case QPainter::CompositionMode_HardLight:
function = QStringLiteral( "HardLight" );
break;
case QPainter::CompositionMode_SoftLight:
function = QStringLiteral( "SoftLight" );
break;
case QPainter::CompositionMode_Difference:
function = QStringLiteral( "Difference" );
break;
case QPainter::CompositionMode_Exclusion:
function = QStringLiteral( "Exclusion" );
break;

default:
QgsDebugMsg( QStringLiteral( "Unsupported PDF blend mode %1" ).arg( component.compositionMode ) );
function = QStringLiteral( "Normal" );
break;
}
blendingElement.setAttribute( QStringLiteral( "function" ), function );
blendingElement.setAttribute( QStringLiteral( "function" ), compositionModeToString( component.compositionMode ) );

pdfDataset.appendChild( blendingElement );
}
@@ -608,3 +586,51 @@ QString QgsAbstractGeoPdfExporter::createCompositionXml( const QList<ComponentLa
return composition;
}

QString QgsAbstractGeoPdfExporter::compositionModeToString( QPainter::CompositionMode mode )
{
switch ( mode )
{
case QPainter::CompositionMode_SourceOver:
return QStringLiteral( "Normal" );

case QPainter::CompositionMode_Multiply:
return QStringLiteral( "Multiply" );

case QPainter::CompositionMode_Screen:
return QStringLiteral( "Screen" );

case QPainter::CompositionMode_Overlay:
return QStringLiteral( "Overlay" );

case QPainter::CompositionMode_Darken:
return QStringLiteral( "Darken" );

case QPainter::CompositionMode_Lighten:
return QStringLiteral( "Lighten" );

case QPainter::CompositionMode_ColorDodge:
return QStringLiteral( "ColorDodge" );

case QPainter::CompositionMode_ColorBurn:
return QStringLiteral( "ColorBurn" );

case QPainter::CompositionMode_HardLight:
return QStringLiteral( "HardLight" );

case QPainter::CompositionMode_SoftLight:
return QStringLiteral( "SoftLight" );

case QPainter::CompositionMode_Difference:
return QStringLiteral( "Difference" );

case QPainter::CompositionMode_Exclusion:
return QStringLiteral( "Exclusion" );

default:
QgsDebugMsg( QStringLiteral( "Unsupported PDF blend mode %1" ).arg( mode ) );
return QStringLiteral( "Normal" );

}
return QString();
}

@@ -311,6 +311,14 @@ class CORE_EXPORT QgsAbstractGeoPdfExporter
*/
QString generateTemporaryFilepath( const QString &filename ) const;

/**
* Returns TRUE if the specified composition \a mode is supported for layers
* during GeoPDF exports.
*
* \since QGIS 3.14
*/
static bool compositionModeSupported( QPainter::CompositionMode mode );

protected:

/**
@@ -358,6 +366,11 @@ class CORE_EXPORT QgsAbstractGeoPdfExporter

QString createCompositionXml( const QList< QgsAbstractGeoPdfExporter::ComponentLayerDetail > &components, const ExportDetails &details );

/**
* Returns the GDAL string representation of the specified QPainter composition \a mode.
*/
static QString compositionModeToString( QPainter::CompositionMode mode );

friend class TestQgsLayoutGeoPdfExport;
friend class TestQgsGeoPdfExport;
};
@@ -61,6 +61,7 @@ class TestQgsGeoPdfExport : public QObject
void testGeorefPolygon();
void testGroups();
void testCustomGroups();
void compositionMode();

private:

@@ -587,5 +588,36 @@ void TestQgsGeoPdfExport::testCustomGroups()

}

void TestQgsGeoPdfExport::compositionMode()
{
QVERIFY( QgsAbstractGeoPdfExporter::compositionModeSupported( QPainter::CompositionMode_SourceOver ) );
QVERIFY( QgsAbstractGeoPdfExporter::compositionModeSupported( QPainter::CompositionMode_Multiply ) );
QVERIFY( QgsAbstractGeoPdfExporter::compositionModeSupported( QPainter::CompositionMode_Screen ) );
QVERIFY( QgsAbstractGeoPdfExporter::compositionModeSupported( QPainter::CompositionMode_Overlay ) );
QVERIFY( QgsAbstractGeoPdfExporter::compositionModeSupported( QPainter::CompositionMode_Darken ) );
QVERIFY( QgsAbstractGeoPdfExporter::compositionModeSupported( QPainter::CompositionMode_Lighten ) );
QVERIFY( QgsAbstractGeoPdfExporter::compositionModeSupported( QPainter::CompositionMode_ColorDodge ) );
QVERIFY( QgsAbstractGeoPdfExporter::compositionModeSupported( QPainter::CompositionMode_ColorBurn ) );
QVERIFY( QgsAbstractGeoPdfExporter::compositionModeSupported( QPainter::CompositionMode_HardLight ) );
QVERIFY( QgsAbstractGeoPdfExporter::compositionModeSupported( QPainter::CompositionMode_SoftLight ) );
QVERIFY( QgsAbstractGeoPdfExporter::compositionModeSupported( QPainter::CompositionMode_Difference ) );
QVERIFY( QgsAbstractGeoPdfExporter::compositionModeSupported( QPainter::CompositionMode_Exclusion ) );
QVERIFY( !QgsAbstractGeoPdfExporter::compositionModeSupported( QPainter::CompositionMode_Plus ) );

QCOMPARE( QgsAbstractGeoPdfExporter::compositionModeToString( QPainter::CompositionMode_SourceOver ), QStringLiteral( "Normal" ) );
QCOMPARE( QgsAbstractGeoPdfExporter::compositionModeToString( QPainter::CompositionMode_Multiply ), QStringLiteral( "Multiply" ) );
QCOMPARE( QgsAbstractGeoPdfExporter::compositionModeToString( QPainter::CompositionMode_Screen ), QStringLiteral( "Screen" ) );
QCOMPARE( QgsAbstractGeoPdfExporter::compositionModeToString( QPainter::CompositionMode_Overlay ), QStringLiteral( "Overlay" ) );
QCOMPARE( QgsAbstractGeoPdfExporter::compositionModeToString( QPainter::CompositionMode_Darken ), QStringLiteral( "Darken" ) );
QCOMPARE( QgsAbstractGeoPdfExporter::compositionModeToString( QPainter::CompositionMode_Lighten ), QStringLiteral( "Lighten" ) );
QCOMPARE( QgsAbstractGeoPdfExporter::compositionModeToString( QPainter::CompositionMode_ColorDodge ), QStringLiteral( "ColorDodge" ) );
QCOMPARE( QgsAbstractGeoPdfExporter::compositionModeToString( QPainter::CompositionMode_ColorBurn ), QStringLiteral( "ColorBurn" ) );
QCOMPARE( QgsAbstractGeoPdfExporter::compositionModeToString( QPainter::CompositionMode_HardLight ), QStringLiteral( "HardLight" ) );
QCOMPARE( QgsAbstractGeoPdfExporter::compositionModeToString( QPainter::CompositionMode_SoftLight ), QStringLiteral( "SoftLight" ) );
QCOMPARE( QgsAbstractGeoPdfExporter::compositionModeToString( QPainter::CompositionMode_Difference ), QStringLiteral( "Difference" ) );
QCOMPARE( QgsAbstractGeoPdfExporter::compositionModeToString( QPainter::CompositionMode_Exclusion ), QStringLiteral( "Exclusion" ) );
QCOMPARE( QgsAbstractGeoPdfExporter::compositionModeToString( QPainter::CompositionMode_Plus ), QStringLiteral( "Normal" ) );
}

QGSTEST_MAIN( TestQgsGeoPdfExport )
#include "testqgsgeopdfexport.moc"

0 comments on commit 0a9d61a

Please sign in to comment.
You can’t perform that action at this time.