Skip to content
Permalink
Browse files

Add QgsTemporaryCursorOverride class

Temporarily sets a QApplication override cursor for the lifetime
of the object, then removes it

Makes it easier to ensure that the override is always removed
regardless of the exit path taken.
  • Loading branch information
nyalldawson committed Mar 12, 2018
1 parent f05e9c3 commit f694f75f5dcb7c3a2a233570a033c50456bb34d5
Showing with 41 additions and 18 deletions.
  1. +4 −18 src/app/dwg/qgsdwgimportdialog.cpp
  2. +15 −0 src/gui/qgsguiutils.cpp
  3. +22 −0 src/gui/qgsguiutils.h
@@ -44,21 +44,7 @@
#include "qgslogger.h"
#include "qgsproperty.h"
#include "qgslayertree.h"


struct CursorOverride
{
CursorOverride()
{
QApplication::setOverrideCursor( Qt::BusyCursor );
}

~CursorOverride()
{
QApplication::restoreOverrideCursor();
}
};

#include "qgsguiutils.h"

QgsDwgImportDialog::QgsDwgImportDialog( QWidget *parent, Qt::WindowFlags f )
: QDialog( parent, f )
@@ -163,7 +149,7 @@ void QgsDwgImportDialog::pbLoadDatabase_clicked()
if ( !QFileInfo::exists( leDatabase->text() ) )
return;

CursorOverride waitCursor;
QgsTemporaryCursorOverride waitCursor( Qt::BusyCursor );

bool lblVisible = false;

@@ -261,7 +247,7 @@ void QgsDwgImportDialog::pbBrowseDrawing_clicked()

void QgsDwgImportDialog::pbImportDrawing_clicked()
{
CursorOverride waitCursor;
QgsTemporaryCursorOverride waitCursor( Qt::BusyCursor );

QgsDwgImporter importer( leDatabase->text(), mCrsSelector->crs() );

@@ -457,7 +443,7 @@ void QgsDwgImportDialog::pbDeselectAll_clicked()

void QgsDwgImportDialog::buttonBox_accepted()
{
CursorOverride waitCursor;
QgsTemporaryCursorOverride waitCursor( Qt::BusyCursor );

QMap<QString, bool> layers;
bool allLayers = true;
@@ -21,6 +21,7 @@

#include <QImageWriter>
#include <QFontDialog>
#include <QApplication>


namespace QgsGuiUtils
@@ -235,3 +236,17 @@ namespace QgsGuiUtils
return key;
}
}

//
// QgsTemporaryCursorOverride
//

QgsTemporaryCursorOverride::QgsTemporaryCursorOverride( const QCursor &cursor )
{
QApplication::setOverrideCursor( cursor );
}

QgsTemporaryCursorOverride::~QgsTemporaryCursorOverride()
{
QApplication::restoreOverrideCursor();
}
@@ -164,4 +164,26 @@ namespace QgsGuiUtils
QString createWidgetKey( QWidget *widget, const QString &keyName = QString() );
}

/**
* Temporarily sets a cursor override for the QApplication for the lifetime of the object.
*
* When the object is deleted, the cursor override is removed.
*
* \ingroup gui
* \since QGIS 3.2
*/
class GUI_EXPORT QgsTemporaryCursorOverride
{
public:

/**
* Constructor for QgsTemporaryCursorOverride. Sets the application override
* cursor to \a cursor.
*/
QgsTemporaryCursorOverride( const QCursor &cursor );

~QgsTemporaryCursorOverride();

};

#endif // QGSGUIUTILS_H

0 comments on commit f694f75

Please sign in to comment.
You can’t perform that action at this time.