diff --git a/src/blackgui/components/flightplancomponent.cpp b/src/blackgui/components/flightplancomponent.cpp index ac1a83e1a..3d0f6d772 100644 --- a/src/blackgui/components/flightplancomponent.cpp +++ b/src/blackgui/components/flightplancomponent.cpp @@ -6,9 +6,11 @@ * or distributed except according to the terms contained in the LICENSE file. */ +#include "flightplancomponent.h" +#include "altitudedialog.h" +#include "selcalcodeselector.h" +#include "stringlistdialog.h" #include "blackgui/uppercasevalidator.h" -#include "blackgui/components/flightplancomponent.h" -#include "blackgui/components/selcalcodeselector.h" #include "blackgui/guiapplication.h" #include "blackcore/context/contextnetwork.h" #include "blackcore/context/contextownaircraft.h" @@ -135,6 +137,9 @@ namespace BlackGui connect(ui->cb_Heavy, &QCheckBox::released, this, &CFlightPlanComponent::prefixCheckBoxChanged, Qt::QueuedConnection); connect(ui->cb_Tcas, &QCheckBox::released, this, &CFlightPlanComponent::prefixCheckBoxChanged, Qt::QueuedConnection); + connect(ui->pb_Remarks, &QPushButton::pressed, this, &CFlightPlanComponent::remarksHistory, Qt::QueuedConnection); + connect(ui->pb_AddRemarks, &QPushButton::pressed, this, &CFlightPlanComponent::remarksHistory, Qt::QueuedConnection); + // web services connect(sGui->getWebDataServices(), &CWebDataServices::swiftDbAllDataRead, this, &CFlightPlanComponent::swiftWebDataRead, Qt::QueuedConnection); @@ -322,7 +327,7 @@ namespace BlackGui v = ui->pte_Remarks->toPlainText().trimmed(); if (v.isEmpty()) { - messages.push_back(CStatusMessage(this).validationError(u"No '%1', voice capabilities are mandatory") << ui->lbl_Remarks->text()); + messages.push_back(CStatusMessage(this).validationError(u"No '%1', voice capabilities are mandatory") << ui->pb_Remarks->text()); } else if (v.length() > CFlightPlan::MaxRemarksLength) { @@ -450,6 +455,7 @@ namespace BlackGui if (m.isSeverityInfoOrLess()) { this->showOverlayHTMLMessage(m, OverlayTimeoutMs); + this->updateRemarksHistories(); // all OK, we keep that in history } else { @@ -665,10 +671,10 @@ namespace BlackGui { if (ui->cb_Tcas->isChecked()) { - const QPointer guard(this); + const QPointer myself(this); QTimer::singleShot(10, this, [ = ] { - if (guard.isNull()) { return; } + if (!myself) { return; } ui->cb_Heavy->setChecked(false); this->buildPrefixIcaoSuffix(); }); @@ -832,6 +838,59 @@ namespace BlackGui } } + void CFlightPlanComponent::updateRemarksHistories() + { + QString r = ui->pte_Remarks->toPlainText(); + if (!r.isEmpty()) + { + QStringList h = m_remarksHistory.get(); + if (consolidateRemarks(h, r)) + { + CStatusMessage m = m_remarksHistory.setAndSave(h); + CLogMessage::preformatted(m); + } + } + + r = ui->pte_AdditionalRemarks->toPlainText(); + if (!r.isEmpty()) + { + QStringList h = m_remarksHistoryAdditional.get(); + if (consolidateRemarks(h, r)) + { + CStatusMessage m = m_remarksHistoryAdditional.setAndSave(h); + CLogMessage::preformatted(m); + } + } + } + + bool CFlightPlanComponent::consolidateRemarks(QStringList &remarks, const QString &newRemarks) + { + if (newRemarks.isEmpty()) { return false; } + remarks.removeAll(newRemarks); + remarks.push_front(newRemarks); + return true; + } + + void CFlightPlanComponent::remarksHistory() + { + const QObject *sender = QObject::sender(); + if (!m_fpRemarksDialog) + { + m_fpRemarksDialog = new CStringListDialog(this); + m_fpRemarksDialog->setModal(true); + } + if (sender == ui->pb_Remarks) { m_fpRemarksDialog->setStrings(m_remarksHistory.getThreadLocal()); } + else if (sender == ui->pb_AddRemarks) { m_fpRemarksDialog->setStrings(m_remarksHistoryAdditional.getThreadLocal()); } + + const int rv = m_fpRemarksDialog->exec(); + if (rv != QDialog::Accepted) { return; } + const QString remarks = m_fpRemarksDialog->getSelectedValue(); + if (remarks.isEmpty()) { return; } + + if (sender == ui->pb_Remarks) { ui->pte_Remarks->setPlainText(remarks); } + else if (sender == ui->pb_AddRemarks) { ui->pte_AdditionalRemarks->setPlainText(remarks); } + } + void CFlightPlanComponent::initCompleters() { if (!sGui || !sGui->hasWebDataServices()) { return; } diff --git a/src/blackgui/components/flightplancomponent.h b/src/blackgui/components/flightplancomponent.h index f31e97b5d..d31f98053 100644 --- a/src/blackgui/components/flightplancomponent.h +++ b/src/blackgui/components/flightplancomponent.h @@ -12,7 +12,6 @@ #define BLACKGUI_COMPONENTS_FLIGHTPLANCOMPONENT_H #include "blackgui/overlaymessagesframe.h" -#include "blackgui/components/altitudedialog.h" #include "blackgui/blackguiexport.h" #include "blackmisc/simulation/data/lastmodel.h" #include "blackmisc/simulation/simulatedaircraft.h" @@ -28,7 +27,7 @@ #include #include -#include +#include #include #include #include @@ -38,6 +37,32 @@ namespace BlackGui { namespace Components { + namespace FlightPlanSettings + { + //! Remarks history + struct TRemarksHistory : public BlackMisc::TSettingTrait + { + //! \copydoc BlackMisc::TSettingTrait::key + static const char *key() { return "flightplan/remarkshistory"; } + + //! \copydoc BlackMisc::TSettingTrait::humanReadable + static const QString &humanReadable() { static const QString name("FP remarks history"); return name; } + }; + + //! Additional remarks history + struct TRemarksHistoryAdditional : public BlackMisc::TSettingTrait + { + //! \copydoc BlackMisc::TSettingTrait::key + static const char *key() { return "flightplan/remarkshistoryadd"; } + + //! \copydoc BlackMisc::TSettingTrait::humanReadable + static const QString &humanReadable() { static const QString name("FP remarks history (add)"); return name; } + }; + } + + class CStringListDialog; + class CAltitudeDialog; + //! Flight plan widget class BLACKGUI_EXPORT CFlightPlanComponent : public COverlayMessagesTabWidget { @@ -66,12 +91,15 @@ namespace BlackGui static constexpr int OverlayTimeoutMs = 5000; QScopedPointer ui; CAltitudeDialog *m_altitudeDialog = nullptr; + CStringListDialog *m_fpRemarksDialog = nullptr; BlackMisc::Aviation::CFlightPlan m_sentFlightPlan; //!< My flight plan BlackMisc::Simulation::CAircraftModel m_model; //!< currently used model BlackMisc::CIdentifier m_identifier { "FlightPlanComponent", this }; //!< Flightplan identifier - BlackMisc::CSetting m_directories { this }; //!< the swift directories - BlackMisc::CDataReadOnly m_lastAircraftModel { this }; //!< recently used aircraft model - BlackMisc::CDataReadOnly m_lastServer { this }; //!< recently used server (VATSIM, other) + BlackMisc::CSetting m_directories { this }; //!< the swift directories + BlackMisc::CSetting m_remarksHistory { this }; //!< remarks history + BlackMisc::CSetting m_remarksHistoryAdditional { this }; //!< remarks history + BlackMisc::CDataReadOnly m_lastAircraftModel { this }; //!< recently used aircraft model + BlackMisc::CDataReadOnly m_lastServer { this }; //!< recently used server (VATSIM, other) //! Validate, generates status messages BlackMisc::CStatusMessageList validateAndInitializeFlightPlan(BlackMisc::Aviation::CFlightPlan &fligtPlan); @@ -183,6 +211,15 @@ namespace BlackGui //! Altitude dialog void altitudeDialog(); + + //! FP remarks history selection + void remarksHistory(); + + //! Update the remarks histories + void updateRemarksHistories(); + + //! Consolidate the new remarks list, latest on front + static bool consolidateRemarks(QStringList &remarks, const QString &newRemarks); }; } // ns } // ns diff --git a/src/blackgui/components/flightplancomponent.ui b/src/blackgui/components/flightplancomponent.ui index d053bbd75..ad23c6445 100644 --- a/src/blackgui/components/flightplancomponent.ui +++ b/src/blackgui/components/flightplancomponent.ui @@ -42,7 +42,7 @@ 0 - 0 + -137 383 480 @@ -312,13 +312,6 @@ - - - - 11. Remarks - - - @@ -739,6 +732,13 @@ + + + + 11.remarks + + + @@ -773,7 +773,7 @@ 0 - 0 + -93 383 436 @@ -811,114 +811,21 @@ 6 - - - - Remarks - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - Required Navigation Performance - - - true - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - Parse - - - - - - - Copy over - - - - - - - - + + - P0 - unrated + Full voice - P1 + Text only - P2 - - - - - P3 - - - - - P4 - - - - - P5 - - - - - - - - - - - Performance category - - - true - - - - - - - - VFR - not required - - - - - 10 miles radius - - - - - 4 miles radius + Receive voice @@ -933,40 +840,13 @@ - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - + + - Airline operator + Remarks - - true - - - - - - - Pilot rating - - - - - - - Navigation equipment - - - true + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop @@ -1007,27 +887,22 @@ - - - - - Full voice - - - - - Text only - - - - - Receive voice - - + + + + Navigation equipment + + + true + - - + + + + SIDs / STARs + + @@ -1036,7 +911,67 @@ - + + + + + + + no SIDs / STARs + + + + + + + + P0 - unrated + + + + + P1 + + + + + P2 + + + + + P3 + + + + + P4 + + + + + P5 + + + + + + + + + 16777215 + 75 + + + + true + + + generated remarks + + + + @@ -1049,16 +984,101 @@ - - + + - Additional remarks - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Airline operator - false + true + + + + + + + Performance category + + + true + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Copy over + + + + + + + + + + + VFR - not required + + + + + 10 miles radius + + + + + 4 miles radius + + + + + + + + + + + Required Navigation Performance + + + true + + + + + + + Pilot rating + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Voice capabilities + + + true @@ -1094,43 +1114,10 @@ - - + + - no SIDs / STARs - - - - - - - Voice capabilities - - - true - - - - - - - SIDs / STARs - - - - - - - - 16777215 - 75 - - - - true - - - generated remarks + add.remarks @@ -1265,7 +1252,6 @@ p, li { white-space: pre-wrap; } cb_PilotRating pte_RemarksGenerated pte_AdditionalRemarks - pb_Parse pb_CopyOver tbr_EquipmentCodes