diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-12-18 12:01:36 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-02-06 10:00:39 -0800 |
commit | 64dae43bddf2894f0891b56e5f419e325309a66f (patch) | |
tree | 07fd968cfdf199483ea69db0d87610b4e1ab4615 /desktop-widgets/mainwindow.h | |
parent | 8a36a100ce073decb5cb236efbd7c4ce93f5abc2 (diff) | |
download | subsurface-64dae43bddf2894f0891b56e5f419e325309a66f.tar.gz |
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>
Diffstat (limited to 'desktop-widgets/mainwindow.h')
-rw-r--r-- | desktop-widgets/mainwindow.h | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/desktop-widgets/mainwindow.h b/desktop-widgets/mainwindow.h index 2233a6090..617e53a09 100644 --- a/desktop-widgets/mainwindow.h +++ b/desktop-widgets/mainwindow.h @@ -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; |