17 #include <QFontDatabase> 21 inline bool operator()(
const double x,
const QPointF& pos)
const 53 bool changed =
_param != par;
68 for (
int i = 0; i <
_marker.size(); i++)
91 double min_Y = std::numeric_limits<double>::max();
92 double max_Y = -min_Y;
93 int visible_points = 0;
95 while (
_marker.size() > curves.size())
101 for (
int i =
_marker.size(); i < curves.size(); i++)
107 double text_X_offset = 0;
109 std::multimap<double, QString> text_lines;
111 for (
int i = 0; i < curves.size(); i++)
120 QColor
color = curve->
pen().color();
122 text_X_offset = rect.width() * 0.02;
131 const QLineF line =
curveLineAt(curve, position.x());
139 double middle_X = (line.p1().x() + line.p2().x()) / 2.0;
141 if (position.x() < middle_X)
148 if (rect.contains(point) &&
_visible)
150 min_Y = std::min(min_Y, point.y());
151 max_Y = std::max(max_Y, point.y());
154 double val = point.y();
160 line = QString(
"<font color=%1>%2</font>").arg(color.name()).
arg(val);
164 QString
value = QString::number(val,
'f', 3);
165 int whitespaces = 8 - value.length();
166 while (whitespaces-- > 0)
167 value.prepend(
" ");
169 line = QString(
"<font color=%1>%2 : %3</font>")
175 text_lines.insert(std::make_pair(val, line));
187 QString text_marker_info;
190 for (
auto it = text_lines.rbegin(); it != text_lines.rend(); it++)
192 text_marker_info += it->second;
193 if (count++ < text_lines.size() - 1)
195 text_marker_info +=
"<br>";
200 QColor background_color =
_plot->palette().background().color();
201 background_color.setAlpha(180);
203 mark_text.
setText(text_marker_info);
205 QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
206 font.setPointSize(9);
216 if (visible_points > 0)
221 double canvas_ratio = rect.width() / double(
_plot->width());
222 double text_width = mark_text.
textSize().width() * canvas_ratio;
245 line.setP1(curve->
sample(index - 1));
246 line.setP2(curve->
sample(index));
void setLineStyle(LineStyle)
Set the line style.
bool operator()(const double x, const QPointF &pos) const
A plot item, that represents a series of points.
void setFont(const QFont &)
const QwtText & title() const
void setValue(double, double)
Set Value.
void setRenderFlags(int)
Change the render flags.
void setText(const QString &, QwtText::TextFormat textFormat=AutoText)
const QwtPlotItemList & itemList() const
A QwtPlotItemList of all attached plot items.
void setBorderPen(const QPen &)
T sample(int index) const
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
QwtSeriesData< T > * data()
A class for drawing symbols.
void setLinePen(const QColor &, qreal width=0.0, Qt::PenStyle=Qt::SolidLine)
virtual QRectF boundingRect() const QWT_OVERRIDE
QwtPlotMarker * _line_marker
constexpr auto count() -> size_t
void setXValue(double)
Set X Value.
A class representing a text.
void setBackgroundBrush(const QBrush &)
void setEnabled(bool enable)
QPointF actualPosition() const
QwtPlotMarker * _text_marker
void setLabel(const QwtText &)
Set the label.
QPointF _prev_trackerpoint
std::vector< QwtPlotMarker * > _marker
virtual void setVisible(bool)
void attach(QwtPlot *plot)
Attach the item to a plot.
void setLabelAlignment(Qt::Alignment)
Set the alignment of the label.
void setYValue(double)
Set Y Value.
virtual QwtScaleMap canvasMap(QwtAxisId) const
virtual size_t dataSize() const QWT_OVERRIDE
void setPosition(const QPointF &pos)
QLineF curveLineAt(const QwtPlotCurve *, double x) const
void setParameter(Parameter par)
A class for drawing markers.