mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-25 18:25:42 +08:00
Ref T111, use Q_DECLARE_FLAGS SimulatorStatus instead of int
* changed emitSimulatorCombinedStatu * changed connected slots/functions
This commit is contained in:
committed by
Mathew Sutcliffe
parent
e55480737e
commit
654c35f666
@@ -85,6 +85,7 @@ namespace BlackCore
|
|||||||
signals:
|
signals:
|
||||||
//! Simulator combined status
|
//! Simulator combined status
|
||||||
//! \sa ISimulator::SimulatorStatus
|
//! \sa ISimulator::SimulatorStatus
|
||||||
|
//! \remark still int for DBus
|
||||||
void simulatorStatusChanged(int status);
|
void simulatorStatusChanged(int status);
|
||||||
|
|
||||||
//! Simulator plugin loaded / unloaded (default info)
|
//! Simulator plugin loaded / unloaded (default info)
|
||||||
|
|||||||
@@ -422,26 +422,25 @@ namespace BlackCore
|
|||||||
m_simulatorPlugin.second->logicallyRemoveRemoteAircraft(callsign);
|
m_simulatorPlugin.second->logicallyRemoveRemoteAircraft(callsign);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CContextSimulator::ps_onSimulatorStatusChanged(int status)
|
void CContextSimulator::ps_onSimulatorStatusChanged(ISimulator::SimulatorStatus status)
|
||||||
{
|
{
|
||||||
ISimulator::SimulatorStatus statusEnum = ISimulator::statusToEnum(status);
|
if (m_initallyAddAircrafts && status.testFlag(ISimulator::Simulating))
|
||||||
if (m_initallyAddAircrafts && statusEnum.testFlag(ISimulator::Simulating))
|
|
||||||
{
|
{
|
||||||
// use network to initally add aircraft
|
// use network to initally add aircraft
|
||||||
IContextNetwork *networkContext = this->getIContextNetwork();
|
IContextNetwork *networkContext = this->getIContextNetwork();
|
||||||
Q_ASSERT(networkContext);
|
Q_ASSERT_X(networkContext, Q_FUNC_INFO, "Need context");
|
||||||
Q_ASSERT(networkContext->isLocalObject());
|
Q_ASSERT_X(networkContext->isLocalObject(), Q_FUNC_INFO, "Need local object");
|
||||||
|
|
||||||
// initially add aircraft
|
// initially add aircraft
|
||||||
const CSimulatedAircraftList aircrafts = networkContext->getAircraftInRange();
|
const CSimulatedAircraftList aircraft = networkContext->getAircraftInRange();
|
||||||
for (const CSimulatedAircraft &simulatedAircraft : aircrafts)
|
for (const CSimulatedAircraft &simulatedAircraft : aircraft)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!simulatedAircraft.getCallsign().isEmpty());
|
BLACK_VERIFY_X(!simulatedAircraft.getCallsign().isEmpty(), Q_FUNC_INFO, "Need callsign");
|
||||||
ps_addedRemoteAircraft(simulatedAircraft);
|
ps_addedRemoteAircraft(simulatedAircraft);
|
||||||
}
|
}
|
||||||
m_initallyAddAircrafts = false;
|
m_initallyAddAircrafts = false;
|
||||||
}
|
}
|
||||||
if (!statusEnum.testFlag(ISimulator::Connected))
|
if (!status.testFlag(ISimulator::Connected))
|
||||||
{
|
{
|
||||||
// we got disconnected, plugin no longer needed
|
// we got disconnected, plugin no longer needed
|
||||||
unloadSimulatorPlugin();
|
unloadSimulatorPlugin();
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ namespace BlackCore
|
|||||||
// ------------ slots connected with network or other contexts ---------
|
// ------------ slots connected with network or other contexts ---------
|
||||||
|
|
||||||
//! Handle new connection status of simulator
|
//! Handle new connection status of simulator
|
||||||
void ps_onSimulatorStatusChanged(int status);
|
void ps_onSimulatorStatusChanged(BlackCore::ISimulator::SimulatorStatus status);
|
||||||
|
|
||||||
//! Model set from model set loader changed
|
//! Model set from model set loader changed
|
||||||
void ps_modelSetChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
void ps_modelSetChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||||
|
|||||||
@@ -22,34 +22,30 @@ using namespace BlackMisc::Simulation;
|
|||||||
|
|
||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
{
|
{
|
||||||
int ISimulator::getSimulatorStatus() const
|
ISimulator::SimulatorStatus ISimulator::getSimulatorStatus() const
|
||||||
{
|
{
|
||||||
int status =
|
const SimulatorStatus status =
|
||||||
(isConnected() ? Connected : static_cast<ISimulator::SimulatorStatus>(0))
|
(isConnected() ? Connected : static_cast<ISimulator::SimulatorStatusFlag>(0))
|
||||||
| (isSimulating() ? Simulating : static_cast<ISimulator::SimulatorStatus>(0))
|
| (isSimulating() ? Simulating : static_cast<ISimulator::SimulatorStatusFlag>(0))
|
||||||
| (isPaused() ? Paused : static_cast<ISimulator::SimulatorStatus>(0));
|
| (isPaused() ? Paused : static_cast<ISimulator::SimulatorStatusFlag>(0));
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ISimulator::statusToString(int status)
|
|
||||||
{
|
{
|
||||||
if (status > 0)
|
|
||||||
{
|
{
|
||||||
QString s;
|
BlackMisc::CSimpleCommandParser::registerCommand({".drv fsuipc on|off", "enable/disable FSUIPC (if applicable)"});
|
||||||
if (status & Connected) { s.append("Connected"); }
|
|
||||||
if (status & Simulating) { if (!s.isEmpty()) { s.append(", "); } s.append("Simulating"); }
|
|
||||||
if (status & Paused) { if (!s.isEmpty()) { s.append(", "); } s.append("Paused"); }
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return "Disconnected";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ISimulator::SimulatorStatus ISimulator::statusToEnum(int status)
|
QString ISimulator::statusToString(SimulatorStatus status)
|
||||||
{
|
{
|
||||||
return static_cast<SimulatorStatus>(status);
|
QStringList s;
|
||||||
|
if (status.testFlag(Unspecified)) s << "Unspecified";
|
||||||
|
if (status.testFlag(Disconnected)) s << "Disconnected";
|
||||||
|
if (status.testFlag(Connected)) s << "Connected";
|
||||||
|
if (status.testFlag(Simulating)) s << "Simulating";
|
||||||
|
if (status.testFlag(Paused)) s << "Paused";
|
||||||
|
return s.join(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
ISimulator::ISimulator(QObject *parent) :
|
ISimulator::ISimulator(QObject *parent) :
|
||||||
|
|||||||
@@ -59,10 +59,11 @@ namespace BlackCore
|
|||||||
//! ISimulator status
|
//! ISimulator status
|
||||||
enum SimulatorStatusFlag
|
enum SimulatorStatusFlag
|
||||||
{
|
{
|
||||||
Disconnected = 0,
|
Unspecified = 0, //!< unspecied, needed as default value
|
||||||
Connected = 1 << 0, //!< Is the plugin connected to the simulator?
|
Disconnected = 1 << 0, //!< not connected, and hence not simulating/paused
|
||||||
Simulating = 1 << 1, //!< Is the simulator actually simulating?
|
Connected = 1 << 1, //!< Is the plugin connected to the simulator?
|
||||||
Paused = 1 << 2, //!< Is the simulator paused?
|
Simulating = 1 << 2, //!< Is the simulator actually simulating?
|
||||||
|
Paused = 1 << 3, //!< Is the simulator paused?
|
||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(SimulatorStatus, SimulatorStatusFlag)
|
Q_DECLARE_FLAGS(SimulatorStatus, SimulatorStatusFlag)
|
||||||
|
|
||||||
@@ -73,7 +74,7 @@ namespace BlackCore
|
|||||||
virtual ~ISimulator() {}
|
virtual ~ISimulator() {}
|
||||||
|
|
||||||
//! Combined status
|
//! Combined status
|
||||||
virtual int getSimulatorStatus() const;
|
virtual SimulatorStatus getSimulatorStatus() const;
|
||||||
|
|
||||||
//! Is time synchronization on?
|
//! Is time synchronization on?
|
||||||
virtual bool isTimeSynchronized() const = 0;
|
virtual bool isTimeSynchronized() const = 0;
|
||||||
@@ -181,16 +182,11 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Status to string
|
//! Status to string
|
||||||
static QString statusToString(int status);
|
static QString statusToString(SimulatorStatus status);
|
||||||
|
|
||||||
//! Status to enum
|
|
||||||
//! \fixme remove with Qt 5.5 when SimulatorStatus can be transferred via DBus
|
|
||||||
static SimulatorStatus statusToEnum(int status);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
//! Simulator combined status
|
//! Simulator combined status
|
||||||
//! \fixme with Qt 5.5 make use of QFlags
|
void simulatorStatusChanged(SimulatorStatus status);
|
||||||
void simulatorStatusChanged(int status);
|
|
||||||
|
|
||||||
//! Emitted when own aircraft model has changed
|
//! Emitted when own aircraft model has changed
|
||||||
void ownAircraftModelChanged(const BlackMisc::Simulation::CAircraftModel &model);
|
void ownAircraftModelChanged(const BlackMisc::Simulation::CAircraftModel &model);
|
||||||
@@ -236,7 +232,7 @@ namespace BlackCore
|
|||||||
//! Emit the combined status
|
//! Emit the combined status
|
||||||
//! \param oldStatus optionally one can capture and provide the old status for comparison. In case of equal status values no signal will be sent
|
//! \param oldStatus optionally one can capture and provide the old status for comparison. In case of equal status values no signal will be sent
|
||||||
//! \sa simulatorStatusChanged;
|
//! \sa simulatorStatusChanged;
|
||||||
void emitSimulatorCombinedStatus(int oldStatus = -1);
|
void emitSimulatorCombinedStatus(SimulatorStatus oldStatus = Unspecified);
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Interface to a simulator listener.
|
//! Interface to a simulator listener.
|
||||||
|
|||||||
@@ -103,26 +103,29 @@ namespace BlackGui
|
|||||||
|
|
||||||
void CInfoBarStatusComponent::ps_onSimulatorStatusChanged(int status)
|
void CInfoBarStatusComponent::ps_onSimulatorStatusChanged(int status)
|
||||||
{
|
{
|
||||||
if (status > 0 && (status & ISimulator::Connected))
|
ISimulator::SimulatorStatus simStatus = static_cast<ISimulator::SimulatorStatus>(status);
|
||||||
|
if (simStatus.testFlag(ISimulator::Connected))
|
||||||
{
|
{
|
||||||
|
// at least connected
|
||||||
const QString s(
|
const QString s(
|
||||||
sGui->getIContextSimulator()->getSimulatorPluginInfo().getDescription() + ": " +
|
sGui->getIContextSimulator()->getSimulatorPluginInfo().getDescription() + ": " +
|
||||||
ISimulator::statusToString(status));
|
ISimulator::statusToString(simStatus)
|
||||||
|
);
|
||||||
|
|
||||||
// at least connected
|
|
||||||
if (status & ISimulator::Paused)
|
if (simStatus.testFlag(ISimulator::Paused))
|
||||||
{
|
{
|
||||||
// in paused state
|
|
||||||
ui->led_Simulator->setTriState();
|
ui->led_Simulator->setTriState();
|
||||||
ui->led_Simulator->setTriStateToolTip(s);
|
ui->led_Simulator->setTriStateToolTip(s);
|
||||||
}
|
}
|
||||||
else if (status & ISimulator::Simulating)
|
else if (simStatus.testFlag(ISimulator::Simulating))
|
||||||
{
|
{
|
||||||
ui->led_Simulator->setOn(true);
|
ui->led_Simulator->setOn(true);
|
||||||
ui->led_Simulator->setOnToolTip(s);
|
ui->led_Simulator->setOnToolTip(s);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// connected only
|
||||||
ui->led_Simulator->setTriState();
|
ui->led_Simulator->setTriState();
|
||||||
ui->led_Simulator->setTriStateToolTip(s);
|
ui->led_Simulator->setTriStateToolTip(s);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,7 +111,12 @@ namespace BlackSimPlugin
|
|||||||
m_fs9Host(fs9Host),
|
m_fs9Host(fs9Host),
|
||||||
m_lobbyClient(lobbyClient)
|
m_lobbyClient(lobbyClient)
|
||||||
{
|
{
|
||||||
connect(lobbyClient.data(), &CLobbyClient::disconnected, this, std::bind(&CSimulatorFs9::simulatorStatusChanged, this, 0));
|
//! \fixme KB 7/2017 change or remove when reviewed Could we just use: connect(lobbyClient.data(), &CLobbyClient::disconnected, this, &CSimulatorFs9::disconnectFrom);
|
||||||
|
connect(lobbyClient.data(), &CLobbyClient::disconnected, this, [ = ]
|
||||||
|
{
|
||||||
|
emit this->simulatorStatusChanged(ISimulator::Disconnected);
|
||||||
|
});
|
||||||
|
|
||||||
m_defaultModel =
|
m_defaultModel =
|
||||||
{
|
{
|
||||||
"Boeing 737-400",
|
"Boeing 737-400",
|
||||||
|
|||||||
@@ -317,7 +317,7 @@ namespace BlackSimPlugin
|
|||||||
void CSimulatorFsxCommon::onSimStopped()
|
void CSimulatorFsxCommon::onSimStopped()
|
||||||
{
|
{
|
||||||
// stopping events in FSX: Load menu, weather and season
|
// stopping events in FSX: Load menu, weather and season
|
||||||
const int oldStatus = getSimulatorStatus();
|
const SimulatorStatus oldStatus = getSimulatorStatus();
|
||||||
m_simSimulating = false;
|
m_simSimulating = false;
|
||||||
m_simulatingChangedTs = QDateTime::currentMSecsSinceEpoch();
|
m_simulatingChangedTs = QDateTime::currentMSecsSinceEpoch();
|
||||||
emitSimulatorCombinedStatus(oldStatus);
|
emitSimulatorCombinedStatus(oldStatus);
|
||||||
|
|||||||
Reference in New Issue
Block a user