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
projectserializer.h
Go to the documentation of this file.
1
26#ifndef PROJECTSERIALIZER_H
27#define PROJECTSERIALIZER_H
28
29#include <QDir>
30#include <QFileInfo>
31#include <QJsonObject>
32#include <QString>
33#include <QVector>
34
36class SWMMVisProject;
38class MapCanvas;
39
41{
42public:
50 static constexpr int kCurrentSchemaVersion = 5;
51
56 static bool saveToFile(const QString &oswpPath,
58 QString *errorOut = nullptr);
59
63 static bool saveToFile(const QString &oswpPath,
64 SWMMVisProject *proj,
65 QString *errorOut = nullptr);
66
76 static bool applyFromFile(const QString &oswpPath,
78 QString *errorOut = nullptr,
79 QStringList *warningsOut = nullptr);
80
86 [[nodiscard]] static inline QString sidecarPathFor(const QString &inpPath);
87
88 // ------------------------------------------------------------
89 // Path helpers (Slice AA-3.2) — used by every file-reference
90 // field written to / read from `.oswp`. Two callers today
91 // (inpPath and basemap urls don't apply); future slices reuse.
92 // ------------------------------------------------------------
93
102 [[nodiscard]] static inline QString toRelativePath(const QString &path,
103 const QString &oswpFile);
104
109 [[nodiscard]] static inline QString resolveStoredPath(const QString &stored,
110 const QString &oswpFile);
111
112private:
113 static QJsonObject serializeSession(SWMMVisProjectWindow *pw,
114 const QString &oswpFile);
115 static bool applySession(const QJsonObject &sessionObj,
117 const QString &oswpFile,
118 QStringList *warningsOut = nullptr);
119
120 static bool writeRootJson(const QString &oswpPath,
121 const QVector<SWMMVisProjectWindow *> &windows,
122 QString *errorOut);
123
124 static QJsonObject serializeBasemapLayer(OpenSWMMVisLayer *layer,
125 const QString &oswpPath);
126 static OpenSWMMVisLayer *deserializeBasemapLayer(const QJsonObject &obj,
127 QObject *parent,
128 const QString &oswpPath,
129 QStringList *warningsOut = nullptr);
130
131 // GIS data layers (schema v4+) — loaded rasters (GDAL) and vector
132 // datasets (OGR shapefiles, GeoPackage, …). Persisted by source path so
133 // they reopen on project load. deserializeGisLayer opens asynchronously
134 // and adds the layer to \p canvas on completion.
135 static QJsonObject serializeGisLayer(OpenSWMMVisLayer *layer,
136 const QString &oswpPath);
137 static void deserializeGisLayer(const QJsonObject &obj,
138 MapCanvas *canvas,
139 const QString &oswpPath,
140 QStringList *warningsOut = nullptr);
141};
142
143// ---------------------------------------------------------------------------
144// Inline path helpers (Slice AA-3.2)
145// ---------------------------------------------------------------------------
146
147inline QString ProjectSerializer::toRelativePath(const QString &path,
148 const QString &oswpFile)
149{
150 if (path.isEmpty()) return {};
151 const QFileInfo oswpFi(oswpFile);
152 const QDir oswpDir = oswpFi.absoluteDir();
153 const QString cleanedAbs = QDir::cleanPath(QFileInfo(path).absoluteFilePath());
154 // QDir::relativeFilePath returns the absolute path unchanged when the
155 // two are on different volumes (cross-drive on Windows) or can't be
156 // made relative — exactly the fallback we want.
157 return oswpDir.relativeFilePath(cleanedAbs);
158}
159
160inline QString ProjectSerializer::resolveStoredPath(const QString &stored,
161 const QString &oswpFile)
162{
163 if (stored.isEmpty()) return {};
164 if (QDir::isAbsolutePath(stored))
165 return QDir::cleanPath(stored);
166 const QFileInfo oswpFi(oswpFile);
167 const QDir oswpDir = oswpFi.absoluteDir();
168 return QDir::cleanPath(oswpDir.absoluteFilePath(stored));
169}
170
171inline QString ProjectSerializer::sidecarPathFor(const QString &inpPath)
172{
173 if (inpPath.isEmpty()) return {};
174 const QFileInfo fi(inpPath);
175 return fi.absoluteDir().filePath(fi.completeBaseName() +
176 QStringLiteral(".oswp"));
177}
178
179#endif // PROJECTSERIALIZER_H
The central map display widget — QGIS-style hybrid rendering.
Definition mapcanvas.h:63
Abstract base class for all layers displayed in the MapCanvas.
Definition openswmmvislayer.h:116
Definition projectserializer.h:41
static bool applyFromFile(const QString &oswpPath, SWMMVisProjectWindow *pw, QString *errorOut=nullptr, QStringList *warningsOut=nullptr)
Definition projectserializer.cpp:1176
static QString resolveStoredPath(const QString &stored, const QString &oswpFile)
Definition projectserializer.h:160
static QString toRelativePath(const QString &path, const QString &oswpFile)
Definition projectserializer.h:147
static constexpr int kCurrentSchemaVersion
Definition projectserializer.h:50
static QString sidecarPathFor(const QString &inpPath)
Definition projectserializer.h:171
static bool saveToFile(const QString &oswpPath, SWMMVisProjectWindow *pw, QString *errorOut=nullptr)
Definition projectserializer.cpp:1144
Definition swmmvisproject.h:31
MDI sub-window owning a MapCanvas, SWMMModelLayer, and map tools.
Definition swmmvisprojectwindow.h:58
int path
Definition pslgminsize.cpp:234
QVector< int > parent
union-find
Definition pslgminsize.cpp:176