Added an (experimental) tree view to ATC stations

This commit is contained in:
Klaus Basan
2015-01-22 11:11:57 +01:00
parent c1bc44b2a9
commit 054db94997
8 changed files with 118 additions and 34 deletions

View File

@@ -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<int>(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

View File

@@ -113,6 +113,8 @@ namespace BlackGui
void ps_setComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit unit);
private:
void updateTreeView();
QScopedPointer<Ui::CAtcStationComponent> ui;
CUpdateTimer *m_updateTimer = nullptr;
QDateTime m_timestampLastReadOnlineStations = CUpdateTimer::epoch(); //!< stations read

View File

@@ -211,6 +211,31 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tb_AtcStationsOnlineTree">
<attribute name="title">
<string>Online (tree)</string>
</attribute>
<layout class="QVBoxLayout" name="vl_AtcStationsOnlineTree">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTreeView" name="tvp_AtcStationsOnlineTree"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="tb_AtcStationsBooked">
<attribute name="title">
<string>Booked</string>

View File

@@ -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<QString, int> 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<QStandardItem *> typeFolderRow { typeFolderFirstColumn };
model->invisibleRootItem()->appendRow(typeFolderRow);
CAtcStationList stations = this->getContainer().findBySuffix(type);
for (const CAtcStation &station : stations)
{
QList<QStandardItem *> stationRow;
switch (m_stationMode)
{
case StationsOnline:
stationRow = QList<QStandardItem *>
{
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<QStandardItem *>
{
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;

View File

@@ -15,6 +15,7 @@
#include "blackmisc/avatcstationlist.h"
#include "blackgui/models/listmodelbase.h"
#include <QAbstractItemModel>
#include <QStandardItemModel>
#include <QDBusConnection>
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;
};
}
}

View File

@@ -411,7 +411,7 @@ QHeaderView::section {
margin: 0px;
}
QTableView {
QTableView, QTreeView {
border: 1px solid green;
border-radius: 5px;
background-color: transparent;

View File

@@ -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();
}

View File

@@ -21,7 +21,7 @@ namespace BlackGui
namespace Views
{
//! ATC stations view
class CAtcStationView : public CViewBase<Models::CAtcStationListModel, BlackMisc::Aviation::CAtcStationList, BlackMisc::Aviation::CAtcStation>
class CAtcStationView : public CViewBase<BlackGui::Models::CAtcStationListModel, BlackMisc::Aviation::CAtcStationList, BlackMisc::Aviation::CAtcStation>
{
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