23#include "moc_qgsfieldcombobox.cpp"
29 setModel( mFieldProxyModel );
36 mFieldProxyModel->setFilters(
filters );
41 mFieldProxyModel->sourceFieldModel()->setAllowEmptyFieldName( allowEmpty );
46 return mFieldProxyModel->sourceFieldModel()->allowEmptyFieldName();
52 mFieldProxyModel->sourceFieldModel()->setLayer( vl );
57 return mFieldProxyModel->sourceFieldModel()->layer();
62 mFieldProxyModel->sourceFieldModel()->setFields(
fields );
67 return mFieldProxyModel->sourceFieldModel()->fields();
73 const QModelIndex idx = mFieldProxyModel->sourceFieldModel()->indexFromName( fieldName );
76 const QModelIndex proxyIdx = mFieldProxyModel->mapFromSource( idx );
77 if ( proxyIdx.isValid() )
79 setCurrentIndex( proxyIdx.row() );
83 setCurrentIndex( -1 );
88 setCurrentIndex( -1 );
97 const int i = currentIndex();
99 const QModelIndex proxyIndex = mFieldProxyModel->index( i, 0 );
100 if ( !proxyIndex.isValid() )
void setFilters(QgsFieldProxyModel::Filters filters)
setFilters allows filtering according to the type of field
void fieldChanged(const QString &fieldName)
Emitted when the currently selected field changes.
void setFields(const QgsFields &fields)
Manually sets the fields to use for the combo box.
void setLayer(QgsMapLayer *layer)
Sets the layer for which fields are listed in the combobox.
QgsFieldProxyModel::Filters filters
QString currentField() const
Returns the currently selected field.
QgsFields fields() const
Returns the fields currently shown in the combobox.
QgsVectorLayer * layer() const
Returns the layer currently associated with the combobox.
void setField(const QString &fieldName)
setField sets the currently selected field
QgsFieldComboBox(QWidget *parent=nullptr)
QgsFieldComboBox creates a combo box to display the fields of a layer.
void setAllowEmptyFieldName(bool allowEmpty)
Sets whether an optional empty field ("not set") option is shown in the combo box.
@ FieldName
Return field name if index corresponds to a field.
A proxy model to filter the list of fields of a layer.
Container of fields for a vector layer.
Base class for all map layer types.
Represents a vector layer which manages a vector based dataset.