2021-01-05 12:51:39 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include "statsgrid.h"
|
2021-01-14 11:37:26 +00:00
|
|
|
#include "chartitem.h"
|
2021-01-05 12:51:39 +00:00
|
|
|
#include "statsaxis.h"
|
|
|
|
#include "statscolors.h"
|
2021-01-14 11:37:26 +00:00
|
|
|
#include "statsview.h"
|
2021-01-05 12:51:39 +00:00
|
|
|
#include "zvalues.h"
|
|
|
|
|
|
|
|
static const double gridWidth = 1.0;
|
|
|
|
|
2021-01-14 11:37:26 +00:00
|
|
|
StatsGrid::StatsGrid(StatsView &view, const StatsAxis &xAxis, const StatsAxis &yAxis)
|
|
|
|
: view(view), xAxis(xAxis), yAxis(yAxis)
|
2021-01-05 12:51:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void StatsGrid::updatePositions()
|
|
|
|
{
|
|
|
|
std::vector<double> xtics = xAxis.ticksPositions();
|
|
|
|
std::vector<double> ytics = yAxis.ticksPositions();
|
2021-01-14 11:37:26 +00:00
|
|
|
|
|
|
|
// We probably should be smarter and reuse existing lines.
|
|
|
|
// For now, this does it.
|
2021-01-18 21:29:34 +00:00
|
|
|
for (auto &line: lines)
|
|
|
|
view.deleteChartItem(line);
|
2021-01-05 12:51:39 +00:00
|
|
|
lines.clear();
|
2021-01-18 21:29:34 +00:00
|
|
|
|
2021-01-05 12:51:39 +00:00
|
|
|
if (xtics.empty() || ytics.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (double x: xtics) {
|
2021-01-14 11:37:26 +00:00
|
|
|
lines.push_back(view.createChartItem<ChartLineItem>(ChartZValue::Grid, gridColor, gridWidth));
|
|
|
|
lines.back()->setLine(QPointF(x, ytics.front()), QPointF(x, ytics.back()));
|
2021-01-05 12:51:39 +00:00
|
|
|
}
|
|
|
|
for (double y: ytics) {
|
2021-01-14 11:37:26 +00:00
|
|
|
lines.push_back(view.createChartItem<ChartLineItem>(ChartZValue::Grid, gridColor, gridWidth));
|
|
|
|
lines.back()->setLine(QPointF(xtics.front(), y), QPointF(xtics.back(), y));
|
2021-01-05 12:51:39 +00:00
|
|
|
}
|
|
|
|
}
|