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
utctimeaxis.h File Reference

A chart time axis whose tick labels are rendered in UTC. More...

#include <QCategoryAxis>
#include <QDateTime>
#include <QString>
Include dependency graph for utctimeaxis.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  openswmmvis::plot::UtcTimeAxis
 

Namespaces

namespace  openswmmvis
 
namespace  openswmmvis::plot
 

Detailed Description

A chart time axis whose tick labels are rendered in UTC.

Model times are UTC end to end: .inp dates and times carry no zone, so swmmDateTimeToQDateTime() tags them Qt::UTC and the viewer must not shift them. Rendering them in the viewer's local zone does not reveal information, it invents it — the same model would plot differently in Denver and Berlin (issue #11).

Qt Charts' QDateTimeAxis cannot do this. It exposes only format, min, max and tickCount, and builds each label through QDateTime::fromMSecsSinceEpoch(ms) — i.e. LOCAL time — with no timezone property to override. (The UTC-defaulting timeZone property is Qt GRAPHS 6.11+, a different module this project does not use.) Forcing the process timezone is not an option either: Qt honours $TZ on Unix but uses system APIs on Windows.

So the labels are generated here instead. X values remain true UTC milliseconds-since-epoch — unchanged, uncorrected, directly comparable with the table — and only the label TEXT is formatted, with Qt::UTC. Shifting the x values to make a local-rendering axis show UTC was the alternative; it puts the axis in a fake coordinate space every read-back has to invert, and it breaks across a DST boundary, which any multi-month series will cross.

The public surface deliberately mirrors QDateTimeAxis so existing call sites (setRange with QDateTimes, min()/max(), setMin/setMax, setFormat, setTickCount) need no changes.

Chart zoom, pan and zoomReset move the NUMERIC range directly (QChart::zoomInQValueAxis::setRange), never through the QDateTime setters, so the axis listens to its own QValueAxis::rangeChanged, relabels for the new window and re-emits the range as instants (rangeChangedUtc). A drag-zoom therefore reaches panel-sync code exactly like a programmatic setRange.

Warning
QCategoryAxis derives from QValueAxis, so a qobject_cast<QValueAxis*> matches this type where it would NOT match QDateTimeAxis. Code that treats "is a QValueAxis" as "takes a printf label spec" or "edits as a number" (ChartProperties, ChartAxisFormatController, InteractiveChartView) must test for this class first.