mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +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:
|
||||
//! Simulator combined status
|
||||
//! \sa ISimulator::SimulatorStatus
|
||||
//! \remark still int for DBus
|
||||
void simulatorStatusChanged(int status);
|
||||
|
||||
//! Simulator plugin loaded / unloaded (default info)
|
||||
|
||||
@@ -422,26 +422,25 @@ namespace BlackCore
|
||||
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 && statusEnum.testFlag(ISimulator::Simulating))
|
||||
if (m_initallyAddAircrafts && status.testFlag(ISimulator::Simulating))
|
||||
{
|
||||
// use network to initally add aircraft
|
||||
IContextNetwork *networkContext = this->getIContextNetwork();
|
||||
Q_ASSERT(networkContext);
|
||||
Q_ASSERT(networkContext->isLocalObject());
|
||||
Q_ASSERT_X(networkContext, Q_FUNC_INFO, "Need context");
|
||||
Q_ASSERT_X(networkContext->isLocalObject(), Q_FUNC_INFO, "Need local object");
|
||||
|
||||
// initially add aircraft
|
||||
const CSimulatedAircraftList aircrafts = networkContext->getAircraftInRange();
|
||||
for (const CSimulatedAircraft &simulatedAircraft : aircrafts)
|
||||
const CSimulatedAircraftList aircraft = networkContext->getAircraftInRange();
|
||||
for (const CSimulatedAircraft &simulatedAircraft : aircraft)
|
||||
{
|
||||
Q_ASSERT(!simulatedAircraft.getCallsign().isEmpty());
|
||||
BLACK_VERIFY_X(!simulatedAircraft.getCallsign().isEmpty(), Q_FUNC_INFO, "Need callsign");
|
||||
ps_addedRemoteAircraft(simulatedAircraft);
|
||||
}
|
||||
m_initallyAddAircrafts = false;
|
||||
}
|
||||
if (!statusEnum.testFlag(ISimulator::Connected))
|
||||
if (!status.testFlag(ISimulator::Connected))
|
||||
{
|
||||
// we got disconnected, plugin no longer needed
|
||||
unloadSimulatorPlugin();
|
||||
|
||||
@@ -151,7 +151,7 @@ namespace BlackCore
|
||||
// ------------ slots connected with network or other contexts ---------
|
||||
|
||||
//! 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
|
||||
void ps_modelSetChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
@@ -22,34 +22,30 @@ using namespace BlackMisc::Simulation;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
int ISimulator::getSimulatorStatus() const
|
||||
ISimulator::SimulatorStatus ISimulator::getSimulatorStatus() const
|
||||
{
|
||||
int status =
|
||||
(isConnected() ? Connected : static_cast<ISimulator::SimulatorStatus>(0))
|
||||
| (isSimulating() ? Simulating : static_cast<ISimulator::SimulatorStatus>(0))
|
||||
| (isPaused() ? Paused : static_cast<ISimulator::SimulatorStatus>(0));
|
||||
const SimulatorStatus status =
|
||||
(isConnected() ? Connected : static_cast<ISimulator::SimulatorStatusFlag>(0))
|
||||
| (isSimulating() ? Simulating : static_cast<ISimulator::SimulatorStatusFlag>(0))
|
||||
| (isPaused() ? Paused : static_cast<ISimulator::SimulatorStatusFlag>(0));
|
||||
return status;
|
||||
}
|
||||
|
||||
QString ISimulator::statusToString(int status)
|
||||
{
|
||||
if (status > 0)
|
||||
{
|
||||
QString s;
|
||||
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";
|
||||
BlackMisc::CSimpleCommandParser::registerCommand({".drv fsuipc on|off", "enable/disable FSUIPC (if applicable)"});
|
||||
}
|
||||
}
|
||||
|
||||
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) :
|
||||
|
||||
@@ -59,10 +59,11 @@ namespace BlackCore
|
||||
//! ISimulator status
|
||||
enum SimulatorStatusFlag
|
||||
{
|
||||
Disconnected = 0,
|
||||
Connected = 1 << 0, //!< Is the plugin connected to the simulator?
|
||||
Simulating = 1 << 1, //!< Is the simulator actually simulating?
|
||||
Paused = 1 << 2, //!< Is the simulator paused?
|
||||
Unspecified = 0, //!< unspecied, needed as default value
|
||||
Disconnected = 1 << 0, //!< not connected, and hence not simulating/paused
|
||||
Connected = 1 << 1, //!< Is the plugin connected to the simulator?
|
||||
Simulating = 1 << 2, //!< Is the simulator actually simulating?
|
||||
Paused = 1 << 3, //!< Is the simulator paused?
|
||||
};
|
||||
Q_DECLARE_FLAGS(SimulatorStatus, SimulatorStatusFlag)
|
||||
|
||||
@@ -73,7 +74,7 @@ namespace BlackCore
|
||||
virtual ~ISimulator() {}
|
||||
|
||||
//! Combined status
|
||||
virtual int getSimulatorStatus() const;
|
||||
virtual SimulatorStatus getSimulatorStatus() const;
|
||||
|
||||
//! Is time synchronization on?
|
||||
virtual bool isTimeSynchronized() const = 0;
|
||||
@@ -181,16 +182,11 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
//! Status to string
|
||||
static QString statusToString(int status);
|
||||
|
||||
//! Status to enum
|
||||
//! \fixme remove with Qt 5.5 when SimulatorStatus can be transferred via DBus
|
||||
static SimulatorStatus statusToEnum(int status);
|
||||
static QString statusToString(SimulatorStatus status);
|
||||
|
||||
signals:
|
||||
//! Simulator combined status
|
||||
//! \fixme with Qt 5.5 make use of QFlags
|
||||
void simulatorStatusChanged(int status);
|
||||
void simulatorStatusChanged(SimulatorStatus status);
|
||||
|
||||
//! Emitted when own aircraft model has changed
|
||||
void ownAircraftModelChanged(const BlackMisc::Simulation::CAircraftModel &model);
|
||||
@@ -236,7 +232,7 @@ namespace BlackCore
|
||||
//! 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
|
||||
//! \sa simulatorStatusChanged;
|
||||
void emitSimulatorCombinedStatus(int oldStatus = -1);
|
||||
void emitSimulatorCombinedStatus(SimulatorStatus oldStatus = Unspecified);
|
||||
};
|
||||
|
||||
//! Interface to a simulator listener.
|
||||
|
||||
@@ -103,26 +103,29 @@ namespace BlackGui
|
||||
|
||||
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(
|
||||
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->setTriStateToolTip(s);
|
||||
}
|
||||
else if (status & ISimulator::Simulating)
|
||||
else if (simStatus.testFlag(ISimulator::Simulating))
|
||||
{
|
||||
ui->led_Simulator->setOn(true);
|
||||
ui->led_Simulator->setOnToolTip(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
// connected only
|
||||
ui->led_Simulator->setTriState();
|
||||
ui->led_Simulator->setTriStateToolTip(s);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,12 @@ namespace BlackSimPlugin
|
||||
m_fs9Host(fs9Host),
|
||||
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 =
|
||||
{
|
||||
"Boeing 737-400",
|
||||
|
||||
@@ -317,7 +317,7 @@ namespace BlackSimPlugin
|
||||
void CSimulatorFsxCommon::onSimStopped()
|
||||
{
|
||||
// stopping events in FSX: Load menu, weather and season
|
||||
const int oldStatus = getSimulatorStatus();
|
||||
const SimulatorStatus oldStatus = getSimulatorStatus();
|
||||
m_simSimulating = false;
|
||||
m_simulatingChangedTs = QDateTime::currentMSecsSinceEpoch();
|
||||
emitSimulatorCombinedStatus(oldStatus);
|
||||
|
||||
Reference in New Issue
Block a user