SWMMVis  6.0.0-alpha.4
Qt6/C++ GIS-based graphical user interface for the SWMMVis engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
loadprogress.h
Go to the documentation of this file.
1
33#ifndef LOADPROGRESS_H
34#define LOADPROGRESS_H
35
36#include <QObject>
37#include <QString>
38
39#include <array>
40#include <functional>
41
53using LoadProgressFn = std::function<void(int localPct, const QString &stage)>;
54
62enum class OpenStage {
63 EngineParse = 0,
64 SoaCopy,
65 GeomCache,
66 CrsFinish,
67 Sidecar,
68 Results,
69 MeshParse,
72 Count_
73};
74
87constexpr int kLoadProgressStride = 101;
88
89inline int packLoadProgress(OpenStage stage, int localPct)
90{
91 if (localPct < 0) localPct = 0;
92 if (localPct > 100) localPct = 100;
93 return static_cast<int>(stage) * kLoadProgressStride + localPct;
94}
95
97{
98 return static_cast<OpenStage>(packed / kLoadProgressStride);
99}
100
101inline int unpackLoadProgressPct(int packed)
102{
103 return packed % kLoadProgressStride;
104}
105
113class OpenProgressModel : public QObject
114{
115 Q_OBJECT
116
117public:
118 explicit OpenProgressModel(QObject *parent = nullptr);
119
123 static int stageWeight(OpenStage stage);
124
127 static QString stageLabel(OpenStage stage);
128
136 void setStage(OpenStage stage, int localPct, const QString &label = QString());
137
145 void finishStage(OpenStage stage);
146
149 void finishAll();
150
152 [[nodiscard]] int percent() const { return m_lastPct; }
153
155 [[nodiscard]] QString label() const { return m_label; }
156
158 [[nodiscard]] bool isComplete() const;
159
160signals:
162 void progressChanged(int pct, const QString &label);
163
166 void finished();
167
168private:
169 void recompute();
170
171 static constexpr int kStageCount = static_cast<int>(OpenStage::Count_);
172
173 std::array<int, kStageCount> m_localPct{};
174 QString m_label;
175 QString m_emittedLabel;
176 int m_lastPct = 0;
177 bool m_finishedEmitted = false;
178};
179
180#endif // LOADPROGRESS_H
Weighted, monotonic progress aggregator for one project open.
Definition loadprogress.h:114
static QString stageLabel(OpenStage stage)
Definition loadprogress.cpp:59
void finishStage(OpenStage stage)
Mark stage fully done (idempotent).
Definition loadprogress.cpp:96
void progressChanged(int pct, const QString &label)
QString label() const
Definition loadprogress.h:155
int percent() const
Definition loadprogress.h:152
bool isComplete() const
Definition loadprogress.cpp:118
static int stageWeight(OpenStage stage)
Definition loadprogress.cpp:51
void setStage(OpenStage stage, int localPct, const QString &label=QString())
Report partial progress within stage.
Definition loadprogress.cpp:76
void finishAll()
Definition loadprogress.cpp:108
OpenStage
The stages of a single project open, in nominal order.
Definition loadprogress.h:62
@ CrsFinish
adoptOpenEngine CRS resolution + finishModelLoad
@ SoaCopy
SWMMModelLayer::buildFromEngine SoA pull.
@ Count_
sentinel — not a stage
@ MeshSceneA
rebuildSceneGeometryLight + LOD pyramid
@ MeshSceneB
finishSceneGeometryAsync (edges/grids/adjacency)
@ EngineParse
swmm_engine_open — the .inp parse itself
@ MeshParse
InpMeshReader::read.
@ GeomCache
buildGeometryCache (5 sub-stages)
@ Sidecar
.oswp sidecar apply
@ Results
sibling .out discovery + open
int unpackLoadProgressPct(int packed)
Definition loadprogress.h:101
OpenStage unpackLoadProgressStage(int packed)
Definition loadprogress.h:96
std::function< void(int localPct, const QString &stage)> LoadProgressFn
Progress sink handed to a worker-side producer.
Definition loadprogress.h:53
int packLoadProgress(OpenStage stage, int localPct)
Definition loadprogress.h:89
constexpr int kLoadProgressStride
Encode a (stage, localPct) pair into a single QPromise progress int.
Definition loadprogress.h:87
QVector< int > parent
union-find
Definition pslgminsize.cpp:176