MCPcopy Create free account
hub / github.com/PlotJuggler/PlotJuggler / TEST

Function TEST

pj_plotting/tests/plot_widget_default_style_test.cpp:50–85  ·  view source on GitHub ↗

Style and width are plot-level properties: changing one restyles/re-pens every existing curve AND is inherited by curves added afterwards. (Two curves in one plot can never differ in style/width — only colour is per-curve.)

Source from the content-addressed store, hash-verified

48// existing curve AND is inherited by curves added afterwards. (Two curves in one
49// plot can never differ in style/width — only colour is per-curve.)
50TEST(PlotWidgetCurveStyle, StyleAndWidthAreInheritedByNewCurves) {
51 PJ::SessionManager session;
52 PJ::CatalogModel catalog(&session);
53 auto dataset = session.dataEngine().createDataset(PJ::DatasetDescriptor{.source_name = "drive.mcap"});
54 ASSERT_TRUE(dataset.has_value()) << dataset.error();
55 const QString key_a = keyForTopic(catalog, addScalarTopic(session, *dataset, "/imu/x"));
56 const QString key_b = keyForTopic(catalog, addScalarTopic(session, *dataset, "/imu/y"));
57 const QString key_c = keyForTopic(catalog, addScalarTopic(session, *dataset, "/imu/z"));
58 ASSERT_FALSE(key_a.isEmpty());
59
60 PJ::PlotWidget plot(&session, &catalog);
61 auto* info_a = plot.addCurve(key_a);
62 ASSERT_NE(info_a, nullptr);
63 QwtPlotCurve* curve_a = info_a->curve; // QwtPlotCurve* is heap-stable across later addCurve() reallocs.
64 ASSERT_NE(curve_a, nullptr);
65 ASSERT_EQ(curve_a->style(), QwtPlotCurve::Lines);
66
67 // Plot-level style change restyles the existing curve...
68 plot.setDefaultStyle(PJ::PlotWidgetBase::kDots);
69 EXPECT_EQ(curve_a->style(), QwtPlotCurve::Dots);
70 // ...and is inherited by a curve added afterwards.
71 auto* info_b = plot.addCurve(key_b);
72 ASSERT_NE(info_b, nullptr);
73 ASSERT_NE(info_b->curve, nullptr);
74 EXPECT_EQ(info_b->curve->style(), QwtPlotCurve::Dots);
75
76 // Same for width: existing and new curves share the plot's line width.
77 plot.setDefaultStyle(PJ::PlotWidgetBase::kLines);
78 plot.setLineWidth(PJ::LineWidth::kPoints30);
79 const double expected_width = PJ::lineWidthValue(PJ::LineWidth::kPoints30);
80 EXPECT_DOUBLE_EQ(curve_a->pen().widthF(), expected_width);
81 auto* info_c = plot.addCurve(key_c);
82 ASSERT_NE(info_c, nullptr);
83 ASSERT_NE(info_c->curve, nullptr);
84 EXPECT_DOUBLE_EQ(info_c->curve->pen().widthF(), expected_width);
85}
86
87// A point-only (Dots) curve draws its dots at dotWidthValue, so they are as
88// visible as the dots of a Lines+Dots curve — not 1px specks. (Regression for

Callers

nothing calls this directly

Calls 15

lineWidthValueFunction · 0.85
dotWidthValueFunction · 0.85
createDatasetMethod · 0.80
setDefaultStyleMethod · 0.80
setModeXYMethod · 0.80
addCurveXYMethod · 0.80
applyCurveElementMethod · 0.80
keyForTopicFunction · 0.70
addScalarTopicFunction · 0.70
isEmptyMethod · 0.45
addCurveMethod · 0.45
styleMethod · 0.45

Tested by

no test coverage detected