QGIS API Documentation  2.5.0-Master
 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 <QObject>
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 
57  QString name() const { return mName; }
58 
60  QString action() const { return mAction; }
61 
63  ActionType type() const { return mType; }
64 
66  bool capture() const { return mCaptureOutput; }
67 
69  bool runable() const
70  {
71  return mType == Generic ||
72  mType == GenericPython ||
73  mType == OpenUrl ||
74 #if defined(Q_OS_WIN)
75  mType == Windows
76 #elif defined(Q_OS_MAC)
77  mType == Mac
78 #else
79  mType == Unix
80 #endif
81  ;
82  }
83 
84  private:
86  QString mName;
87  QString mAction;
89 };
90 
96 class CORE_EXPORT QgsAttributeAction
97 {
98  public:
100  QgsAttributeAction( QgsVectorLayer *layer ) : mLayer( layer ), mDefaultAction( -1 ) {}
101 
103  virtual ~QgsAttributeAction() {}
104 
106  // Will happily have duplicate names and actions. If
107  // capture is true, when running the action using doAction(),
108  // any stdout from the process will be captured and displayed in a
109  // dialog box.
110  void addAction( QgsAction::ActionType type, QString name, QString action, bool capture = false );
111 
113  void removeAction( int index );
114 
120  void doAction( int index,
121  const QgsFeature &feat,
122  int defaultValueIndex = 0 );
123 
131  void doAction( int index,
132  const QgsFeature& feat,
133  const QMap<QString, QVariant> *substitutionMap );
134 
136  void clearActions() { mActions.clear(); }
137 
139  const QList<QgsAction>& listActions() { return mActions; }
140 
142  QgsVectorLayer *layer() { return mLayer; }
143 
147  QString expandAction( QString action, const QgsAttributeMap &attributes, uint defaultValueIndex );
148 
159  QString expandAction( QString action,
160  QgsFeature &feat,
161  const QMap<QString, QVariant> *substitutionMap = 0 );
162 
163 
165  bool writeXML( QDomNode& layer_node, QDomDocument& doc ) const;
166 
168  bool readXML( const QDomNode& layer_node );
169 
170  int size() const { return mActions.size(); }
171  QgsAction &at( int idx ) { return mActions[idx]; }
172  QgsAction &operator[]( int idx ) { return mActions[idx]; }
173 
175  static void setPythonExecute( void ( * )( const QString & ) );
176 
178  int defaultAction() const { return mDefaultAction < 0 || mDefaultAction >= size() ? -1 : mDefaultAction; }
179  void setDefaultAction( int actionNumber ) { mDefaultAction = actionNumber ; }
180 
181  private:
182  QList<QgsAction> mActions;
184  static void ( *smPythonExecute )( const QString & );
185 
186  void runAction( const QgsAction &action,
187  void ( *executePython )( const QString & ) = 0 );
188 
190 };
191 
192 #endif
static unsigned index
QMap< int, QVariant > QgsAttributeMap
Definition: qgsfeature.h:98
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:113
bool capture() const
Whether to capture output for display when this action is run.
QString name() const
The name of the action.
Utility class that encapsulates an action based on vector attributes.
QList< QgsAction > mActions
QgsAction & at(int idx)
QString action() const
The action.
ActionType type() const
The action type.
ActionType mType
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.
QgsVectorLayer * mLayer
Represents a vector layer which manages a vector based data sets.
double size
Definition: qgssvgcache.cpp:77
void setDefaultAction(int actionNumber)
void clearActions()
Removes all actions.
int defaultAction() const
Whether the action is the default action.