Skip to content
Permalink
Browse files

Add user data to identify actions to actionmenu

  • Loading branch information
m-kuhn authored and 3nids committed Aug 13, 2014
1 parent 089652e commit 399fa9927d0d9c5a11c95185ea6c5a969dd42755
Showing with 49 additions and 0 deletions.
  1. +3 −0 src/gui/qgsactionmenu.cpp
  2. +46 −0 src/gui/qgsactionmenu.h
@@ -25,6 +25,7 @@ QgsActionMenu::QgsActionMenu( QgsVectorLayer* layer, const QgsFeature* feature,
, mMapLayerActionSignalMapper( 0 )
, mActions( 0 )
, mFeature( feature )
, mFeatureId( feature->id() )
, mOwnsFeature( false )
{
init();
@@ -127,6 +128,7 @@ void QgsActionMenu::reloadActions()
const QgsAction& qaction( mActions->at( idx ) );

QAction* action = new QAction( qaction.icon(), qaction.name(), this );
action->setData( QVariant::fromValue<ActionData>( ActionData( idx, mFeatureId, mLayer ) ) );

// Only enable items on supported platforms
if ( !qaction.runable() )
@@ -157,6 +159,7 @@ void QgsActionMenu::reloadActions()
{
QgsMapLayerAction* qaction = mapLayerActions.at( i );
QAction* action = new QAction( qaction->text(), this );
action->setData( QVariant::fromValue<ActionData>( ActionData( MapLayerAction, mFeatureId, mLayer ) ) );
mMapLayerActionSignalMapper->setMapping( action, i );
addAction( action );
connect( action, SIGNAL(triggered()), mMapLayerActionSignalMapper, SLOT(map()) );
@@ -29,6 +29,51 @@
class QgsActionMenu : public QMenu
{
Q_OBJECT

public:
enum ActionType
{
Invalid, //!< Invalid
MapLayerAction, //!< Standard actions (defined by core or plugins)
AttributeAction //!< Custom actions (manually defined in layer properties)
};

struct ActionData
{
ActionData()
: actionType( Invalid )
, actionId( 0 )
{}

ActionData( int actionId, QgsFeatureId featureId, QgsMapLayer* mapLayer )
: actionType( AttributeAction )
, actionId( actionId )
, featureId( featureId )
, mapLayer( mapLayer )
{}

ActionData( QgsMapLayerAction* action, QgsFeatureId featureId, QgsMapLayer* mapLayer )
: actionType( AttributeAction )
, actionId( action )
, featureId( featureId )
, mapLayer( mapLayer )
{}

ActionType actionType;

union aid
{
aid( int i ) : id( i ) {}
aid( QgsMapLayerAction* a ) : action( a ) {}
int id;
QgsMapLayerAction* action;
} actionId;

QgsFeatureId featureId;
QgsMapLayer* mapLayer;
};


public:
/**
* Constructs a new QgsActionMenu
@@ -89,5 +134,6 @@ class QgsActionMenu : public QMenu
bool mOwnsFeature;
};

Q_DECLARE_METATYPE( QgsActionMenu::ActionData )

#endif // QGSACTIONMENU_H

0 comments on commit 399fa99

Please sign in to comment.
You can’t perform that action at this time.