QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsactionmenu.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsactionmenu.h
3  --------------------------------------
4  Date : 11.8.2014
5  Copyright : (C) 2014 Matthias Kuhn
6  Email : matthias at opengis dot ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSACTIONMENU_H
17 #define QGSACTIONMENU_H
18 
19 #include <QMenu>
20 #include <QSignalMapper>
21 
22 #include "qgsactionmanager.h"
24 
25 
30 class GUI_EXPORT QgsActionMenu : public QMenu
31 {
32  Q_OBJECT
33 
34  public:
36  {
39  AttributeAction
40  };
41 
42  struct ActionData
43  {
45  : actionType( Invalid )
46  , actionId( 0 )
47  , featureId( 0 )
48  , mapLayer( nullptr )
49  {}
50 
51  ActionData( int actionId, QgsFeatureId featureId, QgsMapLayer* mapLayer )
52  : actionType( AttributeAction )
53  , actionId( actionId )
54  , featureId( featureId )
55  , mapLayer( mapLayer )
56  {}
57 
58  ActionData( QgsMapLayerAction* action, QgsFeatureId featureId, QgsMapLayer* mapLayer )
59  : actionType( MapLayerAction )
60  , actionId( action )
61  , featureId( featureId )
62  , mapLayer( mapLayer )
63  {}
64 
66 
67  union aid
68  {
69  aid( int i ) : id( i ) {}
70  aid( QgsMapLayerAction* a ) : action( a ) {}
71  int id;
73  } actionId;
74 
77  };
78 
87  explicit QgsActionMenu( QgsVectorLayer *layer, const QgsFeature *feature, QWidget *parent = nullptr );
88 
96  explicit QgsActionMenu( QgsVectorLayer *layer, const QgsFeatureId fid, QWidget *parent = nullptr );
97 
101  ~QgsActionMenu();
102 
109  void setFeature( QgsFeature* feature );
110 
116  void setExpressionContextScope( const QgsExpressionContextScope &scope );
117 
123  QgsExpressionContextScope expressionContextScope() const;
124 
125  private slots:
126  void triggerAction();
127  void reloadActions();
128 
129  signals:
130  void reinit();
131 
132  private:
133  void init();
134  const QgsFeature* feature();
135 
136  QgsVectorLayer* mLayer;
137  QgsActionManager* mActions;
138  const QgsFeature* mFeature;
139  QgsFeatureId mFeatureId;
140  bool mOwnsFeature;
141  QgsExpressionContextScope mExpressionContextScope;
142 };
143 
145 
146 #endif // QGSACTIONMENU_H
Base class for all map layer types.
Definition: qgsmaplayer.h:49
Q_DECLARE_METATYPE(QgsMimeDataUtils::UriList)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
Standard actions (defined by core or plugins)
Definition: qgsactionmenu.h:38
ActionData(QgsMapLayerAction *action, QgsFeatureId featureId, QgsMapLayer *mapLayer)
Definition: qgsactionmenu.h:58
This class is a menu that is populated automatically with the actions defined for a given layer...
Definition: qgsactionmenu.h:30
Storage and management of actions associated with a layer.
Single scope for storing variables and functions for use within a QgsExpressionContext.
QgsMapLayerAction * action
Definition: qgsactionmenu.h:72
aid(QgsMapLayerAction *a)
Definition: qgsactionmenu.h:70
qint64 QgsFeatureId
Definition: qgsfeature.h:31
Represents a vector layer which manages a vector based data sets.
ActionData(int actionId, QgsFeatureId featureId, QgsMapLayer *mapLayer)
Definition: qgsactionmenu.h:51
An action which can run on map layers.