From 000d0da92a57213975fd6b8cfa8d4f72699fd7d2 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 17 Apr 2020 11:22:36 +0200 Subject: [PATCH] [UI] Internals page * changed to callsign completer (combobox too long) * allow to display own parts --- src/blackgui/components/callsigncompleter.cpp | 29 +++++++++- src/blackgui/components/callsigncompleter.h | 9 +++ .../components/internalscomponent.cpp | 58 ++++++++++++------- src/blackgui/components/internalscomponent.h | 7 ++- src/blackgui/components/internalscomponent.ui | 23 +++++--- .../components/remoteaircraftselector.h | 4 +- 6 files changed, 95 insertions(+), 35 deletions(-) diff --git a/src/blackgui/components/callsigncompleter.cpp b/src/blackgui/components/callsigncompleter.cpp index 263f3c40c..bf6b7742b 100644 --- a/src/blackgui/components/callsigncompleter.cpp +++ b/src/blackgui/components/callsigncompleter.cpp @@ -8,15 +8,19 @@ #include "callsigncompleter.h" #include "ui_callsigncompleter.h" -#include "blackcore/context/contextnetwork.h" #include "blackgui/guiapplication.h" #include "blackgui/led.h" #include "blackgui/uppercasevalidator.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/context/contextownaircraft.h" +#include "blackmisc/simulation/simulatedaircraftlist.h" + #include using namespace BlackMisc; using namespace BlackMisc::Aviation; using namespace BlackMisc::Network; +using namespace BlackMisc::Simulation; using namespace BlackCore; using namespace BlackCore::Context; @@ -83,7 +87,26 @@ namespace BlackGui if (!sGui || sGui->isShuttingDown()) { return; } if (!sGui->getIContextNetwork()) { return; } if (completer()->wasUpdatedWithinTime(1500)) { return; } // avoid context call via DBus - const CCallsignSet validCallsigns = sGui->getIContextNetwork()->getAircraftInRangeCallsigns(); + CCallsignSet validCallsigns; + if (m_onlyWithParts) + { + //! \todo KB 2020-04 transfers allaircraft via DBus + validCallsigns = sGui->getIContextNetwork()->getAircraftInRange().getCallsignsWithSynchronizedParts(); + } + else + { + validCallsigns = sGui->getIContextNetwork()->getAircraftInRangeCallsigns(); + } + + if (m_addOwnCallsign && sGui->getIContextOwnAircraft()) + { + const CCallsign ownCs = sGui->getIContextOwnAircraft()->getOwnAircraft().getCallsign(); + if (!ownCs.isEmpty()) + { + validCallsigns.insert(ownCs); + } + } + const QStringList modelData = validCallsigns.getCallsignStrings(true); completer()->updateData(modelData, 2000); ui->led_Status->setTriState(500); @@ -109,7 +132,7 @@ namespace BlackGui void CCallsignCompleter::onChangedConnectionStatus(const CConnectionStatus &from, const CConnectionStatus &to) { - Q_UNUSED(from); + Q_UNUSED(from) const bool connected = to.isConnected(); ui->led_Status->setOn(connected); ui->le_Callsign->clear(); diff --git a/src/blackgui/components/callsigncompleter.h b/src/blackgui/components/callsigncompleter.h index 8f9261444..502a4b1c2 100644 --- a/src/blackgui/components/callsigncompleter.h +++ b/src/blackgui/components/callsigncompleter.h @@ -55,6 +55,12 @@ namespace BlackGui //! Set read only void setReadOnly(bool readOnly); + //! Add own callsign + void addOwnCallsign(bool add) { m_addOwnCallsign = add; } + + //! Only with parts + void onlyWithParts(bool partsOnly) { m_onlyWithParts = partsOnly; } + signals: //! Changed callsign entered void validChangedCallsignEntered(); @@ -80,6 +86,9 @@ namespace BlackGui BlackMisc::CDigestSignal m_dsEditingFinished { this, &CCallsignCompleter::editingFinishedDigest, 500, 3 }; BlackMisc::CDigestSignal m_dsValidCallsignEntered { this, &CCallsignCompleter::validCallsignEnteredDigest, 500, 3 }; QString m_lastValue; + + bool m_addOwnCallsign = false; + bool m_onlyWithParts = false; }; } // ns } // ns diff --git a/src/blackgui/components/internalscomponent.cpp b/src/blackgui/components/internalscomponent.cpp index 5186c207d..03079d52c 100644 --- a/src/blackgui/components/internalscomponent.cpp +++ b/src/blackgui/components/internalscomponent.cpp @@ -61,16 +61,16 @@ namespace BlackGui { ui->setupUi(this); ui->tw_Internals->setCurrentIndex(0); - ui->comp_RemoteAircraftSelector->indicatePartsEnabled(true); ui->editor_AircraftParts->showSetButton(false); ui->le_TxtMsgFrom->setValidator(new CUpperCaseValidator(ui->le_TxtMsgFrom)); ui->le_TxtMsgTo->setValidator(new CUpperCaseValidator(ui->le_TxtMsgFrom)); ui->le_AtisCallsign->setValidator(new CUpperCaseValidator(ui->le_AtisCallsign)); - connect(ui->pb_SendAircraftPartsGui, &QPushButton::released, this, &CInternalsComponent::sendAircraftParts); - connect(ui->pb_SendAircraftPartsJson, &QPushButton::released, this, &CInternalsComponent::sendAircraftParts); - connect(ui->pb_CurrentParts, &QPushButton::released, this, &CInternalsComponent::setCurrentParts); + connect(ui->pb_SendAircraftPartsGui, &QPushButton::released, this, &CInternalsComponent::sendAircraftParts); + connect(ui->pb_SendAircraftPartsJson, &QPushButton::released, this, &CInternalsComponent::sendAircraftParts); + connect(ui->pb_CurrentParts, &QPushButton::released, this, &CInternalsComponent::setCurrentParts); + connect(ui->pb_OwnParts, &QPushButton::released, this, &CInternalsComponent::displayOwnParts); connect(ui->cb_DebugContextAudio, &QCheckBox::stateChanged, this, &CInternalsComponent::enableDebug); connect(ui->cb_DebugContextApplication, &QCheckBox::stateChanged, this, &CInternalsComponent::enableDebug); @@ -81,20 +81,20 @@ namespace BlackGui connect(ui->pb_SendTextMessageDirectly, &QPushButton::released, this, &CInternalsComponent::sendTextMessage, Qt::QueuedConnection); connect(ui->pb_SendTextMessageDeferred, &QPushButton::released, this, &CInternalsComponent::sendTextMessage, Qt::QueuedConnection); - connect(ui->tb_LogStatusMessage, &QPushButton::released, this, &CInternalsComponent::logStatusMessage); - connect(ui->le_StatusMessage, &QLineEdit::returnPressed, this, &CInternalsComponent::logStatusMessage); + connect(ui->tb_LogStatusMessage, &QPushButton::released, this, &CInternalsComponent::logStatusMessage); + connect(ui->le_StatusMessage, &QLineEdit::returnPressed, this, &CInternalsComponent::logStatusMessage); - connect(ui->pb_LatestInterpolationLog, &QPushButton::released, this, &CInternalsComponent::showLogFiles); - connect(ui->pb_LatestPartsLog, &QPushButton::released, this, &CInternalsComponent::showLogFiles); - connect(ui->pb_RequestFromNetwork, &QPushButton::released, this, &CInternalsComponent::requestPartsFromNetwork); - connect(ui->pb_DisplayLog, &QPushButton::released, this, &CInternalsComponent::displayLogInSimulator); - connect(ui->pb_SendAtis, &QPushButton::released, this, &CInternalsComponent::sendAtis); + connect(ui->pb_LatestInterpolationLog, &QPushButton::released, this, &CInternalsComponent::showLogFiles); + connect(ui->pb_LatestPartsLog, &QPushButton::released, this, &CInternalsComponent::showLogFiles); + connect(ui->pb_RequestFromNetwork, &QPushButton::released, this, &CInternalsComponent::requestPartsFromNetwork); + connect(ui->pb_DisplayLog, &QPushButton::released, this, &CInternalsComponent::displayLogInSimulator); + connect(ui->pb_SendAtis, &QPushButton::released, this, &CInternalsComponent::sendAtis); - connect(ui->pb_NetworkUpdateAndReset, &QPushButton::released, this, &CInternalsComponent::networkStatistics); - connect(ui->pb_NetworkUpdate, &QPushButton::released, this, &CInternalsComponent::networkStatistics); - connect(ui->cb_NetworkStatistics, &QCheckBox::stateChanged, this, &CInternalsComponent::onNetworkStatisticsToggled); + connect(ui->pb_NetworkUpdateAndReset, &QPushButton::released, this, &CInternalsComponent::networkStatistics); + connect(ui->pb_NetworkUpdate, &QPushButton::released, this, &CInternalsComponent::networkStatistics); + connect(ui->cb_NetworkStatistics, &QCheckBox::stateChanged, this, &CInternalsComponent::onNetworkStatisticsToggled); - connect(ui->comp_RemoteAircraftSelector, &CRemoteAircraftSelector::changedCallsign, this, &CInternalsComponent::selectorChanged); + connect(ui->comp_RemoteAircraftCompleter, &CCallsignCompleter::validCallsignEnteredDigest, this, &CInternalsComponent::onCallsignChanged); if (sGui && sGui->isSupportingCrashpad()) { @@ -109,6 +109,7 @@ namespace BlackGui ui->cb_CrashDumpUpload->setEnabled(false); } + ui->comp_RemoteAircraftCompleter->addOwnCallsign(true); this->contextFlagsToGui(); } @@ -131,7 +132,7 @@ namespace BlackGui CLogMessage(this).validationError(u"Cannot send aircraft parts, network not connected"); return; } - const CCallsign callsign(ui->comp_RemoteAircraftSelector->getSelectedCallsign()); + const CCallsign callsign(ui->comp_RemoteAircraftCompleter->getCallsign(true)); if (callsign.isEmpty()) { CLogMessage(this).validationError(u"No valid callsign selected"); @@ -168,7 +169,7 @@ namespace BlackGui void CInternalsComponent::setCurrentParts() { if (!sGui->getIContextNetwork()->isConnected()) { return; } - const CCallsign callsign(ui->comp_RemoteAircraftSelector->getSelectedCallsign()); + const CCallsign callsign(ui->comp_RemoteAircraftCompleter->getCallsign()); if (callsign.isEmpty()) { return; } const CAircraftPartsList partsList = sGui->getIContextNetwork()->getRemoteAircraftParts(callsign); @@ -288,7 +289,10 @@ namespace BlackGui void CInternalsComponent::requestPartsFromNetwork() { - const CCallsign callsign(ui->comp_RemoteAircraftSelector->getSelectedCallsign()); + if (!sGui || sGui->isShuttingDown()) { return; } + if (!sGui->getIContextNetwork()) { return; } + + const CCallsign callsign(ui->comp_RemoteAircraftCompleter->getCallsign(true)); if (callsign.isEmpty()) { CLogMessage(this).validationError(u"No valid callsign selected"); @@ -308,16 +312,28 @@ namespace BlackGui }); } - void CInternalsComponent::selectorChanged() + void CInternalsComponent::onCallsignChanged() { this->setCurrentParts(); } + void CInternalsComponent::displayOwnParts() + { + if (!sGui || sGui->isShuttingDown()) { return; } + if (!sGui->getIContextOwnAircraft()) { return; } + + const CSimulatedAircraft myAircraft = sGui->getIContextOwnAircraft()->getOwnAircraft(); + const CCallsign cs = myAircraft.getCallsign(); + const CAircraftParts parts = myAircraft.getParts(); + ui->comp_RemoteAircraftCompleter->setCallsign(cs); + ui->editor_AircraftParts->setAircraftParts(parts); + } + void CInternalsComponent::displayLogInSimulator() { if (!sGui || sGui->isShuttingDown()) { return; } - if (!sGui->getIContextSimulator()) { return; } - const CCallsign callsign(ui->comp_RemoteAircraftSelector->getSelectedCallsign()); + if (!sGui->getIContextSimulator()) { return; } + const CCallsign callsign(ui->comp_RemoteAircraftCompleter->getCallsign(true)); if (callsign.isEmpty()) { CLogMessage(this).validationError(u"No valid callsign selected"); diff --git a/src/blackgui/components/internalscomponent.h b/src/blackgui/components/internalscomponent.h index 7c0a63f6e..9ce7b587d 100644 --- a/src/blackgui/components/internalscomponent.h +++ b/src/blackgui/components/internalscomponent.h @@ -66,8 +66,11 @@ namespace BlackGui //! Request parts (aka aircraft config) from network void requestPartsFromNetwork(); - //! Selector has been changed - void selectorChanged(); + //! Completer has been changed + void onCallsignChanged(); + + //! Display own parts + void displayOwnParts(); //! Log in simulator void displayLogInSimulator(); diff --git a/src/blackgui/components/internalscomponent.ui b/src/blackgui/components/internalscomponent.ui index 0c0ca66f9..8dea68b46 100644 --- a/src/blackgui/components/internalscomponent.ui +++ b/src/blackgui/components/internalscomponent.ui @@ -6,7 +6,7 @@ 0 0 - 306 + 326 690 @@ -476,7 +476,7 @@ - + 0 @@ -500,6 +500,13 @@ 0 + + + + own parts + + + @@ -722,18 +729,18 @@
blackgui/editors/aircraftpartsform.h
1 - - BlackGui::Components::CRemoteAircraftSelector - QFrame -
blackgui/components/remoteaircraftselector.h
- 1 -
BlackGui::Components::CRawFsdMessagesComponent QFrame
blackgui/components/rawfsdmessagescomponent.h
1
+ + BlackGui::Components::CCallsignCompleter + QFrame +
blackgui/components/callsigncompleter.h
+ 1 +
tw_Internals diff --git a/src/blackgui/components/remoteaircraftselector.h b/src/blackgui/components/remoteaircraftselector.h index dd2af3b50..a132afcc0 100644 --- a/src/blackgui/components/remoteaircraftselector.h +++ b/src/blackgui/components/remoteaircraftselector.h @@ -30,6 +30,8 @@ namespace BlackGui namespace Components { //! Select a remote aircraft + //! \deprecated list gets too long with many aircraft + //! \remark CCallsignCompleter as a better alternative class BLACKGUI_EXPORT CRemoteAircraftSelector : public QFrame { Q_OBJECT @@ -39,7 +41,7 @@ namespace BlackGui explicit CRemoteAircraftSelector(QWidget *parent = nullptr); //! Destructor - virtual ~CRemoteAircraftSelector(); + virtual ~CRemoteAircraftSelector() override; //! Selected callsign BlackMisc::Aviation::CCallsign getSelectedCallsign() const;