Mercurial > public > ostc_companion
comparison Utils/ProgressEvent.h @ 1:0b3630a29ad8
Initial version based on previous repository.
Project was ported to QT6 and in now cmake based.
| author | Ideenmodellierer <tiefenrauscher@web.de> |
|---|---|
| date | Thu, 27 Nov 2025 18:40:28 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:76ccd6ce50c0 | 1:0b3630a29ad8 |
|---|---|
| 1 ///////////////////////////////////////////////////////////////////////////// | |
| 2 /// \file ProgressEvent.h | |
| 3 /// \brief User event to pass async progress-bar updates to the main window. | |
| 4 /// \author JD Gascuel. | |
| 5 /// \copyright (c) 2015 JD Gascuel. All rights reserved. | |
| 6 /// $Id$ | |
| 7 /////////////////////////////////////////////////////////////////////////////// | |
| 8 // | |
| 9 // BSD 2-Clause License: | |
| 10 // | |
| 11 // Redistribution and use in source and binary forms, with or without | |
| 12 // modification, are permitted provided that the following conditions | |
| 13 // are met: | |
| 14 // | |
| 15 // 1. Redistributions of source code must retain the above copyright notice, | |
| 16 // this list of conditions and the following disclaimer. | |
| 17 // | |
| 18 // 2. Redistributions in binary form must reproduce the above copyright notice, | |
| 19 // this list of conditions and the following disclaimer in the documentation | |
| 20 // and/or other materials provided with the distribution. | |
| 21 // | |
| 22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 23 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 24 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 25 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
| 26 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 27 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 28 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 29 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 30 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 31 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
| 32 // THE POSSIBILITY OF SUCH DAMAGE. | |
| 33 // | |
| 34 ////////////////////////////////////////////////////////////////////////////// | |
| 35 // HISTORY | |
| 36 // 2015-07-14 jDG: Creation. | |
| 37 // 2016-05-24 jDG: BSD-2 version. | |
| 38 | |
| 39 #ifndef PROGRESS_EVENT_H | |
| 40 #define PROGRESS_EVENT_H | |
| 41 | |
| 42 #include <QEvent> | |
| 43 | |
| 44 /////////////////////////////////////////////////////////////////////////////// | |
| 45 | |
| 46 class ProgressEvent : public QEvent | |
| 47 { | |
| 48 static QEvent::Type _logEventType; | |
| 49 | |
| 50 ProgressEvent(int current, int maximum); | |
| 51 | |
| 52 public: | |
| 53 const int current; | |
| 54 const int maximum; | |
| 55 | |
| 56 static ProgressEvent* make(int current, int maximum); | |
| 57 }; | |
| 58 | |
| 59 /////////////////////////////////////////////////////////////////////////////// | |
| 60 | |
| 61 class ProgressManager | |
| 62 { | |
| 63 QObject* _main; | |
| 64 | |
| 65 public: | |
| 66 static ProgressManager* getInstance(); | |
| 67 | |
| 68 ProgressManager(); | |
| 69 | |
| 70 /// \brief Define who manage ProgressEvent events. | |
| 71 void setMainWindow(QObject* main); | |
| 72 | |
| 73 /// \brief Send (async) progress updates to the main progress bar. | |
| 74 /// Use ProgressEvent class to post updates and resets to the progress | |
| 75 /// bar, displayed by the main thread. | |
| 76 /// When \a current > \a range, this is a reset... | |
| 77 void post(int current = 101, int range = 100); | |
| 78 }; | |
| 79 | |
| 80 #define PROGRESS(current, range) \ | |
| 81 ProgressManager::getInstance()->post(current, range) | |
| 82 #define PROGRESS_THROTTLE() \ | |
| 83 ProgressManager::getInstance()->post(0, 0) | |
| 84 #define PROGRESS_RESET() \ | |
| 85 ProgressManager::getInstance()->post() | |
| 86 | |
| 87 #endif // PROGRESS_EVENT_H |
