Debian Codegraph @

src/Base/ProgressIndicator.h

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /***************************************************************************
3 * Copyright (c) 2025 James Stanley <[email protected]> *
4 * *
5 * This file is part of FreeCAD. *
6 * *
7 * FreeCAD is free software: you can redistribute it and/or modify it *
8 * under the terms of the GNU Lesser General Public License as *
9 * published by the Free Software Foundation, either version 2.1 of the *
10 * License, or (at your option) any later version. *
11 * *
12 * FreeCAD is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15 * Lesser General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with FreeCAD. If not, see *
19 * <https://www.gnu.org/licenses/>. *
20 * *
21 **************************************************************************/
22
23 #ifndef BASE_PROGRESSINDICATOR_H
24 #define BASE_PROGRESSINDICATOR_H
25
26 #include "FCGlobal.h"
27
28 namespace Base
29 {
30
31 /**
32 * @class ProgressIndicator
33 * @brief Base interface for reporting and controlling long-running operations.
34 *
35 * This abstract base class provides a uniform way to:
36 * - Display progress updates via @c show().
37 * - Query whether the user has requested cancellation via @c userBreak().
38 *
39 * By default:
40 * - @c userBreak() returns false (no cancellation).
41 * - @c show() is a no-op.
42 *
43 * Derived classes should override these methods to integrate with
44 * specific UI frameworks or console output.
45 */
46 class BaseExport ProgressIndicator
47 {
48 public:
49 /**
50 * @brief Flags to control behavior of the show() update.
51 */
52 enum class ShowFlags
53 {
54 None = 0, ///< Default behavior; update only if significant progress.
55 Force = 1 ///< Force update regardless of progress threshold.
56 };
57
58 ProgressIndicator();
59 ProgressIndicator(const ProgressIndicator&);
60 ProgressIndicator(ProgressIndicator&&) = delete;
61 ProgressIndicator& operator=(const ProgressIndicator&);
62 ProgressIndicator& operator=(ProgressIndicator&&) = delete;
63 virtual ~ProgressIndicator();
64
65 /**
66 * @brief Check if the user has requested to abort the operation.
67 *
68 * Override to implement cancellation logic.
69 *
70 * @return @c true if the user requested a break, @c false otherwise.
71 */
72 virtual bool userBreak()
73 {
74 return false;
75 }
76
77 /**
78 * @brief Update the progress display.
79 *
80 * This method is called whenever the progress position changes.
81 *
82 * The parameter `position` is a normalized progress value:
83 * - Range [0.0, 1.0] for determinate progress (e.g., 0.57 for 57% complete).
84 * - A value of -1.0 indicates infinite (indeterminate) progress.
85 *
86 * @param position Normalized progress value or -1.0 for infinite progress.
87 * @param isForce If true, indicates a forced update even if the change threshold (≈1%) hasn’t
88 * been met.
89 */
90 virtual void show([[maybe_unused]] float position, [[maybe_unused]] ShowFlags flags = ShowFlags::None)
91 {}
92 };
93
94 } // namespace Base
95
96 #endif