QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
16 #include <QItemDelegate>
20 #include <QToolButton>
37 QgsVectorLayer *QgsAttributeTableDelegate::layer(
const QAbstractItemModel *model )
78 QWidget *w = eww->
widget();
80 w->setAutoFillBackground(
true );
81 w->setFocusPolicy( Qt::StrongFocus );
109 const QVariant oldValue = model->data( index, Qt::EditRole );
115 QList<int> indexes = QList<int>() << fieldIdx;
116 QVariantList newValues = QVariantList() << eww->
value();
118 for (
const QString &fieldName : additionalFields )
124 if ( ( oldValue != newValues.at( 0 ) && newValues.at( 0 ).isValid() )
125 || oldValue.isNull() != newValues.at( 0 ).isNull()
126 || newValues.count() > 1 )
136 for (
int i = 0; i < newValues.count(); i++ )
149 const QVariant value = index.model()->data( index, Qt::EditRole );
152 if ( !additionalFields.empty() )
158 QVariantList additionalFieldValues;
159 for (
const QString &fieldName : additionalFields )
161 additionalFieldValues << feat.
attribute( fieldName );
163 eww->
setValues( value, additionalFieldValues );
174 mFeatureSelectionModel = featureSelectionModel;
189 QStyleOptionViewItem myOpt = option;
191 if ( index.model()->data( index, Qt::EditRole ).isNull() )
193 myOpt.font.setItalic(
true );
194 myOpt.palette.setColor( QPalette::Text, QColor(
"gray" ) );
197 if ( mFeatureSelectionModel && mFeatureSelectionModel->
isSelected( fid ) )
198 myOpt.state |= QStyle::State_Selected;
200 QItemDelegate::paint( painter, myOpt, index );
202 if ( option.state & QStyle::State_HasFocus )
204 const QRect r = option.rect.adjusted( 1, 1, -1, -1 );
205 const QPen p( QBrush( QColor( 0, 255, 127 ) ), 2 );
207 painter->setPen( p );
208 painter->drawRect( r );
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
static QgsEditorWidgetRegistry * editorWidgetRegistry()
Returns the global editor widget registry, used for managing all known edit widget factories.
virtual bool isSelected(QgsFeatureId fid)
Returns the selection status of a given feature id.
void setFeatureSelectionModel(QgsFeatureSelectionModel *featureSelectionModel)
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Used to create an editor for when the user tries to change the contents of a cell.
const QgsVectorLayerJoinInfo * joinForFieldIndex(int index, const QgsFields &fields, int &sourceFieldIndex) const
Finds the vector join for a layer field index.
const QgsAttributeEditorContext & editorContext() const
Returns the context in which this table is shown.
void beginEditCommand(const QString &text)
Create edit command for undo/redo operations.
bool changeAttributeValue(QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue=QVariant(), bool skipDefaultValues=false)
Changes an attribute value for a feature (but does not immediately commit the changes).
void setEditorData(QWidget *editor, const QModelIndex &index) const override
Sets data from model into the editor.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
This class wraps a request for features to a vector layer (or directly its vector data provider).
ColumnType
The type of a column.
@ FieldIndexRole
Get the field index of this column.
void endEditCommand()
Finish edit command and add it to undo/redo stack.
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Sets data from editor back to model.
bool isValid() const
Returns the validity of this feature.
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
FieldOrigin fieldOrigin(int fieldIdx) const
Returns the field's origin (value from an enumeration).
QgsAttributeTableModel * masterModel() const
Returns the table model this filter is using.
bool isEditable() const
Returns whether joined fields may be edited through the form of the target layer.
QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
Defines left outer join from our vector layer to some other vector layer. The join is done based on [...
QgsVectorLayer * layer() const
Returns the layer this model uses as backend.
Scoped object for saving and restoring a QPainter object's state.
@ TypeRole
The type of a given column.
@ Popup
A widget was opened as a popup (e.g. attribute table editor widget)
@ FeatureIdRole
Get the feature id of the feature in this row.
@ ColumnTypeActionButton
This column shows action buttons.
QgsFeature feature(const QModelIndex &idx) const
Returns the feature attributes at given model index.
bool nextFeature(QgsFeature &f)
Represents a vector layer which manages a vector based data sets.
QgsEditFormConfig editFormConfig
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Overloads the paint method form the QItemDelegate base class.
QgsVectorLayer * joinLayer() const
Returns joined layer (may be nullptr if the reference was set by layer ID and not resolved yet)
void actionColumnItemPainted(const QModelIndex &index) const
Emitted when an action column item is painted.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
QgsFeature getFeature(QgsFeatureId fid) const
Queries the layer for the feature with the given id.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
This class contains context information for attribute editor widgets. It will be passed to embedded w...
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
@ OriginJoin
Field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index w...
void setFormFeature(const QgsFeature &feature)
Set current feature for the currently edited form or table row.
QgsVectorLayerJoinBuffer * joinBuffer()
Returns the join buffer object.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features