| 2287 | } |
| 2288 | |
| 2289 | void CartesianPlot::childAdded(const AbstractAspect* child) { |
| 2290 | auto* elem = dynamic_cast<const WorksheetElement*>(child); |
| 2291 | if (!elem) |
| 2292 | return; |
| 2293 | |
| 2294 | Q_D(CartesianPlot); |
| 2295 | int cSystemIndex = defaultCoordinateSystemIndex(); |
| 2296 | // check/change ranges when adding new children like curves for example. |
| 2297 | // The ranges must not be checked if just an element like a TextLabel, Custompoint, ... was added |
| 2298 | bool checkRanges = false; |
| 2299 | const auto* plot = dynamic_cast<const Plot*>(child); |
| 2300 | |
| 2301 | if (plot) { |
| 2302 | connect(plot, &WorksheetElement::visibleChanged, this, &CartesianPlot::curveVisibilityChanged); |
| 2303 | connect(plot, &WorksheetElement::aspectDescriptionChanged, this, &CartesianPlot::updateLegend); |
| 2304 | connect(plot, &Plot::legendVisibleChanged, this, &CartesianPlot::updateLegend); |
| 2305 | connect(plot, &Plot::appearanceChanged, this, &CartesianPlot::updateLegend); |
| 2306 | connect(plot, &Plot::appearanceChanged, this, QOverload<>::of(&CartesianPlot::plotColorChanged)); // forward to Worksheet to update CursorDock |
| 2307 | |
| 2308 | connect(plot, &Plot::dataChanged, [this, elem] { |
| 2309 | this->dataChanged(const_cast<WorksheetElement*>(elem)); |
| 2310 | }); |
| 2311 | |
| 2312 | // don't set the default coordinate system index during the project load, |
| 2313 | // the index is read in child's load(). |
| 2314 | // same for range and legend updates - settings are read in load(). |
| 2315 | if (!isLoading()) { |
| 2316 | const_cast<Plot*>(plot)->setCoordinateSystemIndex(cSystemIndex); |
| 2317 | checkRanges = true; |
| 2318 | updateLegend(); |
| 2319 | } |
| 2320 | } else { |
| 2321 | // hover events for plots are handled here in CartesianPlot, for other elements in WorksheetElement. |
| 2322 | // in case a non-plot element like axis, etc. was hovered, unhover the plots |
| 2323 | connect(elem, &WorksheetElement::hoveredChanged, [=](bool on) { |
| 2324 | if (on) { |
| 2325 | for (auto* plot : children<Plot>()) |
| 2326 | plot->setHover(false); |
| 2327 | } |
| 2328 | }); |
| 2329 | } |
| 2330 | |
| 2331 | const auto* curve = dynamic_cast<const XYCurve*>(child); |
| 2332 | const auto* hist = dynamic_cast<const Histogram*>(child); |
| 2333 | const auto* boxPlot = dynamic_cast<const BoxPlot*>(child); |
| 2334 | const auto* barPlot = dynamic_cast<const BarPlot*>(child); |
| 2335 | const auto* lollipopPlot = dynamic_cast<const LollipopPlot*>(child); |
| 2336 | |
| 2337 | const auto* axis = dynamic_cast<const Axis*>(child); |
| 2338 | |
| 2339 | if (curve) { |
| 2340 | DEBUG(Q_FUNC_INFO << ", CURVE") |
| 2341 | // x data |
| 2342 | connect(curve, &XYCurve::xColumnChanged, this, [this, curve](const AbstractColumn* column) { |
| 2343 | if (curveTotalCount() == 1) // first curve addded |
| 2344 | checkAxisFormat(curve->coordinateSystemIndex(), column, Axis::Orientation::Horizontal); |
| 2345 | }); |
| 2346 | connect(curve, &XYCurve::xDataChanged, [this, curve]() { |
nothing calls this directly
no test coverage detected