#include "gtl_gui_chart_line.h" namespace gtl { namespace gui { chart_line::chart_line(::chart::series::series *parent, Qt::Orientation orientation) : ::chart::instrument::primitive::line(parent) , _orientation(orientation) , _behavior(magnetic_to_sample) { setFlag(QGraphicsItem::ItemIsMovable, true); if(_orientation == Qt::Vertical) _cursor = Qt::SplitHCursor; else _cursor = Qt::SplitVCursor; _pen.setStyle(Qt::PenStyle::DashLine); set_pos(0); } void chart_line::set_pos(qreal x) { emit get_nearest_x(x, _behavior); if(_orientation == Qt::Vertical) set_line(x, 0, x, 1); else set_line(0, x, 1, x); } qreal chart_line::pos() { if(_orientation == Qt::Vertical) return _p0.x(); else return _p0.y(); } chart_line::pos_behaviors chart_line::behavior() const { return _behavior; } void chart_line::set_behavior(pos_behaviors behavior) { _behavior = behavior; set_pos(pos()); } void chart_line::set_width(qreal value) { prepareGeometryChange(); _pen.setWidth(value); } qreal chart_line::width() const { return _pen.width(); } QVariant chart_line::itemChange(GraphicsItemChange change, const QVariant &value) { if (change == ItemPositionChange) { blockSignals(true); QVariant value0 = chart::instrument::primitive::line::itemChange(change, value); blockSignals(false); qreal x = pos(); // emit get_nearest_x(x, _behavior); set_pos(x); emit signal_moved(); return value0; } return chart::instrument::primitive::line::itemChange(change, value); } } }