From ccd2cb25020e62f37fbf15dcc8b6eccbd643b7f0 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 22 Aug 2015 07:05:13 -0700 Subject: [PATCH] Continue to separate logic code from UI code We don't want to call into the MainWindow from C code. Signed-off-by: Dirk Hohndel --- qt-ui/mainwindow.cpp | 9 ++------- qt-ui/mainwindow.h | 1 - qthelper.cpp | 14 +++++++++++++- qthelper.h | 2 ++ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index dec550389..4d416d2be 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -1731,10 +1731,10 @@ void MainWindow::setApplicationState(const QByteArray& state) { if (!applicationState.keys().contains(state)) return; - if (currentApplicationState == state) + if (getCurrentAppState() == state) return; - currentApplicationState = state; + setCurrentAppState(state); #define SET_CURRENT_INDEX( X ) \ if (applicationState[state].X) { \ @@ -1762,8 +1762,3 @@ void MainWindow::setApplicationState(const QByteArray& state) { } #undef SET_CURRENT_INDEX } - -bool MainWindow::inPlanner() -{ - return (currentApplicationState == "PlanDive" || currentApplicationState == "EditPlannedDive"); -} diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 2d2ea8847..226e9b6ee 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -243,7 +243,6 @@ private: QHash applicationState; QHash stateProperties; - QByteArray currentApplicationState; WindowTitleUpdate *wtu; }; diff --git a/qthelper.cpp b/qthelper.cpp index 44bb8a33a..de1d893df 100644 --- a/qthelper.cpp +++ b/qthelper.cpp @@ -1274,7 +1274,19 @@ extern "C" void parse_display_units(char *line) qDebug() << line; } +static QByteArray currentApplicationState; + +QByteArray getCurrentAppState() +{ + return currentApplicationState; +} + +void setCurrentAppState(QByteArray state) +{ + currentApplicationState = state; +} + extern "C" bool in_planner() { - return MainWindow::instance()->inPlanner(); + return (currentApplicationState == "PlanDive" || currentApplicationState == "EditPlannedDive"); } diff --git a/qthelper.h b/qthelper.h index 674f036d3..073010d9f 100644 --- a/qthelper.h +++ b/qthelper.h @@ -36,6 +36,8 @@ fraction_t string_to_fraction(const char *str); int getCloudURL(QString &filename); void loadPreferences(); bool parseGpsText(const QString &gps_text, double *latitude, double *longitude); +QByteArray getCurrentAppState(); +void setCurrentAppState(QByteArray state); extern "C" bool in_planner(); #endif // QTHELPER_H