ccProgressDialog.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //##########################################################################
  2. //# #
  3. //# CLOUDCOMPARE #
  4. //# #
  5. //# This program is free software; you can redistribute it and/or modify #
  6. //# it under the terms of the GNU General Public License as published by #
  7. //# the Free Software Foundation; version 2 or later of the License. #
  8. //# #
  9. //# This program is distributed in the hope that it will be useful, #
  10. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  11. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  12. //# GNU General Public License for more details. #
  13. //# #
  14. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  15. //# #
  16. //##########################################################################
  17. #ifndef CC_PROGRESS_DIALOG_HEADER
  18. #define CC_PROGRESS_DIALOG_HEADER
  19. //Local
  20. #include "qCC_db.h"
  21. //Qt
  22. #include <QProgressDialog>
  23. #include <QAtomicInt>
  24. #include <QTimer>
  25. //CCCoreLib
  26. #include <GenericProgressCallback.h>
  27. //! Graphical progress indicator (thread-safe)
  28. /** Implements the GenericProgressCallback interface, in order
  29. to be passed to the CCCoreLib algorithms (check the
  30. CCCoreLib documentation for more information about the
  31. inherited methods).
  32. **/
  33. class QCC_DB_LIB_API ccProgressDialog : public QProgressDialog, public CCCoreLib::GenericProgressCallback
  34. {
  35. Q_OBJECT
  36. public:
  37. //! Default constructor
  38. /** By default, a cancel button is always displayed on the
  39. progress interface. It is only possible to activate or
  40. deactivate this button. Sadly, the fact that this button is
  41. activated doesn't mean it will be possible to stop the ongoing
  42. process: it depends only on the client algorithm implementation.
  43. \param cancelButton activates or deactivates the cancel button
  44. \param parent parent widget
  45. **/
  46. ccProgressDialog( bool cancelButton = false,
  47. QWidget* parent = nullptr );
  48. //! Destructor (virtual)
  49. virtual ~ccProgressDialog() {}
  50. //inherited method
  51. virtual void update(float percent) override;
  52. inline virtual void setMethodTitle(const char* methodTitle) override { setMethodTitle(QString(methodTitle)); }
  53. inline virtual void setInfo(const char* infoStr) override { setInfo(QString(infoStr)); }
  54. inline virtual bool isCancelRequested() override { return wasCanceled(); }
  55. virtual void start() override;
  56. virtual void stop() override;
  57. //! setMethodTitle with a QString as argument
  58. virtual void setMethodTitle(QString methodTitle);
  59. //! setInfo with a QString as argument
  60. virtual void setInfo(QString infoStr);
  61. protected:
  62. //! Refreshes the progress
  63. /** Should only be called in the main Qt thread!
  64. This slot is automatically called by 'update' (in Qt::QueuedConnection mode).
  65. **/
  66. void refresh();
  67. Q_SIGNALS:
  68. //! Schedules a call to refresh
  69. void scheduleRefresh();
  70. protected:
  71. //! Current progress value (percent)
  72. QAtomicInt m_currentValue;
  73. //! Last displayed progress value (percent)
  74. QAtomicInt m_lastRefreshValue;
  75. };
  76. #endif //CC_PROGRESS_DIALOG_HEADER