diff options
author | Lubomir I. Ivanov <neolit123@gmail.com> | 2014-03-11 18:31:00 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-03-12 12:12:13 -0700 |
commit | 5b3dab719e44f5c20304ed48c5df35f8e115c28b (patch) | |
tree | 11ab6f17ef262e6938fe24a81640189b8267ad02 | |
parent | 4abe9d5c8b99049c775f3ca9dbd66dbafea6f98c (diff) | |
download | subsurface-5b3dab719e44f5c20304ed48c5df35f8e115c28b.tar.gz |
MainWindow: maintain one window instance of the yearly statistics
This is a bit tricky because we are using a plain widget for
a window and don't have a class for it (req. more source files).
Also for the table model to update we need to create a new
YearlyStatisticsModel instance each time. At least, in that regard
we can re-create the model each time refreshDisplay() is called.
This patch adds a couple of private variables that are used
to manage the memory of the yearly statistics model and window
and also close that same window on MainWindow::closeEvent().
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-ui/mainwindow.cpp | 41 | ||||
-rw-r--r-- | qt-ui/mainwindow.h | 2 |
2 files changed, 34 insertions, 9 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 426e979f7..4d4d0baa2 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -44,6 +44,8 @@ MainWindow::MainWindow() : QMainWindow(), actionNextDive(0), actionPreviousDive(0), helpView(0), + yearlyStats(0), + yearlyStatsModel(0), state(VIEWALL) { Q_ASSERT_X(m_Instance == NULL, "MainWindow", "MainWindow recreated!"); @@ -110,6 +112,13 @@ void MainWindow::refreshDisplay(bool recreateDiveList) ui.ListWidget->reload(DiveTripModel::CURRENT); ui.ListWidget->setFocus(); WSInfoModel::instance()->updateInfo(); + // refresh the yearly stats if the window has an instance + if (yearlyStats) { + if (yearlyStatsModel) + delete yearlyStatsModel; + yearlyStatsModel = new YearlyStatisticsModel(); + yearlyStats->setModel(yearlyStatsModel); + } } void MainWindow::current_dive_changed(int divenr) @@ -386,15 +395,23 @@ void MainWindow::on_actionAutoGroup_triggered() void MainWindow::on_actionYearlyStatistics_triggered() { - QTreeView *view = new QTreeView(); - QAbstractItemModel *model = new YearlyStatisticsModel(); - view->setModel(model); - view->setWindowModality(Qt::NonModal); - view->setMinimumWidth(600); - view->setAttribute(Qt::WA_QuitOnClose, false); - view->setWindowTitle(tr("Yearly Statistics")); - view->setWindowIcon(QIcon(":subsurface-icon")); - view->show(); + // create the widget only once + if (!yearlyStats) { + yearlyStats = new QTreeView(); + yearlyStats->setWindowModality(Qt::NonModal); + yearlyStats->setMinimumWidth(600); + yearlyStats->setWindowTitle(tr("Yearly Statistics")); + yearlyStats->setWindowIcon(QIcon(":subsurface-icon")); + } + /* problem here is that without more MainWindow variables or a separate YearlyStatistics + * class the user needs to close the window/widget and re-open it for it to update. + */ + if (yearlyStatsModel) + delete yearlyStatsModel; + yearlyStatsModel = new YearlyStatisticsModel(); + yearlyStats->setModel(yearlyStatsModel); + yearlyStats->raise(); + yearlyStats->show(); } #define BEHAVIOR QList<int>() @@ -672,6 +689,12 @@ void MainWindow::closeEvent(QCloseEvent *event) helpView->deleteLater(); } + if (yearlyStats && yearlyStats->isVisible()) { + yearlyStats->close(); + yearlyStats->deleteLater(); + yearlyStatsModel->deleteLater(); + } + if (unsaved_changes() && (askSaveChanges() == false)) { event->ignore(); return; diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 94655e516..8244d0a0f 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -156,6 +156,8 @@ private: QAction *actionNextDive; QAction *actionPreviousDive; UserManual *helpView; + QTreeView *yearlyStats; + QAbstractItemModel *yearlyStatsModel; CurrentState state; QString filter(); static MainWindow *m_Instance; |