mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-27 20:58:47 +00:00
desktop: fold ApplicationState into MainWindow
The application state is a desktop-only thing. The mobile UI also has its application state, but that is something completely different. The last remaining user of the application state was to flag whether the planner is active. Since this has all been unglobalized, the ApplicationState structure can be moved from core to the desktop UI. And there it can be made local to the MainWindow class. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
80c92acc33
commit
5b3cb5898f
10 changed files with 27 additions and 56 deletions
|
@ -28,7 +28,6 @@ SOURCES += subsurface-mobile-main.cpp \
|
|||
core/qtserialbluetooth.cpp \
|
||||
core/plannernotes.c \
|
||||
core/uemis-downloader.c \
|
||||
core/applicationstate.cpp \
|
||||
core/qthelper.cpp \
|
||||
core/checkcloudconnection.cpp \
|
||||
core/color.cpp \
|
||||
|
|
|
@ -37,8 +37,6 @@ endif()
|
|||
|
||||
# compile the core library part in C, part in C++
|
||||
set(SUBSURFACE_CORE_LIB_SRCS
|
||||
applicationstate.cpp
|
||||
applicationstate.h
|
||||
checkcloudconnection.cpp
|
||||
checkcloudconnection.h
|
||||
cloudstorage.cpp
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "applicationstate.h"
|
||||
|
||||
static ApplicationState appState = (ApplicationState)-1; // Set to an invalid value
|
||||
|
||||
ApplicationState getAppState()
|
||||
{
|
||||
return appState;
|
||||
}
|
||||
|
||||
void setAppState(ApplicationState state)
|
||||
{
|
||||
appState = state;
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#ifndef APPLICATIONSTATE_H
|
||||
#define APPLICATIONSTATE_H
|
||||
|
||||
// By using an enum class, the enum entries don't polute the global namespace.
|
||||
// Moreover, they are strongly typed. This means that they are not auto-converted
|
||||
// to integer types if e.g. used as array-indices.
|
||||
enum class ApplicationState {
|
||||
Default,
|
||||
EditDive,
|
||||
PlanDive,
|
||||
EditPlannedDive,
|
||||
EditDiveSite,
|
||||
FilterDive,
|
||||
Statistics,
|
||||
MapMaximized,
|
||||
ProfileMaximized,
|
||||
ListMaximized,
|
||||
InfoMaximized,
|
||||
Count
|
||||
};
|
||||
|
||||
ApplicationState getAppState();
|
||||
void setAppState(ApplicationState state);
|
||||
|
||||
#endif
|
|
@ -13,7 +13,6 @@
|
|||
#include "planner.h"
|
||||
#include "subsurface-time.h"
|
||||
#include "gettextfromc.h"
|
||||
#include "applicationstate.h"
|
||||
#include "metadata.h"
|
||||
#include "exif.h"
|
||||
#include "file.h"
|
||||
|
|
|
@ -181,7 +181,7 @@ void FilterWidget::clearFilter()
|
|||
|
||||
void FilterWidget::closeFilter()
|
||||
{
|
||||
MainWindow::instance()->setApplicationState(ApplicationState::Default);
|
||||
MainWindow::instance()->setApplicationState(MainWindow::ApplicationState::Default);
|
||||
}
|
||||
|
||||
FilterData FilterWidget::createFilterData() const
|
||||
|
|
|
@ -219,7 +219,7 @@ void LocationInformationWidget::acceptChanges()
|
|||
|
||||
MainWindow::instance()->diveList->setEnabled(true);
|
||||
MainWindow::instance()->setEnabledToolbar(true);
|
||||
MainWindow::instance()->setApplicationState(ApplicationState::Default);
|
||||
MainWindow::instance()->setApplicationState(MainWindow::ApplicationState::Default);
|
||||
DiveFilter::instance()->stopFilterDiveSites();
|
||||
|
||||
// Subtlety alert: diveSite must be cleared *after* exiting the dive-site mode.
|
||||
|
|
|
@ -112,6 +112,7 @@ extern "C" void showErrorFromC(char *buf)
|
|||
}
|
||||
|
||||
MainWindow::MainWindow() : QMainWindow(),
|
||||
appState((ApplicationState)-1), // Invalid state
|
||||
actionNextDive(nullptr),
|
||||
actionPreviousDive(nullptr),
|
||||
#ifndef NO_USERMANUAL
|
||||
|
@ -653,8 +654,7 @@ void MainWindow::updateLastUsedDir(const QString &dir)
|
|||
void MainWindow::on_actionPrint_triggered()
|
||||
{
|
||||
#ifndef NO_PRINTING
|
||||
bool in_planner = getAppState() == ApplicationState::PlanDive ||
|
||||
getAppState() == ApplicationState::EditPlannedDive;
|
||||
bool in_planner = appState == ApplicationState::PlanDive || appState == ApplicationState::EditPlannedDive;
|
||||
PrintDialog dlg(in_planner, this);
|
||||
|
||||
dlg.exec();
|
||||
|
@ -1132,7 +1132,7 @@ void MainWindow::writeSettings()
|
|||
settings.setValue("geometry", saveGeometry());
|
||||
settings.setValue("windowState", saveState());
|
||||
settings.setValue("maximized", isMaximized());
|
||||
settings.setValue("lastState", (int)getAppState());
|
||||
settings.setValue("lastState", (int)appState);
|
||||
saveSplitterSizes();
|
||||
settings.endGroup();
|
||||
}
|
||||
|
@ -1562,14 +1562,14 @@ void MainWindow::on_actionFilterTags_triggered()
|
|||
{
|
||||
if (!userMayChangeAppState())
|
||||
return;
|
||||
setApplicationState(getAppState() == ApplicationState::FilterDive ? ApplicationState::Default : ApplicationState::FilterDive);
|
||||
setApplicationState(appState == ApplicationState::FilterDive ? ApplicationState::Default : ApplicationState::FilterDive);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionStats_triggered()
|
||||
{
|
||||
if (!userMayChangeAppState())
|
||||
return;
|
||||
setApplicationState(getAppState() == ApplicationState::Statistics ? ApplicationState::Default : ApplicationState::Statistics);
|
||||
setApplicationState(appState == ApplicationState::Statistics ? ApplicationState::Default : ApplicationState::Statistics);
|
||||
}
|
||||
|
||||
void MainWindow::registerApplicationState(ApplicationState state, Quadrants q)
|
||||
|
@ -1602,17 +1602,17 @@ void MainWindow::setQuadrantWidgets(QSplitter &splitter, const Quadrant &left, c
|
|||
|
||||
bool MainWindow::userMayChangeAppState() const
|
||||
{
|
||||
return applicationState[(int)getAppState()].allowUserChange;
|
||||
return applicationState[(int)appState].allowUserChange;
|
||||
}
|
||||
|
||||
void MainWindow::setApplicationState(ApplicationState state)
|
||||
{
|
||||
if (getAppState() == state)
|
||||
if (appState == state)
|
||||
return;
|
||||
|
||||
saveSplitterSizes();
|
||||
|
||||
setAppState(state);
|
||||
appState = state;
|
||||
|
||||
clearSplitter(*topSplitter);
|
||||
clearSplitter(*bottomSplitter);
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "ui_plannerDetails.h"
|
||||
#include "desktop-widgets/notificationwidget.h"
|
||||
#include "desktop-widgets/filterwidget.h"
|
||||
#include "core/applicationstate.h"
|
||||
#include "core/dive.h"
|
||||
#include "core/subsurface-qt/divelistnotifier.h"
|
||||
|
||||
|
@ -53,6 +52,21 @@ public:
|
|||
LocationInformationWidget *locationInformationWidget();
|
||||
void setTitle();
|
||||
|
||||
enum class ApplicationState {
|
||||
Default,
|
||||
EditDive,
|
||||
PlanDive,
|
||||
EditPlannedDive,
|
||||
EditDiveSite,
|
||||
FilterDive,
|
||||
Statistics,
|
||||
MapMaximized,
|
||||
ProfileMaximized,
|
||||
ListMaximized,
|
||||
InfoMaximized,
|
||||
Count
|
||||
};
|
||||
|
||||
void loadFiles(const QStringList files);
|
||||
void importFiles(const QStringList importFiles);
|
||||
void setToolButtonsEnabled(bool enabled);
|
||||
|
@ -155,6 +169,7 @@ slots:
|
|||
void startDiveSiteEdit();
|
||||
|
||||
private:
|
||||
ApplicationState appState;
|
||||
Ui::MainWindow ui;
|
||||
FilterWidget filterWidget;
|
||||
std::unique_ptr<QSplitter> topSplitter;
|
||||
|
|
|
@ -157,7 +157,7 @@ void StatsWidget::updateRestrictionLabel()
|
|||
|
||||
void StatsWidget::closeStats()
|
||||
{
|
||||
MainWindow::instance()->setApplicationState(ApplicationState::Default);
|
||||
MainWindow::instance()->setApplicationState(MainWindow::ApplicationState::Default);
|
||||
}
|
||||
|
||||
void StatsWidget::chartTypeChanged(int idx)
|
||||
|
|
Loading…
Reference in a new issue