Quantum GIS API Documentation  1.7.4
src/core/qgsattributeaction.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                           qgsattributeaction.h
00003 
00004  These classes store and control the managment and execution of actions
00005  associated with particulay Qgis layers. Actions are defined to be
00006  external programs that are run with user-specified inputs that can
00007  depend on the contents of layer attributes.
00008 
00009                              -------------------
00010     begin                : Oct 24 2004
00011     copyright            : (C) 2004 by Gavin Macaulay
00012     email                : gavin at macaulay dot co dot nz
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 /* $Id$ */
00024 
00025 #ifndef QGSATTRIBUTEACTION_H
00026 #define QGSATTRIBUTEACTION_H
00027 
00028 #include <QString>
00029 #include <QObject>
00030 
00031 #include <qgsfeature.h>
00032 
00033 class QDomNode;
00034 class QDomDocument;
00035 class QgsPythonUtils;
00036 class QgsVectorLayer;
00037 
00041 class CORE_EXPORT QgsAction
00042 {
00043   public:
00044     enum ActionType
00045     {
00046       Generic,
00047       GenericPython,
00048       Mac,
00049       Windows,
00050       Unix,
00051     };
00052 
00053     QgsAction( ActionType type, QString name, QString action, bool capture ) :
00054         mType( type ), mName( name ), mAction( action ), mCaptureOutput( capture ) {}
00055 
00057     QString name() const { return mName; }
00058 
00060     QString action() const { return mAction; }
00061 
00063     ActionType type() const { return mType; }
00064 
00066     bool capture() const { return mCaptureOutput; }
00067 
00069     bool runable() const
00070     {
00071       return mType == Generic ||
00072              mType == GenericPython ||
00073 #if defined(Q_OS_WIN)
00074              mType == Windows
00075 #elif defined(Q_OS_MAC)
00076              mType == Mac
00077 #else
00078              mType == Unix
00079 #endif
00080              ;
00081     }
00082 
00083   private:
00084     ActionType mType;
00085     QString mName;
00086     QString mAction;
00087     bool mCaptureOutput;
00088 };
00089 
00095 class  CORE_EXPORT QgsAttributeAction
00096 {
00097   public:
00099     QgsAttributeAction( QgsVectorLayer *layer ) : mLayer( layer ) {}
00100 
00102     virtual ~QgsAttributeAction() {}
00103 
00105     // Will happily have duplicate names and actions. If
00106     // capture is true, when running the action using doAction(),
00107     // any stdout from the process will be captured and displayed in a
00108     // dialog box.
00109     void addAction( QgsAction::ActionType type, QString name, QString action, bool capture = false );
00110 
00112     // index into values which indicates which value in the values vector
00113     // is to be used if the action has a default placeholder.
00114     // @note parameter executePython deprecated (and missing in python binding)
00115     void doAction( int index,
00116                    const QgsAttributeMap &attributes,
00117                    int defaultValueIndex = 0,
00118                    void ( *executePython )( const QString & ) = 0 );
00119 
00121     void clearActions() { mActions.clear(); }
00122 
00124     // given.
00125     QString expandAction( QString action,
00126                           const QgsAttributeMap &attributes,
00127                           uint defaultValueIndex );
00128 
00130     bool writeXML( QDomNode& layer_node, QDomDocument& doc ) const;
00131 
00133     bool readXML( const QDomNode& layer_node );
00134 
00135     int size() const { return mActions.size(); }
00136     QgsAction &at( int idx ) { return mActions[idx]; }
00137     QgsAction &operator[]( int idx ) { return mActions[idx]; }
00138 
00139     static void setPythonExecute( void ( * )( const QString & ) );
00140 
00141   private:
00142     QList<QgsAction> mActions;
00143     QgsVectorLayer *mLayer;
00144     static void ( *smPythonExecute )( const QString & );
00145 };
00146 
00147 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines