Use nested namespaces (C++17 feature)

This commit is contained in:
Mat Sutcliffe
2021-09-15 21:44:54 +01:00
parent 3f2e5b0b69
commit 57d32da826
1345 changed files with 146075 additions and 150376 deletions

View File

@@ -44,151 +44,148 @@ using namespace BlackMisc::Aviation;
using namespace BlackMisc::Simulation;
using namespace BlackMisc::PhysicalQuantities;
namespace BlackGui
namespace BlackGui::Components
{
namespace Components
CCockpitComComponent::CCockpitComComponent(QWidget *parent) :
QFrame(parent),
CIdentifiable(this),
ui(new Ui::CCockpitComComponent)
{
CCockpitComComponent::CCockpitComComponent(QWidget *parent) :
QFrame(parent),
CIdentifiable(this),
ui(new Ui::CCockpitComComponent)
ui->setupUi(this);
// init from aircraft
this->forceCockpitUpdateFromOwnAircraftContext();
// COM form
connect(ui->editor_Com, &CCockpitComForm::testSelcal, this, &CCockpitComComponent::testSelcal);
connect(ui->editor_Com, &CCockpitComForm::changedCockpitValues, this, &CCockpitComComponent::updateOwnCockpitInContext);
connect(ui->editor_Com, &CCockpitComForm::changedSelcal, this, &CCockpitComComponent::updateSelcalInContext);
connect(ui->editor_Com, &CCockpitComForm::requestCom1TextMessage, this, &CCockpitComComponent::requestCom1TextMessage);
connect(ui->editor_Com, &CCockpitComForm::requestCom2TextMessage, this, &CCockpitComComponent::requestCom2TextMessage);
// Relay COM form signals
connect(ui->editor_Com, &CCockpitComForm::transponderModeChanged, this, &CCockpitComComponent::transponderModeChanged);
connect(ui->editor_Com, &CCockpitComForm::transponderStateIdentEnded, this, &CCockpitComComponent::transponderStateIdentEnded);
// hook up with changes from own aircraft context
if (sGui)
{
ui->setupUi(this);
// own aircraft
connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CCockpitComComponent::updateCockpitFromContext, Qt::QueuedConnection);
connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedSelcal, this, &CCockpitComComponent::updateSelcalFromContext, Qt::QueuedConnection);
// init from aircraft
this->forceCockpitUpdateFromOwnAircraftContext();
// hook up with audio context
// connect(sGui->getIContextAudio(), &IContextAudio::changedVoiceRooms, this, &CCockpitComComponent::updateVoiceRoomStatusFromContext, Qt::QueuedConnection);
// COM form
connect(ui->editor_Com, &CCockpitComForm::testSelcal, this, &CCockpitComComponent::testSelcal);
connect(ui->editor_Com, &CCockpitComForm::changedCockpitValues, this, &CCockpitComComponent::updateOwnCockpitInContext);
connect(ui->editor_Com, &CCockpitComForm::changedSelcal, this, &CCockpitComComponent::updateSelcalInContext);
connect(ui->editor_Com, &CCockpitComForm::requestCom1TextMessage, this, &CCockpitComComponent::requestCom1TextMessage);
connect(ui->editor_Com, &CCockpitComForm::requestCom2TextMessage, this, &CCockpitComComponent::requestCom2TextMessage);
// network
connect(sGui->getIContextNetwork(), &IContextNetwork::changedAtcStationsOnlineDigest, this, &CCockpitComComponent::onAtcStationsChanged, Qt::QueuedConnection);
// Relay COM form signals
connect(ui->editor_Com, &CCockpitComForm::transponderModeChanged, this, &CCockpitComComponent::transponderModeChanged);
connect(ui->editor_Com, &CCockpitComForm::transponderStateIdentEnded, this, &CCockpitComComponent::transponderStateIdentEnded);
// hook up with changes from own aircraft context
if (sGui)
QPointer<CCockpitComComponent> myself(this);
QTimer::singleShot(10 * 1000, this, [ = ]
{
// own aircraft
connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CCockpitComComponent::updateCockpitFromContext, Qt::QueuedConnection);
connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedSelcal, this, &CCockpitComComponent::updateSelcalFromContext, Qt::QueuedConnection);
if (!sGui || sGui->isShuttingDown() || !myself) { return; }
const CSimulatedAircraft aircraft = sGui->getIContextOwnAircraft()->getOwnAircraft();
this->updateCockpitFromContext(aircraft, CIdentifier::fake());
});
}
}
// hook up with audio context
// connect(sGui->getIContextAudio(), &IContextAudio::changedVoiceRooms, this, &CCockpitComComponent::updateVoiceRoomStatusFromContext, Qt::QueuedConnection);
CCockpitComComponent::~CCockpitComComponent()
{ }
// network
connect(sGui->getIContextNetwork(), &IContextNetwork::changedAtcStationsOnlineDigest, this, &CCockpitComComponent::onAtcStationsChanged, Qt::QueuedConnection);
void CCockpitComComponent::setTransponderModeStateIdent()
{
ui->editor_Com->setTransponderModeStateIdent();
}
QPointer<CCockpitComComponent> myself(this);
QTimer::singleShot(10 * 1000, this, [ = ]
{
if (!sGui || sGui->isShuttingDown() || !myself) { return; }
const CSimulatedAircraft aircraft = sGui->getIContextOwnAircraft()->getOwnAircraft();
this->updateCockpitFromContext(aircraft, CIdentifier::fake());
});
void CCockpitComComponent::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event)
CStyleSheetUtility::useStyleSheetInDerivedWidget(this);
}
void CCockpitComComponent::updateCockpitFromContext(const CSimulatedAircraft &ownAircraft, const CIdentifier &originator)
{
if (isMyIdentifier(originator)) { return; } // comes from myself
// update GUI elements
// avoid unnecessary change events as far as possible
const CComSystem com1 = ownAircraft.getCom1System(); // aircraft just updated or set from context
const CComSystem com2 = ownAircraft.getCom2System();
const CTransponder transponder = ownAircraft.getTransponder();
// update the frequencies
ui->editor_Com->setFrequencies(com1, com2);
// update transponder
ui->editor_Com->setTransponder(transponder);
// selected stations
if (sGui)
{
if (sGui->getIContextNetwork())
{
const CAtcStationList selectedStations = sGui->getIContextNetwork()->getSelectedAtcStations();
ui->editor_Com->setSelectedAtcStations(selectedStations);
}
}
}
CCockpitComComponent::~CCockpitComComponent()
{ }
void CCockpitComComponent::setTransponderModeStateIdent()
void CCockpitComComponent::testSelcal()
{
Q_ASSERT_X(sGui, Q_FUNC_INFO, "Need sGui");
const CSelcal selcal = ui->editor_Com->getSelcal();
if (!selcal.isValid())
{
ui->editor_Com->setTransponderModeStateIdent();
CLogMessage().validationWarning(u"Invalid SELCAL code");
}
void CCockpitComComponent::paintEvent(QPaintEvent *event)
else if (sGui->getCContextAudioBase())
{
Q_UNUSED(event)
CStyleSheetUtility::useStyleSheetInDerivedWidget(this);
sGui->getCContextAudioBase()->playSelcalTone(selcal);
}
void CCockpitComComponent::updateCockpitFromContext(const CSimulatedAircraft &ownAircraft, const CIdentifier &originator)
else
{
if (isMyIdentifier(originator)) { return; } // comes from myself
// update GUI elements
// avoid unnecessary change events as far as possible
const CComSystem com1 = ownAircraft.getCom1System(); // aircraft just updated or set from context
const CComSystem com2 = ownAircraft.getCom2System();
const CTransponder transponder = ownAircraft.getTransponder();
// update the frequencies
ui->editor_Com->setFrequencies(com1, com2);
// update transponder
ui->editor_Com->setTransponder(transponder);
// selected stations
if (sGui)
{
if (sGui->getIContextNetwork())
{
const CAtcStationList selectedStations = sGui->getIContextNetwork()->getSelectedAtcStations();
ui->editor_Com->setSelectedAtcStations(selectedStations);
}
}
CLogMessage().validationWarning(u"No audio available");
}
}
void CCockpitComComponent::testSelcal()
{
Q_ASSERT_X(sGui, Q_FUNC_INFO, "Need sGui");
const CSelcal selcal = ui->editor_Com->getSelcal();
if (!selcal.isValid())
{
CLogMessage().validationWarning(u"Invalid SELCAL code");
}
else if (sGui->getCContextAudioBase())
{
sGui->getCContextAudioBase()->playSelcalTone(selcal);
}
else
{
CLogMessage().validationWarning(u"No audio available");
}
}
void CCockpitComComponent::updateSelcalFromContext(const CSelcal &selcal, const CIdentifier &originator)
{
if (isMyIdentifier(originator)) { return; } // comes from myself
ui->editor_Com->setSelcal(selcal);
}
void CCockpitComComponent::updateSelcalFromContext(const CSelcal &selcal, const CIdentifier &originator)
{
if (isMyIdentifier(originator)) { return; } // comes from myself
ui->editor_Com->setSelcal(selcal);
}
CSimulatedAircraft CCockpitComComponent::getOwnAircraft() const
{
// unavailable context during shutdown possible
// mostly when client runs with DBus, but DBus is down
if (!sGui || sGui->isShuttingDown() || !sGui->getIContextOwnAircraft()) { return CSimulatedAircraft(); }
return sGui->getIContextOwnAircraft()->getOwnAircraft();
}
CSimulatedAircraft CCockpitComComponent::getOwnAircraft() const
{
// unavailable context during shutdown possible
// mostly when client runs with DBus, but DBus is down
if (!sGui || sGui->isShuttingDown() || !sGui->getIContextOwnAircraft()) { return CSimulatedAircraft(); }
return sGui->getIContextOwnAircraft()->getOwnAircraft();
}
bool CCockpitComComponent::updateOwnCockpitInContext(const CSimulatedAircraft &ownAircraft)
{
// unavailable context during shutdown possible
// mostly when client runs with DBus, but DBus is down
if (!sGui || sGui->isShuttingDown() || !sGui->getIContextOwnAircraft()) { return false; }
return sGui->getIContextOwnAircraft()->updateCockpit(ownAircraft.getCom1System(), ownAircraft.getCom2System(), ownAircraft.getTransponder(), identifier());
}
bool CCockpitComComponent::updateOwnCockpitInContext(const CSimulatedAircraft &ownAircraft)
{
// unavailable context during shutdown possible
// mostly when client runs with DBus, but DBus is down
if (!sGui || sGui->isShuttingDown() || !sGui->getIContextOwnAircraft()) { return false; }
return sGui->getIContextOwnAircraft()->updateCockpit(ownAircraft.getCom1System(), ownAircraft.getCom2System(), ownAircraft.getTransponder(), identifier());
}
void CCockpitComComponent::forceCockpitUpdateFromOwnAircraftContext()
{
if (!sGui || sGui->isShuttingDown()) { return; }
const CSimulatedAircraft ownAircraft = this->getOwnAircraft();
this->updateCockpitFromContext(ownAircraft, CIdentifier("dummyInitialValues")); // intentionally different name here
}
void CCockpitComComponent::forceCockpitUpdateFromOwnAircraftContext()
{
if (!sGui || sGui->isShuttingDown()) { return; }
const CSimulatedAircraft ownAircraft = this->getOwnAircraft();
this->updateCockpitFromContext(ownAircraft, CIdentifier("dummyInitialValues")); // intentionally different name here
}
void CCockpitComComponent::onAtcStationsChanged()
{
// void
}
void CCockpitComComponent::onAtcStationsChanged()
{
// void
}
void CCockpitComComponent::updateSelcalInContext(const CSelcal &selcal)
{
if (!sGui || sGui->isShuttingDown() || !sGui->getIContextOwnAircraft()) { return; }
sGui->getIContextOwnAircraft()->updateSelcal(selcal, identifier());
}
} // namespace
void CCockpitComComponent::updateSelcalInContext(const CSelcal &selcal)
{
if (!sGui || sGui->isShuttingDown() || !sGui->getIContextOwnAircraft()) { return; }
sGui->getIContextOwnAircraft()->updateSelcal(selcal, identifier());
}
} // namespace