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
rainintervalref.h
Go to the documentation of this file.
1
23#ifndef RAININTERVALREF_H
24#define RAININTERVALREF_H
25
26#include <QMetaType>
27#include <QString>
28#include <QStringList>
29
30#include <openswmm/engine/openswmm_callbacks.h> // SWMM_Engine typedef
31
32class SWMMModelLayer;
33
36{
37 SWMM_Engine engine = nullptr;
38 QString gageName;
39 int seconds = 0;
44
45 bool operator==(const RainIntervalRef &other) const noexcept
46 {
47 return engine == other.engine && gageName == other.gageName
48 && seconds == other.seconds && layer == other.layer;
49 }
50};
51
52Q_DECLARE_METATYPE(RainIntervalRef)
53
54
57
58// ---------------------------------------------------------------------------
59// Shared H:MM helpers (used by the converter, the combo editor, and the
60// attribute-table interval delegate). Header-inline so all three agree.
61// ---------------------------------------------------------------------------
62
63namespace rain_interval {
64
67inline QStringList presetsHMM()
68{
69 return {QStringLiteral("0:01"), QStringLiteral("0:05"),
70 QStringLiteral("0:10"), QStringLiteral("0:15"),
71 QStringLiteral("0:20"), QStringLiteral("0:30"),
72 QStringLiteral("1:00"), QStringLiteral("6:00"),
73 QStringLiteral("12:00"), QStringLiteral("24:00")};
74}
75
78inline QString secondsToHMM(int secs)
79{
80 if (secs < 0) secs = 0;
81 const int h = secs / 3600;
82 const int m = (secs % 3600) / 60;
83 const int s = secs % 60;
84 if (s == 0)
85 return QStringLiteral("%1:%2").arg(h).arg(m, 2, 10, QLatin1Char('0'));
86 return QStringLiteral("%1:%2:%3")
87 .arg(h)
88 .arg(m, 2, 10, QLatin1Char('0'))
89 .arg(s, 2, 10, QLatin1Char('0'));
90}
91
96inline int hmmToSeconds(const QString &text)
97{
98 const QString t = text.trimmed();
99 if (t.isEmpty()) return -1;
100
101 if (!t.contains(QLatin1Char(':'))) {
102 bool ok = false;
103 const double hours = t.toDouble(&ok);
104 if (!ok || hours < 0.0) return -1;
105 return static_cast<int>(hours * 3600.0 + 0.5);
106 }
107
108 const QStringList parts = t.split(QLatin1Char(':'));
109 if (parts.size() < 2 || parts.size() > 3) return -1;
110 int field[3] = {0, 0, 0};
111 for (int i = 0; i < parts.size(); ++i) {
112 bool ok = false;
113 const int v = parts[i].toInt(&ok);
114 if (!ok || v < 0) return -1;
115 field[i] = v;
116 }
117 return field[0] * 3600 + field[1] * 60 + field[2];
118}
119
120} // namespace rain_interval
121
122#endif // RAININTERVALREF_H
Renders the SWMM network elements (nodes, links, subcatchments, rain gages) for one OpenSWMMEngine mo...
Definition swmmmodellayer.h:133
size_t i
Definition contourjob.cpp:27
DiagramType t
Definition diagramspec.cpp:20
double s
Scene px per model length unit.
Definition inletdrawingview.cpp:82
bool ok
Definition inpmeshwriter.cpp:575
MaskMode m
Definition maskspec.cpp:18
int h
Definition mesh2dresultsexport.cpp:387
Definition rainintervalref.h:63
QStringList presetsHMM()
Definition rainintervalref.h:67
QString secondsToHMM(int secs)
Definition rainintervalref.h:78
int hmmToSeconds(const QString &text)
Definition rainintervalref.h:96
void * SWMM_Engine
Definition objectdefaultsapplier.h:19
QVector< int > v
pool vertex indices
Definition pslgminsize.cpp:159
QString text
Definition queryparser.cpp:35
void registerRainIntervalRefConverter()
Definition rainintervalref.cpp:10
Definition rainintervalref.h:36
bool operator==(const RainIntervalRef &other) const noexcept
Definition rainintervalref.h:45
int seconds
Recording interval in seconds.
Definition rainintervalref.h:39
QString gageName
Owning gage id.
Definition rainintervalref.h:38
SWMM_Engine engine
Engine handle (borrow, not owned)
Definition rainintervalref.h:37
SWMMModelLayer * layer
Definition rainintervalref.h:43