Skip to content

Commit aa22c0e

Browse files
committed
Hide new composer when duplicating (loading template) as it is faster
- Show busy indicator dialog - Add busy indicator dialog method to QgsComposer
1 parent f9d9da3 commit aa22c0e

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

src/app/composer/qgscomposer.cpp

+34-1
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@
5656
#include <QCloseEvent>
5757
#include <QCheckBox>
5858
#include <QDesktopWidget>
59+
#include <QDialog>
5960
#include <QFileDialog>
6061
#include <QFileInfo>
6162
#include <QIcon>
6263
#include <QImageWriter>
64+
#include <QLabel>
6365
#include <QMatrix>
6466
#include <QMenuBar>
6567
#include <QMessageBox>
@@ -75,6 +77,7 @@
7577
#include <QToolButton>
7678
#include <QUndoView>
7779
#include <QPaintEngine>
80+
#include <QProgressBar>
7881
#include <QProgressDialog>
7982

8083

@@ -489,6 +492,24 @@ void QgsComposer::setTitle( const QString& title )
489492
}
490493
}
491494

495+
QDialog* QgsComposer::progressDialog( const QString& message, QWidget* parent )
496+
{
497+
QDialog* dlg = new QDialog( parent );
498+
dlg->setLayout( new QVBoxLayout() );
499+
dlg->setWindowModality( Qt::WindowModal );
500+
dlg->setAttribute( Qt::WA_DeleteOnClose );
501+
dlg->setMinimumWidth( 250 );
502+
if ( !message.isEmpty() )
503+
{
504+
dlg->layout()->addWidget( new QLabel( message ) );
505+
}
506+
QProgressBar* pb = new QProgressBar();
507+
pb->setMaximum( 0 ); // show as busy indicator
508+
dlg->layout()->addWidget( pb );
509+
510+
return dlg;
511+
}
512+
492513
void QgsComposer::showItemOptions( QgsComposerItem* item )
493514
{
494515
QWidget* currentWidget = mItemDock->widget();
@@ -1352,7 +1373,19 @@ void QgsComposer::on_mActionDuplicateComposer_triggered()
13521373
{
13531374
return;
13541375
}
1355-
mQgis->duplicateComposer( this, newTitle );
1376+
1377+
// provide feedback, since loading of template into duplicate composer will be hidden
1378+
QDialog* dlg = progressDialog( tr( "Duplicating composer..." ), this );
1379+
dlg->show();
1380+
1381+
QgsComposer* newComposer = mQgis->duplicateComposer( this, newTitle );
1382+
dlg->close();
1383+
1384+
if ( !newComposer )
1385+
{
1386+
QMessageBox::warning( this, tr( "Duplicate Composer" ),
1387+
tr( "Composer duplication failed." ) );
1388+
}
13561389
}
13571390

13581391
void QgsComposer::on_mActionComposerManager_triggered()

src/app/composer/qgscomposer.h

+5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
8484
const QString& title() const {return mTitle;}
8585
void setTitle( const QString& title );
8686

87+
//! Modal busy indicator dialog with no buttons that deletes on close
88+
//! @param message text to show above busy progress indicator
89+
//! @note added in 1.9
90+
QDialog* progressDialog( const QString& message = QString( "" ), QWidget* parent = 0 );
91+
8792
protected:
8893
//! Move event
8994
virtual void moveEvent( QMoveEvent * );

src/app/composer/qgscomposermanager.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "qgsapplication.h"
2020
#include "qgscomposer.h"
2121
#include "qgslogger.h"
22+
23+
#include <QDialog>
2224
#include <QDir>
2325
#include <QInputDialog>
2426
#include <QListWidgetItem>
@@ -250,13 +252,23 @@ void QgsComposerManager::duplicate_clicked()
250252
return;
251253
}
252254

255+
// provide feedback, since loading of template into duplicate composer will be hidden
256+
QDialog* dlg = currentComposer->progressDialog( tr( "Duplicating composer..." ), this );
257+
dlg->show();
258+
253259
QgsComposer* newComposer = QgisApp::instance()->duplicateComposer( currentComposer, newTitle );
260+
dlg->close();
254261

255262
if ( newComposer )
256263
{
257264
// no need to add new composer to list widget, if just closing this->exec();
258265
close();
259266
}
267+
else
268+
{
269+
QMessageBox::warning( this, tr( "Duplicate Composer" ),
270+
tr( "Composer duplication failed." ) );
271+
}
260272
}
261273

262274
void QgsComposerManager::rename_clicked()

src/app/qgisapp.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -4731,9 +4731,8 @@ QgsComposer* QgisApp::duplicateComposer( QgsComposer* currentComposer, QString t
47314731
return newComposer;
47324732
}
47334733

4734-
// disable updates until template is loaded (may be faster, but still gives user feedback),
4735-
// but is not as fast as hiding composer until template is loaded
4736-
newComposer->setUpdatesEnabled( false );
4734+
// hiding composer until template is loaded is much faster, provide feedback to user
4735+
newComposer->hide();
47374736
QApplication::setOverrideCursor( Qt::BusyCursor );
47384737
if ( !newComposer->composition()->loadFromTemplate( currentDoc, 0, false ) )
47394738
{
@@ -4742,7 +4741,6 @@ QgsComposer* QgisApp::duplicateComposer( QgsComposer* currentComposer, QString t
47424741
QgsDebugMsg( "Error, composer could not be duplicated" );
47434742
return newComposer;
47444743
}
4745-
newComposer->setUpdatesEnabled( true );
47464744
newComposer->activate();
47474745
QApplication::restoreOverrideCursor();
47484746

0 commit comments

Comments
 (0)