24 : QAbstractItemModel( parent )
30 QString fldName( fieldName );
35 if (
mLayer && !fldName.isEmpty() )
41 if ( !fieldNameWithAlias.isNull() )
42 fldName = fieldNameWithAlias;
54 QModelIndex idx =
index( r, 0 );
84 disconnect(
mLayer, &QObject::destroyed,
this, &QgsFieldModel::layerDeleted );
92 connect(
mLayer, &QObject::destroyed,
this, &QgsFieldModel::layerDeleted );
98void QgsFieldModel::layerDeleted()
143 for (
int i = 0; i < newFields.
count(); ++i )
153 beginRemoveRows( QModelIndex(), i + offset, i + offset );
188 beginRemoveRows( QModelIndex(), start, end );
201 beginInsertRows( QModelIndex(), 0, 0 );
207 beginRemoveRows( QModelIndex(), 0, 0 );
225 if ( !expression.isEmpty() )
239 if ( hasIndex( row, column,
parent ) )
241 return createIndex( row, column, row );
244 return QModelIndex();
250 return QModelIndex();
271 if ( !
index.isValid() )
284 if ( isEmpty || exprIdx >= 0 )
311 if ( isEmpty || exprIdx >= 0 )
315 return index.row() - fieldOffset;
340 if ( exprIdx < 0 && !isEmpty )
343 return static_cast< int >( field.
type() );
350 if ( exprIdx < 0 && !isEmpty )
364 if ( exprIdx < 0 && !isEmpty )
373 if ( exprIdx < 0 && !isEmpty )
395 case Qt::DisplayRole:
397 case Qt::ToolTipRole:
403 else if ( exprIdx >= 0 )
407 else if ( role == Qt::EditRole )
411 else if ( role == Qt::ToolTipRole )
427 case Qt::ForegroundRole:
429 if ( !isEmpty && exprIdx >= 0 )
440 return QBrush( QColor( Qt::red ) );
448 if ( !isEmpty && exprIdx >= 0 )
451 QFont font = QFont();
452 font.setItalic(
true );
458 case Qt::DecorationRole:
460 if ( !isEmpty && exprIdx < 0 )
475 if ( !field.
alias().isEmpty() )
477 toolTip = QStringLiteral(
"<b>%1</b> (%2)" ).arg( field.
alias(), field.
name() );
481 toolTip = QStringLiteral(
"<b>%1</b>" ).arg( field.
name() );
484 toolTip += QStringLiteral(
"<br><font style='font-family:monospace; white-space: nowrap;'>%3</font>" ).arg( field.
displayType(
true ) );
486 const QString comment = field.
comment();
488 if ( ! comment.isEmpty() )
490 toolTip += QStringLiteral(
"<br><em>%1</em>" ).arg( comment );
509 if ( !expressionString.isEmpty() )
511 toolTip += QStringLiteral(
"<br><font style='font-family:monospace;'>%3</font>" ).arg( expressionString );
@ Expression
Field is calculated from an expression.
@ Join
Field originates from a joined layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
Class for parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
static QString fieldToolTip(const QgsField &field)
Returns a HTML formatted tooltip string for a field, containing details like the field name,...
int columnCount(const QModelIndex &parent) const override
QVariant data(const QModelIndex &index, int role) const override
QModelIndex parent(const QModelIndex &child) const override
void removeExpression()
Removes any custom expression from the model.
bool isField(const QString &expression) const
Returns true if a string represents a field reference, or false if it is an expression consisting of ...
void setAllowExpression(bool allowExpression)
Sets whether custom expressions are accepted and displayed in the model.
@ FieldIsWidgetEditable
true if a is editable from the widget
@ FieldOrigin
Return the field origin (if a field, returns QVariant if expression)
@ Expression
Return field name or expression.
@ IsExpression
Return if index corresponds to an expression.
@ IsEmpty
Return if the index corresponds to the empty value.
@ ExpressionValidity
Return if expression is valid or not.
@ FieldName
Return field name if index corresponds to a field.
@ FieldIndex
Return field index if index corresponds to a field.
@ EditorWidgetType
Editor widget type.
@ FieldType
Return the field type (if a field, return QVariant if expression)
@ JoinedFieldIsEditable
true if a joined field is editable (returns QVariant if not a joined field)
void setLayer(QgsVectorLayer *layer)
Set the layer from which fields are displayed.
void setExpression(const QString &expression)
Sets a single expression to be added after the fields at the end of the model.
QgsFields fields() const
Returns the fields currently shown in the model.
void setFields(const QgsFields &fields)
Manually sets the fields to use for the model.
QgsFieldModel(QObject *parent=nullptr)
Constructor for QgsFieldModel - creates a model to display the fields of a given layer.
static QString fieldToolTipExtended(const QgsField &field, const QgsVectorLayer *layer)
Returns a HTML formatted tooltip string for a field, containing details like the field name,...
QList< QString > mExpression
QModelIndex indexFromName(const QString &fieldName)
Returns the index corresponding to a given fieldName.
void setAllowEmptyFieldName(bool allowEmpty)
Sets whether an optional empty field ("not set") option is present in the model.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
virtual void updateModel()
Called when the model must be updated.
Encapsulate a field in an attribute table or data source.
QString displayType(bool showConstraints=false) const
Returns the type to use when displaying this field, including the length and precision of the datatyp...
QString displayName() const
Returns the name to use when displaying this field.
QgsEditorWidgetSetup editorWidgetSetup() const
Gets the editor widget setup for the field.
Container of fields for a vector layer.
QList< QgsField > toList() const
Utility function to return a list of QgsField instances.
Q_INVOKABLE int indexFromName(const QString &fieldName) const
Gets the field index from the field name.
Q_INVOKABLE int indexOf(const QString &fieldName) const
Gets the field index from the field name.
void remove(int fieldIdx)
Removes the field with the given index.
QgsField field(int fieldIdx) const
Returns the field at particular index (must be in range 0..N-1).
Qgis::FieldOrigin fieldOrigin(int fieldIdx) const
Returns the field's origin (value from an enumeration).
int size() const
Returns number of items.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
QIcon iconForField(int fieldIdx, bool considerOrigin=false) const
Returns an icon corresponding to a field index, based on the field's type and source.
const QgsVectorLayerJoinInfo * joinForFieldIndex(int index, const QgsFields &fields, int &sourceFieldIndex) const
Finds the vector join for a layer field index.
Defines left outer join from our vector layer to some other vector layer.
bool isEditable() const
Returns whether joined fields may be edited through the form of the target layer.
Represents a vector layer which manages a vector based data sets.
QString attributeDisplayName(int index) const
Convenience function that returns the attribute alias if defined or the field name else.
QString expressionField(int index) const
Returns the expression used for a given expression field.
QgsStringMap attributeAliases() const
Returns a map of field name to attribute alias.
QgsVectorLayerJoinBuffer * joinBuffer()
Returns the join buffer object.
void updatedFields()
Emitted whenever the fields available from this layer have been changed.
QgsEditFormConfig editFormConfig