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>
51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
// SPDX-License-Identifier: GPL-2.0
|
|
// A small custom scatter series, where every item represents a dive
|
|
// The original QScatterSeries was buggy and distinctly slower
|
|
#ifndef SCATTER_SERIES_H
|
|
#define SCATTER_SERIES_H
|
|
|
|
#include "statshelper.h"
|
|
#include "statsseries.h"
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
class ChartScatterItem;
|
|
struct InformationBox;
|
|
struct StatsVariable;
|
|
struct dive;
|
|
|
|
class ScatterSeries : public StatsSeries {
|
|
public:
|
|
ScatterSeries(StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
|
|
const StatsVariable &varX, const StatsVariable &varY);
|
|
~ScatterSeries();
|
|
|
|
void updatePositions() override;
|
|
bool hover(QPointF pos) override;
|
|
void unhighlight() override;
|
|
|
|
// Note: this expects that all items are added with increasing pos!
|
|
void append(dive *d, double pos, double value);
|
|
|
|
private:
|
|
// Get items under mouse.
|
|
std::vector<int> getItemsUnderMouse(const QPointF &f) const;
|
|
|
|
struct Item {
|
|
ChartItemPtr<ChartScatterItem> item;
|
|
dive *d;
|
|
double pos, value;
|
|
Item(StatsView &view, ScatterSeries *series, dive *d, double pos, double value);
|
|
void updatePosition(ScatterSeries *series);
|
|
void highlight(bool highlight);
|
|
};
|
|
|
|
ChartItemPtr<InformationBox> information;
|
|
std::vector<Item> items;
|
|
std::vector<int> highlighted;
|
|
const StatsVariable &varX;
|
|
const StatsVariable &varY;
|
|
};
|
|
|
|
#endif
|