Skip to content

Commit 37f3be6

Browse files
committed
[layouts] Use proxy task to show progress/exporting status in task manager
1 parent 21693bd commit 37f3be6

File tree

1 file changed

+102
-7
lines changed

1 file changed

+102
-7
lines changed

src/app/layout/qgslayoutdesignerdialog.cpp

+102-7
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "qgsreportorganizerwidget.h"
6464
#include "qgsreadwritecontext.h"
6565
#include "ui_qgssvgexportoptions.h"
66+
#include "qgsproxyprogresstask.h"
6667
#include "ui_defaults.h"
6768

6869
#include <QShortcut>
@@ -1760,12 +1761,19 @@ void QgsLayoutDesignerDialog::print()
17601761
QgsLayoutExporter::PrintExportSettings printSettings;
17611762
printSettings.rasterizeWholeImage = mLayout->customProperty( QStringLiteral( "rasterize" ), false ).toBool();
17621763

1764+
QgsProxyProgressTask *proxyTask = new QgsProxyProgressTask( tr( "Printing “%1”" ).arg( mMasterLayout->name() ) );
1765+
QgsApplication::taskManager()->addTask( proxyTask );
1766+
17631767
// force a refresh, to e.g. update data defined properties, tables, etc
17641768
mLayout->refresh();
17651769

17661770
QgsLayoutExporter exporter( mLayout );
17671771
QString printerName = printer()->printerName();
1768-
switch ( exporter.print( *printer(), printSettings ) )
1772+
QgsLayoutExporter::ExportResult result = exporter.print( *printer(), printSettings );
1773+
1774+
proxyTask->finalize( result == QgsLayoutExporter::Success );
1775+
1776+
switch ( result )
17691777
{
17701778
case QgsLayoutExporter::Success:
17711779
{
@@ -1864,14 +1872,20 @@ void QgsLayoutDesignerDialog::exportToRaster()
18641872

18651873
mView->setPaintingEnabled( false );
18661874
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );
1875+
QgsProxyProgressTask *proxyTask = new QgsProxyProgressTask( tr( "Exporting “%1”" ).arg( mMasterLayout->name() ) );
1876+
QgsApplication::taskManager()->addTask( proxyTask );
18671877

18681878
// force a refresh, to e.g. update data defined properties, tables, etc
18691879
mLayout->refresh();
18701880

18711881
QgsLayoutExporter exporter( mLayout );
18721882

18731883
QFileInfo fi( fileNExt.first );
1874-
switch ( exporter.exportToImage( fileNExt.first, settings ) )
1884+
QgsLayoutExporter::ExportResult result = exporter.exportToImage( fileNExt.first, settings );
1885+
1886+
proxyTask->finalize( result == QgsLayoutExporter::Success );
1887+
1888+
switch ( result )
18751889
{
18761890
case QgsLayoutExporter::Success:
18771891
mMessageBar->pushMessage( tr( "Export layout" ),
@@ -1963,6 +1977,8 @@ void QgsLayoutDesignerDialog::exportToPdf()
19631977

19641978
mView->setPaintingEnabled( false );
19651979
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );
1980+
QgsProxyProgressTask *proxyTask = new QgsProxyProgressTask( tr( "Exporting “%1”" ).arg( mMasterLayout->name() ) );
1981+
QgsApplication::taskManager()->addTask( proxyTask );
19661982

19671983
QgsLayoutExporter::PdfExportSettings pdfSettings;
19681984
pdfSettings.rasterizeWholeImage = mLayout->customProperty( QStringLiteral( "rasterize" ), false ).toBool();
@@ -1972,7 +1988,11 @@ void QgsLayoutDesignerDialog::exportToPdf()
19721988
mLayout->refresh();
19731989

19741990
QgsLayoutExporter exporter( mLayout );
1975-
switch ( exporter.exportToPdf( outputFileName, pdfSettings ) )
1991+
QgsLayoutExporter::ExportResult result = exporter.exportToPdf( outputFileName, pdfSettings );
1992+
1993+
proxyTask->finalize( result == QgsLayoutExporter::Success );
1994+
1995+
switch ( result )
19761996
{
19771997
case QgsLayoutExporter::Success:
19781998
{
@@ -2074,11 +2094,18 @@ void QgsLayoutDesignerDialog::exportToSvg()
20742094
mView->setPaintingEnabled( false );
20752095
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );
20762096

2097+
QgsProxyProgressTask *proxyTask = new QgsProxyProgressTask( tr( "Exporting “%1”" ).arg( mMasterLayout->name() ) );
2098+
QgsApplication::taskManager()->addTask( proxyTask );
2099+
20772100
// force a refresh, to e.g. update data defined properties, tables, etc
20782101
mLayout->refresh();
20792102

20802103
QgsLayoutExporter exporter( mLayout );
2081-
switch ( exporter.exportToSvg( outputFileName, svgSettings ) )
2104+
QgsLayoutExporter::ExportResult result = exporter.exportToSvg( outputFileName, svgSettings );
2105+
2106+
proxyTask->finalize( result == QgsLayoutExporter::Success );
2107+
2108+
switch ( result )
20822109
{
20832110
case QgsLayoutExporter::Success:
20842111
{
@@ -2324,11 +2351,16 @@ void QgsLayoutDesignerDialog::printAtlas()
23242351
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
23252352
std::unique_ptr< QProgressDialog > progressDialog = qgis::make_unique< QProgressDialog >( tr( "Printing maps…" ), tr( "Abort" ), 0, 100, this );
23262353
progressDialog->setWindowTitle( tr( "Printing Atlas" ) );
2354+
2355+
QgsProxyProgressTask *proxyTask = new QgsProxyProgressTask( tr( "Printing “%1”" ).arg( mMasterLayout->name() ) );
2356+
23272357
connect( feedback.get(), &QgsFeedback::progressChanged, this, [ & ]( double progress )
23282358
{
23292359
progressDialog->setValue( static_cast< int >( progress ) );
23302360
progressDialog->setLabelText( feedback->property( "progress" ).toString() ) ;
23312361

2362+
proxyTask->setProxyProgress( progress );
2363+
23322364
#ifdef Q_OS_LINUX
23332365
// For some reason on Windows hasPendingEvents() always return true,
23342366
// but one iteration is actually enough on Windows to get good interactivity
@@ -2347,8 +2379,14 @@ void QgsLayoutDesignerDialog::printAtlas()
23472379
feedback->cancel();
23482380
} );
23492381

2382+
QgsApplication::taskManager()->addTask( proxyTask );
2383+
23502384
QString printerName = printer()->printerName();
2351-
switch ( QgsLayoutExporter::print( printAtlas, *printer(), printSettings, error, feedback.get() ) )
2385+
QgsLayoutExporter::ExportResult result = QgsLayoutExporter::print( printAtlas, *printer(), printSettings, error, feedback.get() );
2386+
2387+
proxyTask->finalize( result == QgsLayoutExporter::Success );
2388+
2389+
switch ( result )
23522390
{
23532391
case QgsLayoutExporter::Success:
23542392
{
@@ -2494,11 +2532,16 @@ void QgsLayoutDesignerDialog::exportAtlasToRaster()
24942532
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
24952533
std::unique_ptr< QProgressDialog > progressDialog = qgis::make_unique< QProgressDialog >( tr( "Rendering maps…" ), tr( "Abort" ), 0, 100, this );
24962534
progressDialog->setWindowTitle( tr( "Exporting Atlas" ) );
2535+
2536+
QgsProxyProgressTask *proxyTask = new QgsProxyProgressTask( tr( "Exporting “%1”" ).arg( mMasterLayout->name() ) );
2537+
24972538
connect( feedback.get(), &QgsFeedback::progressChanged, this, [ & ]( double progress )
24982539
{
24992540
progressDialog->setValue( static_cast< int >( progress ) );
25002541
progressDialog->setLabelText( feedback->property( "progress" ).toString() ) ;
25012542

2543+
proxyTask->setProxyProgress( progress );
2544+
25022545
#ifdef Q_OS_LINUX
25032546
// For some reason on Windows hasPendingEvents() always return true,
25042547
// but one iteration is actually enough on Windows to get good interactivity
@@ -2517,8 +2560,13 @@ void QgsLayoutDesignerDialog::exportAtlasToRaster()
25172560
feedback->cancel();
25182561
} );
25192562

2563+
QgsApplication::taskManager()->addTask( proxyTask );
2564+
25202565
QString fileName = QDir( dir ).filePath( QStringLiteral( "atlas" ) ); // filename is overridden by atlas
25212566
QgsLayoutExporter::ExportResult result = QgsLayoutExporter::exportToImage( printAtlas, fileName, fileExt, settings, error, feedback.get() );
2567+
2568+
proxyTask->finalize( result == QgsLayoutExporter::Success );
2569+
25222570
cursorOverride.release();
25232571

25242572
switch ( result )
@@ -2644,11 +2692,16 @@ void QgsLayoutDesignerDialog::exportAtlasToSvg()
26442692
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
26452693
std::unique_ptr< QProgressDialog > progressDialog = qgis::make_unique< QProgressDialog >( tr( "Rendering maps…" ), tr( "Abort" ), 0, 100, this );
26462694
progressDialog->setWindowTitle( tr( "Exporting Atlas" ) );
2695+
2696+
QgsProxyProgressTask *proxyTask = new QgsProxyProgressTask( tr( "Exporting “%1”" ).arg( mMasterLayout->name() ) );
2697+
26472698
connect( feedback.get(), &QgsFeedback::progressChanged, this, [ & ]( double progress )
26482699
{
26492700
progressDialog->setValue( static_cast< int >( progress ) );
26502701
progressDialog->setLabelText( feedback->property( "progress" ).toString() ) ;
26512702

2703+
proxyTask->setProxyProgress( progress );
2704+
26522705
#ifdef Q_OS_LINUX
26532706
// For some reason on Windows hasPendingEvents() always return true,
26542707
// but one iteration is actually enough on Windows to get good interactivity
@@ -2667,9 +2720,13 @@ void QgsLayoutDesignerDialog::exportAtlasToSvg()
26672720
feedback->cancel();
26682721
} );
26692722

2723+
QgsApplication::taskManager()->addTask( proxyTask );
2724+
26702725
QString filename = QDir( dir ).filePath( QStringLiteral( "atlas" ) ); // filename is overridden by atlas
26712726
QgsLayoutExporter::ExportResult result = QgsLayoutExporter::exportToSvg( printAtlas, filename, svgSettings, error, feedback.get() );
26722727

2728+
proxyTask->finalize( result == QgsLayoutExporter::Success );
2729+
26732730
cursorOverride.release();
26742731
switch ( result )
26752732
{
@@ -2848,12 +2905,17 @@ void QgsLayoutDesignerDialog::exportAtlasToPdf()
28482905
QString error;
28492906
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
28502907
std::unique_ptr< QProgressDialog > progressDialog = qgis::make_unique< QProgressDialog >( tr( "Rendering maps…" ), tr( "Abort" ), 0, 100, this );
2908+
2909+
QgsProxyProgressTask *proxyTask = new QgsProxyProgressTask( tr( "Exporting “%1”" ).arg( mMasterLayout->name() ) );
2910+
28512911
progressDialog->setWindowTitle( tr( "Exporting Atlas" ) );
28522912
connect( feedback.get(), &QgsFeedback::progressChanged, this, [ & ]( double progress )
28532913
{
28542914
progressDialog->setValue( static_cast< int >( progress ) );
28552915
progressDialog->setLabelText( feedback->property( "progress" ).toString() ) ;
28562916

2917+
proxyTask->setProxyProgress( progress );
2918+
28572919
#ifdef Q_OS_LINUX
28582920
// For some reason on Windows hasPendingEvents() always return true,
28592921
// but one iteration is actually enough on Windows to get good interactivity
@@ -2872,6 +2934,8 @@ void QgsLayoutDesignerDialog::exportAtlasToPdf()
28722934
feedback->cancel();
28732935
} );
28742936

2937+
QgsApplication::taskManager()->addTask( proxyTask );
2938+
28752939
QgsLayoutExporter::ExportResult result = QgsLayoutExporter::Success;
28762940
if ( singleFile )
28772941
{
@@ -2882,6 +2946,8 @@ void QgsLayoutDesignerDialog::exportAtlasToPdf()
28822946
result = QgsLayoutExporter::exportToPdfs( printAtlas, outputFileName, pdfSettings, error, feedback.get() );
28832947
}
28842948

2949+
proxyTask->finalize( result == QgsLayoutExporter::Success );
2950+
28852951
cursorOverride.release();
28862952
switch ( result )
28872953
{
@@ -2974,6 +3040,9 @@ void QgsLayoutDesignerDialog::exportReportToRaster()
29743040
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
29753041
std::unique_ptr< QProgressDialog > progressDialog = qgis::make_unique< QProgressDialog >( tr( "Rendering report…" ), tr( "Abort" ), 0, 0, this );
29763042
progressDialog->setWindowTitle( tr( "Exporting Report" ) );
3043+
3044+
QgsProxyProgressTask *proxyTask = new QgsProxyProgressTask( tr( "Exporting “%1”" ).arg( mMasterLayout->name() ) );
3045+
29773046
connect( feedback.get(), &QgsFeedback::progressChanged, this, [ & ]( double )
29783047
{
29793048
//progressDialog->setValue( progress );
@@ -2997,10 +3066,14 @@ void QgsLayoutDesignerDialog::exportReportToRaster()
29973066
feedback->cancel();
29983067
} );
29993068

3069+
QgsApplication::taskManager()->addTask( proxyTask );
3070+
30003071
QFileInfo fi( fileNExt.first );
30013072
QString dir = fi.path();
30023073
QString fileName = dir + '/' + fi.baseName();
30033074
QgsLayoutExporter::ExportResult result = QgsLayoutExporter::exportToImage( static_cast< QgsReport * >( mMasterLayout ), fileName, fileNExt.second, settings, error, feedback.get() );
3075+
3076+
proxyTask->finalize( result == QgsLayoutExporter::Success );
30043077
cursorOverride.release();
30053078

30063079
switch ( result )
@@ -3087,6 +3160,9 @@ void QgsLayoutDesignerDialog::exportReportToSvg()
30873160
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
30883161
std::unique_ptr< QProgressDialog > progressDialog = qgis::make_unique< QProgressDialog >( tr( "Rendering maps…" ), tr( "Abort" ), 0, 0, this );
30893162
progressDialog->setWindowTitle( tr( "Exporting Report" ) );
3163+
3164+
QgsProxyProgressTask *proxyTask = new QgsProxyProgressTask( tr( "Exporting “%1”" ).arg( mMasterLayout->name() ) );
3165+
30903166
connect( feedback.get(), &QgsFeedback::progressChanged, this, [ & ]( double )
30913167
{
30923168
//progressDialog->setValue( progress );
@@ -3110,11 +3186,14 @@ void QgsLayoutDesignerDialog::exportReportToSvg()
31103186
feedback->cancel();
31113187
} );
31123188

3189+
QgsApplication::taskManager()->addTask( proxyTask );
3190+
31133191
QFileInfo fi( outputFileName );
31143192
QString outFile = fi.path() + '/' + fi.baseName();
31153193
QString dir = fi.path();
31163194
QgsLayoutExporter::ExportResult result = QgsLayoutExporter::exportToSvg( static_cast< QgsReport * >( mMasterLayout ), outFile, svgSettings, error, feedback.get() );
31173195

3196+
proxyTask->finalize( result == QgsLayoutExporter::Success );
31183197
cursorOverride.release();
31193198
switch ( result )
31203199
{
@@ -3218,6 +3297,9 @@ void QgsLayoutDesignerDialog::exportReportToPdf()
32183297
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
32193298
std::unique_ptr< QProgressDialog > progressDialog = qgis::make_unique< QProgressDialog >( tr( "Rendering maps…" ), tr( "Abort" ), 0, 0, this );
32203299
progressDialog->setWindowTitle( tr( "Exporting Report" ) );
3300+
3301+
QgsProxyProgressTask *proxyTask = new QgsProxyProgressTask( tr( "Exporting “%1”" ).arg( mMasterLayout->name() ) );
3302+
32213303
connect( feedback.get(), &QgsFeedback::progressChanged, this, [ & ]( double )
32223304
{
32233305
//progressDialog->setValue( progress );
@@ -3241,7 +3323,11 @@ void QgsLayoutDesignerDialog::exportReportToPdf()
32413323
feedback->cancel();
32423324
} );
32433325

3326+
QgsApplication::taskManager()->addTask( proxyTask );
3327+
32443328
QgsLayoutExporter::ExportResult result = QgsLayoutExporter::exportToPdf( static_cast< QgsReport * >( mMasterLayout ), outputFileName, pdfSettings, error, feedback.get() );
3329+
3330+
proxyTask->finalize( result == QgsLayoutExporter::Success );
32453331
cursorOverride.release();
32463332

32473333
switch ( result )
@@ -3314,6 +3400,9 @@ void QgsLayoutDesignerDialog::printReport()
33143400
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
33153401
std::unique_ptr< QProgressDialog > progressDialog = qgis::make_unique< QProgressDialog >( tr( "Printing maps…" ), tr( "Abort" ), 0, 0, this );
33163402
progressDialog->setWindowTitle( tr( "Printing Report" ) );
3403+
3404+
QgsProxyProgressTask *proxyTask = new QgsProxyProgressTask( tr( "Printing “%1”" ).arg( mMasterLayout->name() ) );
3405+
33173406
connect( feedback.get(), &QgsFeedback::progressChanged, this, [ & ]( double )
33183407
{
33193408
//progressDialog->setValue( progress );
@@ -3337,15 +3426,21 @@ void QgsLayoutDesignerDialog::printReport()
33373426
feedback->cancel();
33383427
} );
33393428

3429+
QgsApplication::taskManager()->addTask( proxyTask );
3430+
33403431
QString printerName = printer()->printerName();
3341-
switch ( QgsLayoutExporter::print( static_cast< QgsReport * >( mMasterLayout ), *printer(), printSettings, error, feedback.get() ) )
3432+
QgsLayoutExporter::ExportResult result = QgsLayoutExporter::print( static_cast< QgsReport * >( mMasterLayout ), *printer(), printSettings, error, feedback.get() );
3433+
3434+
proxyTask->finalize( result == QgsLayoutExporter::Success );
3435+
3436+
switch ( result )
33423437
{
33433438
case QgsLayoutExporter::Success:
33443439
{
33453440
QString message;
33463441
if ( !printerName.isEmpty() )
33473442
{
3348-
message = tr( "Successfully printed report to %1." ).arg( printerName );
3443+
message = tr( "Successfully printed report to %1." ).arg( printerName );
33493444
}
33503445
else
33513446
{

0 commit comments

Comments
 (0)