test_sdk/gui/gtl_gui_chart_axis_y.cpp

85 lines
2.5 KiB
C++
Raw Permalink Normal View History

#include "gtl_gui_chart_axis_y.h"
namespace gtl
{
namespace gui
{
chart_axis_y::chart_axis_y(qreal pos_min, qreal pos_max)
: ::chart::axis_vert(down_to_up, false)
{
_pos_min = pos_min;
_pos_max = pos_max;
}
void chart_axis_y::save(QDomElement &root_element)
{
root_element.setAttribute("min", min());
root_element.setAttribute("max", max());
}
void chart_axis_y::load(const QDomElement &root_element)
{
set_range(root_element.attribute("min", "-1").toDouble(), root_element.attribute("max", "1").toDouble());
}
void chart_axis_y::set_theme(bool is_dack)
{
prepareGeometryChange();
if (is_dack)
_color_labels = Qt::white;
else
_color_labels = Qt::black;
}
void chart_axis_y::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
::chart::axis_vert::paint(painter, option, widget);
QList<chart_series*> series;
emit get_series(series);
QRectF boundary = boundingRect();
int left = boundary.right();
int width = 0;
int height = 0;
int y = 5;
for (auto s: series)
{
if (!s->isVisible())
continue;
QRectF rect(boundary.right() - 105, boundary.top() + y, 100, 20);
QString text = s->name();
int flags_alignment = Qt::AlignRight | Qt::AlignTop;
painter->setPen(s->color());
rect = painter->boundingRect(rect, flags_alignment, text);
if (rect.left() < left)
left = rect.left();
draw_label(painter, rect,flags_alignment, s->color(), text);
/*
QString unit = "";
if (!unit.isEmpty())
{
QRectF r = painter->boundingRect(QRectF(), Qt::AlignCenter, unit);
width += r.width() + 10;
if (r.height() > height)
height = r.height();
}
*/
y += 15;
}
}
}
}