From 27a5b3aae8a26493f13fef99141a4d653acacaa2 Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Sun, 16 Nov 2025 23:44:59 +0100 Subject: [PATCH] refactor: Use lambda to combine common logic --- src/gui/views/atcstationtreeview.cpp | 15 ++++----------- src/gui/views/atcstationtreeview.h | 3 +-- src/gui/views/atcstationview.cpp | 23 ++++++++--------------- src/gui/views/atcstationview.h | 3 +-- 4 files changed, 14 insertions(+), 30 deletions(-) diff --git a/src/gui/views/atcstationtreeview.cpp b/src/gui/views/atcstationtreeview.cpp index 0954491d2..78aa98afb 100644 --- a/src/gui/views/atcstationtreeview.cpp +++ b/src/gui/views/atcstationtreeview.cpp @@ -123,8 +123,8 @@ namespace swift::gui::views auto *text = new QAction(CIcons::appTextMessages16(), "Show text messages", this); auto *resize = new QAction(CIcons::resize16(), "Resize", this); - connect(com1, &QAction::triggered, this, &CAtcStationTreeView::tuneInAtcCom1); - connect(com2, &QAction::triggered, this, &CAtcStationTreeView::tuneInAtcCom2); + connect(com1, &QAction::triggered, this, [this]() { tuneInAtc(CComSystem::Com1); }); + connect(com2, &QAction::triggered, this, [this]() { tuneInAtc(CComSystem::Com2); }); connect(text, &QAction::triggered, this, &CAtcStationTreeView::requestTextMessage); connect(resize, &QAction::triggered, this, &CAtcStationTreeView::fullResizeToContentsImpl); @@ -160,18 +160,11 @@ namespace swift::gui::views } } - void CAtcStationTreeView::tuneInAtcCom1() + void CAtcStationTreeView::tuneInAtc(const misc::aviation::CComSystem::ComUnit unit) { 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); + emit this->requestComFrequency(s.getFrequency(), unit); } void CAtcStationTreeView::requestTextMessage() diff --git a/src/gui/views/atcstationtreeview.h b/src/gui/views/atcstationtreeview.h index 1041fa425..80e146a53 100644 --- a/src/gui/views/atcstationtreeview.h +++ b/src/gui/views/atcstationtreeview.h @@ -107,8 +107,7 @@ namespace swift::gui //! @{ //! Tune in/invoke - void tuneInAtcCom1(); - void tuneInAtcCom2(); + void tuneInAtc(misc::aviation::CComSystem::ComUnit unit); void requestTextMessage(); //! @} diff --git a/src/gui/views/atcstationview.cpp b/src/gui/views/atcstationview.cpp index bdd44f82c..1f9032672 100644 --- a/src/gui/views/atcstationview.cpp +++ b/src/gui/views/atcstationview.cpp @@ -59,12 +59,12 @@ namespace swift::gui::views { if (m_actions.isEmpty()) { m_actions = QList({ nullptr, nullptr, nullptr }); } - m_actions[0] = - menuActions.addAction(m_actions[0], CIcons::appCockpit16(), "Tune in COM1", - CMenuAction::pathClientCom(), { this, &CAtcStationView::tuneInAtcCom1 }); - m_actions[1] = - menuActions.addAction(m_actions[1], CIcons::appCockpit16(), "Tune in COM2", - CMenuAction::pathClientCom(), { this, &CAtcStationView::tuneInAtcCom2 }); + m_actions[0] = menuActions.addAction(m_actions[0], CIcons::appCockpit16(), "Tune in COM1", + CMenuAction::pathClientCom(), + { this, [this]() { tuneInAtc(CComSystem::Com1); } }); + m_actions[1] = menuActions.addAction(m_actions[1], CIcons::appCockpit16(), "Tune in COM2", + CMenuAction::pathClientCom(), + { this, [this]() { tuneInAtc(CComSystem::Com2); } }); m_actions[2] = menuActions.addAction(m_actions[2], CIcons::appTextMessages16(), "Show text messages", CMenuAction::pathClientCom(), { this, &CAtcStationView::requestTextMessage }); @@ -72,18 +72,11 @@ namespace swift::gui::views CViewBase::customMenu(menuActions); } - void CAtcStationView::tuneInAtcCom1() + void CAtcStationView::tuneInAtc(const misc::aviation::CComSystem::ComUnit unit) { const CAtcStation s(this->selectedObject()); if (s.getCallsign().isEmpty()) { return; } - emit this->requestComFrequency(s.getFrequency(), CComSystem::Com1); - } - - void CAtcStationView::tuneInAtcCom2() - { - const CAtcStation s(this->selectedObject()); - if (s.getCallsign().isEmpty()) { return; } - emit this->requestComFrequency(s.getFrequency(), CComSystem::Com2); + emit this->requestComFrequency(s.getFrequency(), unit); } void CAtcStationView::requestTextMessage() diff --git a/src/gui/views/atcstationview.h b/src/gui/views/atcstationview.h index 8bb522e12..8c06f69d7 100644 --- a/src/gui/views/atcstationview.h +++ b/src/gui/views/atcstationview.h @@ -64,8 +64,7 @@ namespace swift::gui private: void emitTestRequest1kAtcOnlineDummies() { emit this->testRequestDummyAtcOnlineStations(1000); } void emitTestRequest3kAtcOnlineDummies() { emit this->testRequestDummyAtcOnlineStations(3000); } - void tuneInAtcCom1(); - void tuneInAtcCom2(); + void tuneInAtc(misc::aviation::CComSystem::ComUnit unit); void requestTextMessage(); QList m_actions; //!< real actions