~ubuntu-branches/ubuntu/trusty/qgis/trusty

« back to all changes in this revision

Viewing changes to src/core/qgsfield.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:
12
12
 *   (at your option) any later version.                                   *
13
13
 *                                                                         *
14
14
 ***************************************************************************/
15
 
/* $Id: qgsfield.h 4502 2006-01-08 01:18:20Z timlinux $ */
 
15
/* $Id$ */
16
16
 
17
17
#ifndef QGSFIELD_H
18
18
#define QGSFIELD_H
19
19
 
20
 
#include <qstring.h>
21
 
 
22
 
/**
23
 
  \class QgsField
24
 
  \brief Class to encapsulate a field in an attribute table or data source.
25
 
 
26
 
  QgsField stores metadata about an attribute field, including name, type
27
 
  length, and if applicable, precision.
 
20
#include <QString>
 
21
#include <QVariant>
 
22
 
 
23
/** \ingroup core
 
24
  * Encapsulate a field in an attribute table or data source.
 
25
  * QgsField stores metadata about an attribute field, including name, type
 
26
  * length, and if applicable, precision.
28
27
 */
29
28
 
30
 
class QgsField
 
29
class CORE_EXPORT QgsField
31
30
{
32
 
public:
 
31
  public:
33
32
    /** Constructor. Constructs a new QgsField object.
34
33
     * @param nam Field name
35
 
     * @param typ Field type (eg. char, varchar, text, int, serial, double). 
 
34
     * @param type Field variant type, currently supported: String / Int / Double
 
35
     * @param typeName Field type (eg. char, varchar, text, int, serial, double).
36
36
     Field types are usually unique to the source and are stored exactly
37
37
     as returned from the data store.
38
38
     * @param len Field length
39
39
     * @param prec Field precision. Usually decimal places but may also be
40
40
     * used in conjunction with other fields types (eg. variable character fields)
41
 
     * @param num Has to be true if field contains numeric values.
 
41
     * @param comment Comment for the field
42
42
     */
43
 
  QgsField(QString nam = "", QString typ = "", int len = 0, int prec = 0, bool num = false);
44
 
 
45
 
  //! Destructor
46
 
   ~QgsField();
47
 
 
48
 
   bool operator==(const QgsField other) const;
49
 
   bool operator!=(const QgsField other) const;
50
 
 
51
 
  //! Gets the name of the field
52
 
  QString const & name() const;
53
 
 
54
 
 
55
 
    /** 
 
43
 
 
44
    QgsField( QString name = QString(),
 
45
              QVariant::Type type = QVariant::Invalid,
 
46
              QString typeName = QString(),
 
47
              int len = 0,
 
48
              int prec = 0,
 
49
              QString comment = QString() );
 
50
 
 
51
    //! Destructor
 
52
    ~QgsField();
 
53
 
 
54
    bool operator==( const QgsField& other ) const;
 
55
 
 
56
    //! Gets the name of the field
 
57
    const QString & name() const;
 
58
 
 
59
    //! Gets variant type of the field as it will be retrieved from data source
 
60
    QVariant::Type type() const;
 
61
 
 
62
    /**
56
63
      Gets the field type. Field types vary depending on the data source. Examples
57
64
      are char, int, double, blob, geometry, etc. The type is stored exactly as
58
65
      the data store reports it, with no attenpt to standardize the value.
59
66
      @return QString containing the field type
60
67
     */
61
 
  QString const & type() const;
 
68
    const QString & typeName() const;
62
69
 
63
70
 
64
71
    /**
65
72
      Gets the length of the field.
66
73
      @return int containing the length of the field
67
74
     */
68
 
  int length() const;
 
75
    int length() const;
69
76
 
70
77
 
71
78
    /**
72
79
      Gets the precision of the field. Not all field types have a related precision.
73
80
      @return int containing the precision or zero if not applicable to the field type.
74
81
     */
75
 
  int precision() const;
 
82
    int precision() const;
76
83
 
77
84
    /**
78
 
     Returns true if field contains numeric values. This information is set by provider.
79
 
     */
80
 
  bool isNumeric() const;
81
 
 
 
85
    Returns the field comment
 
86
    */
 
87
    const QString & comment() const;
82
88
 
83
89
    /**
84
90
      Set the field name.
85
91
      @param nam Name of the field
86
92
     */
87
 
  void setName(QString const & nam);
 
93
    void setName( const QString & nam );
 
94
 
 
95
    /**
 
96
      Set variant type.
 
97
     */
 
98
    void setType( QVariant::Type type );
88
99
 
89
100
    /**
90
101
      Set the field type.
91
102
      @param typ Field type
92
103
     */
93
 
  void setType(QString const & typ);
 
104
    void setTypeName( const QString & typ );
94
105
 
95
106
    /**
96
107
      Set the field length.
97
108
      @param len Length of the field
98
109
     */
99
 
  void setLength(int len);
 
110
    void setLength( int len );
100
111
 
101
112
    /**
102
113
      Set the field precision.
103
114
      @param prec Precision of the field
104
115
     */
105
 
  void setPrecision(int prec);
 
116
    void setPrecision( int prec );
 
117
 
106
118
 
107
119
    /**
108
 
      Set whether field is numeric
 
120
      Set the field comment
109
121
      */
110
 
  void setNumeric(bool num);
111
 
 
112
 
private:
113
 
 
114
 
  //! Name
115
 
  QString mName;
116
 
 
117
 
  //! Type
118
 
  QString mType;
119
 
 
120
 
  //! Length
121
 
  int mLength;
122
 
 
123
 
  //! Precision
124
 
  int mPrecision;
125
 
 
126
 
  //! Numeric
127
 
  bool mNumeric;
 
122
    void setComment( const QString & comment );
 
123
 
 
124
  private:
 
125
 
 
126
    //! Name
 
127
    QString mName;
 
128
 
 
129
    //! Variant type
 
130
    QVariant::Type mType;
 
131
 
 
132
    //! Type name from provider
 
133
    QString mTypeName;
 
134
 
 
135
    //! Length
 
136
    int mLength;
 
137
 
 
138
    //! Precision
 
139
    int mPrecision;
 
140
 
 
141
    //! Comment
 
142
    QString mComment;
128
143
 
129
144
}; // class QgsField
130
145
 
 
146
// key = field index, value=field data
 
147
typedef QMap<int, QgsField> QgsFieldMap;
 
148
 
131
149
#endif