Skip to content

Commit

Permalink
Hide new composer when duplicating (loading template) as it is faster
Browse files Browse the repository at this point in the history
- Show busy indicator dialog
- Add busy indicator dialog method to QgsComposer
  • Loading branch information
dakcarto committed Feb 27, 2013
1 parent f9d9da3 commit aa22c0e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
35 changes: 34 additions & 1 deletion src/app/composer/qgscomposer.cpp
Expand Up @@ -56,10 +56,12 @@
#include <QCloseEvent>
#include <QCheckBox>
#include <QDesktopWidget>
#include <QDialog>
#include <QFileDialog>
#include <QFileInfo>
#include <QIcon>
#include <QImageWriter>
#include <QLabel>
#include <QMatrix>
#include <QMenuBar>
#include <QMessageBox>
Expand All @@ -75,6 +77,7 @@
#include <QToolButton>
#include <QUndoView>
#include <QPaintEngine>
#include <QProgressBar>
#include <QProgressDialog>


Expand Down Expand Up @@ -489,6 +492,24 @@ void QgsComposer::setTitle( const QString& title )
}
}

QDialog* QgsComposer::progressDialog( const QString& message, QWidget* parent )
{
QDialog* dlg = new QDialog( parent );
dlg->setLayout( new QVBoxLayout() );
dlg->setWindowModality( Qt::WindowModal );
dlg->setAttribute( Qt::WA_DeleteOnClose );
dlg->setMinimumWidth( 250 );
if ( !message.isEmpty() )
{
dlg->layout()->addWidget( new QLabel( message ) );
}
QProgressBar* pb = new QProgressBar();
pb->setMaximum( 0 ); // show as busy indicator
dlg->layout()->addWidget( pb );

return dlg;
}

void QgsComposer::showItemOptions( QgsComposerItem* item )
{
QWidget* currentWidget = mItemDock->widget();
Expand Down Expand Up @@ -1352,7 +1373,19 @@ void QgsComposer::on_mActionDuplicateComposer_triggered()
{
return;
}
mQgis->duplicateComposer( this, newTitle );

// provide feedback, since loading of template into duplicate composer will be hidden
QDialog* dlg = progressDialog( tr( "Duplicating composer..." ), this );
dlg->show();

QgsComposer* newComposer = mQgis->duplicateComposer( this, newTitle );
dlg->close();

if ( !newComposer )
{
QMessageBox::warning( this, tr( "Duplicate Composer" ),
tr( "Composer duplication failed." ) );
}
}

void QgsComposer::on_mActionComposerManager_triggered()
Expand Down
5 changes: 5 additions & 0 deletions src/app/composer/qgscomposer.h
Expand Up @@ -84,6 +84,11 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
const QString& title() const {return mTitle;}
void setTitle( const QString& title );

//! Modal busy indicator dialog with no buttons that deletes on close
//! @param message text to show above busy progress indicator
//! @note added in 1.9
QDialog* progressDialog( const QString& message = QString( "" ), QWidget* parent = 0 );

protected:
//! Move event
virtual void moveEvent( QMoveEvent * );
Expand Down
12 changes: 12 additions & 0 deletions src/app/composer/qgscomposermanager.cpp
Expand Up @@ -19,6 +19,8 @@
#include "qgsapplication.h"
#include "qgscomposer.h"
#include "qgslogger.h"

#include <QDialog>
#include <QDir>
#include <QInputDialog>
#include <QListWidgetItem>
Expand Down Expand Up @@ -250,13 +252,23 @@ void QgsComposerManager::duplicate_clicked()
return;
}

// provide feedback, since loading of template into duplicate composer will be hidden
QDialog* dlg = currentComposer->progressDialog( tr( "Duplicating composer..." ), this );
dlg->show();

QgsComposer* newComposer = QgisApp::instance()->duplicateComposer( currentComposer, newTitle );
dlg->close();

if ( newComposer )
{
// no need to add new composer to list widget, if just closing this->exec();
close();
}
else
{
QMessageBox::warning( this, tr( "Duplicate Composer" ),
tr( "Composer duplication failed." ) );
}
}

void QgsComposerManager::rename_clicked()
Expand Down
6 changes: 2 additions & 4 deletions src/app/qgisapp.cpp
Expand Up @@ -4731,9 +4731,8 @@ QgsComposer* QgisApp::duplicateComposer( QgsComposer* currentComposer, QString t
return newComposer;
}

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

Expand Down

0 comments on commit aa22c0e

Please sign in to comment.