QGIS/python/gui/qgsfieldmodel.sip

115 lines
3.5 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:
//! Roles utilized by the model
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) */
FieldOriginRole, /*!< return the field origin (if a field, returns QVariant if expression) */
IsEmptyRole, //!< Return if the index corresponds to the empty value
};
2014-03-24 22:53:10 +01:00
/**
* Constructor for QgsFieldModel - creates a model to display the fields of a given layer.
2014-03-24 22:53:10 +01:00
*/
explicit QgsFieldModel( QObject *parent /TransferThis/ = 0 );
/**
* Returns 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
/**
* Sets whether custom expressions are accepted and displayed in the model.
* @see allowExpression()
* @see setExpression()
*/
void setAllowExpression( bool allowExpression );
/**
* Returns true if the model allows custom expressions to be created and displayed.
* @see setAllowExpression()
*/
bool allowExpression();
/**
* Sets whether an optional empty field ("not set") option is present in the model.
* @see allowEmptyFieldName()
* @note added in QGIS 3.0
*/
void setAllowEmptyFieldName( bool allowEmpty );
/**
* Returns true if the model allows the empty field ("not set") choice.
* @see setAllowEmptyFieldName()
* @note added in QGIS 3.0
*/
bool allowEmptyFieldName() const;
2015-02-03 02:21:52 +01:00
/**
* Returns true if a string represents a field reference, or false if it is an
* expression consisting of more than direct field reference.
*/
bool isField( const QString& expression ) const;
/**
* Sets a single expression to be added after the fields at the end of the model.
* @see setAllowExpression()
* @see allowExpression()
* @see removeExpression()
*/
2014-06-23 08:58:28 +02:00
void setExpression( const QString &expression );
2014-05-02 10:32:37 +02:00
/**
* Removes any custom expression from the model.
* @see setExpression()
* @see allowExpression()
*/
void removeExpression();
/**
* Returns the layer associated with the model.
* @see setLayer()
*/
QgsVectorLayer* layer();
2014-03-24 22:53:10 +01:00
public slots:
/**
* Set the layer from which fields are displayed.
* @see layer()
*/
2014-05-02 07:42:00 +02:00
void setLayer( QgsVectorLayer *layer );
2014-05-02 10:32:37 +02:00
protected slots:
/**
* Called when the model must be updated.
*/
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;
};