diff --git a/src/blackcore/context/contextsimulatorimpl.cpp b/src/blackcore/context/contextsimulatorimpl.cpp index de75da42b..ef0a674cf 100644 --- a/src/blackcore/context/contextsimulatorimpl.cpp +++ b/src/blackcore/context/contextsimulatorimpl.cpp @@ -306,7 +306,7 @@ namespace BlackCore CInterpolationAndRenderingSetupGlobal CContextSimulator::getInterpolationAndRenderingSetupGlobal() const { if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (m_simulatorPlugin.first.isUnspecified()) { return CInterpolationAndRenderingSetupGlobal(); } + if (m_simulatorPlugin.first.isUnspecified()) { return m_renderSettings.get(); } Q_ASSERT(m_simulatorPlugin.second); return m_simulatorPlugin.second->getInterpolationSetupGlobal(); } @@ -338,6 +338,12 @@ namespace BlackCore void CContextSimulator::setInterpolationAndRenderingSetupGlobal(const CInterpolationAndRenderingSetupGlobal &setup) { if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << setup; } + + // anyway save for future reference + const CStatusMessage m = m_renderSettings.setAndSave(setup); + CLogMessage::preformatted(m); + + // transfer to sim if (m_simulatorPlugin.first.isUnspecified()) { return; } Q_ASSERT(m_simulatorPlugin.second); m_simulatorPlugin.second->setInterpolationSetupGlobal(setup); @@ -439,8 +445,9 @@ namespace BlackCore // when everything is set up connected, update the current plugin info m_simulatorPlugin.first = simulatorPluginInfo; m_simulatorPlugin.second = simulator; + m_simulatorPlugin.second->setInterpolationSetupGlobal(m_renderSettings.get()); - // Emit signal after this function completes + // Emit signal after this function completes completely decoupled QPointer myself(this); QTimer::singleShot(0, this, [ = ] { diff --git a/src/blackcore/context/contextsimulatorimpl.h b/src/blackcore/context/contextsimulatorimpl.h index 25fdd9d14..720735839 100644 --- a/src/blackcore/context/contextsimulatorimpl.h +++ b/src/blackcore/context/contextsimulatorimpl.h @@ -23,6 +23,7 @@ #include "blackmisc/simulation/data/modelcaches.h" #include "blackmisc/simulation/settings/modelmatchersettings.h" #include "blackmisc/simulation/settings/simulatorsettings.h" +#include "blackmisc/simulation/settings/interpolationrenderingsetupsettings.h" #include "blackmisc/simulation/aircraftmodellist.h" #include "blackmisc/simulation/interpolationsetuplist.h" #include "blackmisc/simulation/remoteaircraftprovider.h" @@ -244,18 +245,20 @@ namespace BlackCore CWeatherManager m_weatherManager { this }; //!< weather management CAircraftMatcher m_aircraftMatcher { this }; //!< model matcher QMap m_matchingMessages; //!< all matching log messages per callsign - BlackMisc::CSetting m_matchingSettings { this }; //!< settings bool m_initallyAddAircraft = false; bool m_enableMatchingMessages = true; bool m_isWeatherActivated = false; - // settings - BlackMisc::CData m_modelSetSimulator { this }; //!< current simulator (used with radio buttons) - BlackMisc::Simulation::Settings::CMultiSimulatorSettings m_simulatorSettings { this }; //!< for directories of XPlane - BlackMisc::CSettingReadOnly m_messageSettings { this }; //!< settings for messages - BlackMisc::CSettingReadOnly m_enabledSimulators { this, &CContextSimulator::changeEnabledSimulators }; QString m_networkSessionId; //!< Network session of CServer::getServerSessionId, if not connected empty + + // settings + BlackMisc::CSettingReadOnly m_enabledSimulators { this, &CContextSimulator::changeEnabledSimulators }; + BlackMisc::CSetting m_matchingSettings { this }; //!< settings + BlackMisc::CData m_modelSetSimulator { this }; //!< current simulator (used with radio buttons) + BlackMisc::Simulation::Settings::CMultiSimulatorSettings m_simulatorSettings { this }; //!< for directories of XPlane + BlackMisc::CSetting m_renderSettings { this }; //!< rendering/interpolation settings + BlackMisc::CSettingReadOnly m_messageSettings { this }; //!< settings for messages }; } // namespace } // namespace diff --git a/src/blackgui/components/interpolationsetupcomponent.cpp b/src/blackgui/components/interpolationsetupcomponent.cpp index 5364d928b..350da1848 100644 --- a/src/blackgui/components/interpolationsetupcomponent.cpp +++ b/src/blackgui/components/interpolationsetupcomponent.cpp @@ -36,7 +36,7 @@ namespace BlackGui connect(ui->pb_RenderingSetup, &QPushButton::clicked, this, &CInterpolationSetupComponent::requestRenderingRestrictionsWidget); connect(ui->pb_Save, &QPushButton::clicked, this, &CInterpolationSetupComponent::saveSetup); - connect(ui->pb_Delete, &QPushButton::clicked, this, &CInterpolationSetupComponent::removeSetup); + connect(ui->pb_Delete, &QPushButton::clicked, this, &CInterpolationSetupComponent::removeOrResetSetup); connect(ui->pb_Reload, &QPushButton::clicked, this, &CInterpolationSetupComponent::reloadSetup); connect(ui->tvp_InterpolationSetup, &CInterpolationSetupView::doubleClicked, this, &CInterpolationSetupComponent::onRowDoubleClicked); connect(ui->tvp_InterpolationSetup, &CInterpolationSetupView::modelChanged, this, &CInterpolationSetupComponent::onModelChanged, Qt::QueuedConnection); @@ -99,7 +99,7 @@ namespace BlackGui } this->displaySetupsPerCallsign(); ui->comp_CallsignCompleter->setReadOnly(!enableCallsign); - ui->pb_Delete->setEnabled(enableCallsign); + ui->pb_Delete->setText(enableCallsign ? "delete" : "reset"); } void CInterpolationSetupComponent::onModelChanged() @@ -109,9 +109,10 @@ namespace BlackGui void CInterpolationSetupComponent::reloadSetup() { + const bool global = (this->getSetupMode() == CInterpolationSetupComponent::SetupGlobal); const bool overlay = QObject::sender() == ui->pb_Reload; - if (!this->checkPrerequisites(overlay)) { return; } - if (this->getSetupMode() == CInterpolationSetupComponent::SetupGlobal) + if (!this->checkPrerequisites(!global, overlay)) { return; } + if (global) { CInterpolationAndRenderingSetupGlobal gs = sGui->getIContextSimulator()->getInterpolationAndRenderingSetupGlobal(); ui->form_InterpolationSetup->setValue(gs); @@ -127,10 +128,11 @@ namespace BlackGui void CInterpolationSetupComponent::saveSetup() { - if (!this->checkPrerequisites(true)) { return; } + const bool global = (this->getSetupMode() == CInterpolationSetupComponent::SetupGlobal); + if (!this->checkPrerequisites(!global, true)) { return; } CInterpolationAndRenderingSetupPerCallsign setup = ui->form_InterpolationSetup->getValue(); CInterpolationAndRenderingSetupGlobal gs = sGui->getIContextSimulator()->getInterpolationAndRenderingSetupGlobal(); - if (this->getSetupMode() == CInterpolationSetupComponent::SetupGlobal) + if (global) { gs.setBaseValues(setup); gs.setLogInterpolation(false); // that would globally log all values @@ -172,23 +174,32 @@ namespace BlackGui } } - void CInterpolationSetupComponent::removeSetup() + void CInterpolationSetupComponent::removeOrResetSetup() { - if (!this->checkPrerequisites(true)) { return; } - if (this->getSetupMode() == CInterpolationSetupComponent::SetupGlobal) { return; } - const CCallsign cs = ui->comp_CallsignCompleter->getCallsign(false); - CInterpolationSetupList setups = ui->tvp_InterpolationSetup->container(); - const int removed = setups.removeByCallsign(cs); - if (removed < 1) { return; } // nothing done - const bool set = this->setSetupsToContext(setups); - if (!set) { return; } - - const QPointer myself(this); - QTimer::singleShot(100, this, [ = ] + const bool global = (this->getSetupMode() == CInterpolationSetupComponent::SetupGlobal); + if (!this->checkPrerequisites(!global, true)) { } + if (global) { - if (!myself) { return; } - this->displaySetupsPerCallsign(); - }); + CInterpolationAndRenderingSetupGlobal gs; + sGui->getIContextSimulator()->setInterpolationAndRenderingSetupGlobal(gs); + this->reloadSetup(); + } + else + { + const CCallsign cs = ui->comp_CallsignCompleter->getCallsign(false); + CInterpolationSetupList setups = ui->tvp_InterpolationSetup->container(); + const int removed = setups.removeByCallsign(cs); + if (removed < 1) { return; } // nothing done + const bool set = this->setSetupsToContext(setups); + if (!set) { return; } + + const QPointer myself(this); + QTimer::singleShot(100, this, [ = ] + { + if (!myself) { return; } + this->displaySetupsPerCallsign(); + }); + } } void CInterpolationSetupComponent::setUiValuesFromGlobal() @@ -205,7 +216,7 @@ namespace BlackGui ui->tvp_InterpolationSetup->updateContainerMaybeAsync(setups); } - bool CInterpolationSetupComponent::checkPrerequisites(bool showOverlay) + bool CInterpolationSetupComponent::checkPrerequisites(bool checkSim, bool showOverlay) { if (!sGui || !sGui->getIContextSimulator() || sGui->isShuttingDown()) { @@ -216,7 +227,7 @@ namespace BlackGui } return false; } - if (!sGui->getIContextSimulator()->isSimulatorAvailable()) + if (checkSim && !sGui->getIContextSimulator()->isSimulatorAvailable()) { if (showOverlay) { diff --git a/src/blackgui/components/interpolationsetupcomponent.h b/src/blackgui/components/interpolationsetupcomponent.h index 9e057e1be..924bd808e 100644 --- a/src/blackgui/components/interpolationsetupcomponent.h +++ b/src/blackgui/components/interpolationsetupcomponent.h @@ -68,7 +68,7 @@ namespace BlackGui void saveSetup(); //! Delete a setup - void removeSetup(); + void removeOrResetSetup(); //! Values from global setup void setUiValuesFromGlobal(); @@ -77,7 +77,7 @@ namespace BlackGui void displaySetupsPerCallsign(); //! Check prerequisites before saving etc. - bool checkPrerequisites(bool showOverlay); + bool checkPrerequisites(bool checkSim, bool showOverlay); //! Send to context bool setSetupsToContext(const BlackMisc::Simulation::CInterpolationSetupList &setups, bool force = false); diff --git a/src/blackmisc/simulation/settings/interpolationrenderingsetupsettings.h b/src/blackmisc/simulation/settings/interpolationrenderingsetupsettings.h new file mode 100644 index 000000000..3474f372f --- /dev/null +++ b/src/blackmisc/simulation/settings/interpolationrenderingsetupsettings.h @@ -0,0 +1,37 @@ +/* Copyright (C) 2018 + * swift project community / contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKMISC_SIMULATION_SETTINGS_INTERPOLATIONRENDERINGSETUP_H +#define BLACKMISC_SIMULATION_SETTINGS_INTERPOLATIONRENDERINGSETUP_H + +#include "blackmisc/simulation/interpolationrenderingsetup.h" +#include "blackmisc/settingscache.h" + +namespace BlackMisc +{ + namespace Simulation + { + namespace Settings + { + //! Last model used + struct TInterpolationAndRenderingSetupGlobal : public TSettingTrait + { + //! \copydoc BlackCore::TSettingTrait::key + static const char *key() { return "settingsglobalinterpolationsetup"; } + + //! \copydoc BlackCore::TSettingTrait::humanReadable + static const QString &humanReadable() { static const QString name("Interpolation setup"); return name; } + }; + } // ns + } // ns +} // ns + +#endif // guard