Skip to content
Permalink
Browse files

Gracefully handle main annotation layer during layered exports

  • Loading branch information
nyalldawson committed Sep 1, 2020
1 parent 6a5eeca commit 2e9a70fe9b48db7017c89216bcbfd7abf83fb5a4
Showing with 67 additions and 0 deletions.
  1. +8 −0 src/core/layout/qgslayoutitemmap.cpp
  2. +59 −0 tests/src/core/testqgslayoutmap.cpp
@@ -1219,6 +1219,14 @@ QgsLayoutItem::ExportLayerDetail QgsLayoutItemMap::exportLayerDetails() const
else
detail.name = QStringLiteral( "%1: %2" ).arg( displayName(), layer->name() );
}
else if ( mLayout->project()->mainAnnotationLayer()->id() == detail.mapLayerId )
{
// master annotation layer
if ( !detail.mapTheme.isEmpty() )
detail.name = QStringLiteral( "%1 (%2): %3" ).arg( displayName(), detail.mapTheme, tr( "Annotations" ) );
else
detail.name = QStringLiteral( "%1: %2" ).arg( displayName(), tr( "Annotations" ) );
}
else
{
// might be an item based layer
@@ -35,6 +35,8 @@
#include "qgsvectorlayerlabeling.h"
#include "qgstemporalrangeobject.h"
#include "qgsfontutils.h"
#include "qgsannotationlayer.h"
#include "qgsannotationmarkeritem.h"

#include <QObject>
#include "qgstest.h"
@@ -1866,6 +1868,63 @@ void TestQgsLayoutMap::testLayeredExportLabelsByLayer()
QVERIFY( map->shouldDrawPart( QgsLayoutItemMap::Frame ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Background ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Layer ) );

// main annotation layer for project has content, so should be included too
p.mainAnnotationLayer()->addItem( new QgsAnnotationMarkerItem( QgsPoint( 1, 2 ) ) );

map->startLayeredExport();
QVERIFY( map->nextExportPart() );
map->createStagedRenderJob( map->extent(), QSize( 512, 512 ), 72 );
QCOMPARE( map->exportLayerDetails().name, QStringLiteral( "Map 1: points" ) );
QCOMPARE( map->exportLayerDetails().mapLayerId, pointsLayer->id() );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Grid ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::OverviewMapExtent ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Frame ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Background ) );
QVERIFY( map->shouldDrawPart( QgsLayoutItemMap::Layer ) );
QVERIFY( map->nextExportPart() );
QCOMPARE( map->exportLayerDetails().name, QStringLiteral( "Map 1: lines" ) );
QCOMPARE( map->exportLayerDetails().mapLayerId, linesLayer->id() );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Grid ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::OverviewMapExtent ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Frame ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Background ) );
QVERIFY( map->shouldDrawPart( QgsLayoutItemMap::Layer ) );
QVERIFY( map->nextExportPart() );
// annotations
QCOMPARE( map->exportLayerDetails().name, QStringLiteral( "Map 1: Annotations" ) );
QCOMPARE( map->exportLayerDetails().mapLayerId, p.mainAnnotationLayer()->id() );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Grid ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::OverviewMapExtent ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Frame ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Background ) );
QVERIFY( map->shouldDrawPart( QgsLayoutItemMap::Layer ) );
QVERIFY( map->nextExportPart() );

// labels
QCOMPARE( map->exportLayerDetails().name, QStringLiteral( "Map 1: points (Labels)" ) );
QCOMPARE( map->exportLayerDetails().mapLayerId, pointsLayer->id() );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Grid ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::OverviewMapExtent ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Frame ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Background ) );
QVERIFY( map->shouldDrawPart( QgsLayoutItemMap::Layer ) );
QVERIFY( map->nextExportPart() );
QCOMPARE( map->exportLayerDetails().name, QStringLiteral( "Map 1: lines (Labels)" ) );
QCOMPARE( map->exportLayerDetails().mapLayerId, linesLayer->id() );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Grid ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::OverviewMapExtent ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Frame ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Background ) );
QVERIFY( map->shouldDrawPart( QgsLayoutItemMap::Layer ) );
QVERIFY( map->nextExportPart() );
QCOMPARE( map->exportLayerDetails().name, QStringLiteral( "Map 1: Frame" ) );
QVERIFY( map->exportLayerDetails().mapLayerId.isEmpty() );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Grid ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::OverviewMapExtent ) );
QVERIFY( map->shouldDrawPart( QgsLayoutItemMap::Frame ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Background ) );
QVERIFY( !map->shouldDrawPart( QgsLayoutItemMap::Layer ) );
}

void TestQgsLayoutMap::testTemporal()

0 comments on commit 2e9a70f

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