CurveAppearance and CurveAppearanceWidget
CurveAppearanceWidget is a reusable Qt widget that presents a full set
of curve-appearance controls to the user. It edits a CurveAppearance
struct — a plain-data aggregate that bundles every visual property a plot
curve carries. The same struct is the currency exchanged between the widget,
BlackchirpPlotCurveBase (which stores and applies the values at
draw time), and OverlayBase (which serializes a copy in its
metadata blob so overlay curves restore their appearance across sessions).
The widget is used in the plot context-menu’s per-curve configuration panel. The user-guide description of the resulting controls is in Plot Controls.
Appearance fields
CurveAppearance collects the following properties:
color — pen color (
QColor).curveStyle — rendering mode:
QwtPlotCurve::Lines,Sticks,Steps,Dots, orNoCurve.lineThickness — pen width in pixels (
double).lineStyle — dash pattern:
Qt::SolidLine,Qt::DashLine, etc. PassQt::NoPento suppress the line completely.markerStyle — symbol drawn at each data point (
QwtSymbol::Style);QwtSymbol::NoSymbolsuppresses markers.markerSize — symbol size in pixels (
int).visible — whether the curve is drawn at all (
bool).autoscale — whether the curve is included when axis limits are computed during an autoscale operation (
bool).yAxis — which Y axis the curve is plotted against (
QwtAxisId; maps to the left or right axis).
CurveAppearance is registered with Q_DECLARE_METATYPE so it can be
carried in QVariant containers and emitted through queued signals.
Init/apply paths
The widget provides two parallel init/apply paths depending on whether the caller owns a curve object or an overlay object:
Curve path — used by the main plot context menu:
initializeFromCurve(BlackchirpPlotCurveBase*)— reads the current appearance settings from the curve’s storage and populates the controls.applyToCurve(BlackchirpPlotCurveBase*)— writes the current control state back to the curve, triggering an immediate visual update.
Overlay path — used when editing an overlay curve:
initializeFromOverlay(std::shared_ptr<OverlayBase>)— reads the serialized appearance from the overlay’s metadata blob.applyToOverlay(std::shared_ptr<OverlayBase>)— writes the current control state into the overlay’s metadata.
Both paths ultimately operate on the same CurveAppearance struct, which
is also accessible directly via getCurrentAppearance() and
setCurrentAppearance(). Whenever any control changes, the widget emits
curveAppearanceChanged(CurveAppearance) so callers can react
immediately without polling.
Preset management
When a CurveAppearancePresetManager is attached via
setPresetManager(), a preset combo box and Save/Delete buttons become
active. The CurveAppearancePresetManager singleton (stored in
QSettings) ships with nine default presets — three curve, three stem, and
three scatter variants — and persists any user-defined
presets across sessions. The widget provides the following preset surface:
applyPreset(name)— loads the named preset and emitscurveAppearanceChanged().saveCurrentAsPreset(name)— saves the current control state as a preset; overwrites an existing entry if the name matches.deletePreset(name)— removes a user-defined preset (default presets cannot be deleted).refreshPresetList()— repopulates the combo box from the manager, e.g., after an external preset change.
The widget does not open dialogs itself; it delegates user-input steps
(name entry, delete confirmation) to callers via the signals
presetSaveRequested(suggestedName) and
presetDeleteRequested(presetName).
The user-facing description of the preset workflow — including the nine default presets and the Save Curve Appearance Preset dialog — is in Plot Controls.
API Reference
-
class CurveAppearanceWidget : public QWidget
Widget that edits the visual appearance of a single plot curve.
See also
CurveAppearance, BlackchirpPlotCurveBase, OverlayBase, CurveAppearancePresetManager
Public Functions
-
explicit CurveAppearanceWidget(QWidget *parent = nullptr)
Constructs the widget with all appearance controls.
- Parameters:
parent – Parent widget.
-
~CurveAppearanceWidget()
Destructor.
-
void initializeFromCurve(BlackchirpPlotCurveBase *curve)
Populates all controls from the current settings of curve.
- Parameters:
curve – Curve to read appearance from.
-
void applyToCurve(BlackchirpPlotCurveBase *curve)
Writes the current control state to curve.
- Parameters:
curve – Curve to update.
Populates all controls from the metadata stored in overlay.
- Parameters:
overlay – Overlay whose metadata contains the serialized appearance.
Writes the current control state into overlay’s metadata.
- Parameters:
overlay – Overlay to update.
-
CurveAppearance getCurrentAppearance() const
Returns the appearance struct reflecting the current control state.
- Returns:
Current CurveAppearance.
-
void setCurrentAppearance(const CurveAppearance &appearance)
Sets all controls to match appearance.
- Parameters:
appearance – Appearance values to apply to the controls.
-
void setColorButtonEnabled(bool enabled)
Enables or disables the color-picker button.
- Parameters:
enabled – Pass
falseto hide the color control (e.g., when color is managed externally).
-
void setYAxisControlEnabled(bool enabled)
Enables or disables the Y-axis selector.
- Parameters:
enabled – Pass
falsewhen the plot has only one Y axis.
-
void updateColorDisplay(const QColor &color)
Refreshes the color swatch to show color without emitting signals.
- Parameters:
color – New color to display.
-
void setPresetManager(CurveAppearancePresetManager *manager)
Attaches a preset manager so the preset controls become active.
The widget does not take ownership of manager.
- Parameters:
manager – Application-wide preset manager; pass
nullptrto disable preset controls.
-
void applyPreset(const QString &presetName)
Applies the named preset to all controls and emits curveAppearanceChanged().
- Parameters:
presetName – Name of the preset to apply.
-
void saveCurrentAsPreset(const QString &presetName)
Saves the current control state as a preset named presetName.
- Parameters:
presetName – Name under which to store the preset.
-
void deletePreset(const QString &presetName)
Deletes the preset named presetName from the manager.
- Parameters:
presetName – Name of the preset to remove.
-
void refreshPresetList()
Repopulates the preset combo box from the attached manager.
Signals
-
void curveAppearanceChanged(const CurveAppearanceWidget::CurveAppearance &appearance)
Emitted whenever any appearance control changes.
- Parameters:
appearance – Updated appearance struct.
-
void colorChangeRequested()
Emitted when the user clicks the color button; callers may open a color dialog and call updateColorDisplay() with the result.
-
void presetSaveRequested(const QString &suggestedName)
Emitted when the user initiates a save; callers should prompt for a name and call saveCurrentAsPreset().
- Parameters:
suggestedName – Auto-generated name suggestion.
-
void presetDeleteRequested(const QString &presetName)
Emitted when the user initiates a delete; callers should confirm before calling deletePreset().
- Parameters:
presetName – Name of the preset the user wishes to remove.
Private Functions
-
void setupUI()
-
void setupConnections()
-
void emitAppearanceChanged()
-
void updateDeleteButtonState()
-
QString generatePresetSuggestion() const
-
QString getMarkerShapeName(QwtSymbol::Style style) const
-
QString getLineStyleName(Qt::PenStyle style) const
-
QString getColorDescription(const QColor &color) const
Private Members
-
QComboBox *p_presetBox
-
QPushButton *p_savePresetButton
-
QPushButton *p_deletePresetButton
-
QPushButton *p_colorButton
-
QComboBox *p_curveStyleBox
-
QDoubleSpinBox *p_thicknessBox
-
QComboBox *p_lineStyleBox
-
QComboBox *p_markerBox
-
QSpinBox *p_markerSizeBox
-
QCheckBox *p_visibleBox
-
QCheckBox *p_autoscaleBox
-
QComboBox *p_yAxisBox
-
CurveAppearance d_currentAppearance
-
bool d_blockSignals
-
CurveAppearancePresetManager *p_presetManager
Private Slots
-
void onColorButtonClicked()
-
void onCurveStyleChanged(int index)
-
void onLineThicknessChanged(double value)
-
void onLineStyleChanged(int index)
-
void onMarkerStyleChanged(int index)
-
void onMarkerSizeChanged(int value)
-
void onVisibilityChanged(bool visible)
-
void onAutoscaleChanged(bool enabled)
-
void onYAxisChanged(int index)
-
void onPresetSelected(int index)
-
void onSavePresetClicked()
-
void onDeletePresetClicked()
-
struct CurveAppearance
Bundles all visual properties carried by a plot curve.
Public Members
-
QColor color
Pen color.
-
QwtPlotCurve::CurveStyle curveStyle
Rendering style (Lines, Sticks, Steps, Dots, NoCurve).
-
double lineThickness
Pen width in pixels.
-
Qt::PenStyle lineStyle
Line dash pattern (Qt::SolidLine, Qt::DashLine, etc.).
-
QwtSymbol::Style markerStyle
Symbol drawn at each data point; QwtSymbol::NoSymbol suppresses markers.
-
int markerSize
Symbol size in pixels.
-
bool visible
Whether the curve is drawn on the plot.
-
bool autoscale
Whether the curve is included in autoscale range computation.
-
QwtAxisId yAxis
Y axis assignment (left or right).
-
QColor color
-
explicit CurveAppearanceWidget(QWidget *parent = nullptr)