CurveFactory and CurveStorageInterface

CurveFactory is the construction entry point for all BlackchirpPlotCurveBase subclasses. Rather than constructing their own storage, curve objects receive a std::unique_ptr<CurveStorageInterface> at construction time. The factory chooses the concrete implementation — either SettingsStorageWrapper (for standard plot curves) or OverlayMetadataStorage (for overlay curves) — and the curve itself needs no conditional logic to support both persistence paths.

Storage backend abstraction

CurveStorageInterface is the polymorphic contract. It declares two pure virtual methods — set(key, QVariant) and get(key, QVariant) — plus type-safe template overloads that wrap them. Any class that should store curve display settings in a different backend (e.g., a database or a network resource) can implement this interface and pass the result to any curve constructor.

Two concrete backends ship with the codebase:

  • SettingsStorageWrapper — adapts SettingsStorage (QSettings) to the CurveStorageInterface contract. Curves that use this backend persist their appearance (color, line style, thickness, marker, etc.) across application restarts. Standard plot curves — FID traces, FT spectra, auxiliary data series — all use this backend.

  • OverlayMetadataStorage — routes all reads and writes into the metadata map of a OverlayBase instance. Overlay curves use this backend so their appearance is saved as part of the overlay data file rather than globally in QSettings. This means that loading an overlay restores its visual appearance without touching the user’s global curve settings.

OverlayMetadataStorage exposes getOverlay() so that BlackchirpPlotCurveBase can retrieve the associated overlay when it needs to identify which overlay owns the curve.

Factory methods

CurveFactory provides two static templated factory methods:

  • createStandardCurve<CurveType>(key, type, ...) — constructs a SettingsStorageWrapper and passes it to the new curve instance. The key parameter matches the storage key used by SettingsStorage.

  • createOverlayCurve<CurveType>(key, overlay, ...) — constructs an OverlayMetadataStorage pointing at overlay and passes it to the new curve instance.

Both methods accept the same optional visual defaults (line style, symbol style, curve style) that are written to storage on first construction and then overridden by any saved settings on subsequent construction.

API Reference

class CurveStorageInterface

Polymorphic key/value storage contract for curve display settings.

Subclassed by OverlayMetadataStorage, SettingsStorageWrapper

Public Functions

virtual ~CurveStorageInterface() = default

Virtual destructor.

virtual void set(const QString &key, const QVariant &value) = 0

Stores value under key.

Parameters:
  • key – Settings key.

  • value – Value to store.

virtual QVariant get(const QString &key, const QVariant &defaultValue = QVariant()) const = 0

Retrieves the value stored under key.

Parameters:
  • key – Settings key.

  • defaultValue – Returned when key is absent.

Returns:

Stored value, or defaultValue.

template<typename T>
inline T get(const QString key, const T &defaultValue = QVariant().value<T>()) const

Type-safe retrieval.

Template Parameters:

T – Expected value type.

Parameters:
  • key – Settings key.

  • defaultValue – Returned when key is absent.

Returns:

Stored value cast to T, or defaultValue.

template<typename T>
inline void set(const QString &key, const T &value)

Type-safe storage.

Template Parameters:

T – Value type; must be registered with QMetaType.

Parameters:
  • key – Settings key.

  • value – Value to store.

class SettingsStorageWrapper : public CurveStorageInterface, public SettingsStorage

CurveStorageInterface backed by SettingsStorage (QSettings).

Adapts the SettingsStorage / QSettings persistence layer to the CurveStorageInterface contract. Standard (non-overlay) curves use this backend so their appearance survives application restarts.

Public Functions

SettingsStorageWrapper(const QString &key, SettingsStorage::Type type = SettingsStorage::General)

Constructs the wrapper with the given key and storage type.

Parameters:
  • key – Settings key identifying this curve’s storage group.

  • type – Storage category (default: SettingsStorage::General).

virtual void set(const QString &key, const QVariant &value) override

Stores value under key via SettingsStorage.

virtual QVariant get(const QString &key, const QVariant &defaultValue) const override

Retrieves the value stored under key from SettingsStorage.

class OverlayMetadataStorage : public CurveStorageInterface

CurveStorageInterface backed by an OverlayBase metadata blob.

Routes all set / get calls into the metadata map of the supplied OverlayBase. Overlay curves use this backend so their appearance is saved alongside the overlay data rather than in QSettings.

Public Functions

OverlayMetadataStorage(std::shared_ptr<OverlayBase> overlay)

Constructs storage that writes into overlay’s metadata.

Parameters:

overlay – Overlay whose metadata blob receives the curve settings.

virtual void set(const QString &key, const QVariant &value) override

Stores value under key in the overlay metadata.

virtual QVariant get(const QString &key, const QVariant &defaultValue) const override

Retrieves the value stored under key from the overlay metadata.

inline std::shared_ptr<OverlayBase> getOverlay() const

Returns the overlay this storage writes into.

Private Members

std::shared_ptr<OverlayBase> d_overlay
class CurveFactory

Factory that constructs BlackchirpPlotCurveBase subclasses with the correct storage backend.

Public Static Functions

template<typename CurveType>
static inline std::unique_ptr<CurveType> createStandardCurve(const QString &key, SettingsStorage::Type type = SettingsStorage::General, const QString &title = QString(""), Qt::PenStyle defaultLineStyle = Qt::SolidLine, QwtSymbol::Style defaultMarker = QwtSymbol::NoSymbol, QwtPlotCurve::CurveStyle defaultStyle = QwtPlotCurve::Lines)

Creates a curve with a SettingsStorageWrapper backend.

Template Parameters:

CurveType – Concrete subclass of BlackchirpPlotCurveBase to instantiate.

Parameters:
  • key – Settings key for this curve.

  • type – Storage category (default: SettingsStorage::General).

  • title – Curve title shown in the legend (default: empty).

  • defaultLineStyle – Initial line style (default: Qt::SolidLine).

  • defaultMarker – Initial symbol style (default: QwtSymbol::NoSymbol).

  • defaultStyle – Initial curve style (default: QwtPlotCurve::Lines).

Returns:

Owning pointer to the constructed curve.

template<typename CurveType>
static inline std::unique_ptr<CurveType> createOverlayCurve(const QString &key, std::shared_ptr<OverlayBase> overlay, const QString &title = QString(""), Qt::PenStyle defaultLineStyle = Qt::SolidLine, QwtSymbol::Style defaultMarker = QwtSymbol::NoSymbol, QwtPlotCurve::CurveStyle defaultStyle = QwtPlotCurve::Lines)

Creates a curve with an OverlayMetadataStorage backend.

Template Parameters:

CurveType – Concrete subclass of BlackchirpPlotCurveBase to instantiate.

Parameters:
  • key – Settings key for this curve.

  • overlay – Overlay that will own the appearance metadata.

  • title – Curve title shown in the legend (default: empty).

  • defaultLineStyle – Initial line style (default: Qt::SolidLine).

  • defaultMarker – Initial symbol style (default: QwtSymbol::NoSymbol).

  • defaultStyle – Initial curve style (default: QwtPlotCurve::Lines).

Returns:

Owning pointer to the constructed curve.