Ref T539, tree view can select objects and hence refresh ATIS display

* select signal for tree view
* signal/slots and connects
This commit is contained in:
Klaus Basan
2019-02-14 23:34:20 +01:00
committed by Mat Sutcliffe
parent d68726080f
commit cc6adc6c40
5 changed files with 61 additions and 21 deletions

View File

@@ -99,15 +99,18 @@ namespace BlackGui
connect(ui->tb_Audio, &QPushButton::clicked, this, &CAtcStationComponent::requestAudioWidget); connect(ui->tb_Audio, &QPushButton::clicked, this, &CAtcStationComponent::requestAudioWidget);
connect(ui->tb_TextMessageOverlay, &QPushButton::clicked, this, &CAtcStationComponent::showOverlayInlineTextMessage); connect(ui->tb_TextMessageOverlay, &QPushButton::clicked, this, &CAtcStationComponent::showOverlayInlineTextMessage);
connect(ui->tw_Atc, &QTabWidget::currentChanged, this, &CAtcStationComponent::atcStationsTabChanged); // "local" tab changed (booked, online) connect(ui->tw_Atc, &QTabWidget::currentChanged, this, &CAtcStationComponent::atcStationsTabChanged); // "local" tab changed (booked, online)
connect(ui->tvp_AtcStationsOnline, &CAtcStationView::objectClicked, this, &CAtcStationComponent::onlineAtcStationSelected);
connect(ui->tvp_AtcStationsOnline, &CAtcStationView::objectSelected, this, &CAtcStationComponent::onlineAtcStationSelected); connect(ui->tvp_AtcStationsOnline, &CAtcStationView::objectClicked, this, &CAtcStationComponent::onOnlineAtcStationVariantSelected, Qt::QueuedConnection);
connect(ui->tvp_AtcStationsOnline, &CAtcStationView::objectSelected, this, &CAtcStationComponent::onOnlineAtcStationVariantSelected, Qt::QueuedConnection);
connect(ui->tvp_AtcStationsOnline, &CAtcStationView::testRequestDummyAtcOnlineStations, this, &CAtcStationComponent::testCreateDummyOnlineAtcStations); connect(ui->tvp_AtcStationsOnline, &CAtcStationView::testRequestDummyAtcOnlineStations, this, &CAtcStationComponent::testCreateDummyOnlineAtcStations);
connect(ui->tvp_AtcStationsOnline, &CAtcStationView::requestUpdate, this, &CAtcStationComponent::requestOnlineStationsUpdate); connect(ui->tvp_AtcStationsOnline, &CAtcStationView::requestUpdate, this, &CAtcStationComponent::requestOnlineStationsUpdate);
connect(ui->tvp_AtcStationsOnline, &CAtcStationView::requestNewBackendData, this, &CAtcStationComponent::requestOnlineStationsUpdate); connect(ui->tvp_AtcStationsOnline, &CAtcStationView::requestNewBackendData, this, &CAtcStationComponent::requestOnlineStationsUpdate);
connect(ui->tvp_AtcStationsOnline, &CAtcStationView::modelDataChangedDigest, this, &CAtcStationComponent::onCountChanged); connect(ui->tvp_AtcStationsOnline, &CAtcStationView::modelDataChangedDigest, this, &CAtcStationComponent::onCountChanged);
connect(ui->tvp_AtcStationsOnline, &CAtcStationView::requestComFrequency, this, &CAtcStationComponent::setComFrequency); connect(ui->tvp_AtcStationsOnline, &CAtcStationView::requestComFrequency, this, &CAtcStationComponent::setComFrequency);
connect(ui->tvp_AtcStationsOnline, &CAtcStationView::requestTextMessageWidget, this, &CAtcStationComponent::requestTextMessageWidget); connect(ui->tvp_AtcStationsOnline, &CAtcStationView::requestTextMessageWidget, this, &CAtcStationComponent::requestTextMessageWidget);
connect(ui->tvp_AtcStationsOnlineTree, &CAtcStationTreeView::requestComFrequency, this, &CAtcStationComponent::setComFrequency); connect(ui->tvp_AtcStationsOnlineTree, &CAtcStationTreeView::requestComFrequency, this, &CAtcStationComponent::setComFrequency);
connect(ui->tvp_AtcStationsOnlineTree, &CAtcStationTreeView::objectSelected, this, &CAtcStationComponent::onOnlineAtcStationSelected, Qt::QueuedConnection);
connect(ui->tvp_AtcStationsOnlineTree, &CAtcStationTreeView::requestTextMessageWidget, this, &CAtcStationComponent::requestTextMessageWidget); connect(ui->tvp_AtcStationsOnlineTree, &CAtcStationTreeView::requestTextMessageWidget, this, &CAtcStationComponent::requestTextMessageWidget);
connect(ui->comp_AtcStationsSettings, &CSettingsAtcStationsInlineComponent::changed, this, &CAtcStationComponent::forceUpdate, Qt::QueuedConnection); connect(ui->comp_AtcStationsSettings, &CSettingsAtcStationsInlineComponent::changed, this, &CAtcStationComponent::forceUpdate, Qt::QueuedConnection);
@@ -116,7 +119,7 @@ namespace BlackGui
connect(ui->tvp_AtcStationsBooked, &CAtcStationView::requestNewBackendData, this, &CAtcStationComponent::reloadAtcStationsBooked); connect(ui->tvp_AtcStationsBooked, &CAtcStationView::requestNewBackendData, this, &CAtcStationComponent::reloadAtcStationsBooked);
connect(ui->tvp_AtcStationsBooked, &CAtcStationView::modelDataChangedDigest, this, &CAtcStationComponent::onCountChanged); connect(ui->tvp_AtcStationsBooked, &CAtcStationView::modelDataChangedDigest, this, &CAtcStationComponent::onCountChanged);
connect(ui->tb_AtcStationsAtisReload, &QPushButton::clicked, this, &CAtcStationComponent::requestAtis); connect(ui->tb_AtcStationsAtisReload, &QPushButton::clicked, this, &CAtcStationComponent::requestAtisUpdates);
connect(&m_updateTimer, &QTimer::timeout, this, &CAtcStationComponent::update); connect(&m_updateTimer, &QTimer::timeout, this, &CAtcStationComponent::update);
// Group box // Group box
@@ -153,7 +156,7 @@ namespace BlackGui
CAtcStationComponent::~CAtcStationComponent() CAtcStationComponent::~CAtcStationComponent()
{ } { }
void CAtcStationComponent::setTab(CAtcStationComponent::AtcTab tab) void CAtcStationComponent::setTab(AtcTab tab)
{ {
const int t = static_cast<int>(tab); const int t = static_cast<int>(tab);
ui->tw_Atc->setCurrentIndex(t); ui->tw_Atc->setCurrentIndex(t);
@@ -433,22 +436,21 @@ namespace BlackGui
} }
} }
void CAtcStationComponent::onlineAtcStationSelected(const CVariant &object) void CAtcStationComponent::onOnlineAtcStationVariantSelected(const CVariant &object)
{ {
ui->te_AtcStationsOnlineInfo->setText(""); // reset ui->te_AtcStationsOnlineInfo->setText(""); // reset
if (!object.isValid() || !object.canConvert<CAtcStation>()) { return; } if (!object.isValid() || !object.canConvert<CAtcStation>()) { return; }
const CAtcStation stationClicked = object.valueOrDefault(CAtcStation()); const CAtcStation station = object.valueOrDefault(CAtcStation());
QString infoMessage; this->onOnlineAtcStationSelected(station);
}
if (stationClicked.hasAtis()) void CAtcStationComponent::onOnlineAtcStationSelected(const CAtcStation &station)
{ {
infoMessage.append(stationClicked.getAtis().getMessage()); if (!station.hasCallsign()) { return; }
} const QString infoMessage =
if (stationClicked.hasMetar()) station.getCallsignAsString() % u": " % station.getFrequency().valueRoundedWithUnit(CFrequencyUnit::MHz(), 3) %
{ (station.hasAtis() ? u"\n\n" % station.getAtis().getMessage() : QStringLiteral("")) %
if (!infoMessage.isEmpty()) { infoMessage.append("\n\n"); } (station.hasMetar() ? u"\n\n" % station.getMetar().getMessage() : QStringLiteral(""));
infoMessage.append(stationClicked.getMetar().getMessage());
}
ui->te_AtcStationsOnlineInfo->setText(infoMessage); ui->te_AtcStationsOnlineInfo->setText(infoMessage);
} }
@@ -465,10 +467,18 @@ namespace BlackGui
ui->gb_Details->setVisible(!booked); ui->gb_Details->setVisible(!booked);
} }
void CAtcStationComponent::requestAtis() void CAtcStationComponent::requestAtisUpdates()
{ {
if (!this->canAccessContext()) return; if (!this->canAccessContext()) { return; }
sGui->getIContextNetwork()->requestAtisUpdates(); sGui->getIContextNetwork()->requestAtisUpdates();
if (ui->tw_Atc->currentIndex() == TabAtcOnline)
{
ui->tvp_AtcStationsOnline->showOverlayHTMLMessage("Requested ATIS update", 5000);
}
else
{
ui->tvp_AtcStationsOnlineTree->showOverlayHTMLMessage("Requested ATIS update", 5000);
}
} }
bool CAtcStationComponent::canAccessContext() const bool CAtcStationComponent::canAccessContext() const

View File

@@ -98,10 +98,13 @@ namespace BlackGui
void getMetarAsEntered(); void getMetarAsEntered();
//! Request new ATIS //! Request new ATIS
void requestAtis(); void requestAtisUpdates();
//! A tree view station has been selected
void onOnlineAtcStationSelected(const BlackMisc::Aviation::CAtcStation &station);
//! Online ATC station selected //! Online ATC station selected
void onlineAtcStationSelected(const BlackMisc::CVariant &object); void onOnlineAtcStationVariantSelected(const BlackMisc::CVariant &object);
//! Tab changed //! Tab changed
void atcStationsTabChanged(); void atcStationsTabChanged();

View File

@@ -34,7 +34,8 @@ namespace BlackGui
this->setModel(new CAtcStationTreeModel(this)); this->setModel(new CAtcStationTreeModel(this));
this->setContextMenuPolicy(Qt::CustomContextMenu); this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, &CAtcStationTreeView::customContextMenuRequested, this, &CAtcStationTreeView::customMenu); connect(this, &CAtcStationTreeView::customContextMenuRequested, this, &CAtcStationTreeView::customMenu);
connect(this, &CAtcStationTreeView::expanded, this, &CAtcStationTreeView::onExpanded); connect(this, &CAtcStationTreeView::expanded, this, &CAtcStationTreeView::onExpanded, Qt::QueuedConnection);
connect(this->selectionModel(), &QItemSelectionModel::selectionChanged, this, &CAtcStationTreeView::onSelected, Qt::QueuedConnection);
} }
void CAtcStationTreeView::changedAtcStationConnectionStatus(const CAtcStation &station, bool added) void CAtcStationTreeView::changedAtcStationConnectionStatus(const CAtcStation &station, bool added)
@@ -94,6 +95,11 @@ namespace BlackGui
CAtcStation CAtcStationTreeView::selectedObject() const CAtcStation CAtcStationTreeView::selectedObject() const
{ {
const QModelIndex index = this->currentIndex(); const QModelIndex index = this->currentIndex();
return this->selectedObject(index);
}
CAtcStation CAtcStationTreeView::selectedObject(const QModelIndex &index) const
{
const QVariant data = this->model()->data(index.siblingAtColumn(0)); // supposed to be the callsign const QVariant data = this->model()->data(index.siblingAtColumn(0)); // supposed to be the callsign
const QString callsign = data.toString(); const QString callsign = data.toString();
const CAtcStationTreeModel *model = this->stationModel(); const CAtcStationTreeModel *model = this->stationModel();
@@ -113,6 +119,15 @@ namespace BlackGui
this->fullResizeToContents(); this->fullResizeToContents();
} }
void CAtcStationTreeView::onSelected(const QItemSelection &selected, const QItemSelection &deselected)
{
Q_UNUSED(deselected);
if (selected.isEmpty()) { return; }
const CAtcStation atcStation = this->selectedObject(selected.indexes().front());
if (!atcStation.hasCallsign()) { return; }
emit this->objectSelected(atcStation);
}
void CAtcStationTreeView::customMenu(const QPoint &point) void CAtcStationTreeView::customMenu(const QPoint &point)
{ {
if (!this->stationModel()) { return; } if (!this->stationModel()) { return; }

View File

@@ -73,6 +73,9 @@ namespace BlackGui
//! Request a text message to //! Request a text message to
void requestTextMessageWidget(const BlackMisc::Aviation::CCallsign &callsign); void requestTextMessageWidget(const BlackMisc::Aviation::CCallsign &callsign);
//! This object has been selected
void objectSelected(const BlackMisc::Aviation::CAtcStation &station);
private: private:
//! Used model //! Used model
const Models::CAtcStationTreeModel *stationModel() const; const Models::CAtcStationTreeModel *stationModel() const;
@@ -86,12 +89,18 @@ namespace BlackGui
//! The selected object //! The selected object
BlackMisc::Aviation::CAtcStation selectedObject() const; BlackMisc::Aviation::CAtcStation selectedObject() const;
//! The selected object
BlackMisc::Aviation::CAtcStation selectedObject(const QModelIndex &index) const;
//! Suffix for index //! Suffix for index
QString suffixForIndex(const QModelIndex &index); QString suffixForIndex(const QModelIndex &index);
//! Expanded //! Expanded
void onExpanded(const QModelIndex &index); void onExpanded(const QModelIndex &index);
//! Selected
void onSelected(const QItemSelection &selected, const QItemSelection &deselected);
//! Custom menu //! Custom menu
void customMenu(const QPoint &point); void customMenu(const QPoint &point);

View File

@@ -89,6 +89,9 @@ namespace BlackMisc
//! Get callsign. //! Get callsign.
const CCallsign &getCallsign() const { return m_callsign; } const CCallsign &getCallsign() const { return m_callsign; }
//! Has callsign?
bool hasCallsign() const { return !m_callsign.isEmpty(); }
//! Get callsign as string. //! Get callsign as string.
QString getCallsignAsString() const { return m_callsign.asString(); } QString getCallsignAsString() const { return m_callsign.asString(); }