Skip to content
Permalink
Browse files
New utility class QgsTemporaryCursorRestoreOverride
This class temporarily removes ALL cursor overrides for the
QApplication for the lifetime of the object, and restores them
(in the same order) upon object destruction.
  • Loading branch information
nyalldawson committed Mar 19, 2019
1 parent 6bb0723 commit 5fb980222976ebd5ea58847a743b65a011be8ffb
Showing with 59 additions and 0 deletions.
  1. +28 −0 src/gui/qgsguiutils.cpp
  2. +31 −0 src/gui/qgsguiutils.h
@@ -272,3 +272,31 @@ void QgsTemporaryCursorOverride::release()
mHasOverride = false;
QApplication::restoreOverrideCursor();
}


//
// QgsTemporaryCursorRestoreOverride
//

QgsTemporaryCursorRestoreOverride::QgsTemporaryCursorRestoreOverride()
{
while ( QApplication::overrideCursor() )
{
mCursors.emplace_back( QCursor( *QApplication::overrideCursor() ) );
QApplication::restoreOverrideCursor();
}
}

QgsTemporaryCursorRestoreOverride::~QgsTemporaryCursorRestoreOverride()
{
restore();
}

void QgsTemporaryCursorRestoreOverride::restore()
{
for ( auto it = mCursors.rbegin(); it != mCursors.rend(); ++it )
{
QApplication::setOverrideCursor( *it );
}
mCursors.clear();
}
@@ -206,4 +206,35 @@ class GUI_EXPORT QgsTemporaryCursorOverride

};

/**
* Temporarily removes all cursor overrides for the QApplication for the lifetime of the object.
*
* When the object is deleted, all stacked cursor overrides are restored.
*
* \ingroup gui
* \since QGIS 3.8
*/
class GUI_EXPORT QgsTemporaryCursorRestoreOverride
{
public:

/**
* Constructor for QgsTemporaryCursorRestoreOverride. Removes all application override
* cursors.
*/
QgsTemporaryCursorRestoreOverride();

~QgsTemporaryCursorRestoreOverride();

/**
* Restores the cursor override early (i.e. before this object is destroyed).
*/
void restore();

private:

std::vector< QCursor > mCursors;

};

#endif // QGSGUIUTILS_H

0 comments on commit 5fb9802

Please sign in to comment.