| 46 | ReferenceLine::~ReferenceLine() = default; |
| 47 | |
| 48 | void ReferenceLine::init(bool loading) { |
| 49 | Q_D(ReferenceLine); |
| 50 | |
| 51 | // create the line |
| 52 | d->line = new Line(QString()); |
| 53 | d->line->setHidden(true); |
| 54 | addChild(d->line); |
| 55 | connect(d->line, &Line::updatePixmapRequested, [=] { |
| 56 | d->update(); |
| 57 | Q_EMIT changed(); |
| 58 | }); |
| 59 | connect(d->line, &Line::updateRequested, [=] { |
| 60 | d->recalcShapeAndBoundingRect(); |
| 61 | }); |
| 62 | |
| 63 | // init the properties |
| 64 | if (!loading) { |
| 65 | KConfig config; |
| 66 | KConfigGroup group = config.group(QStringLiteral("ReferenceLine")); |
| 67 | d->orientation = (Orientation)group.readEntry(QStringLiteral("Orientation"), static_cast<int>(Orientation::Vertical)); |
| 68 | d->updatePositionLimit(); // set the position limit after the orientation was set |
| 69 | d->line->init(group); |
| 70 | |
| 71 | if (plot()) { |
| 72 | d->coordinateBindingEnabled = true; |
| 73 | // default position |
| 74 | auto cs = plot()->coordinateSystem(plot()->defaultCoordinateSystemIndex()); |
| 75 | const auto x = d->m_plot->range(Dimension::X, cs->index(Dimension::X)).center(); |
| 76 | const auto y = d->m_plot->range(Dimension::Y, cs->index(Dimension::Y)).center(); |
| 77 | DEBUG(Q_FUNC_INFO << ", x/y pos = " << x << " / " << y) |
| 78 | d->positionLogical = QPointF(x, y); |
| 79 | } else |
| 80 | d->position.point = QPointF(0, 0); |
| 81 | d->updatePosition(); // To update also scene coordinates |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | /*! |
| 86 | Returns an icon to be used in the project explorer. |
nothing calls this directly
no test coverage detected