summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-07-30 20:59:07 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-07-30 13:55:23 -0700
commit7fe76a5dbdef4a833122e0311191dd51896575f4 (patch)
tree34b1d4f8a7c2d6d4b6b97a142ca27937c4ec4284
parent4bdd811f06096c2420a05dd3cc78fffbd7f3a663 (diff)
downloadsubsurface-7fe76a5dbdef4a833122e0311191dd51896575f4.tar.gz
Cleanup: Make WindowsTitleUpdate a global object
WindowsTitleUpdate is such a trivial object (a QObject with a single signal and no own state), that it's not really understandable why it would need all that "singleton" boiler-plate. Just make it a default constructed/destructed global object. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/windowtitleupdate.cpp28
-rw-r--r--core/windowtitleupdate.h9
-rw-r--r--desktop-widgets/mainwindow.cpp3
-rw-r--r--desktop-widgets/mainwindow.h2
-rw-r--r--export-html.cpp2
5 files changed, 5 insertions, 39 deletions
diff --git a/core/windowtitleupdate.cpp b/core/windowtitleupdate.cpp
index 810acd4dc..a0cc277b3 100644
--- a/core/windowtitleupdate.cpp
+++ b/core/windowtitleupdate.cpp
@@ -1,33 +1,9 @@
// SPDX-License-Identifier: GPL-2.0
#include "windowtitleupdate.h"
-WindowTitleUpdate *WindowTitleUpdate::m_instance = NULL;
-
-WindowTitleUpdate::WindowTitleUpdate(QObject *parent) : QObject(parent)
-{
- Q_ASSERT_X(m_instance == NULL, "WindowTitleUpdate", "WindowTitleUpdate recreated!");
-
- m_instance = this;
-}
-
-WindowTitleUpdate *WindowTitleUpdate::instance()
-{
- return m_instance;
-}
-
-WindowTitleUpdate::~WindowTitleUpdate()
-{
- m_instance = NULL;
-}
-
-void WindowTitleUpdate::emitSignal()
-{
- emit updateTitle();
-}
+WindowTitleUpdate windowTitleUpdate;
extern "C" void updateWindowTitle()
{
- WindowTitleUpdate *wt = WindowTitleUpdate::instance();
- if (wt)
- wt->emitSignal();
+ emit windowTitleUpdate.updateTitle();
}
diff --git a/core/windowtitleupdate.h b/core/windowtitleupdate.h
index dcda821e9..f08467789 100644
--- a/core/windowtitleupdate.h
+++ b/core/windowtitleupdate.h
@@ -7,15 +7,10 @@
class WindowTitleUpdate : public QObject
{
Q_OBJECT
-public:
- explicit WindowTitleUpdate(QObject *parent = 0);
- ~WindowTitleUpdate();
- static WindowTitleUpdate *instance();
- void emitSignal();
signals:
void updateTitle();
-private:
- static WindowTitleUpdate *m_instance;
};
+extern WindowTitleUpdate windowTitleUpdate;
+
#endif // WINDOWTITLEUPDATE_H
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index 64ea2ef6d..9da89f8f5 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -218,8 +218,7 @@ MainWindow::MainWindow() : QMainWindow(),
connect(information(), SIGNAL(diveSiteChanged(struct dive_site *)), mapWidget, SLOT(centerOnDiveSite(struct dive_site *)));
connect(this, &MainWindow::showError, ui.mainErrorMessage, &NotificationWidget::showError, Qt::AutoConnection);
- wtu = new WindowTitleUpdate();
- connect(WindowTitleUpdate::instance(), SIGNAL(updateTitle()), this, SLOT(setAutomaticTitle()));
+ connect(&windowTitleUpdate, &WindowTitleUpdate::updateTitle, this, &MainWindow::setAutomaticTitle);
#ifdef NO_PRINTING
plannerDetails->printPlan()->hide();
ui.menuFile->removeAction(ui.actionPrint);
diff --git a/desktop-widgets/mainwindow.h b/desktop-widgets/mainwindow.h
index 8c7347fd3..da3396981 100644
--- a/desktop-widgets/mainwindow.h
+++ b/desktop-widgets/mainwindow.h
@@ -17,7 +17,6 @@
#include "ui_mainwindow.h"
#include "ui_plannerDetails.h"
#include "desktop-widgets/notificationwidget.h"
-#include "core/windowtitleupdate.h"
#include "core/gpslocation.h"
#define NUM_RECENT_FILES 4
@@ -253,7 +252,6 @@ private:
QHash<QByteArray, WidgetForQuadrant> applicationState;
QHash<QByteArray, PropertiesForQuadrant> stateProperties;
- WindowTitleUpdate *wtu;
GpsLocation *locationProvider;
QMenu *connections;
QAction *share_on_fb;
diff --git a/export-html.cpp b/export-html.cpp
index 652cb2c93..2371d5551 100644
--- a/export-html.cpp
+++ b/export-html.cpp
@@ -13,7 +13,6 @@
#include "git2.h"
#include "core/subsurfacestartup.h"
#include "core/divelogexportlogic.h"
-#include "core/windowtitleupdate.h"
#include "core/statistics.h"
int main(int argc, char **argv)
@@ -42,7 +41,6 @@ int main(int argc, char **argv)
qDebug() << "need --source and --output";
exit(1);
}
- WindowTitleUpdate *wtu = new WindowTitleUpdate();
int ret = parse_file(qPrintable(source));
if (ret) {
fprintf(stderr, "parse_file returned %d\n", ret);