From 054db94997bfac00f53b96e6dc2e354abc408ef7 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 22 Jan 2015 11:11:57 +0100 Subject: [PATCH] Added an (experimental) tree view to ATC stations --- .../components/atcstationcomponent.cpp | 28 +++++++- src/blackgui/components/atcstationcomponent.h | 2 + .../components/atcstationcomponent.ui | 25 +++++++ src/blackgui/models/atcstationlistmodel.cpp | 68 +++++++++++++++---- src/blackgui/models/atcstationlistmodel.h | 6 +- src/blackgui/qss/mainwindow.qss | 2 +- src/blackgui/views/atcstationview.cpp | 17 +---- src/blackgui/views/atcstationview.h | 4 +- 8 files changed, 118 insertions(+), 34 deletions(-) diff --git a/src/blackgui/components/atcstationcomponent.cpp b/src/blackgui/components/atcstationcomponent.cpp index e1d4c4016..0e4d39975 100644 --- a/src/blackgui/components/atcstationcomponent.cpp +++ b/src/blackgui/components/atcstationcomponent.cpp @@ -8,7 +8,6 @@ */ #include "atcstationcomponent.h" -#include "../views/atcstationview.h" #include "../guiutility.h" #include "ui_atcstationcomponent.h" #include "blackmisc/avinformationmessage.h" @@ -47,6 +46,9 @@ namespace BlackGui this->ui->tvp_AtcStationsBooked->setStationMode(CAtcStationListModel::StationsBooked); this->ui->tvp_AtcStationsBooked->setResizeMode(CAtcStationView::ResizingOnce); + // header + this->ui->tvp_AtcStationsOnlineTree->setHeaderHidden(true); + // Signal / Slots bool connected = this->connect(this->ui->le_AtcStationsOnlineMetar, SIGNAL(returnPressed()), this, SLOT(getMetar())); Q_ASSERT(connected); @@ -123,11 +125,14 @@ namespace BlackGui this->ui->tvp_AtcStationsOnline->updateContainerMaybeAsync(this->getIContextNetwork()->getAtcStationsOnline()); this->m_timestampLastReadOnlineStations = QDateTime::currentDateTimeUtc(); this->m_timestampOnlineStationsChanged = this->m_timestampLastReadOnlineStations; + + this->updateTreeView(); } } else { this->ui->tvp_AtcStationsOnline->clear(); + this->updateTreeView(); this->ui->le_AtcStationsOnlineMetar->clear(); } } @@ -146,9 +151,9 @@ namespace BlackGui } QString icao = airportIcaoCode.isEmpty() ? this->ui->le_AtcStationsOnlineMetar->text().trimmed().toUpper() : airportIcaoCode.trimmed().toUpper(); this->ui->le_AtcStationsOnlineMetar->setText(icao); - if (icao.length() != 4) return; + if (icao.length() != 4) { return; } CInformationMessage metar = this->getIContextNetwork()->getMetar(icao); - if (metar.getType() != CInformationMessage::METAR) return; + if (metar.getType() != CInformationMessage::METAR) { return; } if (metar.isEmpty()) { this->ui->te_AtcStationsOnlineInfo->clear(); @@ -202,6 +207,7 @@ namespace BlackGui if (INetwork::isDisconnectedStatus(toStatus)) { this->ui->tvp_AtcStationsOnline->clear(); + this->updateTreeView(); this->ui->le_AtcStationsOnlineMetar->clear(); } } @@ -252,6 +258,22 @@ namespace BlackGui this->getIContextOwnAircraft()->updateComFrequency(frequency, static_cast(unit), originator()); } + void CAtcStationComponent::updateTreeView() + { + QAbstractItemModel *old = (this->ui->tvp_AtcStationsOnlineTree->model()); + this->ui->tvp_AtcStationsOnlineTree->setModel( + this->ui->tvp_AtcStationsOnline->derivedModel()->toAtcGroupModel() + ); + if (old) { old->deleteLater(); } + if (!this->ui->tvp_AtcStationsOnlineTree->model()) { return; } + + this->ui->tvp_AtcStationsOnlineTree->expandAll(); + for (int i = 0; i < this->ui->tvp_AtcStationsOnlineTree->model()->columnCount(); i++) + { + this->ui->tvp_AtcStationsOnlineTree->resizeColumnToContents(i); + } + } + void CAtcStationComponent::ps_onlineAtcStationSelected(QModelIndex index) { this->ui->te_AtcStationsOnlineInfo->setText(""); // reset diff --git a/src/blackgui/components/atcstationcomponent.h b/src/blackgui/components/atcstationcomponent.h index 98320e5e4..02881b9ae 100644 --- a/src/blackgui/components/atcstationcomponent.h +++ b/src/blackgui/components/atcstationcomponent.h @@ -113,6 +113,8 @@ namespace BlackGui void ps_setComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit unit); private: + void updateTreeView(); + QScopedPointer ui; CUpdateTimer *m_updateTimer = nullptr; QDateTime m_timestampLastReadOnlineStations = CUpdateTimer::epoch(); //!< stations read diff --git a/src/blackgui/components/atcstationcomponent.ui b/src/blackgui/components/atcstationcomponent.ui index 650931ad6..472ec40f2 100644 --- a/src/blackgui/components/atcstationcomponent.ui +++ b/src/blackgui/components/atcstationcomponent.ui @@ -211,6 +211,31 @@ + + + Online (tree) + + + + 3 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + Booked diff --git a/src/blackgui/models/atcstationlistmodel.cpp b/src/blackgui/models/atcstationlistmodel.cpp index 54968842e..6b54c2d82 100644 --- a/src/blackgui/models/atcstationlistmodel.cpp +++ b/src/blackgui/models/atcstationlistmodel.cpp @@ -25,19 +25,19 @@ namespace BlackGui * Constructor */ CAtcStationListModel::CAtcStationListModel(AtcStationMode stationMode, QObject *parent) : - CListModelBase("ViewAtcList", parent), m_stationMode(NotSet) + CListModelBase("ModelAtcList", parent), m_stationMode(NotSet) { this->setStationMode(stationMode); // force strings for translation in resource files - (void)QT_TRANSLATE_NOOP("ViewAtcList", "callsign"); - (void)QT_TRANSLATE_NOOP("ViewAtcList", "distance"); - (void)QT_TRANSLATE_NOOP("ViewAtcList", "frequency"); - (void)QT_TRANSLATE_NOOP("ViewAtcList", "controllername"); - (void)QT_TRANSLATE_NOOP("ViewAtcList", "online"); - (void)QT_TRANSLATE_NOOP("ViewAtcList", "bookedfrom"); - (void)QT_TRANSLATE_NOOP("ViewAtcList", "bookeduntil"); - (void)QT_TRANSLATE_NOOP("ViewAtcList", "voiceroomurl"); + (void)QT_TRANSLATE_NOOP("ModelAtcList", "callsign"); + (void)QT_TRANSLATE_NOOP("ModelAtcList", "distance"); + (void)QT_TRANSLATE_NOOP("ModelAtcList", "frequency"); + (void)QT_TRANSLATE_NOOP("ModelAtcList", "controllername"); + (void)QT_TRANSLATE_NOOP("ModelAtcList", "online"); + (void)QT_TRANSLATE_NOOP("ModelAtcList", "bookedfrom"); + (void)QT_TRANSLATE_NOOP("ModelAtcList", "bookeduntil"); + (void)QT_TRANSLATE_NOOP("ModelAtcList", "voiceroomurl"); } void CAtcStationListModel::setStationMode(CAtcStationListModel::AtcStationMode stationMode) @@ -50,7 +50,7 @@ namespace BlackGui case NotSet: case StationsOnline: { - this->m_columns.addColumn(CColumn::standardString("call", "callsign", { CAtcStation::IndexCallsign, CCallsign::IndexCallsignStringAsSet })); + this->m_columns.addColumn(CColumn::standardString("cs.", "callsign", { CAtcStation::IndexCallsign, CCallsign::IndexCallsignStringAsSet })); CColumn col = CColumn("type", CAtcStation::IndexIcon); col.setSortPropertyIndex({ CAtcStation::IndexCallsign, CCallsign::IndexSuffix }); this->m_columns.addColumn(col); @@ -69,10 +69,11 @@ namespace BlackGui case StationsBooked: { - this->m_columns.addColumn(CColumn::standardString("call", "callsign", { CAtcStation::IndexCallsign, CCallsign::IndexCallsignStringAsSet })); + this->m_columns.addColumn(CColumn::standardString("cs.", "callsign", { CAtcStation::IndexCallsign, CCallsign::IndexCallsignStringAsSet })); CColumn col = CColumn("type", CAtcStation::IndexIcon); col.setSortPropertyIndex({ CAtcStation::IndexCallsign, CCallsign::IndexSuffix }); - this->m_columns.addColumn(col); this->m_columns.addColumn(CColumn("", "on/offline", CAtcStation::IndexIsOnline, new CBoolLedFormatter("online", "offline"))); + this->m_columns.addColumn(col); + this->m_columns.addColumn(CColumn("", "on/offline", CAtcStation::IndexIsOnline, new CBoolLedFormatter("online", "offline"))); this->m_columns.addColumn(CColumn::standardString("controllername", { CAtcStation::IndexController, CUser::IndexRealName })); this->m_columns.addColumn(CColumn("from", "booked from", CAtcStation::IndexBookedFrom, new CDateTimeFormatter(CDateTimeFormatter::formatYmdhm()))); this->m_columns.addColumn(CColumn("until", "booked until", CAtcStation::IndexBookedUntil, new CDateTimeFormatter(CDateTimeFormatter::formatYmdhm()))); @@ -90,6 +91,49 @@ namespace BlackGui } } + QStandardItemModel *CAtcStationListModel::toAtcGroupModel() const + { + QStandardItemModel *model = new QStandardItemModel(); + if (this->isEmpty()) { return model; } + model->setColumnCount(4); + QMap types = this->getContainer().getSuffixes(); + for (const QString &type : types.keys()) + { + // ownership of QStandardItem is taken by model + QStandardItem *typeFolderFirstColumn = new QStandardItem(CCallsign::suffixToIcon(type).toQIcon(), type); + QList typeFolderRow { typeFolderFirstColumn }; + model->invisibleRootItem()->appendRow(typeFolderRow); + CAtcStationList stations = this->getContainer().findBySuffix(type); + for (const CAtcStation &station : stations) + { + QList stationRow; + switch (m_stationMode) + { + case StationsOnline: + stationRow = QList + { + new QStandardItem(station.getCallsign().toQString()), + new QStandardItem(station.getFrequency().valueRoundedWithUnit(CFrequencyUnit::MHz(), 2, true)), + new QStandardItem(station.getControllerRealName()), + new QStandardItem(station.getDistanceToPlane().valueRoundedWithUnit(CLengthUnit::NM(), 1, true)) + }; + break; + case StationsBooked: + stationRow = QList + { + new QStandardItem(station.getCallsign().toQString()), + new QStandardItem(station.getControllerRealName()), + new QStandardItem(station.getBookedFromUtc().toString(CDateTimeFormatter::formatYmdhm())), + new QStandardItem(station.getBookedUntilUtc().toString(CDateTimeFormatter::formatYmdhm())) + }; + break; + } + typeFolderFirstColumn->appendRow(stationRow); + } + } + return model; + } + void CAtcStationListModel::changedAtcStationConnectionStatus(const CAtcStation &station, bool added) { if (station.getCallsign().isEmpty()) return; diff --git a/src/blackgui/models/atcstationlistmodel.h b/src/blackgui/models/atcstationlistmodel.h index c9a26909d..568996dfe 100644 --- a/src/blackgui/models/atcstationlistmodel.h +++ b/src/blackgui/models/atcstationlistmodel.h @@ -15,6 +15,7 @@ #include "blackmisc/avatcstationlist.h" #include "blackgui/models/listmodelbase.h" #include +#include #include namespace BlackGui @@ -46,12 +47,15 @@ namespace BlackGui //! Station mode AtcStationMode getStationMode() const { return this->m_stationMode; } + //! A group by type (TWR, APP, ...) model + QStandardItemModel *toAtcGroupModel() const; + public slots: //! Used to quickly update single station (better response for the user) void changedAtcStationConnectionStatus(const BlackMisc::Aviation::CAtcStation &station, bool added); private: - AtcStationMode m_stationMode; + AtcStationMode m_stationMode = NotSet; }; } } diff --git a/src/blackgui/qss/mainwindow.qss b/src/blackgui/qss/mainwindow.qss index 2408aaaa3..3828cb56b 100644 --- a/src/blackgui/qss/mainwindow.qss +++ b/src/blackgui/qss/mainwindow.qss @@ -411,7 +411,7 @@ QHeaderView::section { margin: 0px; } -QTableView { +QTableView, QTreeView { border: 1px solid green; border-radius: 5px; background-color: transparent; diff --git a/src/blackgui/views/atcstationview.cpp b/src/blackgui/views/atcstationview.cpp index 5d7d9e070..34cfb82e8 100644 --- a/src/blackgui/views/atcstationview.cpp +++ b/src/blackgui/views/atcstationview.cpp @@ -23,27 +23,14 @@ namespace BlackGui CAtcStationView::CAtcStationView(QWidget *parent) : CViewBase(parent) { this->standardInit(new CAtcStationListModel(CAtcStationListModel::StationsOnline, this)); + this->m_withMenuItemClear = true; + this->m_withMenuItemRefresh = true; } void CAtcStationView::setStationMode(CAtcStationListModel::AtcStationMode stationMode) { Q_ASSERT(this->m_model); this->m_model->setStationMode(stationMode); - this->m_withMenuItemClear = true; - this->m_withMenuItemRefresh = true; - - switch (stationMode) - { - case CAtcStationListModel::NotSet: - case CAtcStationListModel::StationsOnline: - this->m_model->setSortColumnByPropertyIndex(BlackMisc::Aviation::CAtcStation::IndexDistance); - break; - case CAtcStationListModel::StationsBooked: - this->m_model->setSortColumnByPropertyIndex(BlackMisc::Aviation::CAtcStation::IndexBookedFrom); - break; - default: - break; - } this->setSortIndicator(); } diff --git a/src/blackgui/views/atcstationview.h b/src/blackgui/views/atcstationview.h index 1f5a3da3e..e4f91fa6e 100644 --- a/src/blackgui/views/atcstationview.h +++ b/src/blackgui/views/atcstationview.h @@ -21,7 +21,7 @@ namespace BlackGui namespace Views { //! ATC stations view - class CAtcStationView : public CViewBase + class CAtcStationView : public CViewBase { Q_OBJECT @@ -31,7 +31,7 @@ namespace BlackGui explicit CAtcStationView(QWidget *parent = nullptr); //! Set station mode - void setStationMode(Models::CAtcStationListModel::AtcStationMode stationMode); + void setStationMode(BlackGui::Models::CAtcStationListModel::AtcStationMode stationMode); signals: //! Request some dummy ATC stations