mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-27 20:58:47 +00:00
b5aac29cea
To enable rudimentary theming, collect all colors in a new theme class. The class has to be passed down to the various items. In general the items save a reference to the them in the constructor. Alternatively, they might also just query the StatsView everytime they need to access a color. For now, it's hard the say what is preferred: a reference per item or a function call per invokation? Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
38 lines
1.1 KiB
C++
38 lines
1.1 KiB
C++
// SPDX-License-Identifier: GPL-2.0
|
|
#include "statsgrid.h"
|
|
#include "chartitem.h"
|
|
#include "statsaxis.h"
|
|
#include "statscolors.h"
|
|
#include "statsview.h"
|
|
#include "zvalues.h"
|
|
|
|
static const double gridWidth = 1.0;
|
|
|
|
StatsGrid::StatsGrid(StatsView &view, const StatsAxis &xAxis, const StatsAxis &yAxis)
|
|
: view(view), theme(view.getCurrentTheme()), xAxis(xAxis), yAxis(yAxis)
|
|
{
|
|
}
|
|
|
|
void StatsGrid::updatePositions()
|
|
{
|
|
std::vector<double> xtics = xAxis.ticksPositions();
|
|
std::vector<double> ytics = yAxis.ticksPositions();
|
|
|
|
// We probably should be smarter and reuse existing lines.
|
|
// For now, this does it.
|
|
for (auto &line: lines)
|
|
view.deleteChartItem(line);
|
|
lines.clear();
|
|
|
|
if (xtics.empty() || ytics.empty())
|
|
return;
|
|
|
|
for (double x: xtics) {
|
|
lines.push_back(view.createChartItem<ChartLineItem>(ChartZValue::Grid, theme.gridColor, gridWidth));
|
|
lines.back()->setLine(QPointF(x, ytics.front()), QPointF(x, ytics.back()));
|
|
}
|
|
for (double y: ytics) {
|
|
lines.push_back(view.createChartItem<ChartLineItem>(ChartZValue::Grid, theme.gridColor, gridWidth));
|
|
lines.back()->setLine(QPointF(xtics.front(), y), QPointF(xtics.back(), y));
|
|
}
|
|
}
|