File tree 2 files changed +59
-0
lines changed
2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -272,3 +272,31 @@ void QgsTemporaryCursorOverride::release()
272
272
mHasOverride = false ;
273
273
QApplication::restoreOverrideCursor ();
274
274
}
275
+
276
+
277
+ //
278
+ // QgsTemporaryCursorRestoreOverride
279
+ //
280
+
281
+ QgsTemporaryCursorRestoreOverride::QgsTemporaryCursorRestoreOverride ()
282
+ {
283
+ while ( QApplication::overrideCursor () )
284
+ {
285
+ mCursors .emplace_back ( QCursor ( *QApplication::overrideCursor () ) );
286
+ QApplication::restoreOverrideCursor ();
287
+ }
288
+ }
289
+
290
+ QgsTemporaryCursorRestoreOverride::~QgsTemporaryCursorRestoreOverride ()
291
+ {
292
+ restore ();
293
+ }
294
+
295
+ void QgsTemporaryCursorRestoreOverride::restore ()
296
+ {
297
+ for ( auto it = mCursors .rbegin (); it != mCursors .rend (); ++it )
298
+ {
299
+ QApplication::setOverrideCursor ( *it );
300
+ }
301
+ mCursors .clear ();
302
+ }
Original file line number Diff line number Diff line change @@ -206,4 +206,35 @@ class GUI_EXPORT QgsTemporaryCursorOverride
206
206
207
207
};
208
208
209
+ /* *
210
+ * Temporarily removes all cursor overrides for the QApplication for the lifetime of the object.
211
+ *
212
+ * When the object is deleted, all stacked cursor overrides are restored.
213
+ *
214
+ * \ingroup gui
215
+ * \since QGIS 3.8
216
+ */
217
+ class GUI_EXPORT QgsTemporaryCursorRestoreOverride
218
+ {
219
+ public:
220
+
221
+ /* *
222
+ * Constructor for QgsTemporaryCursorRestoreOverride. Removes all application override
223
+ * cursors.
224
+ */
225
+ QgsTemporaryCursorRestoreOverride ();
226
+
227
+ ~QgsTemporaryCursorRestoreOverride ();
228
+
229
+ /* *
230
+ * Restores the cursor override early (i.e. before this object is destroyed).
231
+ */
232
+ void restore ();
233
+
234
+ private:
235
+
236
+ std::vector< QCursor > mCursors ;
237
+
238
+ };
239
+
209
240
#endif // QGSGUIUTILS_H
You can’t perform that action at this time.
0 commit comments