From 82a0a5362abc262e9f388a0537d2d0fde044f72a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Sun, 2 Nov 2014 10:59:44 +0200 Subject: [PATCH] Refactor|UI|Client: Ownership of notification widgets Now using the UniqueWidgetPtr template. --- doomsday/client/src/clientapp.cpp | 1 + doomsday/client/src/ui/clientwindow.cpp | 7 ++-- .../client/src/ui/dialogs/alertdialog.cpp | 11 ++---- .../client/src/ui/widgets/tutorialwidget.cpp | 15 +++----- doomsday/client/src/updater/updater.cpp | 38 +++++-------------- 5 files changed, 22 insertions(+), 50 deletions(-) diff --git a/doomsday/client/src/clientapp.cpp b/doomsday/client/src/clientapp.cpp index 9c5501c4fc..ec68c3f966 100644 --- a/doomsday/client/src/clientapp.cpp +++ b/doomsday/client/src/clientapp.cpp @@ -208,6 +208,7 @@ DENG2_PIMPL(ClientApp) Sys_Shutdown(); DD_Shutdown(); + updater.reset(); delete worldSys; //delete infineSys; delete winSys; diff --git a/doomsday/client/src/ui/clientwindow.cpp b/doomsday/client/src/ui/clientwindow.cpp index 44bf1ff6fc..c8083ec641 100644 --- a/doomsday/client/src/ui/clientwindow.cpp +++ b/doomsday/client/src/ui/clientwindow.cpp @@ -92,7 +92,7 @@ DENG2_PIMPL(ClientWindow) bool cursorHasBeenHidden; // FPS notifications. - LabelWidget *fpsCounter; + UniqueWidgetPtr fpsCounter; float oldFps; /// @todo Switch dynamically between VR and plain. @@ -120,7 +120,6 @@ DENG2_PIMPL(ClientWindow) , cursorX(new ConstantRule(0)) , cursorY(new ConstantRule(0)) , cursorHasBeenHidden(false) - , fpsCounter(0) , oldFps(0) , contentXf(*i) { @@ -218,7 +217,7 @@ DENG2_PIMPL(ClientWindow) root.add(alerts); // FPS counter for the notification area. - fpsCounter = new LabelWidget; + fpsCounter.reset(new LabelWidget); fpsCounter->setSizePolicy(ui::Expand, ui::Expand); fpsCounter->setAlignment(ui::AlignRight); @@ -474,7 +473,7 @@ DENG2_PIMPL(ClientWindow) void updateFpsNotification(float fps) { - notifications->showOrHide(fpsCounter, self.isFPSCounterVisible()); + notifications->showOrHide(*fpsCounter, self.isFPSCounterVisible()); if(!fequal(oldFps, fps)) { diff --git a/doomsday/client/src/ui/dialogs/alertdialog.cpp b/doomsday/client/src/ui/dialogs/alertdialog.cpp index c8d304faec..1ab06627af 100644 --- a/doomsday/client/src/ui/dialogs/alertdialog.cpp +++ b/doomsday/client/src/ui/dialogs/alertdialog.cpp @@ -83,7 +83,7 @@ DENG_GUI_PIMPL(AlertDialog) } }; - ButtonWidget *notification; + UniqueWidgetPtr notification; MenuWidget *alerts; bool clearOnDismiss; TextStyling styling; @@ -100,7 +100,7 @@ DENG_GUI_PIMPL(AlertDialog) , clearOnDismiss(false) , maxCount(100) { - notification = new ButtonWidget; + notification.reset(new ButtonWidget); notification->setSizePolicy(ui::Expand, ui::Expand); notification->setImage(style().images().image("alert")); notification->setOverrideImageSize(style().fonts().font("default").height().value()); @@ -129,11 +129,6 @@ DENG_GUI_PIMPL(AlertDialog) ~Instance() { - if(!notification->parentWidget()) - { - GuiWidget::destroy(notification); - } - App::config(VAR_AUTOHIDE).audienceForChange() -= this; } @@ -251,7 +246,7 @@ DENG_GUI_PIMPL(AlertDialog) // Change color to indicate new alerts. notification->setImageColor(style().colors().colorf("accent")); - notifs().showOrHide(notification, true); + notifs().showOrHide(*notification, true); // Restart the autohiding timer. if(autoHideAfterSeconds() > 0) diff --git a/doomsday/client/src/ui/widgets/tutorialwidget.cpp b/doomsday/client/src/ui/widgets/tutorialwidget.cpp index 841e73355c..b9d8dcff05 100644 --- a/doomsday/client/src/ui/widgets/tutorialwidget.cpp +++ b/doomsday/client/src/ui/widgets/tutorialwidget.cpp @@ -48,10 +48,10 @@ DENG_GUI_PIMPL(TutorialWidget) }; Step current; - MessageDialog *dlg; + MessageDialog *dlg = nullptr; LabelWidget *highlight; - NotificationAreaWidget *notifs; ///< Fake notifications just for an example. - LabelWidget *exampleAlert; + NotificationAreaWidget *notifs = nullptr; ///< Fake notifications just for an example. + UniqueWidgetPtr exampleAlert; QTimer flashing; bool taskBarInitiallyOpen; Untrapper untrapper; @@ -59,21 +59,16 @@ DENG_GUI_PIMPL(TutorialWidget) Instance(Public *i) : Base(i) , current(Welcome) - , dlg(0) - , notifs(0) - , exampleAlert(0) , taskBarInitiallyOpen(ClientWindow::main().taskBar().isOpen()) , untrapper(ClientWindow::main()) { // Create an example alert (lookalike). /// @todo There could be a class for an alert notification widget. -jk - exampleAlert = new LabelWidget; + exampleAlert.reset(new LabelWidget); exampleAlert->setSizePolicy(ui::Expand, ui::Expand); exampleAlert->setImage(style().images().image("alert")); exampleAlert->setOverrideImageSize(style().fonts().font("default").height().value()); exampleAlert->setImageColor(style().colors().colorf("accent")); - exampleAlert->hide(); - self.add(exampleAlert); // Highlight rectangle. self.add(highlight = new LabelWidget); @@ -203,7 +198,7 @@ DENG_GUI_PIMPL(TutorialWidget) notifs = new NotificationAreaWidget("tutorial-notifications"); notifs->useDefaultPlacement(ClientWindow::main().game().rule()); root().addOnTop(notifs); - notifs->showChild(exampleAlert); + notifs->showChild(*exampleAlert); dlg->title().setText(tr("Notifications")); dlg->message().setText(tr("The notification area shows the current notifications. " diff --git a/doomsday/client/src/updater/updater.cpp b/doomsday/client/src/updater/updater.cpp index da03a04363..05332ecb68 100644 --- a/doomsday/client/src/updater/updater.cpp +++ b/doomsday/client/src/updater/updater.cpp @@ -153,28 +153,22 @@ class UpdaterStatusWidget : public ProgressWidget ButtonWidget *_clickable; }; -DENG2_PIMPL(Updater), -DENG2_OBSERVES(App, StartupComplete) +DENG2_PIMPL(Updater) +, DENG2_OBSERVES(App, StartupComplete) { - QNetworkAccessManager *network; - DownloadDialog *download; - UpdaterStatusWidget *status; + QNetworkAccessManager *network = nullptr; + DownloadDialog *download = nullptr; // not owned (in the widget tree, if exists) + UniqueWidgetPtr status; + UpdateAvailableDialog *availableDlg = nullptr; ///< If currently open (not owned). bool alwaysShowNotification; - UpdateAvailableDialog *availableDlg; ///< If currently open (not owned). - bool savingSuggested; + bool savingSuggested = false; VersionInfo latestVersion; QString latestPackageUri; QString latestPackageUri2; // fallback location QString latestLogUri; - Instance(Public *up) - : Base(up), - network(0), - download(0), - status(0), - availableDlg(0), - savingSuggested(false) + Instance(Public *i) : Base(i) { network = new QNetworkAccessManager(thisPublic); @@ -196,18 +190,6 @@ DENG2_OBSERVES(App, StartupComplete) st.setPathToDeleteAtStartup(""); } - ~Instance() - { - //if(settingsDlg) delete settingsDlg; - if(!status->parentWidget()) - { - GuiWidget::destroy(status); - } - - // Delete the ongoing download. - if(download) delete download; - } - void setupUI() { status = new UpdaterStatusWidget; @@ -286,7 +268,7 @@ DENG2_OBSERVES(App, StartupComplete) void showNotification(bool show) { - ClientWindow::main().notifications().showOrHide(status, show); + ClientWindow::main().notifications().showOrHide(*status, show); } void showCheckingNotification() @@ -426,7 +408,7 @@ DENG2_OBSERVES(App, StartupComplete) void startDownload() { - DENG2_ASSERT(download == 0); + DENG2_ASSERT(!download); // The notification provides access to the download dialog. showDownloadNotification();