116 lines
2.7 KiB
C++
116 lines
2.7 KiB
C++
|
#include "gtl_gui_chart_marker.h"
|
||
|
|
||
|
namespace gtl
|
||
|
{
|
||
|
namespace gui
|
||
|
{
|
||
|
chart_marker::chart_marker(::chart::series::series* parent, bool is_dark_theme)
|
||
|
: ::chart::instrument::instrument(parent)
|
||
|
, _idx(-1)
|
||
|
{
|
||
|
if(is_dark_theme)
|
||
|
_color = Qt::white;
|
||
|
else
|
||
|
_color = Qt::black;
|
||
|
|
||
|
_line = new chart_marker_line(parent, _idx);
|
||
|
::chart::instrument::instrument::add(_line);
|
||
|
connect(_line, &chart_marker_line::get_nearest_x, this, &chart_marker::get_nearest_x);
|
||
|
connect(_line, &chart_marker_line::get_series_data, this, &chart_marker::get_series_data);
|
||
|
connect(_line, &chart_marker_line::signal_moved, this, &chart_marker::line_moved);
|
||
|
|
||
|
/*
|
||
|
_label = new chart_marker_label(parent);
|
||
|
_label->set_color(Qt::black);
|
||
|
::chart::instrument::instrument::add(_label);
|
||
|
*/
|
||
|
}
|
||
|
|
||
|
chart_marker::~chart_marker()
|
||
|
{
|
||
|
emit deleting();
|
||
|
}
|
||
|
|
||
|
void chart_marker::set_pos(QPoint p)
|
||
|
{
|
||
|
qreal x = _series->axis_x()->map_from_widget(p.x());
|
||
|
|
||
|
_line->set_pos(x);
|
||
|
}
|
||
|
|
||
|
void chart_marker::set_pos(qreal x)
|
||
|
{
|
||
|
_line->set_pos(x);
|
||
|
}
|
||
|
|
||
|
void chart_marker::set_pos()
|
||
|
{
|
||
|
set_pos(pos());
|
||
|
}
|
||
|
|
||
|
qreal chart_marker::pos() const
|
||
|
{
|
||
|
return _line->pos();
|
||
|
}
|
||
|
|
||
|
bool chart_marker::contains(const QPointF& point) const
|
||
|
{
|
||
|
return _line->contains(point);
|
||
|
}
|
||
|
|
||
|
void chart_marker::set_idx(int idx)
|
||
|
{
|
||
|
if(idx != _idx)
|
||
|
{
|
||
|
_line->set_idx(idx);
|
||
|
_idx = idx;
|
||
|
|
||
|
emit idx_changed();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int chart_marker::idx() const
|
||
|
{
|
||
|
return _line->idx();
|
||
|
}
|
||
|
|
||
|
qreal chart_marker::value(int series_idx)
|
||
|
{
|
||
|
QVariantList values;
|
||
|
emit get_series_data(_line->pos(), false, values);
|
||
|
|
||
|
return values[series_idx*2].toDouble();
|
||
|
}
|
||
|
|
||
|
void chart_marker::set_width(qreal width)
|
||
|
{
|
||
|
_line->set_width(width);
|
||
|
}
|
||
|
|
||
|
qreal chart_marker::width() const
|
||
|
{
|
||
|
return _line->width();
|
||
|
}
|
||
|
|
||
|
void chart_marker::add(const QPointF &/*point*/)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
void chart_marker::draw(const QPointF &/*point*/)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
void chart_marker::line_moved()
|
||
|
{
|
||
|
emit position_changed();
|
||
|
}
|
||
|
|
||
|
void chart_marker::set_color(const QColor &color)
|
||
|
{
|
||
|
::chart::instrument::instrument::set_color(color);
|
||
|
}
|
||
|
}
|
||
|
}
|