mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 07:35:48 +08:00
Improved aircraft selector
* digest signal to fill combobox * sorted by callsigns
This commit is contained in:
committed by
Roland Winklmeier
parent
7590be1a54
commit
337f661499
@@ -37,11 +37,11 @@ namespace BlackGui
|
||||
ui(new Ui::CRemoteAircraftSelector)
|
||||
{
|
||||
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);
|
||||
s = connect(sGui->getIContextNetwork(), &IContextNetwork::addedAircraft, this, &CRemoteAircraftSelector::ps_onAddedAircraft);
|
||||
s = connect(sGui->getIContextNetwork(), &IContextNetwork::addedAircraft, this, &CRemoteAircraftSelector::onAddedAircraft);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -49,9 +49,9 @@ namespace BlackGui
|
||||
|
||||
BlackMisc::Aviation::CCallsign CRemoteAircraftSelector::getSelectedCallsign() const
|
||||
{
|
||||
const CCallsign empty {};
|
||||
int index = ui->cb_RemoteAircraftSelector->currentIndex();
|
||||
if (index < 0 || index > this->m_aircraft.size()) { return empty; }
|
||||
static const CCallsign empty {};
|
||||
const int index = ui->cb_RemoteAircraftSelector->currentIndex();
|
||||
if (index < 0 || index > m_aircraft.size()) { return empty; }
|
||||
return m_aircraft[index].getCallsign();
|
||||
}
|
||||
|
||||
@@ -63,39 +63,41 @@ namespace BlackGui
|
||||
void CRemoteAircraftSelector::showEvent(QShowEvent *event)
|
||||
{
|
||||
// force new combobox when visible
|
||||
this->fillComboBox();
|
||||
m_dsFillComboBox.inputSignal(); // fill combo box
|
||||
QWidget::showEvent(event);
|
||||
}
|
||||
|
||||
void CRemoteAircraftSelector::ps_onAddedAircraft(const CSimulatedAircraft &aircraft)
|
||||
void CRemoteAircraftSelector::onAddedAircraft(const CSimulatedAircraft &aircraft)
|
||||
{
|
||||
CCallsign cs(aircraft.getCallsign());
|
||||
if (cs.isEmpty()) { return; }
|
||||
if (this->m_aircraft.containsCallsign(cs)) { return; }
|
||||
this->fillComboBox();
|
||||
if (m_aircraft.containsCallsign(cs)) { return; }
|
||||
m_dsFillComboBox.inputSignal(); // fill combo box
|
||||
}
|
||||
|
||||
void CRemoteAircraftSelector::ps_onRemovedAircraft(const CCallsign &callsign)
|
||||
void CRemoteAircraftSelector::onRemovedAircraft(const CCallsign &callsign)
|
||||
{
|
||||
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; }
|
||||
this->m_currentText = text;
|
||||
if (m_currentText == text) { return; }
|
||||
m_currentText = text;
|
||||
emit this->changedCallsign();
|
||||
}
|
||||
|
||||
void CRemoteAircraftSelector::fillComboBox()
|
||||
{
|
||||
if (!this->isVisible()) { return; } // for performance reasons
|
||||
if (!sGui || sGui->isShuttingDown()) { return; }
|
||||
|
||||
const CCallsign currentSelection(this->getSelectedCallsign());
|
||||
m_aircraft = sGui->getIContextNetwork()->getAircraftInRange();
|
||||
m_aircraft = sGui->getIContextNetwork()->getAircraftInRange().sortedByCallsign();
|
||||
ui->cb_RemoteAircraftSelector->clear();
|
||||
if (m_aircraft.isEmpty()) { return; }
|
||||
|
||||
@@ -106,19 +108,19 @@ namespace BlackGui
|
||||
QString i(aircraft.getCallsign().toQString());
|
||||
if (aircraft.hasAircraftDesignator())
|
||||
{
|
||||
i += QLatin1String(" (") %
|
||||
i += QStringLiteral(" (") %
|
||||
aircraft.getAircraftIcaoCode().toQString(false) %
|
||||
QLatin1String(")");
|
||||
QStringLiteral(")");
|
||||
}
|
||||
if (aircraft.hasRealName())
|
||||
{
|
||||
i += QLatin1String(" - ") % aircraft.getPilotRealName();
|
||||
i += QStringLiteral(" - ") % aircraft.getPilotRealName();
|
||||
}
|
||||
if (m_showPartsEnabled)
|
||||
{
|
||||
if (aircraft.isPartsSynchronized())
|
||||
{
|
||||
i += " [parts]";
|
||||
i += QStringLiteral(" [parts]");
|
||||
}
|
||||
}
|
||||
items.append(i);
|
||||
|
||||
@@ -13,8 +13,9 @@
|
||||
#define BLACKGUI_REMOTEAIRCRAFTSELECTOR_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackmisc/aviation/callsign.h"
|
||||
#include "blackmisc/simulation/simulatedaircraftlist.h"
|
||||
#include "blackmisc/aviation/callsign.h"
|
||||
#include "blackmisc/digestsignal.h"
|
||||
|
||||
#include <QFrame>
|
||||
#include <QObject>
|
||||
@@ -55,25 +56,24 @@ namespace BlackGui
|
||||
//! \copydoc QWidget::showEvent
|
||||
virtual void showEvent(QShowEvent *event) override;
|
||||
|
||||
private slots:
|
||||
//! Change content of combobox
|
||||
void ps_onAddedAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
|
||||
private:
|
||||
//! Added aircraft, change content of combobox
|
||||
void onAddedAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
|
||||
|
||||
//! IContextNetwork::removedAircraft
|
||||
void ps_onRemovedAircraft(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
//! Removed aircraft, change content of combobox
|
||||
void onRemovedAircraft(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
|
||||
//! Combo box has been changed
|
||||
void ps_comboBoxChanged(const QString &text);
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::CRemoteAircraftSelector> ui;
|
||||
|
||||
QString m_currentText;
|
||||
bool m_showPartsEnabled = false;
|
||||
BlackMisc::Simulation::CSimulatedAircraftList m_aircraft;
|
||||
void comboBoxChanged(const QString &text);
|
||||
|
||||
//! Set combobox items
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user