Skip to content

Commit

Permalink
Add user data to identify actions to actionmenu
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn authored and 3nids committed Sep 16, 2014
1 parent 089652e commit 399fa99
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/gui/qgsactionmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ QgsActionMenu::QgsActionMenu( QgsVectorLayer* layer, const QgsFeature* feature,
, mMapLayerActionSignalMapper( 0 )
, mActions( 0 )
, mFeature( feature )
, mFeatureId( feature->id() )
, mOwnsFeature( false )
{
init();
Expand Down Expand Up @@ -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() )
Expand Down Expand Up @@ -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()) );
Expand Down
46 changes: 46 additions & 0 deletions src/gui/qgsactionmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.