QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsattributeaction.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsattributeaction.h
3 
4  These classes store and control the managment and execution of actions
5  associated with particulay Qgis layers. Actions are defined to be
6  external programs that are run with user-specified inputs that can
7  depend on the contents of layer attributes.
8 
9  -------------------
10  begin : Oct 24 2004
11  copyright : (C) 2004 by Gavin Macaulay
12  email : gavin at macaulay dot co dot nz
13  ***************************************************************************/
14 
15 /***************************************************************************
16  * *
17  * This program is free software; you can redistribute it and/or modify *
18  * it under the terms of the GNU General Public License as published by *
19  * the Free Software Foundation; either version 2 of the License, or *
20  * (at your option) any later version. *
21  * *
22  ***************************************************************************/
23 
24 #ifndef QGSATTRIBUTEACTION_H
25 #define QGSATTRIBUTEACTION_H
26 
27 #include <QString>
28 #include <QIcon>
29 
30 #include <qgsfeature.h>
31 
32 class QDomNode;
33 class QDomDocument;
34 class QgsPythonUtils;
35 class QgsVectorLayer;
36 
40 class CORE_EXPORT QgsAction
41 {
42  public:
44  {
47  Mac,
51  };
52 
53  QgsAction( ActionType type, QString name, QString action, bool capture ) :
54  mType( type ), mName( name ), mAction( action ), mCaptureOutput( capture ) {}
55 
56  QgsAction( ActionType type, QString name, QString action, const QString& icon, bool capture ) :
57  mType( type ), mName( name ), mIcon( icon ), mAction( action ), mCaptureOutput( capture ) {}
58 
60  QString name() const { return mName; }
61 
63  const QString iconPath() const { return mIcon; }
64 
66  const QIcon icon() const { return QIcon( mIcon ); }
67 
69  QString action() const { return mAction; }
70 
72  ActionType type() const { return mType; }
73 
75  bool capture() const { return mCaptureOutput; }
76 
78  bool runable() const
79  {
80  return mType == Generic ||
81  mType == GenericPython ||
82  mType == OpenUrl ||
83 #if defined(Q_OS_WIN)
84  mType == Windows
85 #elif defined(Q_OS_MAC)
86  mType == Mac
87 #else
88  mType == Unix
89 #endif
90  ;
91  }
92 
93  private:
94  ActionType mType;
95  QString mName;
96  QString mIcon;
97  QString mAction;
98  bool mCaptureOutput;
99 };
100 
106 class CORE_EXPORT QgsAttributeAction
107 {
108  public:
110  QgsAttributeAction( QgsVectorLayer *layer ) : mLayer( layer ), mDefaultAction( -1 ) {}
111 
113  virtual ~QgsAttributeAction() {}
114 
121  void addAction( QgsAction::ActionType type, QString name, QString action, bool capture = false );
122 
129  void addAction( QgsAction::ActionType type, QString name, QString action, const QString& icon, bool capture = false );
130 
132  void removeAction( int index );
133 
138  void doAction( int index,
139  const QgsFeature &feat,
140  int defaultValueIndex = 0 );
141 
148  void doAction( int index,
149  const QgsFeature &feat,
150  const QMap<QString, QVariant> *substitutionMap );
151 
153  void clearActions() { mActions.clear(); }
154 
156  const QList<QgsAction>& listActions() { return mActions; }
157 
159  QgsVectorLayer *layer() { return mLayer; }
160 
164  QString expandAction( QString action, const QgsAttributeMap &attributes, uint defaultValueIndex );
165 
174  QString expandAction( QString action,
175  QgsFeature &feat,
176  const QMap<QString, QVariant> *substitutionMap = 0 );
177 
178 
180  bool writeXML( QDomNode& layer_node, QDomDocument& doc ) const;
181 
183  bool readXML( const QDomNode& layer_node );
184 
185  int size() const { return mActions.size(); }
186  QgsAction &at( int idx ) { return mActions[idx]; }
187  QgsAction &operator[]( int idx ) { return mActions[idx]; }
188 
190  static void setPythonExecute( void ( * )( const QString & ) );
191 
193  int defaultAction() const { return mDefaultAction < 0 || mDefaultAction >= size() ? -1 : mDefaultAction; }
194  void setDefaultAction( int actionNumber ) { mDefaultAction = actionNumber ; }
195 
196  private:
197  QList<QgsAction> mActions;
198  QgsVectorLayer *mLayer;
199  static void ( *smPythonExecute )( const QString & );
200 
201  void runAction( const QgsAction &action,
202  void ( *executePython )( const QString & ) = 0 );
203 
204  int mDefaultAction;
205 };
206 
207 #endif
static unsigned index
const QString iconPath() const
The path to the icon.
QgsAction(ActionType type, QString name, QString action, const QString &icon, bool capture)
QgsAction & operator[](int idx)
Storage and management of actions associated with Qgis layer attributes.
QgsAction(ActionType type, QString name, QString action, bool capture)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:162
bool capture() const
Whether to capture output for display when this action is run.
QString name() const
The name of the action.
const QIcon icon() const
The icon.
Utility class that encapsulates an action based on vector attributes.
QgsAction & at(int idx)
QString action() const
The action.
ActionType type() const
The action type.
virtual ~QgsAttributeAction()
Destructor.
const QList< QgsAction > & listActions()
List all actions.
QgsVectorLayer * layer()
Return the layer.
bool runable() const
Whether the action is runable on the current platform.
QgsAttributeAction(QgsVectorLayer *layer)
Constructor.
Represents a vector layer which manages a vector based data sets.
void setDefaultAction(int actionNumber)
void clearActions()
Removes all actions.
int defaultAction() const
Whether the action is the default action.