From 16bc52ac3ffeb43cc30c3734d2f5968a26703aeb Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 25 Sep 2008 09:34:32 +0000 Subject: [PATCH] 0013946: Implement QActionGroup functionality for SALOME series 5x --- src/Qtx/QtxActionGroup.cxx | 22 ++++- src/Qtx/QtxActionGroup.h | 1 + src/SALOME_PYQT/SalomePyQt/Makefile.am | 2 + src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx | 14 +-- src/SALOME_PYQT/SalomePyQt/SalomePyQt.h | 9 +- src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip | 100 +++++++++++++++++++++- 6 files changed, 133 insertions(+), 15 deletions(-) diff --git a/src/Qtx/QtxActionGroup.cxx b/src/Qtx/QtxActionGroup.cxx index 88a80dbbe..cc3da3471 100644 --- a/src/Qtx/QtxActionGroup.cxx +++ b/src/Qtx/QtxActionGroup.cxx @@ -62,7 +62,7 @@ QtxActionGroup::QtxActionGroup( QObject* parent ) setMenu( new QMenu( 0 ) ); myActionGroup = new QActionGroup( this ); - connect( myActionGroup, SIGNAL( triggered( QAction* ) ), this, SIGNAL( selected( QAction* ) ) ); + connect( myActionGroup, SIGNAL( triggered( QAction* ) ), this, SLOT( onTriggered( QAction* ) ) ); } /*! @@ -187,6 +187,26 @@ void QtxActionGroup::onActivated( int id ) } } +/*! + \brief Called when some action owned by this action group is activated by the user + \param a action being activated +*/ +void QtxActionGroup::onTriggered( QAction* a ) +{ + int id = actionId( a ); + if ( id != -1 ) { + QList lst = createdWidgets(); + for ( QList::iterator it = lst.begin(); it != lst.end(); ++it ) + { + QtxComboBox* cb = ::qobject_cast( *it ); + if ( cb ) + cb->setCurrentId( id ); + } + } + + emit selected( a ); +} + /*! \brief Update action group for the specified widget. \param w a widget this action group is added to diff --git a/src/Qtx/QtxActionGroup.h b/src/Qtx/QtxActionGroup.h index bb39763e4..108d40a53 100644 --- a/src/Qtx/QtxActionGroup.h +++ b/src/Qtx/QtxActionGroup.h @@ -54,6 +54,7 @@ signals: private slots: void onActivated( int ); + void onTriggered( QAction* ); protected: virtual void updateAction( QWidget* ); diff --git a/src/SALOME_PYQT/SalomePyQt/Makefile.am b/src/SALOME_PYQT/SalomePyQt/Makefile.am index 7622446d1..9b1e6328c 100644 --- a/src/SALOME_PYQT/SalomePyQt/Makefile.am +++ b/src/SALOME_PYQT/SalomePyQt/Makefile.am @@ -27,6 +27,8 @@ SIP_SRC = sipAPISalomePyQt.h \ sipSalomePyQtSalomePyQt.cc \ sipSalomePyQtSALOME_Selection.cc \ sipSalomePyQtQtxAction.cc \ + sipSalomePyQtQtxActionGroup.cc \ + sipSalomePyQtQtxActionSet.cc \ sipSalomePyQtcmodule.cc # Sip definition file diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx index 0d2c16032..8e5b736c1 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx @@ -32,8 +32,8 @@ #include -//#include #include +#include #include #include #include @@ -1675,14 +1675,14 @@ QAction* SalomePyQt::createAction( const int id, const QString& menuTe } /*! - \fn QActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive ) + \fn QtxActionGroup* SalomePyQt::createActionGroup( const int id, const bool exclusive ) \brief Create an action group which can be then used in the menu or toolbar \param id : the unique id action group to be registered to \param exclusive : if \c true the action group does exclusive toggling */ -/* + struct TcreateActionGroupEvent: public SALOME_Event { - typedef QActionGroup* TResult; + typedef QtxActionGroup* TResult; TResult myResult; int myId; bool myExclusive; @@ -1692,14 +1692,14 @@ struct TcreateActionGroupEvent: public SALOME_Event { { SALOME_PYQT_Module* module = getActiveModule(); if ( module ) - myResult = (QAction*)module->createActionGroup( myId, myExclusive ); + myResult = module->createActionGroup( myId, myExclusive ); } }; -QActionGroup* SalomePyQt::createActionGroup(const int id, const bool exclusive) +QtxActionGroup* SalomePyQt::createActionGroup(const int id, const bool exclusive) { return ProcessEvent( new TcreateActionGroupEvent( id, exclusive ) ); } -*/ + /*! \fn QAction* SalomePyQt::action( const int id ) \brief Get action by specified identifier. diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h index 829c20f17..a7c8645ea 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h @@ -36,7 +36,7 @@ class QMenuBar; class QMenu; class QWidget; class QAction; -class QActionGroup; +class QtxActionGroup; class SALOME_Selection : public QObject { @@ -79,6 +79,7 @@ enum { }; enum { + PT_Auto = LightApp_Preferences::Auto, PT_Space = LightApp_Preferences::Space, PT_Bool = LightApp_Preferences::Bool, PT_Color = LightApp_Preferences::Color, @@ -89,6 +90,8 @@ enum { PT_Double = LightApp_Preferences::Double, PT_Integer = LightApp_Preferences::Integer, PT_GroupBox = LightApp_Preferences::GroupBox, + PT_Tab = LightApp_Preferences::Tab, + PT_Frame = LightApp_Preferences::Frame, PT_Font = LightApp_Preferences::Font, PT_DirList = LightApp_Preferences::DirList, PT_File = LightApp_Preferences::File, @@ -156,7 +159,7 @@ public: const QString& = QString(), const QString& = QString(), const QString& = QString(), const int = 0, const bool = false ); - // static QActionGroup* createActionGroup( const int, const bool = true ); + static QtxActionGroup* createActionGroup( const int, const bool = true ); static QAction* action( const int ); static int actionId( const QAction* ); @@ -184,7 +187,7 @@ public: static int addGlobalPreference( const QString& ); static int addPreference( const QString& ); static int addPreference( const QString&, - const int, const int = -1, + const int, const int = PT_Auto, const QString& = QString(), const QString& = QString() ); static QVariant preferenceProperty( const int, const QString& ); diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip index 1a2a12a7f..4c42971db 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip @@ -26,6 +26,9 @@ %Import QtXmlmod.sip %ExportedHeaderCode +#include +#include +#include #include %End @@ -65,6 +68,7 @@ enum WindowType { }; enum PrefType { + PT_Auto, PT_Space, PT_Bool, PT_Color, @@ -75,6 +79,8 @@ enum PrefType { PT_Double, PT_Integer, PT_GroupBox, + PT_Tab, + PT_Frame, PT_Font, PT_DirList, PT_File, @@ -91,14 +97,100 @@ enum Action { SplitAt = 2 }; -class QtxAction : QAction +class QtxAction : QWidgetAction { %TypeHeaderCode #include %End +%ConvertToSubClassCode + if ( qobject_cast( sipCpp ) ) + sipClass = sipClass_QtxAction; + else + sipClass = NULL; +%End + +public: + explicit QtxAction( QObject* /TransferThis/ = 0, bool = false ); + QtxAction( const QString&, const QString&, int, QObject* /TransferThis/, bool = false ); + QtxAction( const QString&, const QIcon&, const QString&, int, QObject* /TransferThis/, bool = false ); + virtual ~QtxAction(); + +private: + QtxAction( const QtxAction& ); +}; + +class QtxActionSet : QtxAction +{ +%TypeHeaderCode +#include +%End + +%ConvertToSubClassCode + if ( qobject_cast( sipCpp ) ) + sipClass = sipClass_QtxActionSet; + else + sipClass = NULL; +%End + +public: + explicit QtxActionSet( QObject* /TransferThis/ = 0 ); + virtual ~QtxActionSet(); + + QList actions() const; + void setActions( const QList& ); + + void insertActions( const QList&, const int = -1 ); + + int insertAction( QAction*, const int id = -1, const int = -1 ); + int insertAction( const QString&, const int id = -1, const int = -1 ); + int insertAction( const QString&, const QIcon&, const int id = -1, const int = -1 ); + + void removeAction( QAction* ); + void removeAction( const int ); + + void clear(); + +signals: + void triggered( int ); + void triggered( QAction* ); + +private: + QtxActionSet( const QtxActionSet& ); +}; + +class QtxActionGroup : QtxActionSet +{ +%TypeHeaderCode +#include +%End + +%ConvertToSubClassCode + if ( qobject_cast( sipCpp ) ) + sipClass = sipClass_QtxActionGroup; + else + sipClass = NULL; +%End + +public: + explicit QtxActionGroup( QObject* /TransferThis/ = 0 ); + QtxActionGroup( QObject* /TransferThis/, const bool ); + virtual ~QtxActionGroup(); + + bool isExclusive() const; + bool usesDropDown() const; + + void add( QAction* ); + +public slots: + void setExclusive( const bool ); + void setUsesDropDown( const bool ); + +signals: + void selected( QAction* ); + private: - QtxAction(const QtxAction &); + QtxActionGroup( const QtxActionGroup& ); }; class SalomePyQt @@ -153,7 +245,7 @@ public: const QString& = QString(), const QString& = QString(), const QString& = QString(), const int = 0, const bool = false ) /ReleaseGIL/ ; - //static QActionGroup* createActionGroup( const int, const bool = true ) /ReleaseGIL/ ; + static QtxActionGroup* createActionGroup( const int, const bool = true ) /ReleaseGIL/ ; static QAction* action( const int ) /ReleaseGIL/ ; static int actionId( const QAction* ) /ReleaseGIL/ ; @@ -182,7 +274,7 @@ public: static int addGlobalPreference( const QString& ) /ReleaseGIL/ ; static int addPreference( const QString& ) /ReleaseGIL/ ; static int addPreference( const QString&, - const int, const int = -1, + const int, const int = PT_Auto, const QString& = QString(), const QString& = QString() ) /ReleaseGIL/ ; static QVariant preferenceProperty( const int, const QString& ) /ReleaseGIL/ ; -- 2.39.2