src/WhiskerToolbox/DataViewer_Widget/Core/DataViewerStateData.hpp
src/WhiskerToolbox/DataViewer_Widget/Core/DataViewerStateData.hpp
Comprehensive serializable state data structure for DataViewer_Widget. More…
Classes
| Name | |
|---|---|
| struct | AnalogSeriesOptionsData Serializable display options for analog time series. |
| struct | DigitalEventSeriesOptionsData Serializable display options for digital event series. |
| struct | DigitalIntervalSeriesOptionsData Serializable display options for digital interval series. |
| struct | DataViewerThemeState Theme and color settings. |
| struct | DataViewerGridState Grid overlay configuration. |
| struct | DataViewerUIPreferences UI layout and behavior preferences. |
| struct | DataViewerLayoutConfig Configurable layout parameters for stacked series. |
| struct | SeriesLaneOverrideData Per-series lane placement override. |
| struct | LaneOverrideData Lane-level metadata override keyed by lane_id. |
| struct | StackableOrderingConstraintData Relative ordering constraint for stackable series. |
| struct | GroupScalingState Scaling state for a group of analog series. |
| struct | DataViewerInteractionState Current interaction state. |
| struct | DataViewerStateData Complete serializable state for DataViewer_Widget. |
| struct | LaneLayoutSeriesEntry One displayed series entry in a saved DataViewer lane profile. |
| struct | LaneLayoutLaneEntry Stable lane declaration in a saved DataViewer lane profile. |
| struct | LaneLayoutEventAssociation Stable event-to-lane association in a saved DataViewer lane profile. |
| struct | LaneLayoutFile Versioned DataViewer lane profile for save/load. |
Types
| Name | |
|---|---|
| enum class | AnalogGapHandlingMode { AlwaysConnect, DetectGaps, ShowMarkers} Gap handling mode for analog series. |
| enum class | EventPlottingModeData { FullCanvas, Stacked} Plotting mode for digital event series. |
| enum class | EventGlyphShapeData { Tick, TopLine, Box} Visual glyph shape for digital event markers in data coordinates / screen space. |
| enum class | DataViewerTheme { Dark, Light} Visual theme for the DataViewer. |
| enum class | DataViewerZoomScalingMode { Fixed, Adaptive} Zoom scaling mode. |
| enum class | LaneOverlayMode { Auto, Overlay, Separate} Overlay behavior hint for mixed-lane rendering. |
| enum class | DataViewerInteractionMode { Normal, CreateInterval, ModifyInterval, CreateLine} Interaction mode for the DataViewer. |
| enum class | LaneLayoutLoadMode { Merge, Replace} Load behavior for a saved DataViewer lane profile. |
| enum class | LaneLayoutSeriesType { Analog, DigitalEvent, DigitalInterval} Data object type stored in a lane profile series entry. |
| enum class | LaneLayoutEventPlacement { Above, Below, Overlay} Relative placement of an event series near a target lane. |
Detailed Description
Comprehensive serializable state data structure for DataViewer_Widget.
This file defines the full state structure that DataViewerState serializes to JSON using reflect-cpp. It captures all persistent state needed for workspace save/restore:
- Display options for all series types (analog, digital events, digital intervals)
- View state (time window, Y bounds, zoom, pan)
- Theme and grid settings
- UI preferences
- Active interaction mode
Design Principles
- Separation of concerns - Only user-configurable options are stored here. Computed state (layout transforms, data caches) stays in TimeSeriesDataStore.
- Nested objects for clarity - Top-level structure uses nested objects for clear JSON organization
- Native enum serialization - Enums serialize as strings automatically
- No Qt types - All Qt types converted to std equivalents (QString → std::string)
- Transient state excluded - Hover positions, drag state, preview flags NOT included
Example JSON Output
{
"instance_id": "abc123",
"display_name": "Data Viewer",
"view": {
"time_start": 0,
"time_end": 10000,
"y_min": -1.0,
"y_max": 1.0,
"global_y_scale": 1.5
},
"theme": {
"theme": "Dark",
"background_color": "#000000"
},
"analog_options": {
"channel_1": { "hex_color": "#0000ff", "is_visible": true }
}
}DataViewerState for the Qt wrapper class
TimeSeriesDataStore for runtime data storage
Types Documentation
enum AnalogGapHandlingMode
| Enumerator | Value | Description |
|---|---|---|
| AlwaysConnect | Always connect points (default). | |
| DetectGaps | Break lines when gaps exceed threshold. | |
| ShowMarkers | Show individual markers instead of lines. |
Gap handling mode for analog series.
Serializes as “AlwaysConnect”, “DetectGaps”, or “ShowMarkers” automatically.
enum EventPlottingModeData
| Enumerator | Value | Description |
|---|---|---|
| FullCanvas | Events extend full canvas height. | |
| Stacked | Events allocated portion of canvas. |
Plotting mode for digital event series.
Serializes as “FullCanvas” or “Stacked” automatically.
enum EventGlyphShapeData
| Enumerator | Value | Description |
|---|---|---|
| Tick | Standard vertical line at the event time. | |
| TopLine | Horizontal line at the top of the lane (screen-space extent). | |
| Box | Filled or outlined box; X extent is box_width_ticks in data coordinates. |
Visual glyph shape for digital event markers in data coordinates / screen space.
Serializes as “Tick”, “TopLine”, or “Box” automatically. Used by the renderer to choose the event pipeline (tick/top line vs. data-width box overlay).
enum DataViewerTheme
| Enumerator | Value | Description |
|---|---|---|
| Dark | Dark background, light text/axes. | |
| Light | Light background, dark text/axes. |
Visual theme for the DataViewer.
Serializes as “Dark” or “Light” automatically.
enum DataViewerZoomScalingMode
| Enumerator | Value | Description |
|---|---|---|
| Fixed | Fixed zoom factor. | |
| Adaptive | Zoom factor scales with current zoom level. |
Zoom scaling mode.
Serializes as “Fixed” or “Adaptive” automatically.
enum LaneOverlayMode
| Enumerator | Value | Description |
|---|---|---|
| Auto | Let renderer/layout decide overlay behavior. | |
| Overlay | Force overlay behavior within the target lane. | |
| Separate | Keep series visually separated even if lane is shared. |
Overlay behavior hint for mixed-lane rendering.
enum DataViewerInteractionMode
| Enumerator | Value | Description |
|---|---|---|
| Normal | Default: pan, select, hover tooltips. | |
| CreateInterval | Click-drag to create a new interval. | |
| ModifyInterval | Edge dragging to modify existing interval. | |
| CreateLine | Click-drag to draw a selection line. |
Interaction mode for the DataViewer.
Serializes as “Normal”, “CreateInterval”, “ModifyInterval”, or “CreateLine”.
enum LaneLayoutLoadMode
| Enumerator | Value | Description |
|---|---|---|
| Merge | Add/update series named in the profile without removing unrelated displayed series. | |
| Replace | Clear displayed series and layout state before applying the profile. |
Load behavior for a saved DataViewer lane profile.
enum LaneLayoutSeriesType
| Enumerator | Value | Description |
|---|---|---|
| Analog | AnalogTimeSeries. | |
| DigitalEvent | DigitalEventSeries. | |
| DigitalInterval | DigitalIntervalSeries. |
Data object type stored in a lane profile series entry.
enum LaneLayoutEventPlacement
| Enumerator | Value | Description |
|---|---|---|
| Above | Event gets its own lane immediately above the target lane. | |
| Below | Event gets its own lane immediately below the target lane. | |
| Overlay | Event shares the target lane band. |
Relative placement of an event series near a target lane.
Source code
#ifndef DATAVIEWER_STATE_DATA_HPP
#define DATAVIEWER_STATE_DATA_HPP
#include "CorePlotting/CoordinateTransform/ViewStateData.hpp"
#include "CorePlotting/DataTypes/SeriesStyle.hpp"
#include <rfl.hpp>
#include <rfl/json.hpp>
#include <cstdint>
#include <map>
#include <optional>
#include <string>
#include <vector>
// ==================== Per-Series Display Options ====================
enum class AnalogGapHandlingMode {
AlwaysConnect,
DetectGaps,
ShowMarkers
};
struct AnalogSeriesOptionsData {
rfl::Flatten<CorePlotting::SeriesStyle> style;
// Analog-specific user settings
float user_scale_factor = 1.0f;
float y_offset = 0.0f;
// Gap handling
AnalogGapHandlingMode gap_handling = AnalogGapHandlingMode::AlwaysConnect;
bool enable_gap_detection = false;
float gap_threshold = 5.0f;
bool enable_min_max_line_decimation = false;
// Convenience accessors for style fields
[[nodiscard]] std::string const & hex_color() const { return style.get().hex_color; }
[[nodiscard]] float get_alpha() const { return style.get().alpha; }
[[nodiscard]] float get_line_thickness() const { return style.get().line_thickness; }
[[nodiscard]] bool get_is_visible() const { return style.get().is_visible; }
std::string & hex_color() { return style.get().hex_color; }
float & alpha() { return style.get().alpha; }
float & line_thickness() { return style.get().line_thickness; }
bool & is_visible() { return style.get().is_visible; }
};
enum class EventPlottingModeData {
FullCanvas,
Stacked
};
enum class EventGlyphShapeData {
Tick,
TopLine,
Box
};
struct DigitalEventSeriesOptionsData {
rfl::Flatten<CorePlotting::SeriesStyle> style;
// Event-specific settings
EventPlottingModeData plotting_mode = EventPlottingModeData::FullCanvas;
EventGlyphShapeData glyph_shape = EventGlyphShapeData::Tick;
int box_width_ticks = 10;
float vertical_spacing = 0.1f;
float event_height = 0.05f;
float margin_factor = 0.95f;
// Convenience accessors for style fields
[[nodiscard]] std::string const & hex_color() const { return style.get().hex_color; }
[[nodiscard]] float get_alpha() const { return style.get().alpha; }
[[nodiscard]] float get_line_thickness() const { return style.get().line_thickness; }
[[nodiscard]] bool get_is_visible() const { return style.get().is_visible; }
std::string & hex_color() { return style.get().hex_color; }
float & alpha() { return style.get().alpha; }
float & line_thickness() { return style.get().line_thickness; }
bool & is_visible() { return style.get().is_visible; }
};
struct DigitalIntervalSeriesOptionsData {
rfl::Flatten<CorePlotting::SeriesStyle> style;
// Interval-specific settings
bool extend_full_canvas = true;
float margin_factor = 0.95f;
float interval_height = 1.0f;
// Convenience accessors for style fields
[[nodiscard]] std::string const & hex_color() const { return style.get().hex_color; }
[[nodiscard]] float get_alpha() const { return style.get().alpha; }
[[nodiscard]] float get_line_thickness() const { return style.get().line_thickness; }
[[nodiscard]] bool get_is_visible() const { return style.get().is_visible; }
std::string & hex_color() { return style.get().hex_color; }
float & alpha() { return style.get().alpha; }
float & line_thickness() { return style.get().line_thickness; }
bool & is_visible() { return style.get().is_visible; }
};
// ==================== Theme State ====================
enum class DataViewerTheme {
Dark,
Light
};
struct DataViewerThemeState {
DataViewerTheme theme = DataViewerTheme::Dark;
std::string background_color = "#000000";
std::string axis_color = "#FFFFFF";
};
// ==================== Grid State ====================
struct DataViewerGridState {
bool enabled = false;
int spacing = 100;
};
// ==================== UI Preferences ====================
enum class DataViewerZoomScalingMode {
Fixed,
Adaptive
};
struct DataViewerUIPreferences {
DataViewerZoomScalingMode zoom_scaling_mode = DataViewerZoomScalingMode::Adaptive;
bool properties_panel_collapsed = false;
bool developer_mode = false;
// Note: splitter sizes not serialized (Qt-specific, layout-dependent)
};
// ==================== Layout Config ====================
struct DataViewerLayoutConfig {
float margin_factor = 0.8f;
};
// ==================== Mixed-Lane Overrides ====================
enum class LaneOverlayMode {
Auto,
Overlay,
Separate
};
struct SeriesLaneOverrideData {
std::string lane_id;
std::optional<int> lane_order = std::nullopt;
float lane_weight = 1.0f;
LaneOverlayMode overlay_mode = LaneOverlayMode::Auto;
int overlay_z = 0;
};
struct LaneOverrideData {
std::string display_label;
std::optional<float> lane_weight = std::nullopt;
};
// ==================== Ordering Constraints ====================
struct StackableOrderingConstraintData {
std::string above_series_key;
std::string below_series_key;
};
// ==================== Group Scaling State ====================
struct GroupScalingState {
bool unified_scaling = true;
float group_std_dev = 0.0f;
};
// ==================== Interaction State ====================
enum class DataViewerInteractionMode {
Normal,
CreateInterval,
ModifyInterval,
CreateLine
};
struct DataViewerInteractionState {
DataViewerInteractionMode mode = DataViewerInteractionMode::Normal;
};
// ==================== Main State Structure ====================
struct DataViewerStateData {
// === Identity ===
std::string instance_id;
std::string display_name = "Data Viewer";
// === View State ===
CorePlotting::ViewStateData view{
.x_min = 0.0,
.x_max = 1000.0,
.y_min = -1.0,
.y_max = 1.0,
.x_zoom = 1.0,
.y_zoom = 1.0,
.x_pan = 0.0,
.y_pan = 0.0};
// === Global Y Scale (data amplitude gain, NOT a view transform) ===
float global_y_scale = 1.0f;
// === Theme and Grid ===
DataViewerThemeState theme;
DataViewerGridState grid;
// === UI Preferences ===
DataViewerUIPreferences ui;
// === Layout Config ===
DataViewerLayoutConfig layout;
// === Interaction State ===
DataViewerInteractionState interaction;
// === Per-Series Display Options ===
// Each key is a data key (e.g., "channel_1"), value is the display options.
// The 'is_visible' field in each options struct indicates if that series is displayed.
std::map<std::string, AnalogSeriesOptionsData> analog_options;
std::map<std::string, DigitalEventSeriesOptionsData> event_options;
std::map<std::string, DigitalIntervalSeriesOptionsData> interval_options;
// === Mixed-Lane Placement Overrides ===
// series_lane_overrides: key is series key, value is per-series lane placement metadata.
// lane_overrides: key is lane_id, value is lane-level metadata and optional lane weight override.
std::map<std::string, SeriesLaneOverrideData> series_lane_overrides;
std::map<std::string, LaneOverrideData> lane_overrides;
// === Stackable Ordering Constraints ===
// Relative ordering rules for stackable series only.
// Conflict handling is applied by DataViewerState normalization and
// ordering policy resolution.
std::vector<StackableOrderingConstraintData> ordering_constraints;
// === Group Scaling ===
// Maps group name (e.g., "voltage") to scaling state.
// Applied when analog series in a group should share the same std_dev normalization.
std::map<std::string, GroupScalingState> group_scaling;
};
// ==================== Lane Layout Profile File ====================
enum class LaneLayoutLoadMode {
Merge,
Replace
};
enum class LaneLayoutSeriesType {
Analog,
DigitalEvent,
DigitalInterval
};
enum class LaneLayoutEventPlacement {
Above,
Below,
Overlay
};
struct LaneLayoutSeriesEntry {
std::string key;
LaneLayoutSeriesType type;
std::string color = "#FFFFFF";
bool visible = true;
std::optional<EventPlottingModeData> event_plotting_mode = std::nullopt;
std::optional<EventGlyphShapeData> event_glyph_shape = std::nullopt;
};
struct LaneLayoutLaneEntry {
std::string lane_id;
std::string display_label;
std::optional<int> lane_order = std::nullopt;
float lane_weight = 1.0f;
std::vector<LaneLayoutSeriesEntry> series;
};
struct LaneLayoutEventAssociation {
std::string event_key;
std::string target_lane_id;
LaneLayoutEventPlacement placement = LaneLayoutEventPlacement::Above;
std::string color = "#FF0000";
bool visible = true;
std::optional<EventGlyphShapeData> glyph_shape = std::nullopt;
};
struct LaneLayoutFile {
int version = 2;
LaneLayoutLoadMode mode = LaneLayoutLoadMode::Merge;
std::vector<LaneLayoutLaneEntry> lanes;
std::vector<LaneLayoutEventAssociation> event_associations;
};
#endif// DATAVIEWER_STATE_DATA_HPPUpdated on 2026-11-13 at 20:25:45 +0000