src/WhiskerToolbox/Plots/EventPlotWidget/Core/EventPlotState.hpp
src/WhiskerToolbox/Plots/EventPlotWidget/Core/EventPlotState.hpp
State class for EventPlotWidget. More…
Classes
| Name | |
|---|---|
| class | EventPlotState State class for EventPlotWidget. |
Detailed Description
State class for EventPlotWidget.
See: EditorState for base class documentation
EventPlotState manages the serializable state for the EventPlotWidget, enabling workspace save/restore and inter-widget communication via SelectionContext.
Source code
#ifndef EVENT_PLOT_STATE_HPP
#define EVENT_PLOT_STATE_HPP
#include "Plots/EventPlotWidget/Core/EventPlotStateData.hpp"
#include "EditorState/EditorState.hpp"
#include "CorePlotting/CoordinateTransform/ViewStateData.hpp"
#include "Plots/Common/GlyphStyleWidget/Core/GlyphStyleState.hpp"
#include "Plots/Common/PlotAlignmentWidget/Core/PlotAlignmentData.hpp"
#include "Plots/Common/PlotAlignmentWidget/Core/PlotAlignmentState.hpp"
#include "Plots/Common/RelativeTimeAxisWidget/Core/RelativeTimeAxisStateData.hpp"
#include "Plots/Common/RelativeTimeAxisWidget/Core/RelativeTimeAxisState.hpp"
#include <rfl.hpp>
#include <rfl/json.hpp>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <vector>
class EventPlotState : public EditorState {
Q_OBJECT
public:
explicit EventPlotState(QObject * parent = nullptr);
~EventPlotState() override = default;
// === Type Identification ===
[[nodiscard]] QString getTypeName() const override { return QStringLiteral("EventPlotWidget"); }
[[nodiscard]] QString getDisplayName() const override;
void setDisplayName(QString const & name) override;
// === Alignment Event ===
// === Alignment Event ===
[[nodiscard]] QString getAlignmentEventKey() const;
void setAlignmentEventKey(QString const & key);
// === Interval Alignment ===
[[nodiscard]] IntervalAlignmentType getIntervalAlignmentType() const;
void setIntervalAlignmentType(IntervalAlignmentType type);
// === Offset ===
[[nodiscard]] double getOffset() const;
void setOffset(double offset);
// === Window Size ===
[[nodiscard]] double getWindowSize() const;
void setWindowSize(double window_size);
[[nodiscard]] PlotAlignmentState * alignmentState() { return _alignment_state.get(); }
[[nodiscard]] RelativeTimeAxisState * relativeTimeAxisState() { return _relative_time_axis_state.get(); }
// === View State ===
[[nodiscard]] CorePlotting::ViewStateData const & viewState() const
{
return _data.view_state;
}
void setXZoom(double zoom);
void setYZoom(double zoom);
void setPan(double x_pan, double y_pan);
void setXBounds(double x_min, double x_max);
// === Axis Options ===
[[nodiscard]] EventPlotAxisOptions const & axisOptions() const { return _data.axis_options; }
void setAxisOptions(EventPlotAxisOptions const & options);
// === Background Color ===
[[nodiscard]] QString getBackgroundColor() const;
void setBackgroundColor(QString const & hex_color);
// === Pinning (for cross-widget linking) ===
[[nodiscard]] bool isPinned() const { return _data.pinned; }
void setPinned(bool pinned);
// === Trial Sorting ===
[[nodiscard]] TrialSortMode getSortingMode() const { return _data.sorting_mode; }
void setSortingMode(TrialSortMode mode);
// === Direct Data Access ===
[[nodiscard]] EventPlotStateData const & data() const { return _data; }
// === Plot Events Management ===
void addPlotEvent(QString const & event_name, QString const & event_key,
std::optional<IntervalAlignmentType> interval_edge = std::nullopt);
void removePlotEvent(QString const & event_name);
[[nodiscard]] std::vector<QString> getPlotEventNames() const;
[[nodiscard]] std::optional<EventPlotOptions> getPlotEventOptions(QString const & event_name) const;
// === Per-Key Glyph Style ===
[[nodiscard]] GlyphStyleState * glyphStyleStateForKey(QString const & event_name);
[[nodiscard]] CorePlotting::GlyphStyleData getEventGlyphStyle(QString const & event_name) const;
void updatePlotEventOptions(QString const & event_name, EventPlotOptions const & options);
// === Serialization ===
[[nodiscard]] std::string toJson() const override;
bool fromJson(std::string const & json) override;
signals:
void alignmentEventKeyChanged(QString const & key);
void intervalAlignmentTypeChanged(IntervalAlignmentType type);
void offsetChanged(double offset);
void windowSizeChanged(double window_size);
void plotEventAdded(QString const & event_name);
void plotEventRemoved(QString const & event_name);
void plotEventOptionsChanged(QString const & event_name);
// === View State Signals (consolidated) ===
void viewStateChanged();
void axisOptionsChanged();
void backgroundColorChanged(QString const & hex_color);
void pinnedChanged(bool pinned);
void sortingModeChanged(TrialSortMode mode);
void glyphStyleChanged();
void eventGlyphStyleChanged(QString const & event_name);
private:
EventPlotStateData _data;
std::unique_ptr<PlotAlignmentState> _alignment_state;
std::unique_ptr<RelativeTimeAxisState> _relative_time_axis_state;
std::map<std::string, std::unique_ptr<GlyphStyleState>> _event_glyph_style_states;
void _createGlyphStyleStateForKey(std::string const & key);
};
#endif// EVENT_PLOT_STATE_HPPUpdated on 2026-11-13 at 20:25:45 +0000