11 #include "gui/menus/menuaction.h"
18 using namespace swift::misc::aviation;
26 this->setContextMenuPolicy(Qt::CustomContextMenu);
27 connect(
this, &CAtcStationTreeView::customContextMenuRequested,
this, &CAtcStationTreeView::customMenu);
28 connect(
this, &CAtcStationTreeView::expanded,
this, &CAtcStationTreeView::onExpanded, Qt::QueuedConnection);
29 connect(this->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &CAtcStationTreeView::onSelected,
30 Qt::QueuedConnection);
35 if (!this->stationModel()) {
return; }
41 if (!this->stationModel()) {
return; }
49 if (!this->stationModel()) {
return; }
50 this->stationModel()->
clear();
57 if (this->stationModel()) { this->stationModel()->
setColumns(columns); }
62 void CAtcStationTreeView::fullResizeToContentsImpl()
64 if (this->
isEmpty()) {
return; }
65 for (
int c = 0; c < this->model()->columnCount(); c++) { this->resizeColumnToContents(c); }
70 return qobject_cast<const CAtcStationTreeModel *>(this->model());
75 return qobject_cast<CAtcStationTreeModel *>(this->model());
78 CAtcStation CAtcStationTreeView::selectedObject()
const
80 const QModelIndex index = this->currentIndex();
81 return this->selectedObject(index);
84 CAtcStation CAtcStationTreeView::selectedObject(
const QModelIndex &index)
const
86 const QVariant data = this->model()->data(index.siblingAtColumn(0));
87 const QString callsign = data.toString();
93 QString CAtcStationTreeView::suffixForIndex(
const QModelIndex &index)
95 const QVariant data = this->model()->data(index);
96 return data.toString();
99 void CAtcStationTreeView::onExpanded(
const QModelIndex &index)
105 void CAtcStationTreeView::onSelected(
const QItemSelection &selected,
const QItemSelection &deselected)
107 Q_UNUSED(deselected);
108 if (selected.isEmpty()) {
return; }
109 const CAtcStation atcStation = this->selectedObject(selected.indexes().front());
114 void CAtcStationTreeView::customMenu(
const QPoint &point)
116 if (!this->stationModel()) {
return; }
117 if (this->stationModel()->container().
isEmpty()) {
return; }
119 QMenu *menu =
new QMenu(
this);
121 QAction *com1 =
new QAction(CIcons::appCockpit16(),
"Tune in COM1",
this);
122 QAction *com2 =
new QAction(CIcons::appCockpit16(),
"Tune in COM2",
this);
123 QAction *text =
new QAction(CIcons::appTextMessages16(),
"Show text messages",
this);
124 QAction *resize =
new QAction(CIcons::resize16(),
"Resize",
this);
126 connect(com1, &QAction::triggered,
this, &CAtcStationTreeView::tuneInAtcCom1);
127 connect(com2, &QAction::triggered,
this, &CAtcStationTreeView::tuneInAtcCom2);
128 connect(text, &QAction::triggered,
this, &CAtcStationTreeView::requestTextMessage);
129 connect(resize, &QAction::triggered,
this, &CAtcStationTreeView::fullResizeToContentsImpl);
131 menu->addAction(com1);
132 menu->addAction(com2);
133 menu->addAction(text);
134 menu->addSeparator();
135 menu->addAction(resize);
137 menu->popup(this->viewport()->mapToGlobal(point));
140 void CAtcStationTreeView::storeState()
143 for (
int row = 0; row < this->model()->rowCount(); ++row)
145 const QModelIndex i = this->model()->index(row, 0);
146 const bool expanded = this->isExpanded(i);
147 const QString suffix = this->suffixForIndex(i);
148 m_expanded.insert(suffix, expanded);
152 void CAtcStationTreeView::restoreState()
154 for (
int row = 0; row < this->model()->rowCount(); ++row)
156 const QModelIndex i = this->model()->index(row, 0);
157 const QString suffix = this->suffixForIndex(i);
158 const bool expanded = m_expanded.value(suffix,
true);
159 this->setExpanded(i, expanded);
163 void CAtcStationTreeView::tuneInAtcCom1()
166 if (s.getCallsign().isEmpty()) {
return; }
170 void CAtcStationTreeView::tuneInAtcCom2()
173 if (s.getCallsign().isEmpty()) {
return; }
177 void CAtcStationTreeView::requestTextMessage()
180 if (s.getCallsign().isEmpty()) {
return; }
Using this class provides a QTableView with the overlay functionality already integrated.
void clear()
Clear everything.
void setColumns(const CColumns &columns)
Set columns.
void updateContainer(const swift::misc::aviation::CAtcStationList &stations)
Update container.
const swift::misc::aviation::CAtcStationList & container() const
Get container.
void changedAtcStationConnectionStatus(const swift::misc::aviation::CAtcStation &station, bool added)
Used to quickly update single station (better response for the user)
void objectSelected(const swift::misc::aviation::CAtcStation &station)
This object has been selected.
bool isEmpty() const
Empty.
void requestComFrequency(const swift::misc::physical_quantities::CFrequency &frequency, swift::misc::aviation::CComSystem::ComUnit unit)
Request COM frequency.
void updateContainer(const swift::misc::aviation::CAtcStationList &stations)
Update container.
void requestTextMessageWidget(const swift::misc::aviation::CCallsign &callsign)
Request a text message to.
void fullResizeToContents()
Resize all columns.
void changedAtcStationConnectionStatus(const swift::misc::aviation::CAtcStation &station, bool added)
Used to quickly update single station (better response for the user)
void setColumns(const models::CColumns &columns)
Set columns.
void inputSignal()
Received input signal, or manually trigger.
Value object encapsulating information about an ATC station.
bool hasCallsign() const
Has callsign?
Value object for a list of ATC stations.
Value object encapsulating information of a callsign.
OBJ findFirstByCallsign(const CCallsign &callsign, const OBJ &ifNotFound={}) const
Find the first aircraft by callsign, if none return given one.
Models to be used with views, mainly QTableView.
Views, mainly QTableView.
Free functions in swift::misc.