QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
139  void doAction( int index,
140  const QgsFeature &feat,
141  int defaultValueIndex = 0 );
142 
150  void doAction( int index,
151  const QgsFeature& feat,
152  const QMap<QString, QVariant> *substitutionMap );
153 
155  void clearActions() { mActions.clear(); }
156 
158  const QList<QgsAction>& listActions() { return mActions; }
159 
161  QgsVectorLayer *layer() { return mLayer; }
162 
166  QString expandAction( QString action, const QgsAttributeMap &attributes, uint defaultValueIndex );
167 
178  QString expandAction( QString action,
179  QgsFeature &feat,
180  const QMap<QString, QVariant> *substitutionMap = 0 );
181 
182 
184  bool writeXML( QDomNode& layer_node, QDomDocument& doc ) const;
185 
187  bool readXML( const QDomNode& layer_node );
188 
189  int size() const { return mActions.size(); }
190  QgsAction &at( int idx ) { return mActions[idx]; }
191  QgsAction &operator[]( int idx ) { return mActions[idx]; }
192 
194  static void setPythonExecute( void ( * )( const QString & ) );
195 
197  int defaultAction() const { return mDefaultAction < 0 || mDefaultAction >= size() ? -1 : mDefaultAction; }
198  void setDefaultAction( int actionNumber ) { mDefaultAction = actionNumber ; }
199 
200  private:
201  QList<QgsAction> mActions;
202  QgsVectorLayer *mLayer;
203  static void ( *smPythonExecute )( const QString & );
204 
205  void runAction( const QgsAction &action,
206  void ( *executePython )( const QString & ) = 0 );
207 
208  int mDefaultAction;
209 };
210 
211 #endif
static unsigned index
Definition: mersenne-twister.cpp:36
ActionType
Definition: qgsattributeaction.h:43
const QString iconPath() const
The path to the icon.
Definition: qgsattributeaction.h:63
QMap< int, QVariant > QgsAttributeMap
Definition: qgsfeature.h:98
QgsAction(ActionType type, QString name, QString action, const QString &icon, bool capture)
Definition: qgsattributeaction.h:56
QgsAction & operator[](int idx)
Definition: qgsattributeaction.h:191
Storage and management of actions associated with Qgis layer attributes.
Definition: qgsattributeaction.h:106
Definition: qgsattributeaction.h:46
QgsAction(ActionType type, QString name, QString action, bool capture)
Definition: qgsattributeaction.h:53
Definition: qgsattributeaction.h:50
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
static QIcon icon(QString icon)
Definition: qgsmessagelogviewer.cpp:32
bool capture() const
Whether to capture output for display when this action is run.
Definition: qgsattributeaction.h:75
Definition: qgsattributeaction.h:47
Definition: qgsattributeaction.h:45
Definition: qgsattributeaction.h:49
QString name() const
The name of the action.
Definition: qgsattributeaction.h:60
const QIcon icon() const
The icon.
Definition: qgsattributeaction.h:66
Utility class that encapsulates an action based on vector attributes.
Definition: qgsattributeaction.h:40
QgsAction & at(int idx)
Definition: qgsattributeaction.h:190
QString action() const
The action.
Definition: qgsattributeaction.h:69
int size() const
Definition: qgsattributeaction.h:189
ActionType type() const
The action type.
Definition: qgsattributeaction.h:72
virtual ~QgsAttributeAction()
Destructor.
Definition: qgsattributeaction.h:113
const QList< QgsAction > & listActions()
List all actions.
Definition: qgsattributeaction.h:158
QgsVectorLayer * layer()
Return the layer.
Definition: qgsattributeaction.h:161
bool runable() const
Whether the action is runable on the current platform.
Definition: qgsattributeaction.h:78
QgsAttributeAction(QgsVectorLayer *layer)
Constructor.
Definition: qgsattributeaction.h:110
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:470
double size
Definition: qgssvgcache.cpp:77
void setDefaultAction(int actionNumber)
Definition: qgsattributeaction.h:198
Definition: qgsattributeaction.h:48
void clearActions()
Removes all actions.
Definition: qgsattributeaction.h:155
int defaultAction() const
Whether the action is the default action.
Definition: qgsattributeaction.h:197