statistics: refactor QSG memory management

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>
This commit is contained in:
Berthold Stoeger 2021-01-18 22:29:34 +01:00 committed by bstoeger
parent 9d3de1801e
commit db69c38245
17 changed files with 245 additions and 88 deletions

View file

@ -3,6 +3,7 @@
#ifndef PIE_SERIES_H
#define PIE_SERIES_H
#include "statshelper.h"
#include "statsseries.h"
#include <memory>
@ -33,12 +34,12 @@ private:
// Get item under mouse pointer, or -1 if none
int getItemUnderMouse(const QPointF &f) const;
std::unique_ptr<ChartPieItem> item;
ChartItemPtr<ChartPieItem> item;
QString categoryName;
std::vector<QString> makeInfo(int idx) const;
struct Item {
std::unique_ptr<ChartTextItem> innerLabel, outerLabel;
ChartItemPtr<ChartTextItem> innerLabel, outerLabel;
QString name;
double angleFrom, angleTo; // In fraction of total
int count;
@ -58,7 +59,7 @@ private:
};
std::vector<OtherItem> other;
std::unique_ptr<InformationBox> information;
ChartItemPtr<InformationBox> information;
QPointF center; // center of drawing area
double radius; // radius of pie
int highlighted;