16 #include <QItemDelegate>
26 #include "qgseditorwidgetregistry.h"
50 const QStyleOptionViewItem &option,
51 const QModelIndex &
index )
const
62 QgsEditorWidgetWrapper* eww = QgsEditorWidgetRegistry::instance()->create( widgetType, vl, fieldIdx, cfg, 0, parent );
63 QWidget* w = eww->widget();
65 w->setAutoFillBackground(
true );
80 QVariant oldValue = model->data( index, Qt::EditRole );
83 QgsEditorWidgetWrapper* eww = QgsEditorWidgetWrapper::fromWidget( editor );
87 newValue = eww->value();
89 if ( oldValue != newValue && newValue.isValid() )
99 QgsEditorWidgetWrapper* eww = QgsEditorWidgetWrapper::fromWidget( editor );
103 eww->setValue( index.model()->data( index, Qt::EditRole ) );
112 const QStyleOptionViewItem & option,
113 const QModelIndex &
index )
const
117 QStyleOptionViewItem myOpt = option;
119 if ( index.model()->data( index, Qt::EditRole ).isNull() )
121 myOpt.font.setItalic(
true );
122 myOpt.palette.setColor( QPalette::Text, QColor(
"gray" ) );
126 myOpt.state |= QStyle::State_Selected;
128 QItemDelegate::paint( painter, myOpt, index );
130 if ( option.state & QStyle::State_HasFocus )
132 QRect r = option.rect.adjusted( 1, 1, -1, -1 );
133 QPen p( QBrush( QColor( 0, 255, 127 ) ), 2 );
135 painter->setPen( p );
136 painter->drawRect( r );
const QgsEditorWidgetConfig editorWidgetV2Config(int fieldIdx) const
Get the configuration for the editor widget used to represent the field at the given index...
bool fieldEditable(int idx)
is edit widget editable
virtual bool isSelected(QgsFeatureId fid)
Returns the selection status of a given feature id.
void beginEditCommand(QString text)
Create edit command for undo/redo operations.
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
Used to create an editor for when the user tries to change the contents of a cell.
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
void setFeatureSelectionModel(QgsFeatureSelectionModel *featureSelectionModel)
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
QgsVectorLayer * layer(const QAbstractItemModel *model) const
const QString editorWidgetV2(int fieldIdx) const
Get the id for the editor widget used to represent the field at the given index.
Q_DECL_DEPRECATED bool changeAttributeValue(QgsFeatureId fid, int field, QVariant value, bool emitSignal)
Changes an attribute value (but does not commit it)
void endEditCommand()
Finish edit command and add it to undo/redo stack.
QgsFeatureSelectionModel * mFeatureSelectionModel
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Sets data from editor back to model.
void setEditorData(QWidget *editor, const QModelIndex &index) const
Sets data from model into the editor.
QgsVectorLayer * layer() const
Returns the layer this model uses as backend.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Overloads the paint method form the QItemDelegate bas class.
Represents a vector layer which manages a vector based data sets.