From 18788a8d4de0e208a05f1bd48c90d1e69444c174 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 5 Dec 2018 03:58:08 +0100 Subject: [PATCH] Ref T442, own ATC station tree view class --- src/blackgui/views/atcstationtreeview.cpp | 99 +++++++++++++++++++++++ src/blackgui/views/atcstationtreeview.h | 69 ++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 src/blackgui/views/atcstationtreeview.cpp create mode 100644 src/blackgui/views/atcstationtreeview.h diff --git a/src/blackgui/views/atcstationtreeview.cpp b/src/blackgui/views/atcstationtreeview.cpp new file mode 100644 index 000000000..639271a14 --- /dev/null +++ b/src/blackgui/views/atcstationtreeview.cpp @@ -0,0 +1,99 @@ +/* Copyright (C) 2018 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackgui/views/atcstationtreeview.h" +#include "blackgui/models/atcstationtreemodel.h" +#include "blackgui/menus/menuaction.h" +#include "blackmisc/aviation/atcstationlist.h" +#include "blackmisc/aviation/callsign.h" +#include "blackmisc/icons.h" +#include "blackconfig/buildconfig.h" + +#include +#include +#include +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::Aviation; +using namespace BlackGui::Models; + +namespace BlackGui +{ + namespace Views + { + CAtcStationTreeView::CAtcStationTreeView(QWidget *parent) : QTreeView(parent) + { + this->setContextMenuPolicy(Qt::CustomContextMenu); + connect(this, &CAtcStationTreeView::customContextMenuRequested, this, &CAtcStationTreeView::customMenu); + } + + void CAtcStationTreeView::changedAtcStationConnectionStatus(const CAtcStation &station, bool added) + { + Q_UNUSED(station); + Q_UNUSED(added); + } + + const CAtcStationTreeModel *CAtcStationTreeView::stationModel() const + { + return qobject_cast(this->model()); + } + + CAtcStation CAtcStationTreeView::selectedObject() const + { + const QModelIndex index = this->currentIndex(); + const QVariant data = this->model()->data(index.siblingAtColumn(0)); // supposed to be the callsign + const QString callsign = data.toString(); + const CAtcStationTreeModel *model = this->stationModel(); + if (!model) { return CAtcStation(); } + return model->container().findFirstByCallsign(CCallsign(callsign, CCallsign::Atc)); + } + + void CAtcStationTreeView::customMenu(const QPoint &point) + { + QMenu *menu = new QMenu(this); // menu + + QAction *com1 = new QAction(CIcons::appCockpit16(), "Tune in COM1", this); + QAction *com2 = new QAction(CIcons::appCockpit16(), "Tune in COM2", this); + QAction *text = new QAction(CIcons::appTextMessages16(), "Show text messages", this); + + connect(com1, &QAction::triggered, this, &CAtcStationTreeView::tuneInAtcCom1); + connect(com2, &QAction::triggered, this, &CAtcStationTreeView::tuneInAtcCom2); + connect(text, &QAction::triggered, this, &CAtcStationTreeView::requestTextMessage); + + menu->addAction(com1); + menu->addAction(com2); + menu->addAction(text); + + menu->popup(this->viewport()->mapToGlobal(point)); + } + + void CAtcStationTreeView::tuneInAtcCom1() + { + const CAtcStation s(this->selectedObject()); + if (s.getCallsign().isEmpty()) { return; } + emit this->requestComFrequency(s.getFrequency(), CComSystem::Com1); + } + + void CAtcStationTreeView::tuneInAtcCom2() + { + const CAtcStation s(this->selectedObject()); + if (s.getCallsign().isEmpty()) { return; } + emit this->requestComFrequency(s.getFrequency(), CComSystem::Com2); + } + + void CAtcStationTreeView::requestTextMessage() + { + const CAtcStation s(this->selectedObject()); + if (s.getCallsign().isEmpty()) { return; } + emit this->requestTextMessageWidget(s.getCallsign()); + } + } // namespace +} // namespace diff --git a/src/blackgui/views/atcstationtreeview.h b/src/blackgui/views/atcstationtreeview.h new file mode 100644 index 000000000..db100a4aa --- /dev/null +++ b/src/blackgui/views/atcstationtreeview.h @@ -0,0 +1,69 @@ +/* Copyright (C) 2018 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_ATCSTATIONTREEVIEW_H +#define BLACKGUI_ATCSTATIONTREEVIEW_H + +#include "blackgui/blackguiexport.h" +#include "blackmisc/aviation/atcstationlist.h" +#include "blackmisc/aviation/comsystem.h" +#include "blackmisc/pq/frequency.h" + +#include +#include +#include +#include + +namespace BlackGui +{ + namespace Models { class CAtcStationTreeModel; } + namespace Views + { + //! ATC stations view + class BLACKGUI_EXPORT CAtcStationTreeView : public QTreeView + { + Q_OBJECT + + public: + //! Constructor + explicit CAtcStationTreeView(QWidget *parent = nullptr); + + //! \copydoc Models::CAtcStationListModel::changedAtcStationConnectionStatus + void changedAtcStationConnectionStatus(const BlackMisc::Aviation::CAtcStation &station, bool added); + + signals: + //! Request some dummy ATC stations + void testRequestDummyAtcOnlineStations(int number); + + //! Request COM frequency + void requestComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit unit); + + //! Request a text message to + void requestTextMessageWidget(const BlackMisc::Aviation::CCallsign &callsign); + + private: + //! Used model + const Models::CAtcStationTreeModel *stationModel() const; + + //! The selected object + BlackMisc::Aviation::CAtcStation selectedObject() const; + + //! Custom menu + void customMenu(const QPoint &point); + + void tuneInAtcCom1(); + void tuneInAtcCom2(); + void requestTextMessage(); + }; + } // ns +} // ns + +#endif // guard