32#include <QItemDelegate>
37#include "moc_qgsattributetabledelegate.cpp"
39QgsVectorLayer *QgsAttributeTableDelegate::layer(
const QAbstractItemModel *model )
41 const QgsAttributeTableModel *tm = qobject_cast<const QgsAttributeTableModel *>( model );
45 const QgsAttributeTableFilterModel *fm = qobject_cast<const QgsAttributeTableFilterModel *>( model );
54 const QgsAttributeTableModel *tm = qobject_cast<const QgsAttributeTableModel *>( model );
58 const QgsAttributeTableFilterModel *fm = qobject_cast<const QgsAttributeTableFilterModel *>( model );
82 QWidget *w = eww->
widget();
83 w->setAutoFillBackground(
true );
84 w->setFocusPolicy( Qt::StrongFocus );
112 const QVariant oldValue = model->data( index, Qt::EditRole );
118 QList<int> indexes = QList<int>() << fieldIdx;
119 QVariantList newValues = QVariantList() << eww->
value();
121 for (
const QString &fieldName : additionalFields )
127 if ( ( oldValue != newValues.at( 0 ) && newValues.at( 0 ).isValid() )
129 || newValues.count() > 1 )
139 for (
int i = 0; i < newValues.count(); i++ )
152 const QVariant value = index.model()->data( index, Qt::EditRole );
155 if ( !additionalFields.empty() )
161 QVariantList additionalFieldValues;
162 for (
const QString &fieldName : additionalFields )
164 additionalFieldValues << feat.
attribute( fieldName );
166 eww->
setValues( value, additionalFieldValues );
177 mFeatureSelectionModel = featureSelectionModel;
192 QStyleOptionViewItem myOpt = option;
196 myOpt.font.setItalic(
true );
197 myOpt.palette.setColor( QPalette::Text, QColor(
"gray" ) );
200 if ( mFeatureSelectionModel && mFeatureSelectionModel->isSelected( fid ) )
201 myOpt.state |= QStyle::State_Selected;
203 QItemDelegate::paint( painter, myOpt, index );
205 if ( option.state & QStyle::State_HasFocus )
207 const QRect r = option.rect.adjusted( 1, 1, -1, -1 );
208 const QPen p( QBrush( QColor( 0, 255, 127 ) ), 2 );
210 painter->setPen( p );
211 painter->drawRect( r );
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
@ Join
Field originates from a joined layer.
Contains context information for attribute editor widgets.
void setFormFeature(const QgsFeature &feature)
Set current feature for the currently edited form or table row.
@ Popup
A widget was opened as a popup (e.g. attribute table editor widget).
QgsFeature formFeature() const
Returns current feature from the currently edited form or table row.
void actionColumnItemPainted(const QModelIndex &index) const
Emitted when an action column item is painted.
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Sets data from editor back to model.
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.
void setEditorData(QWidget *editor, const QModelIndex &index) const override
Sets data from model into the editor.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Overloads the paint method form the QItemDelegate base class.
void setFeatureSelectionModel(QgsFeatureSelectionModel *featureSelectionModel)
@ Type
The type of a given column.
QgsAttributeTableModel * masterModel() const
Returns the table model this filter is using.
ColumnType
The type of a column.
@ ColumnTypeActionButton
This column shows action buttons.
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...
QgsFeature feature(const QModelIndex &idx) const
Returns the feature attributes at given model index.
QgsVectorLayer * layer() const
Returns the layer this model uses as backend.
@ FeatureId
Get the feature id of the feature in this row.
@ FieldIndex
Get the field index of this column.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
Wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(Qgis::FeatureRequestFlags flags)
Sets flags that affect how features will be fetched.
Item selection model for selecting features.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool isValid() const
Returns the validity of this feature.
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
Qgis::FieldOrigin fieldOrigin(int fieldIdx) const
Returns the field's origin (value from an enumeration).
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
static QgsEditorWidgetRegistry * editorWidgetRegistry()
Returns the global editor widget registry, used for managing all known edit widget factories.
Scoped object for saving and restoring a QPainter object's state.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
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.
QgsVectorLayer * joinLayer() const
Returns joined layer (may be nullptr if the reference was set by layer ID and not resolved yet).
Represents a vector layer which manages a vector based dataset.
Q_INVOKABLE bool changeAttributeValue(QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue=QVariant(), bool skipDefaultValues=false, QgsVectorLayerToolsContext *context=nullptr)
Changes an attribute value for a feature (but does not immediately commit the changes).
void endEditCommand()
Finish edit command and add it to undo/redo stack.
QgsVectorLayerJoinBuffer * joinBuffer()
Returns the join buffer object.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const final
Queries the layer for features specified in request.
void beginEditCommand(const QString &text)
Create edit command for undo/redo operations.
QgsEditFormConfig editFormConfig
Q_INVOKABLE QgsFeature getFeature(QgsFeatureId fid) const
Queries the layer for the feature with the given id.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features