desktop: do own memory management of quadrant widgets

The memory management of the quadrant widgets is a total mess:
When setting the widget, the QSplitters take ownership, which
means that they will delete the widget in their destructor.

This is inherently incompatible with singletons, which must
not be deleted.

To avoid all these troubles, remove the widgets from the
QSplitters in the desctructor of the MainWindow. This of
course means that we now have to take care about deletion
of the widgets.

For local widgets use std::unique_ptr, for singletons use
a static variable that is deleted on application exit.

Sadly, for the map widget we can't use a normal singleton,
because the QML MapWidget's memory management is buggy.
Add a comment in the source code explaining this.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-12-18 12:01:36 +01:00 committed by Dirk Hohndel
parent 8a36a100ce
commit 64dae43bdd
3 changed files with 59 additions and 43 deletions

View file

@ -30,12 +30,14 @@ class DiveTripModel;
class QItemSelection;
class DiveListView;
class MainTab;
class MapWidget;
class QWebView;
class QSettings;
class UpdateManager;
class UserManual;
class PlannerWidgets;
class ProfileWidget2;
class StatsWidget;
class LocationInformationWidget;
class MainWindow : public QMainWindow {
@ -63,8 +65,11 @@ public:
std::unique_ptr<MainTab> mainTab;
std::unique_ptr<PlannerWidgets> plannerWidgets;
std::unique_ptr<StatsWidget> statistics;
ProfileWidget2 *graphics;
DiveListView *diveList;
std::unique_ptr<DiveListView> diveList;
std::unique_ptr<QWidget> profileContainer;
std::unique_ptr<MapWidget> mapWidget;
private
slots:
/* file menu action */
@ -152,8 +157,8 @@ slots:
private:
Ui::MainWindow ui;
FilterWidget filterWidget;
QSplitter *topSplitter;
QSplitter *bottomSplitter;
std::unique_ptr<QSplitter> topSplitter;
std::unique_ptr<QSplitter> bottomSplitter;
QAction *actionNextDive;
QAction *actionPreviousDive;
QAction *undoAction;
@ -215,7 +220,7 @@ private:
Quadrants applicationState[(size_t)ApplicationState::Count];
static void addWidgets(const Quadrant &);
bool userMayChangeAppState() const;
void setQuadrantWidget(const Quadrant &q, QSplitter *splitter);
void setQuadrantWidget(const Quadrant &q, QSplitter &splitter);
void registerApplicationState(ApplicationState state, Quadrants q);
QMenu *connections;