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 ).
This commit is contained in:
parent
5dac42edc0
commit
4682d5606d
3 changed files with 39 additions and 52 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@
|
|||
#include <QtWidgets/QAction>
|
||||
#include <QtWidgets/QMenuBar>
|
||||
|
||||
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<wxMenu*>(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 );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<wxWindowQt*>(GetHandler())->QtHandleShortcut( command );
|
||||
}
|
||||
#endif // wxUSE_ACCEL
|
||||
|
||||
//##############################################################################
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue