QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
qgsfieldmodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfieldmodel.h
3  --------------------------------------
4  Date : 01.04.2014
5  Copyright : (C) 2014 Denis Rouzaud
6  Email : denis.rouzaud@gmail.com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15 
16 #ifndef QGSFIELDMODEL_H
17 #define QGSFIELDMODEL_H
18 
19 #include <QAbstractItemModel>
20 #include <QItemSelectionModel>
21 #include <QComboBox>
22 
23 #include "qgsvectorlayer.h"
24 
31 class GUI_EXPORT QgsFieldModel : public QAbstractItemModel
32 {
33  Q_OBJECT
34  public:
36  {
37  FieldNameRole = Qt::UserRole + 1, /* return field name if index corresponds to a field */
38  FieldIndexRole = Qt::UserRole + 2, /* return field index if index corresponds to a field */
39  ExpressionRole = Qt::UserRole + 3, /* return field name or expression */
40  IsExpressionRole = Qt::UserRole + 4, /* return if index corresponds to an expression */
41  ExpressionValidityRole = Qt::UserRole + 5, /* return if expression is valid or not */
42  FieldTypeRole = Qt::UserRole + 6 /* return the field type (if a field, return QVariant if expression) */
43  };
44 
48  explicit QgsFieldModel( QObject *parent = 0 );
49 
51  QModelIndex indexFromName( const QString &fieldName );
52 
54  void setAllowExpression( bool allowExpression );
55  bool allowExpression() { return mAllowExpression; }
56 
57  bool isField( const QString& expression );
58 
62  void setExpression( const QString &expression );
63 
65  void removeExpression();
66 
68  QgsVectorLayer* layer() { return mLayer; }
69 
70  public slots:
72  void setLayer( QgsVectorLayer *layer );
73 
74  protected slots:
75  virtual void updateModel();
76 
77  private slots:
78  void layerDeleted();
79 
80  protected:
82  QList<QString> mExpression;
83 
86 
87  private:
88  void fetchFeature();
89 
90  // QAbstractItemModel interface
91  public:
92  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
93  QModelIndex parent( const QModelIndex &child ) const;
94  int rowCount( const QModelIndex &parent = QModelIndex() ) const;
95  int columnCount( const QModelIndex &parent ) const;
96  QVariant data( const QModelIndex &index, int role ) const;
97 };
98 
99 #endif // QGSFIELDMODEL_H
static unsigned index
Definition: mersenne-twister.cpp:36
Container of fields for a vector layer.
Definition: qgsfield.h:172
The QgsFieldModel class is a model to display the list of fields of a layer in widgets.
Definition: qgsfieldmodel.h:31
QgsVectorLayer * layer()
returns the currently used layer
Definition: qgsfieldmodel.h:68
bool mAllowExpression
Definition: qgsfieldmodel.h:85
FieldRoles
Definition: qgsfieldmodel.h:35
QgsFields mFields
Definition: qgsfieldmodel.h:81
QList< QString > mExpression
Definition: qgsfieldmodel.h:82
QgsVectorLayer * mLayer
Definition: qgsfieldmodel.h:84
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:470
bool allowExpression()
Definition: qgsfieldmodel.h:55