QGIS/python/gui/qgsfieldmodel.sip

63 lines
2.1 KiB
Plaintext
Raw Normal View History

2014-03-24 22:53:10 +01:00
/**
* @brief The QgsFieldModel class is a model to display the list of fields of a layer in widgets.
* If allowed, expressions might be added to the end of the model.
2014-03-24 22:53:10 +01:00
* It can be associated with a QgsMapLayerModel to dynamically display a layer and its fields.
* @note added in 2.3
*/
class QgsFieldModel : QAbstractItemModel
{
%TypeHeaderCode
#include "qgsfieldmodel.h"
%End
public:
2014-05-18 15:22:26 +02:00
enum FieldRoles
{
FieldNameRole, /* return field name if index corresponds to a field */
FieldIndexRole, /* return field index if index corresponds to a field */
ExpressionRole, /* return field name or expression */
IsExpressionRole, /* return if index corresponds to an expression */
ExpressionValidityRole, /* return if expression is valid or not */
FieldTypeRole /* return the field type (if a field, return QVariant if expression) */
};
2014-03-24 22:53:10 +01:00
/**
* @brief QgsFieldModel creates a model to display the fields of a given layer
*/
explicit QgsFieldModel( QObject *parent /TransferThis/ = 0 );
//! return the index corresponding to a given fieldName
2014-05-18 15:22:26 +02:00
QModelIndex indexFromName( const QString &fieldName );
2014-05-02 10:32:37 +02:00
//! returns the currently used layer
void setAllowExpression( bool allowExpression );
bool allowExpression();
/**
* @brief setExpression sets a single expression to be added after the fields at the end of the model
*/
2014-06-23 08:58:28 +02:00
void setExpression( const QString &expression );
2014-05-02 10:32:37 +02:00
//! remove expressions from the model
void removeExpression();
//! returns the currently used layer
QgsVectorLayer* layer();
2014-03-24 22:53:10 +01:00
public slots:
//! set the layer of whch fields are displayed
2014-05-02 07:42:00 +02:00
void setLayer( QgsVectorLayer *layer );
2014-05-02 10:32:37 +02:00
protected slots:
virtual void updateModel();
2014-05-02 10:32:37 +02:00
2014-03-24 22:53:10 +01:00
// QAbstractItemModel interface
public:
QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
QModelIndex parent( const QModelIndex &child ) const;
2014-05-02 07:42:00 +02:00
int rowCount( const QModelIndex &parent = QModelIndex() ) const;
2014-03-24 22:53:10 +01:00
int columnCount( const QModelIndex &parent ) const;
QVariant data( const QModelIndex &index, int role ) const;
};