00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00106
00107
00108
00109 void addAction( QgsAction::ActionType type, QString name, QString action, bool capture = false );
00110
00112
00113
00114
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
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