QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
28 : QAbstractItemModel( parent )
34 QString fldName( fieldName );
39 if (
mLayer && !fldName.isEmpty() )
45 if ( !fieldNameWithAlias.isNull() )
46 fldName = fieldNameWithAlias;
58 QModelIndex idx =
index( r, 0 );
88 disconnect(
mLayer, &QObject::destroyed,
this, &QgsFieldModel::layerDeleted );
96 connect(
mLayer, &QObject::destroyed,
this, &QgsFieldModel::layerDeleted );
102 void QgsFieldModel::layerDeleted()
147 for (
int i = 0; i < newFields.
count(); ++i )
157 beginRemoveRows( QModelIndex(), i + offset, i + offset );
192 beginRemoveRows( QModelIndex(), start, end );
205 beginInsertRows( QModelIndex(), 0, 0 );
211 beginRemoveRows( QModelIndex(), 0, 0 );
229 if ( !expression.isEmpty() )
243 if ( hasIndex( row, column,
parent ) )
245 return createIndex( row, column, row );
248 return QModelIndex();
254 return QModelIndex();
275 if ( !
index.isValid() )
288 if ( isEmpty || exprIdx >= 0 )
315 if ( isEmpty || exprIdx >= 0 )
319 return index.row() - fieldOffset;
344 if ( exprIdx < 0 && !isEmpty )
347 return static_cast< int >(
field.
type() );
354 if ( exprIdx < 0 && !isEmpty )
368 if ( exprIdx < 0 && !isEmpty )
377 if ( exprIdx < 0 && !isEmpty )
399 case Qt::DisplayRole:
401 case Qt::ToolTipRole:
407 else if ( exprIdx >= 0 )
411 else if ( role == Qt::EditRole )
415 else if ( role == Qt::ToolTipRole )
431 case Qt::ForegroundRole:
433 if ( !isEmpty && exprIdx >= 0 )
444 return QBrush( QColor( Qt::red ) );
452 if ( !isEmpty && exprIdx >= 0 )
455 QFont font = QFont();
456 font.setItalic(
true );
462 case Qt::DecorationRole:
464 if ( !isEmpty && exprIdx < 0 )
485 toolTip = QStringLiteral(
"<b>%1</b>" ).arg(
field.
name() );
488 toolTip += QStringLiteral(
"<br><font style='font-family:monospace; white-space: nowrap;'>%3</font>" ).arg(
field.
displayType(
true ) );
492 if ( ! comment.isEmpty() )
494 toolTip += QStringLiteral(
"<br><em>%1</em>" ).arg( comment );
513 if ( !expressionString.isEmpty() )
515 toolTip += QStringLiteral(
"<br><font style='font-family:monospace;'>%3</font>" ).arg( expressionString );
QModelIndex parent(const QModelIndex &child) const override
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QIcon iconForField(int fieldIdx, bool considerOrigin=false) const
Returns an icon corresponding to a field index, based on the field's type and source.
QgsFieldModel(QObject *parent=nullptr)
Constructor for QgsFieldModel - creates a model to display the fields of a given layer.
void setAllowEmptyFieldName(bool allowEmpty)
Sets whether an optional empty field ("not set") option is present in the model.
@ IsExpressionRole
Return if index corresponds to an expression.
QList< QString > mExpression
@ JoinedFieldIsEditable
true if a joined field is editable (returns QVariant if not a joined field)
@ FieldIndexRole
Return field index if index corresponds to a field.
@ ExpressionValidityRole
Return if expression is valid or not.
int count() const
Returns number of items.
Container of fields for a vector layer.
void setLayer(QgsVectorLayer *layer)
Set the layer from which fields are displayed.
QVariant data(const QModelIndex &index, int role) const override
const QgsVectorLayerJoinInfo * joinForFieldIndex(int index, const QgsFields &fields, int &sourceFieldIndex) const
Finds the vector join for a layer field index.
static QString fieldToolTipExtended(const QgsField &field, const QgsVectorLayer *layer)
Returns a HTML formatted tooltip string for a field, containing details like the field name,...
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
void setFields(const QgsFields &fields)
Manually sets the fields to use for the model.
@ FieldOriginRole
Return the field origin (if a field, returns QVariant if expression)
@ FieldNameRole
Return field name if index corresponds to a field.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QList< QgsField > toList() const
Utility function to return a list of QgsField instances.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
@ FieldTypeRole
Return the field type (if a field, return QVariant if expression)
bool isField(const QString &expression) const
Returns true if a string represents a field reference, or false if it is an expression consisting of ...
static QString fieldToolTip(const QgsField &field)
Returns a HTML formatted tooltip string for a field, containing details like the field name,...
void setAllowExpression(bool allowExpression)
Sets whether custom expressions are accepted and displayed in the model.
int size() const
Returns number of items.
FieldOrigin fieldOrigin(int fieldIdx) const
Gets field's origin (value from an enumeration)
bool isEditable() const
Returns whether joined fields may be edited through the form of the target layer.
@ EditorWidgetType
Editor widget type.
Defines left outer join from our vector layer to some other vector layer.
void removeExpression()
Removes any custom expression from the model.
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
QgsField field(int fieldIdx) const
Gets field at particular index (must be in range 0..N-1)
@ OriginExpression
Field is calculated from an expression.
QString displayType(bool showConstraints=false) const
Returns the type to use when displaying this field, including the length and precision of the datatyp...
QString attributeDisplayName(int index) const
Convenience function that returns the attribute alias if defined or the field name else.
Represents a vector layer which manages a vector based data sets.
QgsEditFormConfig editFormConfig
@ ExpressionRole
Return field name or expression.
int columnCount(const QModelIndex &parent) const override
QString displayName() const
Returns the name to use when displaying this field.
QgsFields fields() const
Returns the fields currently shown in the model.
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
void updatedFields()
Emitted whenever the fields available from this layer have been changed.
QModelIndex indexFromName(const QString &fieldName)
Returns the index corresponding to a given fieldName.
void setExpression(const QString &expression)
Sets a single expression to be added after the fields at the end of the model.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
QgsEditorWidgetSetup editorWidgetSetup() const
Gets the editor widget setup for the field.
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
Class for parsing and evaluation of expressions (formerly called "search strings").
void remove(int fieldIdx)
Removes a field with the given index.
@ FieldIsWidgetEditable
true if a is editable from the widget
QString expressionField(int index) const
Returns the expression used for a given expression field.
virtual void updateModel()
Called when the model must be updated.
int indexFromName(const QString &fieldName) const
Gets the field index from the field name.
@ OriginJoin
Field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index w...
QgsVectorLayerJoinBuffer * joinBuffer()
Returns the join buffer object.
int indexOf(const QString &fieldName) const
Gets the field index from the field name.
QgsStringMap attributeAliases() const
Returns a map of field name to attribute alias.
@ IsEmptyRole
Return if the index corresponds to the empty value.
Encapsulate a field in an attribute table or data source.