From d057158e1d7355b78f272cd2b6ff883ea6199283 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 27 Nov 2016 02:05:31 +0100 Subject: [PATCH] Improvements of swift GUI - pilot client * support for headers, allow to load files when caches are outdated (refs #787) * display error when no model set is initialized * removed some unused members --- src/swiftguistandard/swiftguistd.cpp | 41 +++++++++++++++++++++--- src/swiftguistandard/swiftguistd.h | 21 +++++------- src/swiftguistandard/swiftguistdinit.cpp | 5 +++ 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/src/swiftguistandard/swiftguistd.cpp b/src/swiftguistandard/swiftguistd.cpp index 371c66c3c..def807a73 100644 --- a/src/swiftguistandard/swiftguistd.cpp +++ b/src/swiftguistandard/swiftguistd.cpp @@ -10,7 +10,9 @@ #include "blackcore/context/contextapplication.h" #include "blackcore/context/contextaudio.h" #include "blackcore/context/contextnetwork.h" +#include "blackcore/context/contextsimulator.h" #include "blackcore/network.h" +#include "blackcore/webdataservices.h" #include "blackgui/components/infobarstatuscomponent.h" #include "blackgui/components/logcomponent.h" #include "blackgui/components/settingscomponent.h" @@ -48,6 +50,7 @@ namespace BlackGui namespace BlackMisc { class CIdentifiable; } using namespace BlackCore; +using namespace BlackCore::Context; using namespace BlackMisc; using namespace BlackGui; using namespace BlackGui::Components; @@ -57,6 +60,7 @@ using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::Geo; using namespace BlackMisc::Audio; using namespace BlackMisc::Input; +using namespace BlackMisc::Simulation; /* * Constructor @@ -153,7 +157,7 @@ void SwiftGuiStd::changeEvent(QEvent *event) QAction *SwiftGuiStd::getWindowMinimizeAction(QObject *parent) { - QIcon i(CIcons::changeIconBackgroundColor(this->style()->standardIcon(QStyle::SP_TitleBarMinButton), Qt::white, QSize(16, 16))); + const QIcon i(CIcons::changeIconBackgroundColor(this->style()->standardIcon(QStyle::SP_TitleBarMinButton), Qt::white, QSize(16, 16))); QAction *a = new QAction(i, "Window minimized", parent); connect(a, &QAction::triggered, this, &SwiftGuiStd::ps_showMinimized); return a; @@ -287,7 +291,6 @@ void SwiftGuiStd::ps_handleTimerBasedUpdates() void SwiftGuiStd::setContextAvailability() { bool corePreviouslyAvailable = this->m_coreAvailable; - if (sGui && sGui->getIContextApplication()->isUsingImplementingObject()) { this->m_coreAvailable = true; @@ -295,9 +298,8 @@ void SwiftGuiStd::setContextAvailability() else { // ping to check if core is still alive - this->m_coreAvailable = - sGui && - this->isMyIdentifier(sGui->getIContextApplication()->registerApplication(getCurrentTimestampIdentifier())); + this->m_coreAvailable = sGui && + this->isMyIdentifier(sGui->getIContextApplication()->registerApplication(getCurrentTimestampIdentifier())); } this->m_contextNetworkAvailable = this->m_coreAvailable || (sGui && sGui->getIContextNetwork()->isUsingImplementingObject()); this->m_contextAudioAvailable = this->m_coreAvailable || (sGui && sGui->getIContextAudio()->isUsingImplementingObject()); @@ -388,6 +390,35 @@ void SwiftGuiStd::ps_navigatorClosed() this->showNormal(); } +void SwiftGuiStd::ps_verifyDataAvailability() +{ + const CSimulatorInfo sims = sGui->getIContextSimulator()->simulatorsWithInitializedModelSet(); + if (sims.isNoSimulator()) + { + CLogMessage(this).error("No model set so far, you need at least one model set"); + } +} + +void SwiftGuiStd::ps_sharedFilesHeadersLoaded() +{ + Q_ASSERT_X(sGui && sGui->hasWebDataServices(), Q_FUNC_INFO, "Missing web services"); + const CEntityFlags::Entity newEntities = sGui->getWebDataServices()->getEntitiesWithNewerHeaderTimestamp(CEntityFlags::AllDbEntities); + if (newEntities == CEntityFlags::NoEntity) { return; } + CStatusMessage sm = CStatusMessage(this).info("New data for shared files:"); + CStatusMessageList sms({sm}); + const QSet newSingleEntities = CEntityFlags::asSingleEntities(newEntities); + for (CEntityFlags::Entity newSingleEntity : newSingleEntities) + { + sm = CStatusMessage(this).info("Load data for '%1'?") << CEntityFlags::flagToString(newSingleEntity); + sms.push_back(sm); + } + auto lambda = [this, newEntities]() + { + sGui->getWebDataServices()->triggerLoadingDirectlyFromSharedFiles(newEntities, false); + }; + ui->fr_CentralFrameInside->showOverlayMessagesWithConfirmation(sms, "Load data?", lambda); +} + void SwiftGuiStd::playNotifcationSound(CNotificationSounds::Notification notification) const { if (!this->m_contextAudioAvailable) { return; } diff --git a/src/swiftguistandard/swiftguistd.h b/src/swiftguistandard/swiftguistd.h index 77e1dd99e..d51f74347 100644 --- a/src/swiftguistandard/swiftguistd.h +++ b/src/swiftguistandard/swiftguistd.h @@ -70,7 +70,7 @@ public: SwiftGuiStd(WindowMode windowMode, QWidget *parent = nullptr); //! Destructor - ~SwiftGuiStd(); + virtual ~SwiftGuiStd(); //! Log message category static QString getLogCategory() { return "swift.gui.stdgui"; } @@ -103,8 +103,7 @@ protected: private: QScopedPointer ui; - // if I pass the parent, the dialog is always center over the parent - QScopedPointer m_navigator{new BlackGui::Components::CNavigatorDialog()}; + QScopedPointer m_navigator{new BlackGui::Components::CNavigatorDialog()}; // if I pass the parent, the dialog is always centered over the parent bool m_init = false; BlackGui::CManagedStatusBar m_statusBar; BlackMisc::CLogSubscriber m_logSubscriber { this, &SwiftGuiStd::ps_displayStatusMessageInGui }; @@ -115,16 +114,6 @@ private: bool m_contextAudioAvailable = false; QTimer *m_timerContextWatchdog = nullptr; //!< core available? BlackMisc::Simulation::CSimulatedAircraft m_ownAircraft; //!< own aircraft's state - QSize m_windowMinSizeWithMainPageShown; - QSize m_windowMinSizeWithMainPageHidden; - - // cockpit - QString m_transponderResetValue; //!< Temp. storage of XPdr mode to reset, req. until timer allows singleShoot with Lambdas - QWidget *m_inputFocusedWidget = nullptr; //!< currently used widget for input, mainly used with cockpit - - // actions - BlackCore::CActionBind m_action50 { "/swiftGui/Change opacity to 50%", this, &SwiftGuiStd::ps_onChangedWindowOpacityTo50 }; - BlackCore::CActionBind m_action100 { "/swiftGui/Change opacity to 100%", this, &SwiftGuiStd::ps_onChangedWindowOpacityTo100 }; //! GUI status update void updateGuiStatusInformation(); @@ -255,6 +244,12 @@ private slots: //! Navigator dialog has been closed void ps_navigatorClosed(); + + //! Checks if data such as model set etc. are available + void ps_verifyDataAvailability(); + + //! The shared headers have been loaded + void ps_sharedFilesHeadersLoaded(); }; #pragma pop_macro("interface") diff --git a/src/swiftguistandard/swiftguistdinit.cpp b/src/swiftguistandard/swiftguistdinit.cpp index 0aef7f421..0e305c5f7 100644 --- a/src/swiftguistandard/swiftguistdinit.cpp +++ b/src/swiftguistandard/swiftguistdinit.cpp @@ -8,6 +8,7 @@ */ #include "blackconfig/buildconfig.h" +#include "blackcore/webdataservices.h" #include "blackcore/context/contextnetwork.h" #include "blackgui/components/aircraftcomponent.h" #include "blackgui/components/atcstationcomponent.h" @@ -58,6 +59,8 @@ using namespace BlackGui::Components; void SwiftGuiStd::init() { // POST(!) GUI init + Q_ASSERT_X(sGui, Q_FUNC_INFO, "Missing sGui"); + Q_ASSERT_X(sGui->getWebDataServices(), Q_FUNC_INFO, "Missing web services"); if (this->m_init) { return; } @@ -118,6 +121,7 @@ void SwiftGuiStd::init() this->initGuiSignals(); // signal / slots contexts / timers + connect(sGui->getWebDataServices(), &CWebDataServices::allSwiftSharedAllHeadersReceived, this, &SwiftGuiStd::ps_sharedFilesHeadersLoaded); connect(sGui->getIContextNetwork(), &IContextNetwork::connectionTerminated, this, &SwiftGuiStd::ps_onConnectionTerminated); connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &SwiftGuiStd::ps_onConnectionStatusChanged); connect(sGui->getIContextNetwork(), &IContextNetwork::textMessagesReceived, ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::onTextMessageReceived); @@ -147,6 +151,7 @@ void SwiftGuiStd::init() sGui->startUpCompleted(true); this->m_init = true; + QTimer::singleShot(2500, this, &SwiftGuiStd::ps_verifyDataAvailability); if (!CNetworkUtils::hasConnectedInterface()) {