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.)
| 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.) |
| 50 | TEST(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 |
nothing calls this directly
no test coverage detected