comparison Utils/ProgressEvent.cpp @ 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.cpp
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
36 #include "Utils/ProgressEvent.h"
37
38 #include "Utils/Log.h"
39
40 #include <QCoreApplication>
41
42 ///////////////////////////////////////////////////////////////////////////////
43
44 QEvent::Type ProgressEvent::_logEventType = QEvent::None;
45
46 ///////////////////////////////////////////////////////////////////////////////
47
48 ProgressEvent::ProgressEvent(int current, int range)
49 : QEvent(_logEventType),
50 current(current),
51 maximum(range)
52 {}
53
54 ///////////////////////////////////////////////////////////////////////////////
55
56 ProgressEvent* ProgressEvent::make(int current, int range)
57 {
58 if( _logEventType == QEvent::None )
59 _logEventType = (QEvent::Type) QEvent::registerEventType();
60 return new ProgressEvent(current, range);
61 }
62
63 ///////////////////////////////////////////////////////////////////////////////
64
65 ProgressManager::ProgressManager()
66 : _main(0)
67 {}
68
69 ProgressManager* ProgressManager::getInstance()
70 {
71 static ProgressManager manager;
72 return & manager;
73 }
74
75 void ProgressManager::setMainWindow(QObject* main)
76 {
77 _main = main;
78 assert(main);
79 }
80
81 void ProgressManager::post(int current, int range)
82 {
83 assert(_main);
84 qApp->postEvent(_main, ProgressEvent::make(current, range));
85 qApp->processEvents(QEventLoop::ExcludeUserInputEvents, 10);
86 }