swift
atcstationview.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include <QFlags>
7 #include <QtGlobal>
8 
9 #include "config/buildconfig.h"
10 #include "gui/menus/menuaction.h"
12 #include "misc/aviation/callsign.h"
13 #include "misc/icons.h"
14 
15 using namespace swift::config;
16 using namespace swift::misc;
17 using namespace swift::misc::aviation;
18 using namespace swift::gui::models;
19 using namespace swift::gui::menus;
20 
21 namespace swift::gui::views
22 {
23  CAtcStationView::CAtcStationView(QWidget *parent) : CViewWithCallsignObjects(parent)
24  {
25  this->standardInit(new CAtcStationListModel(CAtcStationListModel::StationsOnline, this));
27  }
28 
30  {
31  Q_ASSERT(m_model);
32  m_model->setStationMode(stationMode);
33  this->setSortIndicator();
34  }
35 
37  {
38  m_model->changedAtcStationConnectionStatus(station, added);
39 
40  // resize the first, rest will be resized with normal updates
41  if (this->rowCount() == 1) { this->fullResizeToContents(); }
42  }
43 
45  {
46  menuActions.addMenuCom();
47  if (CBuildConfig::isDebugBuild())
48  {
49  if (m_debugActions.isEmpty()) { m_debugActions = QList<QAction *>({ nullptr, nullptr }); }
50  m_debugActions[0] = menuActions.addAction(m_debugActions[0], CIcons::tableSheet16(),
51  "Test: 1k ATC online stations", CMenuAction::pathClientCom(),
52  { this, &CAtcStationView::emitTestRequest1kAtcOnlineDummies });
53  m_debugActions[1] = menuActions.addAction(m_debugActions[1], CIcons::tableSheet16(),
54  "Test: 3k ATC online stations", CMenuAction::pathClientCom(),
55  { this, &CAtcStationView::emitTestRequest3kAtcOnlineDummies });
56  }
57 
58  if (this->hasSelection())
59  {
60  if (m_actions.isEmpty()) { m_actions = QList<QAction *>({ nullptr, nullptr, nullptr, nullptr, nullptr }); }
61 
62  m_actions[0] = menuActions.addAction(m_actions[0], CIcons::appCockpit16(), "Tune in COM1 (active)",
63  CMenuAction::pathClientCom(),
64  { this, [this]() { tuneInAtc(CComSystem::Com1, true); } });
65  m_actions[1] = menuActions.addAction(m_actions[1], CIcons::appCockpit16(), "Tune in COM2 (active)",
66  CMenuAction::pathClientCom(),
67  { this, [this]() { tuneInAtc(CComSystem::Com2, true); } });
68  m_actions[2] = menuActions.addAction(m_actions[2], CIcons::appCockpit16(), "Tune in COM1 (standby)",
69  CMenuAction::pathClientCom(),
70  { this, [this]() { tuneInAtc(CComSystem::Com1, false); } });
71  m_actions[3] = menuActions.addAction(m_actions[3], CIcons::appCockpit16(), "Tune in COM2 (standby)",
72  CMenuAction::pathClientCom(),
73  { this, [this]() { tuneInAtc(CComSystem::Com2, false); } });
74  m_actions[4] =
75  menuActions.addAction(m_actions[4], CIcons::appTextMessages16(), "Show text messages",
76  CMenuAction::pathClientCom(), { this, &CAtcStationView::requestTextMessage });
77  }
78  CViewBase::customMenu(menuActions);
79  }
80 
81  void CAtcStationView::tuneInAtc(const misc::aviation::CComSystem::ComUnit unit, const bool active)
82  {
83  const CAtcStation s(this->selectedObject());
84  if (s.getCallsign().isEmpty()) { return; }
85  emit this->requestComFrequency(s.getFrequency(), unit, active);
86  }
87 
88  void CAtcStationView::requestTextMessage()
89  {
90  const CAtcStation s(this->selectedObject());
91  if (s.getCallsign().isEmpty()) { return; }
92  emit this->requestTextMessageWidget(s.getCallsign());
93  }
94 } // namespace swift::gui::views
Bunch of CMenuAction objects.
Definition: menuaction.h:384
CMenuAction addMenuCom()
Add COM model menu.
Definition: menuaction.cpp:467
CMenuAction addAction(const CMenuAction &menuAction)
Add menu action.
Definition: menuaction.cpp:210
void setStationMode(swift::gui::models::CAtcStationListModel::AtcStationMode stationMode)
Set station mode.
void requestComFrequency(const swift::misc::physical_quantities::CFrequency &frequency, swift::misc::aviation::CComSystem::ComUnit unit, bool active)
Request COM frequency.
void customMenu(swift::gui::menus::CMenuActions &menuActions)
Method creating the menu.
void requestTextMessageWidget(const swift::misc::aviation::CCallsign &callsign)
Request a text message to.
void changedAtcStationConnectionStatus(const swift::misc::aviation::CAtcStation &station, bool added)
Used to quickly update single station (better response for the user)
void standardInit(ModelClass *model=nullptr)
Standard initialization.
Definition: viewbase.cpp:572
ModelClass * m_model
corresponding model
Definition: viewbase.h:877
void setSortIndicator()
Set the search indicator based on model.
Definition: viewbase.cpp:562
int rowCount() const
Elements in container.
Definition: viewbase.cpp:386
ObjectType selectedObject() const
Selected object (or default)
Definition: viewbase.cpp:307
void customMenu(menus::CMenuActions &menuActions)
Method creating the menu.
Definition: viewbase.cpp:680
Menu m_menus
Default menu settings.
Definition: viewbase.h:603
virtual void fullResizeToContents()
Full resizing to content, might be slow.
@ MenuClear
allow clearing the view via menu
Definition: viewbase.h:120
@ MenuRefresh
allow refreshing the view via menu
Definition: viewbase.h:122
bool hasSelection() const
Selection (selected rows)
Base class for views with DB objects.
Value object encapsulating information about an ATC station.
Definition: atcstation.h:38
Models to be used with views, mainly QTableView.
Views, mainly QTableView.
Free functions in swift::misc.
bool isEmpty() const const