Improved aircraft selector

* digest signal to fill combobox
* sorted by callsigns
This commit is contained in:
Klaus Basan
2018-05-07 02:06:39 +02:00
committed by Roland Winklmeier
parent 7590be1a54
commit 337f661499
2 changed files with 37 additions and 35 deletions

View File

@@ -37,11 +37,11 @@ namespace BlackGui
ui(new Ui::CRemoteAircraftSelector) ui(new Ui::CRemoteAircraftSelector)
{ {
ui->setupUi(this); ui->setupUi(this);
bool s = connect(sGui->getIContextNetwork(), &IContextNetwork::removedAircraft, this, &CRemoteAircraftSelector::ps_onRemovedAircraft); bool s = connect(sGui->getIContextNetwork(), &IContextNetwork::removedAircraft, this, &CRemoteAircraftSelector::onRemovedAircraft);
Q_ASSERT(s); Q_ASSERT(s);
s = connect(sGui->getIContextNetwork(), &IContextNetwork::addedAircraft, this, &CRemoteAircraftSelector::ps_onAddedAircraft); s = connect(sGui->getIContextNetwork(), &IContextNetwork::addedAircraft, this, &CRemoteAircraftSelector::onAddedAircraft);
Q_ASSERT(s); Q_ASSERT(s);
s = connect(ui->cb_RemoteAircraftSelector, &QComboBox::currentTextChanged, this, &CRemoteAircraftSelector::ps_comboBoxChanged); s = connect(ui->cb_RemoteAircraftSelector, &QComboBox::currentTextChanged, this, &CRemoteAircraftSelector::comboBoxChanged);
Q_UNUSED(s); Q_UNUSED(s);
} }
@@ -49,9 +49,9 @@ namespace BlackGui
BlackMisc::Aviation::CCallsign CRemoteAircraftSelector::getSelectedCallsign() const BlackMisc::Aviation::CCallsign CRemoteAircraftSelector::getSelectedCallsign() const
{ {
const CCallsign empty {}; static const CCallsign empty {};
int index = ui->cb_RemoteAircraftSelector->currentIndex(); const int index = ui->cb_RemoteAircraftSelector->currentIndex();
if (index < 0 || index > this->m_aircraft.size()) { return empty; } if (index < 0 || index > m_aircraft.size()) { return empty; }
return m_aircraft[index].getCallsign(); return m_aircraft[index].getCallsign();
} }
@@ -63,39 +63,41 @@ namespace BlackGui
void CRemoteAircraftSelector::showEvent(QShowEvent *event) void CRemoteAircraftSelector::showEvent(QShowEvent *event)
{ {
// force new combobox when visible // force new combobox when visible
this->fillComboBox(); m_dsFillComboBox.inputSignal(); // fill combo box
QWidget::showEvent(event); QWidget::showEvent(event);
} }
void CRemoteAircraftSelector::ps_onAddedAircraft(const CSimulatedAircraft &aircraft) void CRemoteAircraftSelector::onAddedAircraft(const CSimulatedAircraft &aircraft)
{ {
CCallsign cs(aircraft.getCallsign()); CCallsign cs(aircraft.getCallsign());
if (cs.isEmpty()) { return; } if (cs.isEmpty()) { return; }
if (this->m_aircraft.containsCallsign(cs)) { return; } if (m_aircraft.containsCallsign(cs)) { return; }
this->fillComboBox(); m_dsFillComboBox.inputSignal(); // fill combo box
} }
void CRemoteAircraftSelector::ps_onRemovedAircraft(const CCallsign &callsign) void CRemoteAircraftSelector::onRemovedAircraft(const CCallsign &callsign)
{ {
if (callsign.isEmpty()) { return; } if (callsign.isEmpty()) { return; }
if (this->m_aircraft.containsCallsign(callsign)) if (m_aircraft.containsCallsign(callsign))
{ {
this->fillComboBox(); m_dsFillComboBox.inputSignal(); // fill combo box
} }
} }
void CRemoteAircraftSelector::ps_comboBoxChanged(const QString &text) void CRemoteAircraftSelector::comboBoxChanged(const QString &text)
{ {
if (this->m_currentText == text) { return; } if (m_currentText == text) { return; }
this->m_currentText = text; m_currentText = text;
emit this->changedCallsign(); emit this->changedCallsign();
} }
void CRemoteAircraftSelector::fillComboBox() void CRemoteAircraftSelector::fillComboBox()
{ {
if (!this->isVisible()) { return; } // for performance reasons if (!this->isVisible()) { return; } // for performance reasons
if (!sGui || sGui->isShuttingDown()) { return; }
const CCallsign currentSelection(this->getSelectedCallsign()); const CCallsign currentSelection(this->getSelectedCallsign());
m_aircraft = sGui->getIContextNetwork()->getAircraftInRange(); m_aircraft = sGui->getIContextNetwork()->getAircraftInRange().sortedByCallsign();
ui->cb_RemoteAircraftSelector->clear(); ui->cb_RemoteAircraftSelector->clear();
if (m_aircraft.isEmpty()) { return; } if (m_aircraft.isEmpty()) { return; }
@@ -106,19 +108,19 @@ namespace BlackGui
QString i(aircraft.getCallsign().toQString()); QString i(aircraft.getCallsign().toQString());
if (aircraft.hasAircraftDesignator()) if (aircraft.hasAircraftDesignator())
{ {
i += QLatin1String(" (") % i += QStringLiteral(" (") %
aircraft.getAircraftIcaoCode().toQString(false) % aircraft.getAircraftIcaoCode().toQString(false) %
QLatin1String(")"); QStringLiteral(")");
} }
if (aircraft.hasRealName()) if (aircraft.hasRealName())
{ {
i += QLatin1String(" - ") % aircraft.getPilotRealName(); i += QStringLiteral(" - ") % aircraft.getPilotRealName();
} }
if (m_showPartsEnabled) if (m_showPartsEnabled)
{ {
if (aircraft.isPartsSynchronized()) if (aircraft.isPartsSynchronized())
{ {
i += " [parts]"; i += QStringLiteral(" [parts]");
} }
} }
items.append(i); items.append(i);

View File

@@ -13,8 +13,9 @@
#define BLACKGUI_REMOTEAIRCRAFTSELECTOR_H #define BLACKGUI_REMOTEAIRCRAFTSELECTOR_H
#include "blackgui/blackguiexport.h" #include "blackgui/blackguiexport.h"
#include "blackmisc/aviation/callsign.h"
#include "blackmisc/simulation/simulatedaircraftlist.h" #include "blackmisc/simulation/simulatedaircraftlist.h"
#include "blackmisc/aviation/callsign.h"
#include "blackmisc/digestsignal.h"
#include <QFrame> #include <QFrame>
#include <QObject> #include <QObject>
@@ -55,25 +56,24 @@ namespace BlackGui
//! \copydoc QWidget::showEvent //! \copydoc QWidget::showEvent
virtual void showEvent(QShowEvent *event) override; virtual void showEvent(QShowEvent *event) override;
private slots: private:
//! Change content of combobox //! Added aircraft, change content of combobox
void ps_onAddedAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); void onAddedAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
//! IContextNetwork::removedAircraft //! Removed aircraft, change content of combobox
void ps_onRemovedAircraft(const BlackMisc::Aviation::CCallsign &callsign); void onRemovedAircraft(const BlackMisc::Aviation::CCallsign &callsign);
//! Combo box has been changed //! Combo box has been changed
void ps_comboBoxChanged(const QString &text); void comboBoxChanged(const QString &text);
private:
QScopedPointer<Ui::CRemoteAircraftSelector> ui;
QString m_currentText;
bool m_showPartsEnabled = false;
BlackMisc::Simulation::CSimulatedAircraftList m_aircraft;
//! Set combobox items //! Set combobox items
void fillComboBox(); void fillComboBox();
QScopedPointer<Ui::CRemoteAircraftSelector> ui;
QString m_currentText;
bool m_showPartsEnabled = false;
BlackMisc::Simulation::CSimulatedAircraftList m_aircraft;
BlackMisc::CDigestSignal m_dsFillComboBox { this, &CRemoteAircraftSelector::fillComboBox, 3000, 5 };
}; };
} // namespace } // namespace
} // namespace } // namespace