Skip to content
Permalink
Browse files

Fix map canvas decoration not shown when exporting temporal animation

  • Loading branch information
nirvn committed May 18, 2020
1 parent 32d341f commit f55de3cb9e54320e49094ff60e5b83aaf9375de8
@@ -7524,7 +7524,7 @@ void QgisApp::updateFilterLegend()
}
}

void QgisApp::saveMapAsImage()
QList< QgsDecorationItem * > QgisApp::activeDecorationItems()
{
QList< QgsDecorationItem * > decorations;
const auto constMDecorationItems = mDecorationItems;
@@ -7535,25 +7535,18 @@ void QgisApp::saveMapAsImage()
decorations << decoration;
}
}

QgsMapSaveDialog *dlg = new QgsMapSaveDialog( this, mMapCanvas, decorations, QgsProject::instance()->annotationManager()->annotations() );
return decorations;
}
void QgisApp::saveMapAsImage()
{
QgsMapSaveDialog *dlg = new QgsMapSaveDialog( this, mMapCanvas, activeDecorationItems(), QgsProject::instance()->annotationManager()->annotations() );
dlg->setAttribute( Qt::WA_DeleteOnClose );
dlg->show();
} // saveMapAsImage

void QgisApp::saveMapAsPdf()
{
QList< QgsDecorationItem * > decorations;
const auto constMDecorationItems = mDecorationItems;
for ( QgsDecorationItem *decoration : constMDecorationItems )
{
if ( decoration->enabled() )
{
decorations << decoration;
}
}

QgsMapSaveDialog *dlg = new QgsMapSaveDialog( this, mMapCanvas, decorations, QgsProject::instance()->annotationManager()->annotations(), QgsMapSaveDialog::Pdf );
QgsMapSaveDialog *dlg = new QgsMapSaveDialog( this, mMapCanvas, activeDecorationItems(), QgsProject::instance()->annotationManager()->annotations(), QgsMapSaveDialog::Pdf );
dlg->setAttribute( Qt::WA_DeleteOnClose );
dlg->show();
} // saveMapAsPdf
@@ -695,6 +695,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

void emitCustomCrsValidation( QgsCoordinateReferenceSystem &crs );

QList<QgsDecorationItem *> activeDecorationItems();
QList<QgsDecorationItem *> decorationItems() { return mDecorationItems; }
void addDecorationItem( QgsDecorationItem *item ) { mDecorationItems.append( item ); }

@@ -17,14 +17,15 @@

#include "qgsanimationexportdialog.h"
#include "qgsmapcanvas.h"
#include "qgsdecorationitem.h"
#include "qgsexpressioncontextutils.h"
#include "qgstemporalnavigationobject.h"
#include "qgsprojecttimesettings.h"
#include "qgstemporalutils.h"

Q_GUI_EXPORT extern int qt_defaultDpiX();

QgsAnimationExportDialog::QgsAnimationExportDialog( QWidget *parent, QgsMapCanvas *mapCanvas )
QgsAnimationExportDialog::QgsAnimationExportDialog( QWidget *parent, QgsMapCanvas *mapCanvas, const QList< QgsDecorationItem * > &decorations )
: QDialog( parent )
, mMapCanvas( mapCanvas )
{
@@ -44,6 +45,17 @@ QgsAnimationExportDialog::QgsAnimationExportDialog( QWidget *parent, QgsMapCanva
mStartDateTime->setDisplayFormat( "yyyy-MM-dd HH:mm:ss" );
mEndDateTime->setDisplayFormat( "yyyy-MM-dd HH:mm:ss" );

QString activeDecorations;
const auto constDecorations = decorations;
for ( QgsDecorationItem *decoration : constDecorations )
{
if ( activeDecorations.isEmpty() )
activeDecorations = decoration->name().toLower();
else
activeDecorations += QStringLiteral( ", %1" ).arg( decoration->name().toLower() );
}
mDrawDecorations->setText( tr( "Draw active decorations: %1" ).arg( !activeDecorations.isEmpty() ? activeDecorations : tr( "none" ) ) );

QgsSettings settings;

const QString templateText = settings.value( QStringLiteral( "ExportAnimation/fileNameTemplate" ),
@@ -275,3 +287,8 @@ void QgsAnimationExportDialog::lockChanged( const bool locked )
mExtentGroupBox->setRatio( QSize( 0, 0 ) );
}
}

bool QgsAnimationExportDialog::drawDecorations() const
{
return mDrawDecorations->isChecked();
}
@@ -44,7 +44,9 @@ class APP_EXPORT QgsAnimationExportDialog: public QDialog, private Ui::QgsAnimat
/**
* Constructor for QgsAnimationExportDialog
*/
QgsAnimationExportDialog( QWidget *parent = nullptr, QgsMapCanvas *mapCanvas = nullptr );
QgsAnimationExportDialog( QWidget *parent = nullptr,
QgsMapCanvas *mapCanvas = nullptr,
const QList< QgsDecorationItem * > &decorations = QList< QgsDecorationItem * >() );

//! Returns extent rectangle
QgsRectangle extent() const;
@@ -67,6 +69,9 @@ class APP_EXPORT QgsAnimationExportDialog: public QDialog, private Ui::QgsAnimat
//! configure a map settings object
void applyMapSettings( QgsMapSettings &mapSettings );

//! returns whether the draw decorations element is checked
bool drawDecorations() const;

signals:

void startExport();
@@ -19,7 +19,9 @@
#include "qgstemporalcontrollerwidget.h"
#include "qgspanelwidgetstack.h"
#include "qgsanimationexportdialog.h"
#include "qgsdecorationitem.h"
#include "qgsmapcanvas.h"
#include "qgsmapdecoration.h"

#include "qgstemporalutils.h"
#include "qgstaskmanager.h"
@@ -51,7 +53,7 @@ QgsTemporalController *QgsTemporalControllerDockWidget::temporalController()

void QgsTemporalControllerDockWidget::exportAnimation()
{
QgsAnimationExportDialog *dlg = new QgsAnimationExportDialog( this, QgisApp::instance()->mapCanvas() );
QgsAnimationExportDialog *dlg = new QgsAnimationExportDialog( this, QgisApp::instance()->mapCanvas(), QgisApp::instance()->activeDecorationItems() );
connect( dlg, &QgsAnimationExportDialog::startExport, this, [ = ]
{
QgsMapSettings s = QgisApp::instance()->mapCanvas()->mapSettings();
@@ -82,11 +84,22 @@ void QgsTemporalControllerDockWidget::exportAnimation()

connect( &progressDialog, &QProgressDialog::canceled, &progressFeedback, &QgsFeedback::cancel );

QList<QgsMapDecoration *> decorations;
if ( dlg->drawDecorations() )
{
const QList<QgsDecorationItem *> decorationItems = QgisApp::instance()->activeDecorationItems();
for ( QgsMapDecoration *decoration : decorationItems )
{
decorations << decoration;
}
}

QgsTemporalUtils::AnimationExportSettings animationSettings;
animationSettings.frameDuration = frameDuration;
animationSettings.animationRange = animationRange;
animationSettings.outputDirectory = outputDir;
animationSettings.fileNameTemplate = fileNameExpression;
animationSettings.decorations = decorations;

bool success = QgsTemporalUtils::exportAnimation(
s,
@@ -23,6 +23,7 @@
#include "qgsrasterlayertemporalproperties.h"
#include "qgsmeshlayertemporalproperties.h"
#include "qgstemporalnavigationobject.h"
#include "qgsmapdecoration.h"
#include "qgsmapsettings.h"
#include "qgsmaprenderercustompainterjob.h"
#include "qgsexpressioncontextutils.h"
@@ -118,6 +119,16 @@ bool QgsTemporalUtils::exportAnimation( const QgsMapSettings &mapSettings, const
QgsMapRendererCustomPainterJob job( ms, &p );
job.start();
job.waitForFinished();

QgsRenderContext context = QgsRenderContext::fromMapSettings( ms );
context.setPainter( &p );

const auto constMDecorations = settings.decorations;
for ( QgsMapDecoration *decoration : constMDecorations )
{
decoration->render( ms, context );
}

p.end();

img.save( path );
@@ -23,6 +23,7 @@
class QgsProject;
class QgsMapSettings;
class QgsFeedback;
class QgsMapDecoration;

/**
* \ingroup core
@@ -64,6 +65,9 @@ class CORE_EXPORT QgsTemporalUtils
* e.g. my###.jpg will create frames my001.jpg, my002.jpg, etc
*/
QString fileNameTemplate;

//! List of decorations to draw onto exported frames.
QList<QgsMapDecoration *> decorations;

};

@@ -234,6 +234,16 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="mDrawDecorations">
<property name="text">
<string>Draw active decorations</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>

0 comments on commit f55de3c

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