mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Code cleanup: implement window title update via signal
This seems quite convoluted to me but I can't seem to make a more straight forward implementation work. The idea is that core code should never directly call into the UI. So instead the core code (this is C code) calls a helper function. That helper function calls a member function of a class which in return emits a signal. The UI code connects to that signal and acts accordingly when it is received. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
c593dea119
commit
0fa0eb2879
6 changed files with 63 additions and 6 deletions
|
@ -274,6 +274,7 @@ set(SUBSURFACE_CORE_LIB_SRCS
|
||||||
configuredivecomputer.cpp
|
configuredivecomputer.cpp
|
||||||
configuredivecomputerthreads.cpp
|
configuredivecomputerthreads.cpp
|
||||||
divesitehelpers.cpp
|
divesitehelpers.cpp
|
||||||
|
windowtitleupdate.cpp
|
||||||
${SUBSURFACE_PRINTING_SRCS}
|
${SUBSURFACE_PRINTING_SRCS}
|
||||||
${PLATFORM_SRC}
|
${PLATFORM_SRC}
|
||||||
)
|
)
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "usersurvey.h"
|
#include "usersurvey.h"
|
||||||
#include "divesitehelpers.h"
|
#include "divesitehelpers.h"
|
||||||
#include "locationinformation.h"
|
#include "locationinformation.h"
|
||||||
|
#include "windowtitleupdate.h"
|
||||||
#ifndef NO_USERMANUAL
|
#ifndef NO_USERMANUAL
|
||||||
#include "usermanual.h"
|
#include "usermanual.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -148,7 +149,8 @@ MainWindow::MainWindow() : QMainWindow(),
|
||||||
connect(locationInformation, SIGNAL(startEditDiveSite(uint32_t)), globeGps, SLOT(prepareForGetDiveCoordinates()));
|
connect(locationInformation, SIGNAL(startEditDiveSite(uint32_t)), globeGps, SLOT(prepareForGetDiveCoordinates()));
|
||||||
connect(locationInformation, SIGNAL(endEditDiveSite()), globeGps, SLOT(prepareForGetDiveCoordinates()));
|
connect(locationInformation, SIGNAL(endEditDiveSite()), globeGps, SLOT(prepareForGetDiveCoordinates()));
|
||||||
connect(information(), SIGNAL(diveSiteChanged(uint32_t)), globeGps, SLOT(centerOnDiveSite(uint32_t)));
|
connect(information(), SIGNAL(diveSiteChanged(uint32_t)), globeGps, SLOT(centerOnDiveSite(uint32_t)));
|
||||||
|
wtu = new WindowTitleUpdate();
|
||||||
|
connect(WindowTitleUpdate::instance(), SIGNAL(updateTitle()), this, SLOT(setAutomaticTitle()));
|
||||||
#ifdef NO_PRINTING
|
#ifdef NO_PRINTING
|
||||||
plannerDetails->printPlan()->hide();
|
plannerDetails->printPlan()->hide();
|
||||||
ui.menuFile->removeAction(ui.actionPrint);
|
ui.menuFile->removeAction(ui.actionPrint);
|
||||||
|
@ -1439,6 +1441,11 @@ QString MainWindow::displayedFilename(QString fullFilename)
|
||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::setAutomaticTitle()
|
||||||
|
{
|
||||||
|
setTitle();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::setTitle(enum MainWindowTitleFormat format)
|
void MainWindow::setTitle(enum MainWindowTitleFormat format)
|
||||||
{
|
{
|
||||||
switch (format) {
|
switch (format) {
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include "notificationwidget.h"
|
#include "notificationwidget.h"
|
||||||
|
#include "windowtitleupdate.h"
|
||||||
|
|
||||||
struct DiveList;
|
struct DiveList;
|
||||||
class QSortFilterProxyModel;
|
class QSortFilterProxyModel;
|
||||||
|
@ -171,6 +172,7 @@ slots:
|
||||||
void on_actionConfigure_Dive_Computer_triggered();
|
void on_actionConfigure_Dive_Computer_triggered();
|
||||||
void enableDiveSiteEdit(uint32_t id);
|
void enableDiveSiteEdit(uint32_t id);
|
||||||
void setDefaultState();
|
void setDefaultState();
|
||||||
|
void setAutomaticTitle();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *);
|
void closeEvent(QCloseEvent *);
|
||||||
|
@ -228,6 +230,7 @@ private:
|
||||||
};
|
};
|
||||||
QHash<QByteArray, WidgetForQuadrant> applicationState;
|
QHash<QByteArray, WidgetForQuadrant> applicationState;
|
||||||
QByteArray currentApplicationState;
|
QByteArray currentApplicationState;
|
||||||
|
WindowTitleUpdate *wtu;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
@ -1073,11 +1073,6 @@ extern "C" bool canReachCloudServer()
|
||||||
return CheckCloudConnection::checkServer();
|
return CheckCloudConnection::checkServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void updateWindowTitle()
|
|
||||||
{
|
|
||||||
MainWindow::instance()->setTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void subsurface_mkdir(const char *dir)
|
extern "C" void subsurface_mkdir(const char *dir)
|
||||||
{
|
{
|
||||||
QDir directory;
|
QDir directory;
|
||||||
|
|
31
windowtitleupdate.cpp
Normal file
31
windowtitleupdate.cpp
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#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();
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void updateWindowTitle()
|
||||||
|
{
|
||||||
|
WindowTitleUpdate *wt = WindowTitleUpdate::instance();
|
||||||
|
wt->emitSignal();
|
||||||
|
}
|
20
windowtitleupdate.h
Normal file
20
windowtitleupdate.h
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#ifndef WINDOWTITLEUPDATE_H
|
||||||
|
#define WINDOWTITLEUPDATE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // WINDOWTITLEUPDATE_H
|
Loading…
Add table
Reference in a new issue