mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
db69c38245
The code was wrong, because it deleted the ChartItems in the main UI thread, not the render thread. This would delete the QSG nodes in the UI thread and then crash on mobile. Therefore refactor this part of the code by adding the items to be deleted to a list that will be deleted by the render thread. As a drop in replacement of std::unique_ptr, implement a silly ChartItemPtr class, which auto-initializes to null. This turns the deterministic and easily controlled memory management into a steaming pile of insanity. Obviously, this can be made much more elegant, but this has to do for now. 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), 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, 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, gridColor, gridWidth));
|
|
lines.back()->setLine(QPointF(xtics.front(), y), QPointF(xtics.back(), y));
|
|
}
|
|
}
|