Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 /* $Id$ */
24 
25 #ifndef QGSATTRIBUTEACTION_H
26 #define QGSATTRIBUTEACTION_H
27 
28 #include <QString>
29 #include <QObject>
30 
31 #include <qgsfeature.h>
32 
33 class QDomNode;
34 class QDomDocument;
35 class QgsPythonUtils;
36 class QgsVectorLayer;
37 
41 class CORE_EXPORT QgsAction
42 {
43  public:
45  {
48  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 #if defined(Q_OS_WIN)
74  mType == Windows
75 #elif defined(Q_OS_MAC)
76  mType == Mac
77 #else
78  mType == Unix
79 #endif
80  ;
81  }
82 
83  private:
85  QString mName;
86  QString mAction;
88 };
89 
95 class CORE_EXPORT QgsAttributeAction
96 {
97  public:
99  QgsAttributeAction( QgsVectorLayer *layer ) : mLayer( layer ) {}
100 
102  virtual ~QgsAttributeAction() {}
103 
105  // Will happily have duplicate names and actions. If
106  // capture is true, when running the action using doAction(),
107  // any stdout from the process will be captured and displayed in a
108  // dialog box.
109  void addAction( QgsAction::ActionType type, QString name, QString action, bool capture = false );
110 
112  // index into values which indicates which value in the values vector
113  // is to be used if the action has a default placeholder.
114  // @note parameter executePython deprecated (and missing in python binding)
115  void doAction( int index,
116  const QgsAttributeMap &attributes,
117  int defaultValueIndex = 0,
118  void ( *executePython )( const QString & ) = 0 );
119 
121  void clearActions() { mActions.clear(); }
122 
124  // given.
125  QString expandAction( QString action,
126  const QgsAttributeMap &attributes,
127  uint defaultValueIndex );
128 
130  bool writeXML( QDomNode& layer_node, QDomDocument& doc ) const;
131 
133  bool readXML( const QDomNode& layer_node );
134 
135  int size() const { return mActions.size(); }
136  QgsAction &at( int idx ) { return mActions[idx]; }
137  QgsAction &operator[]( int idx ) { return mActions[idx]; }
138 
139  static void setPythonExecute( void ( * )( const QString & ) );
140 
141  private:
142  QList<QgsAction> mActions;
144  static void ( *smPythonExecute )( const QString & );
145 };
146 
147 #endif