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

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