|
| 1 | +/*************************************************************************** |
| 2 | + qgsproxyprogresstask.h |
| 3 | + ---------------------- |
| 4 | + begin : August 2018 |
| 5 | + copyright : (C) 2018 by Nyall Dawson |
| 6 | + email : nyall dot dawson at gmail dot com |
| 7 | + ***************************************************************************/ |
| 8 | + |
| 9 | +/*************************************************************************** |
| 10 | + * * |
| 11 | + * This program is free software; you can redistribute it and/or modify * |
| 12 | + * it under the terms of the GNU General Public License as published by * |
| 13 | + * the Free Software Foundation; either version 2 of the License, or * |
| 14 | + * (at your option) any later version. * |
| 15 | + * * |
| 16 | + ***************************************************************************/ |
| 17 | + |
| 18 | +#ifndef QGSPROXYPROGRESSTASK_H |
| 19 | +#define QGSPROXYPROGRESSTASK_H |
| 20 | + |
| 21 | +#include "qgsvectorlayer.h" |
| 22 | +#include "qgsvirtuallayerdefinition.h" |
| 23 | +#include "qgstaskmanager.h" |
| 24 | + |
| 25 | +/** |
| 26 | + * \ingroup core |
| 27 | + * |
| 28 | + * A QgsTask shell which proxies progress reports. |
| 29 | + * |
| 30 | + * Simple task shell which runs until finalized and reports progress only. |
| 31 | + * This is usually used to expose a blocking operation's progress via |
| 32 | + * task manager. |
| 33 | + * |
| 34 | + * \since QGIS 3.4 |
| 35 | + */ |
| 36 | +class CORE_EXPORT QgsProxyProgressTask : public QgsTask |
| 37 | +{ |
| 38 | + Q_OBJECT |
| 39 | + |
| 40 | + public: |
| 41 | + |
| 42 | + /** |
| 43 | + * Constructor for QgsProxyProgressTask, with the specified \a description. |
| 44 | + */ |
| 45 | + QgsProxyProgressTask( const QString &description ); |
| 46 | + |
| 47 | + /** |
| 48 | + * Finalizes the task, with the specified \a result. |
| 49 | + * |
| 50 | + * This should be called when the operation being proxied has completed, |
| 51 | + * to remove this proxy task from the task manager. |
| 52 | + */ |
| 53 | + void finalize( bool result ); |
| 54 | + |
| 55 | + bool run() override; |
| 56 | + |
| 57 | + /** |
| 58 | + * Sets the \a progress (from 0 to 100) for the proxied operation. |
| 59 | + * |
| 60 | + * This method is safe to call from the main thread. |
| 61 | + */ |
| 62 | + void setProxyProgress( double progress ); |
| 63 | + |
| 64 | + private: |
| 65 | + |
| 66 | + QWaitCondition mNotFinishedWaitCondition; |
| 67 | + QMutex mNotFinishedMutex; |
| 68 | + bool mResult = true; |
| 69 | + |
| 70 | +}; |
| 71 | + |
| 72 | +#endif // QGSPROXYPROGRESSTASK_H |
0 commit comments