Skip to content
Permalink
Browse files
Hide new composer when duplicating (loading template) as it is faster
- Show busy indicator dialog
- Add busy indicator dialog method to QgsComposer
  • Loading branch information
dakcarto committed Feb 27, 2013
1 parent f9d9da3 commit aa22c0e0d1b2f8a4e16d5b4a0306e928faecedba
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
@@ -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>
@@ -75,6 +77,7 @@
#include <QToolButton>
#include <QUndoView>
#include <QPaintEngine>
#include <QProgressBar>
#include <QProgressDialog>


@@ -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();
@@ -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()
@@ -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 * );
@@ -19,6 +19,8 @@
#include "qgsapplication.h"
#include "qgscomposer.h"
#include "qgslogger.h"

#include <QDialog>
#include <QDir>
#include <QInputDialog>
#include <QListWidgetItem>
@@ -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()
@@ -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 ) )
{
@@ -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();

0 comments on commit aa22c0e

Please sign in to comment.