@@ -12,6 +12,8 @@ class QgsFieldModel : QAbstractItemModel
1212%End
1313
1414 public:
15+
16+ //! Roles utilised by the model
1517 enum FieldRoles
1618 {
1719 FieldNameRole, /*!< return field name if index corresponds to a field */
@@ -21,38 +23,85 @@ class QgsFieldModel : QAbstractItemModel
2123 ExpressionValidityRole, /*!< return if expression is valid or not */
2224 FieldTypeRole, /*!< return the field type (if a field, return QVariant if expression) */
2325 FieldOriginRole, /*!< return the field origin (if a field, returns QVariant if expression) */
26+ IsEmptyRole, //!< Return if the index corresponds to the empty value
2427 };
2528
2629 /**
27- * @brief QgsFieldModel creates a model to display the fields of a given layer
30+ * Constructor for QgsFieldModel - creates a model to display the fields of a given layer.
2831 */
2932 explicit QgsFieldModel( QObject *parent /TransferThis/ = 0 );
3033
31- //! return the index corresponding to a given fieldName
34+ /**
35+ * Returns the index corresponding to a given fieldName.
36+ */
3237 QModelIndex indexFromName( const QString &fieldName );
3338
34- //! returns the currently used layer
39+ /**
40+ * Sets whether custom expressions are accepted and displayed in the model.
41+ * @see allowExpression()
42+ * @see setExpression()
43+ */
3544 void setAllowExpression( bool allowExpression );
45+
46+ /**
47+ * Returns true if the model allows custom expressions to be created and displayed.
48+ * @see setAllowExpression()
49+ */
3650 bool allowExpression();
3751
38- bool isField( const QString& expression );
52+ /**
53+ * Sets whether an optional empty field ("not set") option is present in the model.
54+ * @see allowEmptyFieldName()
55+ * @note added in QGIS 3.0
56+ */
57+ void setAllowEmptyFieldName( bool allowEmpty );
58+
59+ /**
60+ * Returns true if the model allows the empty field ("not set") choice.
61+ * @see setAllowEmptyFieldName()
62+ * @note added in QGIS 3.0
63+ */
64+ bool allowEmptyFieldName() const;
3965
4066 /**
41- * @brief setExpression sets a single expression to be added after the fields at the end of the model
67+ * Returns true if a string represents a field reference, or false if it is an
68+ * expression consisting of more than direct field reference.
69+ */
70+ bool isField( const QString& expression ) const;
71+
72+ /**
73+ * Sets a single expression to be added after the fields at the end of the model.
74+ * @see setAllowExpression()
75+ * @see allowExpression()
76+ * @see removeExpression()
4277 */
4378 void setExpression( const QString &expression );
4479
45- //! remove expressions from the model
80+ /**
81+ * Removes any custom expression from the model.
82+ * @see setExpression()
83+ * @see allowExpression()
84+ */
4685 void removeExpression();
4786
48- //! returns the currently used layer
87+ /**
88+ * Returns the layer associated with the model.
89+ * @see setLayer()
90+ */
4991 QgsVectorLayer* layer();
5092
5193 public slots:
52- //! set the layer of whch fields are displayed
94+ /**
95+ * Set the layer from which fields are displayed.
96+ * @see layer()
97+ */
5398 void setLayer( QgsVectorLayer *layer );
5499
55100 protected slots:
101+
102+ /**
103+ * Called when the model must be updated.
104+ */
56105 virtual void updateModel();
57106
58107 // QAbstractItemModel interface
0 commit comments