1
/***************************************************************************
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.
11
copyright : (C) 2004 by Gavin Macaulay
12
email : gavin at macaulay dot co dot nz
13
***************************************************************************/
15
/***************************************************************************
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. *
22
***************************************************************************/
23
/* $Id: qgsattributeaction.h 4992 2006-03-10 03:11:06Z g_j_m $ */
25
#ifndef QGSATTRIBUTEACTION_H
26
#define QGSATTRIBUTEACTION_H
37
class QgsMessageViewer;
41
* \brief Utility class that encapsulates an action and associated information
46
QgsAction(QString name, QString action, bool capture) :
47
mName(name), mAction(action), mCaptureOutput(capture) {}
49
//! The name of the action
50
QString name() const { return mName; }
53
QString action() const { return mAction; }
55
//! Whether to capture output for display when this action is run
56
bool capture() const { return mCaptureOutput; }
64
/*! \class QgsAttributeAction
65
* \brief Storage and management of actions associated with Qgis layer
69
class QgsAttributeAction
73
typedef std::list<QgsAction> AttributeActions;
74
typedef AttributeActions::const_iterator aIter;
77
QgsAttributeAction() {};
80
virtual ~QgsAttributeAction() {};
82
//! Add an action with the given name and action details.
83
// Will happily have duplicate names and actions. If
84
// capture is true, when running the action using doAction(),
85
// any stdout from the process will be captured and displayed in a
87
void addAction(QString name, QString action, bool capture = false);
89
//! Does the action using the given values. defaultValueIndex is an
90
// index into values which indicates which value in the values vector
91
// is to be used if the action has a default placeholder.
92
void doAction(unsigned int index, const std::vector<std::pair<QString, QString> >& values,
93
int defaultValueIndex = 0);
95
//! Returns a const_iterator that points to the QgsAction at the
96
// given position in the data collection. The insertion order is
97
// preserved. The index starts at 0 and goes to one less than the
98
// number of actions. An index outside that range will return an
99
// a const_iterator equal to that returned by end().
100
aIter retrieveAction(unsigned int index) const;
102
//! Removes all actions
103
void clearActions() { mActions.clear(); }
105
//! A const iterator to the start of the action pairs
106
const AttributeActions::const_iterator begin() const
107
{ return mActions.begin(); }
109
//! A const iterator to the one past the end of the action pairs
110
const AttributeActions::const_iterator end() const
111
{ return mActions.end(); }
113
//! Returns the number of stored actions
114
int size() const { return mActions.size(); }
116
//! Expands the given action, replacing all %'s with the value as
118
static QString expandAction(QString action, const std::vector<std::pair<QString, QString> >& values,
119
int defaultValueIndex);
121
//! Writes the actions out in XML format
122
bool writeXML(QDomNode& layer_node, QDomDocument& doc) const;
124
//! Reads the actions in in XML format
125
bool readXML(QDomNode& layer_node);
129
// Stores the name/action pairs.
130
AttributeActions mActions;