diff --git a/src/blackcore/context/contextownaircraft.h b/src/blackcore/context/contextownaircraft.h index 68b4c2530..09a9b1919 100644 --- a/src/blackcore/context/contextownaircraft.h +++ b/src/blackcore/context/contextownaircraft.h @@ -104,9 +104,6 @@ namespace BlackCore //! Own pilot (aka the swift user) changed void changedPilot(const BlackMisc::Network::CUser &pilot); - //! Changed aircraft model - void changedModel(const BlackMisc::Simulation::CAircraftModel &model); - //! Aircraft has been moved from one location to another (changed scenery) void movedAircraft(); diff --git a/src/blackcore/context/contextownaircraftimpl.cpp b/src/blackcore/context/contextownaircraftimpl.cpp index 953d88341..f6870197f 100644 --- a/src/blackcore/context/contextownaircraftimpl.cpp +++ b/src/blackcore/context/contextownaircraftimpl.cpp @@ -238,6 +238,11 @@ namespace BlackCore } bool CContextOwnAircraft::updateOwnModel(const CAircraftModel &model) + { + return updateOwnModel(model, this->identifier()); + } + + bool CContextOwnAircraft::updateOwnModel(const CAircraftModel &model, const CIdentifier &identifier) { CAircraftModel updateModel(this->reverseLookupModel(model)); { @@ -248,7 +253,7 @@ namespace BlackCore } // changed model - emit this->changedModel(updateModel); + emit this->ps_changedModel(updateModel, identifier); return true; } @@ -433,9 +438,9 @@ namespace BlackCore } } - void CContextOwnAircraft::xCtxChangedSimulatorModel(const CAircraftModel &model) + void CContextOwnAircraft::xCtxChangedSimulatorModel(const CAircraftModel &model, const CIdentifier &identifier) { - this->updateOwnModel(model); + this->updateOwnModel(model, identifier); } void CContextOwnAircraft::xCtxChangedSimulatorStatus(int status) diff --git a/src/blackcore/context/contextownaircraftimpl.h b/src/blackcore/context/contextownaircraftimpl.h index 1f5e7f161..ddab63179 100644 --- a/src/blackcore/context/contextownaircraftimpl.h +++ b/src/blackcore/context/contextownaircraftimpl.h @@ -113,6 +113,11 @@ namespace BlackCore //! \copydoc BlackMisc::IProvider::asQObject virtual QObject *asQObject() override { return this; } + signals: + //! Changed aircraft model + //! \private Use ISimulatorContext::ownAircraftModelChanged + void ps_changedModel(const BlackMisc::Simulation::CAircraftModel &model, const BlackMisc::CIdentifier &identifier); + public slots: //! \copydoc IContextOwnAircraft::getOwnAircraft() //! \ingroup ownaircraftprovider @@ -226,7 +231,7 @@ namespace BlackCore //! Simulator model has been changed //! \ingroup crosscontextfunction - void xCtxChangedSimulatorModel(const BlackMisc::Simulation::CAircraftModel &model); + void xCtxChangedSimulatorModel(const BlackMisc::Simulation::CAircraftModel &model, const BlackMisc::CIdentifier &identifier); //! Simulator status changed //! \ingroup crosscontextfunction @@ -249,6 +254,9 @@ namespace BlackCore //! Update position history void evaluateUpdateHistory(); + //! Update own model and emit signal with identifier + bool updateOwnModel(const BlackMisc::Simulation::CAircraftModel &model, const BlackMisc::CIdentifier &identifier); + //! Reverse lookup of the model against DB data static BlackMisc::Simulation::CAircraftModel reverseLookupModel(const BlackMisc::Simulation::CAircraftModel &model); }; diff --git a/src/blackcore/context/contextownaircraftproxy.cpp b/src/blackcore/context/contextownaircraftproxy.cpp index bcde2d159..207c458d5 100644 --- a/src/blackcore/context/contextownaircraftproxy.cpp +++ b/src/blackcore/context/contextownaircraftproxy.cpp @@ -51,9 +51,6 @@ namespace BlackCore s = connection.connect(serviceName, IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName(), "changedPilot", this, SIGNAL(changedPilot(BlackMisc::Network::CUser))); Q_ASSERT(s); - s = connection.connect(serviceName, IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName(), - "changedModel", this, SIGNAL(changedModel(BlackMisc::Simulation::CAircraftModel))); - Q_ASSERT(s); s = connection.connect(serviceName, IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName(), "movedAircraft", this, SIGNAL(movedAircraft())); Q_ASSERT(s); diff --git a/src/blackcore/context/contextsimulatorimpl.cpp b/src/blackcore/context/contextsimulatorimpl.cpp index 96b477e8a..253fb3d16 100644 --- a/src/blackcore/context/contextsimulatorimpl.cpp +++ b/src/blackcore/context/contextsimulatorimpl.cpp @@ -682,6 +682,14 @@ namespace BlackCore m_simulatorPlugin.second->changeRemoteAircraftModel(aircraft); } + void CContextSimulator::xCtxChangedOwnAircraftModel(const CAircraftModel &aircraftModel, const CIdentifier &originator) + { + if (CIdentifiable::isMyIdentifier(originator)) { return; } + if (!this->isSimulatorAvailable()) { return; } + + emit this->ownAircraftModelChanged(aircraftModel); + } + void CContextSimulator::xCtxChangedRemoteAircraftEnabled(const CSimulatedAircraft &aircraft) { if (!this->isSimulatorAvailable()) { return; } diff --git a/src/blackcore/context/contextsimulatorimpl.h b/src/blackcore/context/contextsimulatorimpl.h index 6e1f9882e..708c479ab 100644 --- a/src/blackcore/context/contextsimulatorimpl.h +++ b/src/blackcore/context/contextsimulatorimpl.h @@ -186,6 +186,9 @@ namespace BlackCore //! Changed remote aircraft model void xCtxChangedRemoteAircraftModel(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); + //! Changed own aircraft model + void xCtxChangedOwnAircraftModel(const BlackMisc::Simulation::CAircraftModel &aircraftModel, const BlackMisc::CIdentifier &originator); + //! Enable / disable aircraft void xCtxChangedRemoteAircraftEnabled(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); diff --git a/src/blackcore/corefacade.cpp b/src/blackcore/corefacade.cpp index deb282c84..a4bed991c 100644 --- a/src/blackcore/corefacade.cpp +++ b/src/blackcore/corefacade.cpp @@ -237,12 +237,27 @@ namespace BlackCore c = connect(m_contextOwnAircraft, &IContextOwnAircraft::changedSelcal, this->getCContextSimulator(), &CContextSimulator::xCtxUpdateSimulatorSelcalFromContext); Q_ASSERT(c); + + // relay changed aircraft to own aircraft provider but with identifier + // identifier is needed because own aircraft context also reports changed aircraft to xCtxChangedOwnAircraftModel + // and we avoid roundtrips c = connect(this->getCContextSimulator(), &CContextSimulator::ownAircraftModelChanged, - this->getCContextOwnAircraft(), &CContextOwnAircraft::xCtxChangedSimulatorModel); + this->getCContextOwnAircraft(), [ = ](const CAircraftModel & changedModel) + { + if (!this->getIContextOwnAircraft()) { return; } + if (!this->getCContextSimulator()) { return; } + this->getCContextOwnAircraft()->xCtxChangedSimulatorModel(changedModel, this->getCContextSimulator()->identifier()); + }); + Q_ASSERT(c); c = connect(this->getCContextSimulator(), &CContextSimulator::simulatorStatusChanged, this->getCContextOwnAircraft(), &CContextOwnAircraft::xCtxChangedSimulatorStatus); Q_ASSERT(c); + + // this is used if the value in own aircraft is changed, to callback simulator + c = connect(this->getCContextOwnAircraft(), &CContextOwnAircraft::ps_changedModel, + this->getCContextSimulator(), &CContextSimulator::xCtxChangedOwnAircraftModel); + Q_ASSERT(c); } // times