From 9a0f2263cc58d3967cf7514dd90929638e75c281 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 27 Apr 2019 01:41:23 +0200 Subject: [PATCH] Ref T639, unify the connect buttons * toggle connection from button bar directly -> public * use Qt::QueuedConnection * allow to reset values --- src/blackgui/components/logincomponent.cpp | 32 ++++++++++++++-------- src/blackgui/components/logincomponent.h | 10 +++---- src/swiftguistandard/swiftguistd.cpp | 3 +- src/swiftguistandard/swiftguistdinit.cpp | 2 +- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/blackgui/components/logincomponent.cpp b/src/blackgui/components/logincomponent.cpp index 80899f5a3..6d82b2f35 100644 --- a/src/blackgui/components/logincomponent.cpp +++ b/src/blackgui/components/logincomponent.cpp @@ -91,11 +91,11 @@ namespace BlackGui connect(ui->comp_OtherServers, &CServerListSelector::serverChanged, this, &CLoginComponent::onSelectedServerChanged); connect(ui->comp_VatsimServers, &CServerListSelector::serverChanged, this, &CLoginComponent::onSelectedServerChanged); connect(ui->pb_RefreshOtherServers, &QToolButton::clicked, this, &CLoginComponent::reloadOtherServersSetup); - connect(ui->tw_Network, &QTabWidget::currentChanged, this, &CLoginComponent::onServerTabWidgetChanged); - connect(ui->pb_Cancel, &QPushButton::clicked, this, &CLoginComponent::loginCancelled); - connect(ui->pb_Ok, &QPushButton::clicked, this, &CLoginComponent::toggleNetworkConnection); + connect(ui->tw_Network, &QTabWidget::currentChanged, this, &CLoginComponent::onServerTabWidgetChanged); + connect(ui->pb_Cancel, &QPushButton::clicked, this, &CLoginComponent::loginCancelled, Qt::QueuedConnection); + connect(ui->pb_Ok, &QPushButton::clicked, this, &CLoginComponent::toggleNetworkConnection, Qt::QueuedConnection); connect(ui->pb_OtherServersGotoSettings, &QPushButton::pressed, this, &CLoginComponent::requestNetworkSettings); - connect(ui->pb_MappingWizard, &QToolButton::clicked, this, &CLoginComponent::mappingWizard); + connect(ui->pb_MappingWizard, &QToolButton::clicked, this, &CLoginComponent::mappingWizard, Qt::QueuedConnection); connect(&m_networkSetup, &CNetworkSetup::setupChanged, this, &CLoginComponent::reloadOtherServersSetup, Qt::QueuedConnection); ui->form_FsdDetails->showEnableInfo(true); @@ -184,19 +184,20 @@ namespace BlackGui m_logoffCountdownTimer.stop(); // in any case stop the timer if (currentWidget != this && currentWidget != this->parentWidget()) { - const bool wasVisible = m_visible; + // const bool wasVisible = m_visible; m_visible = false; m_logoffCountdownTimer.stop(); - if (wasVisible) + /** T639 + if (!wasVisible) { // set own values, and send signals this->setOwnModelAndIcaoValues(); } + **/ } else { - this->setOwnModelAndIcaoValues(); if (m_visible) { // already visible: @@ -206,6 +207,7 @@ namespace BlackGui else { m_visible = true; + this->setOwnModelAndIcaoValues(); const bool isConnected = sGui->getIContextNetwork()->isConnected(); this->setUiLoginState(isConnected); if (isConnected) { this->startLogoffTimerCountdown(); } @@ -503,15 +505,18 @@ namespace BlackGui m_logoffCountdownTimer.start(); } - void CLoginComponent::setOwnModelAndIcaoValues() + void CLoginComponent::setOwnModelAndIcaoValues(const CAircraftModel &ownModel) { if (!this->hasValidContexts()) { return; } - CAircraftModel model; + CAircraftModel model = ownModel; const bool simulating = sGui->getIContextSimulator() && (sGui->getIContextSimulator()->getSimulatorStatus() & ISimulator::Simulating); if (simulating) { - model = sGui->getIContextOwnAircraft()->getOwnAircraft().getModel(); + if (!model.hasModelString()) + { + model = sGui->getIContextOwnAircraft()->getOwnAircraft().getModel(); + } const QString modelAndKey(model.getModelStringAndDbKey()); ui->le_SimulatorModel->setText(modelAndKey); ui->le_SimulatorModel->home(false); @@ -524,7 +529,10 @@ namespace BlackGui } else { - model = this->getPrefillModel(); + if (!model.hasModelString()) + { + model = this->getPrefillModel(); + } ui->le_SimulatorModel->clear(); this->highlightModelField(); } @@ -698,7 +706,7 @@ namespace BlackGui CLogMessage(this).validationInfo(u"Hint: Are you using the emulated driver? Set a model if so!"); return; } - this->setOwnModelAndIcaoValues(); + this->setOwnModelAndIcaoValues(reverseModel); // open dialog for model mapping if (m_autoPopupWizard && !reverseModel.isLoadedFromDb()) diff --git a/src/blackgui/components/logincomponent.h b/src/blackgui/components/logincomponent.h index 62c9fa0a0..f2585d362 100644 --- a/src/blackgui/components/logincomponent.h +++ b/src/blackgui/components/logincomponent.h @@ -72,7 +72,7 @@ namespace BlackGui explicit CLoginComponent(QWidget *parent = nullptr); //! Destructor - virtual ~CLoginComponent(); + virtual ~CLoginComponent() override; //! Automatically popup void setAutoPopupWizad(bool autoPopup); @@ -83,6 +83,9 @@ namespace BlackGui //! Set a logoff time void setLogoffCountdown(int timeoutSeconds = -1); + //! Login requested + void toggleNetworkConnection(); + signals: //! Login void loginOrLogoffSuccessful(); @@ -158,9 +161,6 @@ namespace BlackGui //! Login cancelled void loginCancelled(); - //! Login requested - void toggleNetworkConnection(); - //! VATSIM data file was loaded void onWebServiceDataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number); @@ -198,7 +198,7 @@ namespace BlackGui void setUiLoginState(bool connected); //! Own model and ICAO data for GUI and own aircraft - void setOwnModelAndIcaoValues(); + void setOwnModelAndIcaoValues(const BlackMisc::Simulation::CAircraftModel &ownModel = {}); //! Set OK button string void setOkButtonString(bool connected); diff --git a/src/swiftguistandard/swiftguistd.cpp b/src/swiftguistandard/swiftguistd.cpp index 7287643ab..b55daf442 100644 --- a/src/swiftguistandard/swiftguistd.cpp +++ b/src/swiftguistandard/swiftguistd.cpp @@ -231,7 +231,8 @@ void SwiftGuiStd::loginRequested() if (ui->sw_MainMiddle->currentIndex() == static_cast(MainPageLogin)) { // already main page, we fake a re-trigger here - emit this->currentMainInfoAreaChanged(ui->sw_MainMiddle->currentWidget()); + // emit this->currentMainInfoAreaChanged(ui->sw_MainMiddle->currentWidget()); + ui->comp_Login->toggleNetworkConnection(); } else { diff --git a/src/swiftguistandard/swiftguistdinit.cpp b/src/swiftguistandard/swiftguistdinit.cpp index 957794619..17c6f26cb 100644 --- a/src/swiftguistandard/swiftguistdinit.cpp +++ b/src/swiftguistandard/swiftguistdinit.cpp @@ -245,7 +245,7 @@ void SwiftGuiStd::initGuiSignals() if (!sApp || sApp->isShuttingDown()) { return; } ui->sw_MainMiddle->setCurrentIndex(MainPageLogin); }); - connect(this, &SwiftGuiStd::currentMainInfoAreaChanged, ui->comp_Login, &CLoginComponent::mainInfoAreaChanged); + connect(this, &SwiftGuiStd::currentMainInfoAreaChanged, ui->comp_Login, &CLoginComponent::mainInfoAreaChanged, Qt::QueuedConnection); // text messages connect(ui->comp_MainInfoArea->getAtcStationComponent(), &CAtcStationComponent::requestTextMessageWidget, ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::showCorrespondingTab, Qt::QueuedConnection);