From 4682d5606d3da436f0691eb130845239be83f5cd Mon Sep 17 00:00:00 2001 From: ali kettab Date: Thu, 11 Jan 2024 20:01:40 +0100 Subject: [PATCH] Stop deriving some internal classes from wxQtSignalHandler under wxQt It is not necessary (nor beneficial) to derive these classes: wxQtActionGroup, wxQtAction and wxQtShortcutHandler from wxQtSignalHandler ( which is intended for use exclusively with wxWindow handlers only ). --- src/qt/menu.cpp | 27 ++++++++++++--------------- src/qt/menuitem.cpp | 35 ++++++++++++++--------------------- src/qt/window.cpp | 29 +++++++++++++---------------- 3 files changed, 39 insertions(+), 52 deletions(-) diff --git a/src/qt/menu.cpp b/src/qt/menu.cpp index 4e577fc884..8a3791fbbd 100644 --- a/src/qt/menu.cpp +++ b/src/qt/menu.cpp @@ -25,13 +25,12 @@ static void ApplyStyle( QMenu *qtMenu, long style ) // wxQtActionGroup: an exclusive group which synchronizes QActions in // QActionGroup with their wx wrappers. -class wxQtActionGroup : public QActionGroup, public wxQtSignalHandler +class wxQtActionGroup : public QActionGroup { public: explicit wxQtActionGroup( wxMenu* handler ) - : QActionGroup( handler->GetHandle() ), - wxQtSignalHandler( handler ) + : QActionGroup( handler->GetHandle() ) { setExclusive(true); @@ -44,7 +43,16 @@ public: } private: - void triggered ( QAction* action ); + void triggered ( QAction* action ) + { + if ( action != m_activeAction ) + { + if ( m_activeAction->isCheckable() ) + m_activeAction->setChecked(false); + + m_activeAction = action; + } + } QAction* m_activeAction; }; @@ -342,14 +350,3 @@ QWidget *wxMenuBar::GetHandle() const { return m_qtMenuBar; } - -void wxQtActionGroup::triggered( QAction* action ) -{ - if ( action != m_activeAction ) - { - if ( m_activeAction->isCheckable() ) - m_activeAction->setChecked(false); - - m_activeAction = action; - } -} diff --git a/src/qt/menuitem.cpp b/src/qt/menuitem.cpp index 65006a3bd4..1a5aa7dc94 100644 --- a/src/qt/menuitem.cpp +++ b/src/qt/menuitem.cpp @@ -18,12 +18,12 @@ #include #include -class wxQtAction : public QAction, public wxQtSignalHandler +class wxQtAction : public QAction { public: wxQtAction( wxMenu *handler, int id, const wxString &text, const wxString &help, - wxItemKind kind, wxMenu *subMenu, wxMenuItem *menuItem ); + wxItemKind kind, wxMenu *subMenu, wxMenuItem *menuItem ); // Set the action shortcut to correspond to the accelerator specified by // the given label. They set the primary shortcut the first time they are @@ -32,11 +32,6 @@ public: void UpdateShortcuts(const wxString& text); void UpdateShortcutsFromLabel(const wxString& text); - wxMenu* GetMenu() const - { - return static_cast(wxQtSignalHandler::GetHandler()); - } - // Convert hyphenated shortcuts to use the plus sign (+) which Qt understands. // Example: [ Ctrl-Shift-- ] should be converted to [ Ctrl+Shift+- ] static wxString Normalize(const wxString& text) @@ -47,9 +42,17 @@ public: } private: - void onActionToggled( bool checked ); - void onActionTriggered( bool checked ); + void onActionToggled( bool checked ) + { + m_handler->Check(m_mitemId, checked); + } + void onActionTriggered( bool checked ) + { + m_handler->SendEvent(m_mitemId, m_isCheckable ? checked : -1 ); + } + + wxMenu* m_handler; const wxWindowID m_mitemId; const bool m_isCheckable; }; @@ -182,9 +185,9 @@ void wxMenuItem::ClearExtraAccels() //============================================================================= wxQtAction::wxQtAction( wxMenu *handler, int id, const wxString &text, const wxString &help, - wxItemKind kind, wxMenu *subMenu, wxMenuItem *menuItem ) + wxItemKind kind, wxMenu *subMenu, wxMenuItem *menuItem ) : QAction( wxQtConvertString( text ), handler->GetHandle() ), - wxQtSignalHandler( handler ), + m_handler(handler), m_mitemId(menuItem->GetId()), m_isCheckable(menuItem->IsCheckable()) { setStatusTip( wxQtConvertString( help )); @@ -259,13 +262,3 @@ void wxQtAction::UpdateShortcuts(const wxString& text) wxUnusedVar(text); #endif // wxUSE_ACCEL } - -void wxQtAction::onActionToggled( bool checked ) -{ - GetMenu()->Check(m_mitemId, checked); -} - -void wxQtAction::onActionTriggered( bool checked ) -{ - GetMenu()->SendEvent(m_mitemId, m_isCheckable ? checked : -1 ); -} diff --git a/src/qt/window.cpp b/src/qt/window.cpp index c88fca784d..16974f8b2e 100644 --- a/src/qt/window.cpp +++ b/src/qt/window.cpp @@ -218,27 +218,24 @@ void wxQtScrollArea::OnSliderReleased() } #if wxUSE_ACCEL || defined( Q_MOC_RUN ) -class wxQtShortcutHandler : public QObject, public wxQtSignalHandler + +class wxQtShortcutHandler : public QObject { - public: - wxQtShortcutHandler( wxWindowQt *window ); + explicit wxQtShortcutHandler( wxWindow *handler ) : m_handler(handler) { } -public: - void activated(); + void activated() + { + const int command = sender()->property("wxQt_Command").toInt(); + + m_handler->QtHandleShortcut( command ); + } + +private: + + wxWindow* const m_handler; }; -wxQtShortcutHandler::wxQtShortcutHandler( wxWindowQt *window ) - : wxQtSignalHandler( window ) -{ -} - -void wxQtShortcutHandler::activated() -{ - int command = sender()->property("wxQt_Command").toInt(); - - static_cast(GetHandler())->QtHandleShortcut( command ); -} #endif // wxUSE_ACCEL //##############################################################################