refactor: Use lambda to combine common logic

This commit is contained in:
Lars Toenning
2025-11-16 23:44:59 +01:00
parent 14ff2066b7
commit 27a5b3aae8
4 changed files with 14 additions and 30 deletions

View File

@@ -123,8 +123,8 @@ namespace swift::gui::views
auto *text = new QAction(CIcons::appTextMessages16(), "Show text messages", this); auto *text = new QAction(CIcons::appTextMessages16(), "Show text messages", this);
auto *resize = new QAction(CIcons::resize16(), "Resize", this); auto *resize = new QAction(CIcons::resize16(), "Resize", this);
connect(com1, &QAction::triggered, this, &CAtcStationTreeView::tuneInAtcCom1); connect(com1, &QAction::triggered, this, [this]() { tuneInAtc(CComSystem::Com1); });
connect(com2, &QAction::triggered, this, &CAtcStationTreeView::tuneInAtcCom2); connect(com2, &QAction::triggered, this, [this]() { tuneInAtc(CComSystem::Com2); });
connect(text, &QAction::triggered, this, &CAtcStationTreeView::requestTextMessage); connect(text, &QAction::triggered, this, &CAtcStationTreeView::requestTextMessage);
connect(resize, &QAction::triggered, this, &CAtcStationTreeView::fullResizeToContentsImpl); 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()); const CAtcStation s(this->selectedObject());
if (s.getCallsign().isEmpty()) { return; } if (s.getCallsign().isEmpty()) { return; }
emit this->requestComFrequency(s.getFrequency(), CComSystem::Com1); emit this->requestComFrequency(s.getFrequency(), unit);
}
void CAtcStationTreeView::tuneInAtcCom2()
{
const CAtcStation s(this->selectedObject());
if (s.getCallsign().isEmpty()) { return; }
emit this->requestComFrequency(s.getFrequency(), CComSystem::Com2);
} }
void CAtcStationTreeView::requestTextMessage() void CAtcStationTreeView::requestTextMessage()

View File

@@ -107,8 +107,7 @@ namespace swift::gui
//! @{ //! @{
//! Tune in/invoke //! Tune in/invoke
void tuneInAtcCom1(); void tuneInAtc(misc::aviation::CComSystem::ComUnit unit);
void tuneInAtcCom2();
void requestTextMessage(); void requestTextMessage();
//! @} //! @}

View File

@@ -59,12 +59,12 @@ namespace swift::gui::views
{ {
if (m_actions.isEmpty()) { m_actions = QList<QAction *>({ nullptr, nullptr, nullptr }); } if (m_actions.isEmpty()) { m_actions = QList<QAction *>({ nullptr, nullptr, nullptr }); }
m_actions[0] = m_actions[0] = menuActions.addAction(m_actions[0], CIcons::appCockpit16(), "Tune in COM1",
menuActions.addAction(m_actions[0], CIcons::appCockpit16(), "Tune in COM1", CMenuAction::pathClientCom(),
CMenuAction::pathClientCom(), { this, &CAtcStationView::tuneInAtcCom1 }); { this, [this]() { tuneInAtc(CComSystem::Com1); } });
m_actions[1] = m_actions[1] = menuActions.addAction(m_actions[1], CIcons::appCockpit16(), "Tune in COM2",
menuActions.addAction(m_actions[1], CIcons::appCockpit16(), "Tune in COM2", CMenuAction::pathClientCom(),
CMenuAction::pathClientCom(), { this, &CAtcStationView::tuneInAtcCom2 }); { this, [this]() { tuneInAtc(CComSystem::Com2); } });
m_actions[2] = m_actions[2] =
menuActions.addAction(m_actions[2], CIcons::appTextMessages16(), "Show text messages", menuActions.addAction(m_actions[2], CIcons::appTextMessages16(), "Show text messages",
CMenuAction::pathClientCom(), { this, &CAtcStationView::requestTextMessage }); CMenuAction::pathClientCom(), { this, &CAtcStationView::requestTextMessage });
@@ -72,18 +72,11 @@ namespace swift::gui::views
CViewBase::customMenu(menuActions); CViewBase::customMenu(menuActions);
} }
void CAtcStationView::tuneInAtcCom1() void CAtcStationView::tuneInAtc(const misc::aviation::CComSystem::ComUnit unit)
{ {
const CAtcStation s(this->selectedObject()); const CAtcStation s(this->selectedObject());
if (s.getCallsign().isEmpty()) { return; } if (s.getCallsign().isEmpty()) { return; }
emit this->requestComFrequency(s.getFrequency(), CComSystem::Com1); emit this->requestComFrequency(s.getFrequency(), unit);
}
void CAtcStationView::tuneInAtcCom2()
{
const CAtcStation s(this->selectedObject());
if (s.getCallsign().isEmpty()) { return; }
emit this->requestComFrequency(s.getFrequency(), CComSystem::Com2);
} }
void CAtcStationView::requestTextMessage() void CAtcStationView::requestTextMessage()

View File

@@ -64,8 +64,7 @@ namespace swift::gui
private: private:
void emitTestRequest1kAtcOnlineDummies() { emit this->testRequestDummyAtcOnlineStations(1000); } void emitTestRequest1kAtcOnlineDummies() { emit this->testRequestDummyAtcOnlineStations(1000); }
void emitTestRequest3kAtcOnlineDummies() { emit this->testRequestDummyAtcOnlineStations(3000); } void emitTestRequest3kAtcOnlineDummies() { emit this->testRequestDummyAtcOnlineStations(3000); }
void tuneInAtcCom1(); void tuneInAtc(misc::aviation::CComSystem::ComUnit unit);
void tuneInAtcCom2();
void requestTextMessage(); void requestTextMessage();
QList<QAction *> m_actions; //!< real actions QList<QAction *> m_actions; //!< real actions