Skip to content

Commit

Permalink
Move busy indicator dialog out of composer and into own gui class
Browse files Browse the repository at this point in the history
  • Loading branch information
dakcarto committed Mar 28, 2013
1 parent 2304350 commit 25f067c
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 31 deletions.
1 change: 1 addition & 0 deletions python/gui/gui.sip
Expand Up @@ -10,6 +10,7 @@
%Include qgisinterface.sip
%Include qgsannotationitem.sip
%Include qgsattributeeditor.sip
%Include qgsbusyindicatordialog.sip
%Include qgscollapsiblegroupbox.sip
%Include qgscolorbutton.sip
%Include qgscolordialog.sip
Expand Down
22 changes: 22 additions & 0 deletions python/gui/qgsbusyindicatordialog.sip
@@ -0,0 +1,22 @@

/** \ingroup gui
* \class QgsBusyIndicatorDialog
* A simple dialog to show an indeterminate busy progress indicator.
*/
class QgsBusyIndicatorDialog : QDialog
{
%TypeHeaderCode
#include <qgsbusyindicatordialog.h>
%End
public:
/** Constructor
* 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
*/
QgsBusyIndicatorDialog( const QString& message = "", QWidget *parent = 0, Qt::WFlags fl = QgisGui::ModalDialogFlags );
~QgsBusyIndicatorDialog();

QString message() const;
void setMessage( const QString& message );
};
35 changes: 13 additions & 22 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -20,6 +20,7 @@

#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsbusyindicatordialog.h"
#include "qgscomposerruler.h"
#include "qgscomposerview.h"
#include "qgscomposition.h"
Expand Down Expand Up @@ -522,24 +523,6 @@ void QgsComposer::setTitle( const QString& title )
}
}

QDialog* QgsComposer::busyIndicatorDialog( 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 @@ -1412,11 +1395,16 @@ void QgsComposer::on_mActionDuplicateComposer_triggered()
}

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

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

if ( dlg ) // user may have already closed busy indicator
{
dlg->close();
}

if ( !newComposer )
{
Expand Down Expand Up @@ -1531,15 +1519,18 @@ void QgsComposer::loadTemplate( bool newCompser )
if ( templateDoc.setContent( &templateFile ) )
{
// provide feedback, since composer will be hidden when loading template (much faster)
QDialog* dlg = busyIndicatorDialog( tr( "Loading template into composer..." ), 0 );
QDialog* dlg = new QgsBusyIndicatorDialog( tr( "Loading template into composer..." ) );
dlg->setStyleSheet( mQgis->styleSheet() );
dlg->show();

c->hide();
comp->loadFromTemplate( templateDoc, 0, false );
c->activate();

dlg->close();
if ( dlg ) // user may have already closed busy indicator
{
dlg->close();
}
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/app/composer/qgscomposer.h
Expand Up @@ -92,11 +92,6 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! @note added in 1.9
void loadTemplate( bool newCompser );

//! 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* busyIndicatorDialog( const QString& message = QString( "" ), QWidget* parent = 0 );

protected:
//! Move event
virtual void moveEvent( QMoveEvent * );
Expand Down
19 changes: 15 additions & 4 deletions src/app/composer/qgscomposermanager.cpp
Expand Up @@ -17,6 +17,7 @@
#include "qgscomposermanager.h"
#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsbusyindicatordialog.h"
#include "qgscomposer.h"
#include "qgscomposition.h"
#include "qgslogger.h"
Expand Down Expand Up @@ -185,12 +186,17 @@ void QgsComposerManager::on_mAddButton_clicked()
{
// provide feedback, since composer will be hidden when loading template (much faster)
// (not needed for empty composer)
QDialog* dlg = newComposer->busyIndicatorDialog( tr( "Loading template into composer..." ), this );
QDialog* dlg = new QgsBusyIndicatorDialog( tr( "Loading template into composer..." ) );
dlg->setStyleSheet( QgisApp::instance()->styleSheet() );
dlg->show();
newComposer->hide();
loadedOK = newComposer->composition()->loadFromTemplate( templateDoc, 0, false );
newComposer->activate();
dlg->close();

if ( dlg ) // user may have already closed busy indicator
{
dlg->close();
}
}
}

Expand Down Expand Up @@ -384,11 +390,16 @@ void QgsComposerManager::duplicate_clicked()
}

// provide feedback, since loading of template into duplicate composer will be hidden
QDialog* dlg = currentComposer->busyIndicatorDialog( tr( "Duplicating composer..." ), this );
QDialog* dlg = new QgsBusyIndicatorDialog( tr( "Duplicating composer..." ) );
dlg->setStyleSheet( QgisApp::instance()->styleSheet() );
dlg->show();

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

if ( dlg ) // user may have already closed busy indicator
{
dlg->close();
}

if ( newComposer )
{
Expand Down
3 changes: 3 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -50,6 +50,7 @@ qgisinterface.cpp
qgsannotationitem.cpp
qgsattributeeditor.cpp
qgsattributedialog.cpp
qgsbusyindicatordialog.cpp
qgslegendinterface.cpp
qgsblendmodecombobox.cpp
qgscharacterselectdialog.cpp
Expand Down Expand Up @@ -170,6 +171,7 @@ attributetable/qgsdualview.h
qgsattributedialog.h
qgsattributeeditor.h
qgsblendmodecombobox.h
qgsbusyindicatordialog.h
qgscharacterselectdialog.h
qgscolordialog.h
qgscomposerview.h
Expand Down Expand Up @@ -222,6 +224,7 @@ QT4_WRAP_CPP(QGIS_GUI_MOC_SRCS ${QGIS_GUI_MOC_HDRS})
SET(QGIS_GUI_HDRS
qgisgui.h
qgisinterface.h
qgsbusyindicatordialog.h
qgscharacterselectdialog.h
qgscolordialog.h
qgscursors.h
Expand Down
57 changes: 57 additions & 0 deletions src/gui/qgsbusyindicatordialog.cpp
@@ -0,0 +1,57 @@
/***************************************************************************
qgsbusyindicatordialog.cpp
--------------------------
begin : Mar 27, 2013
copyright : (C) 2013 by Larry Shaffer
email : larrys at dakcarto dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsbusyindicatordialog.h"

#include <QDialog>
#include <QLayout>
#include <QLabel>
#include <QProgressBar>

QgsBusyIndicatorDialog::QgsBusyIndicatorDialog( const QString& message, QWidget* parent, Qt::WFlags fl )
: QDialog( parent, fl ), mMessage( QString( message ) ), mMsgLabel( 0 )
{
setLayout( new QVBoxLayout() );
setWindowModality( Qt::WindowModal );
setAttribute( Qt::WA_DeleteOnClose );
setMinimumWidth( 250 );
mMsgLabel = new QLabel( mMessage );
layout()->addWidget( mMsgLabel );

QProgressBar* pb = new QProgressBar();
pb->setMaximum( 0 ); // show as busy indicator
layout()->addWidget( pb );

if ( mMessage.isEmpty() )
{
mMsgLabel->hide();
}
}

QgsBusyIndicatorDialog::~QgsBusyIndicatorDialog()
{
}

void QgsBusyIndicatorDialog::setMessage( const QString& message )
{
if ( !message.isEmpty() )
{
mMessage = QString( message );
mMsgLabel->setText( mMessage );
mMsgLabel->show();
}
}
51 changes: 51 additions & 0 deletions src/gui/qgsbusyindicatordialog.h
@@ -0,0 +1,51 @@
/***************************************************************************
qgsbusyindicatordialog.h
------------------------
begin : Mar 27, 2013
copyright : (C) 2013 by Larry Shaffer
email : larrys at dakcarto dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSBUSYINDICATORDIALOG_H
#define QGSBUSYINDICATORDIALOG_H

#include "qgisgui.h"

#include <QDialog>
#include <QLabel>


/** \ingroup gui
* \class QgsBusyIndicatorDialog
* A simple dialog to show an indeterminate busy progress indicator.
*/
class GUI_EXPORT QgsBusyIndicatorDialog : public QDialog
{
Q_OBJECT
public:
/** Constructor
* 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
*/
QgsBusyIndicatorDialog( const QString& message = "", QWidget *parent = 0, Qt::WFlags fl = QgisGui::ModalDialogFlags );
~QgsBusyIndicatorDialog();

QString message() const { return mMessage; }
void setMessage( const QString& message );

private:
QString mMessage;
QLabel* mMsgLabel;
};

#endif // QGSBUSYINDICATORDIALOG_H

0 comments on commit 25f067c

Please sign in to comment.