#include "QtxActionSet.h"
-#include <QMenu>
-#include <QActionGroup>
+/*!
+ \class QtxActionSet
+ \brief An action class which is represented in the menu bar (or toolbar) as
+ a group of items (which can be customized).
+
+ Example: Window menu in the MDI application with menu items:
+ - Cascade
+ - Tile vertically
+ - Tile horizontally
+ - <separator>
+ - Window1
+ - Window2
+*/
/*!
- Constructor
+ \brief Constructor.
+ \param parent parent object
*/
QtxActionSet::QtxActionSet( QObject* parent )
: QtxAction( parent )
}
/*!
- Destructor
+ \brief Destructor.
*/
QtxActionSet::~QtxActionSet()
{
}
+/*!
+ \brief Get list of child actions.
+ \return list of assigned actions.
+*/
QList<QAction*> QtxActionSet::actions() const
{
return mySet;
}
+/*!
+ \brief Assign child actions.
+ \param lst list of actions
+*/
void QtxActionSet::setActions( const QList<QAction*>& lst )
{
for ( ActionList::iterator it = mySet.begin(); it != mySet.end(); ++it )
insertActions( lst );
}
+/*!
+ \brief Insert actions at the specified position.
+ \param lst list of actions
+ \param index position in the action list (if < 0, items are appended to the end of list)
+*/
void QtxActionSet::insertActions( const QList<QAction*>& lst, const int index )
{
int idx = qMin( index < 0 ? mySet.count() : index, mySet.count() );
update();
}
+/*!
+ \brief Insert action at the specified position.
+
+ If \a id < 0, it is generated automatically.
+
+ \param a action being inserted
+ \param id action ID
+ \param index position in the action list (if < 0, item is appended to the end of list)
+ \return action identifier
+*/
int QtxActionSet::insertAction( QAction* a, const int id, const int index )
{
if ( !a )
return ident;
}
+/*!
+ \brief Insert action at the specified position.
+
+ If \a id < 0, it is generated automatically.
+
+ \param txt action text
+ \param id action ID
+ \param index position in the action list (if < 0, item is appended to the end of list)
+ \return action identifier
+*/
int QtxActionSet::insertAction( const QString& txt, const int id, const int index )
{
return insertAction( new QtxAction( txt, txt, 0, this ), id, index );
}
-int QtxActionSet::insertAction( const QString& txt, const QIcon& ico, const int id, const int index )
+/*!
+ \brief Insert action at the specified position.
+
+ If \a id < 0, it is generated automatically.
+
+ \param txt action text
+ \param icon action icon
+ \param id action ID
+ \param index position in the action list (if < 0, item is appended to the end of list)
+ \return action identifier
+*/
+int QtxActionSet::insertAction( const QString& txt, const QIcon& icon, const int id, const int index )
{
- return insertAction( new QtxAction( txt, ico, txt, 0, this ), id, index );
+ return insertAction( new QtxAction( txt, icon, txt, 0, this ), id, index );
}
+/*!
+ \brief Remove specified action.
+
+ An action is removed from the action list and destroyed.
+
+ \param a action to be removed.
+*/
void QtxActionSet::removeAction( QAction* a )
{
if ( !mySet.contains( a ) )
delete a;
}
+/*!
+ \brief Remove specified action.
+
+ An action is removed from the action list and destroyed.
+
+ \param id action identifier
+*/
void QtxActionSet::removeAction( const int id )
{
removeAction( action( id ) );
}
+/*!
+ \brief Remove all actions.
+
+ An actions list is cleared and all actions are destroyed.
+*/
void QtxActionSet::clear()
{
qDeleteAll( mySet );
update();
}
+/*!
+ \brief Called when action is changed.
+
+ Update action state.
+*/
void QtxActionSet::onChanged()
{
if ( !isVisible() )
blockSignals( block );
}
-void QtxActionSet::onActionTriggered( bool )
+/*!
+ \brief Called when some action is activated by the user.
+ \param on toggled state (not used)
+*/
+void QtxActionSet::onActionTriggered( bool /*on*/ )
{
QAction* a = ::qobject_cast<QAction*>( sender() );
if ( !a )
emit triggered( a );
}
+/*!
+ \brief Called when this action set is added to the menu bar (or toolbar).
+ \param w widget this action set is added to
+*/
void QtxActionSet::addedTo( QWidget* w )
{
QtxAction::addedTo( w );
update( w );
}
+/*!
+ \brief Called when this action set is removed from the menu bar (or toolbar).
+ \param w widget this action set is removed from
+*/
void QtxActionSet::removedFrom( QWidget* w )
{
QtxAction::removedFrom( w );
update( w );
}
+/*!
+ \brief Get action by specified identifier.
+ \param id action ID
+ \return action or 0 if not found
+*/
QAction* QtxActionSet::action( int id ) const
{
QAction* a = 0;
return a;
}
+/*!
+ \brief Get action identifier for the action.
+ \param a action
+ \return action ID or -1 if not found
+*/
int QtxActionSet::actionId( QAction* a ) const
{
int id = -1;
return id;
}
+/*!
+ \brief Set action identifier for the action.
+ \param a action
+ \param id new action ID
+*/
void QtxActionSet::setActionId( QAction* a, const int id )
{
if ( !a || id == -1 )
a->setData( id );
}
+/*!
+ \brief Getneration unique action identifier
+ \return generation action ID
+*/
int QtxActionSet::generateId() const
{
QMap<int, int> map;
return id;
}
+/*!
+ \brief Update action set.
+*/
void QtxActionSet::update()
{
QList<QWidget*> lst = associatedWidgets();
update( *it );
}
+/*!
+ \brief Update action set for the specified widget.
+ \param w a widget this action is added to
+*/
void QtxActionSet::update( QWidget* w )
{
if ( !w )