~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/gui/qgsattributeaction.h

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
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: qgsattributeaction.h 4992 2006-03-10 03:11:06Z g_j_m $ */
24
 
 
25
 
#ifndef QGSATTRIBUTEACTION_H
26
 
#define QGSATTRIBUTEACTION_H
27
 
 
28
 
#include <QString>
29
 
#include <QObject>
30
 
 
31
 
#include <list>
32
 
#include <vector>
33
 
#include <utility>
34
 
 
35
 
class QDomNode;
36
 
class QDomDocument;
37
 
class QgsMessageViewer;
38
 
 
39
 
 
40
 
/*! \class QgsAction
41
 
 * \brief Utility class that encapsulates an action and associated information
42
 
 */
43
 
class QgsAction
44
 
{
45
 
 public:
46
 
  QgsAction(QString name, QString action, bool capture) :
47
 
    mName(name), mAction(action), mCaptureOutput(capture) {}
48
 
 
49
 
  //! The name of the action
50
 
  QString name() const { return mName; }
51
 
 
52
 
  //! The action
53
 
  QString action() const { return mAction; }
54
 
 
55
 
  //! Whether to capture output for display when this action is run
56
 
  bool capture() const { return mCaptureOutput; }
57
 
 
58
 
 private:
59
 
  QString mName;
60
 
  QString mAction;
61
 
  bool mCaptureOutput;
62
 
};
63
 
 
64
 
/*! \class QgsAttributeAction
65
 
 * \brief Storage and management of actions associated with Qgis layer
66
 
 * attributes.
67
 
 */
68
 
 
69
 
class QgsAttributeAction
70
 
{
71
 
 public:
72
 
 
73
 
  typedef std::list<QgsAction> AttributeActions;
74
 
  typedef AttributeActions::const_iterator aIter;
75
 
  
76
 
  //! Constructor
77
 
  QgsAttributeAction() {};
78
 
  
79
 
  //! Destructor
80
 
  virtual ~QgsAttributeAction() {};
81
 
 
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
86
 
  // dialog box.
87
 
  void addAction(QString name, QString action, bool capture = false);
88
 
 
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);
94
 
 
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; 
101
 
 
102
 
  //! Removes all actions
103
 
  void clearActions() { mActions.clear(); }
104
 
 
105
 
  //! A const iterator to the start of the action pairs
106
 
  const AttributeActions::const_iterator begin() const
107
 
    { return mActions.begin(); }
108
 
 
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(); }
112
 
 
113
 
  //! Returns the number of stored actions
114
 
  int size() const { return mActions.size(); }
115
 
 
116
 
  //! Expands the given action, replacing all %'s with the value as
117
 
  // given.  
118
 
  static QString expandAction(QString action, const std::vector<std::pair<QString, QString> >& values,
119
 
                              int defaultValueIndex);
120
 
 
121
 
  //! Writes the actions out in XML format
122
 
  bool writeXML(QDomNode& layer_node, QDomDocument& doc) const;
123
 
 
124
 
  //! Reads the actions in in XML format
125
 
  bool readXML(QDomNode& layer_node);
126
 
 
127
 
 private:
128
 
 
129
 
  // Stores the name/action pairs.
130
 
  AttributeActions mActions;
131
 
};
132
 
 
133
 
#endif