40 , mLayerCache( layerCache )
57 if ( !
layer()->hasGeometryType() )
64 connect(
layer(), SIGNAL( attributeDeleted(
int ) ),
this, SLOT( attributeDeleted(
int ) ) );
65 connect(
layer(), SIGNAL( updatedFields() ),
this, SLOT( updatedFields() ) );
66 connect(
layer(), SIGNAL( editCommandEnded() ),
this, SLOT( editCommandEnded() ) );
71 bool QgsAttributeTableModel::loadFeatureAtId(
QgsFeatureId fid )
const 100 int currentRowCount = 0;
104 Q_FOREACH (
int row, rows )
107 qDebug() <<
"Row: " << row <<
", begin " << beginRow <<
", last " << lastRow <<
", current " << currentRowCount <<
", removed " << removedRows;
114 if ( row != lastRow + 1 && lastRow != -1 )
116 if ( rows.
count() > 100 && currentRowCount < 10 )
121 removeRows( beginRow - removedRows, currentRowCount );
124 removedRows += currentRowCount;
134 removeRows( beginRow - removedRows, currentRowCount );
141 if ( row < 0 || count < 1 )
151 for (
int i = row; i < row + count; i++ )
160 for (
int i = row + count; i < n; i++ )
195 featOk = loadFeatureAtId( fid );
213 void QgsAttributeTableModel::updatedFields()
220 void QgsAttributeTableModel::editCommandEnded()
225 mChangedCellBounds =
QRect();
228 void QgsAttributeTableModel::attributeDeleted(
int idx )
230 if ( idx == mCachedField )
252 if ( idx == mCachedField )
253 mFieldCache[fid] = value;
262 if ( loadFeatureAtId( fid ) )
297 bool ins =
false, rm =
false;
306 for (
int idx = 0; idx < fields.
count(); ++idx )
310 if ( widgetFactory && widgetType !=
"Hidden" )
403 if ( fieldIndex == -1 )
452 QModelIndexList indexes;
456 indexes.reserve( columns );
457 for (
int column = 0; column < columns; ++column )
459 indexes.append(
index( row, column ) );
504 if ( role == Qt::DisplayRole )
506 if ( orientation == Qt::Vertical )
516 attributeName = field.
name();
522 return tr(
"feature id" );
534 ( role != Qt::TextAlignmentRole
535 && role != Qt::DisplayRole
536 && role != Qt::EditRole
540 && role != Qt::BackgroundColorRole
541 && role != Qt::TextColorRole
542 && role != Qt::DecorationRole
543 && role != Qt::FontRole
554 return role == Qt::DisplayRole ? rowId :
QVariant();
563 QVariant::Type fldType = field.
type();
564 bool fldRightAlign = ( fldType == QVariant::Int || fldType == QVariant::Double || fldType == QVariant::LongLong
565 || fldType == QVariant::DateTime || fldType == QVariant::Date || fldType == QVariant::Time );
567 if ( role == Qt::TextAlignmentRole )
578 if ( mCachedField == fieldId )
580 val = mFieldCache[rowId];
586 if ( !loadFeatureAtId( rowId ) )
596 if ( role == Qt::DisplayRole )
601 if ( role == Qt::BackgroundColorRole || role == Qt::TextColorRole || role == Qt::DecorationRole || role == Qt::FontRole )
619 styles.
insert( 0, rowstyle );
628 if ( role == Qt::DecorationRole )
630 if ( role == Qt::FontRole )
648 if ( mChangedCellBounds.
isNull() )
654 if ( index.
column() < mChangedCellBounds.
left() )
658 if ( index.
row() < mChangedCellBounds.
top() )
660 mChangedCellBounds.
setTop( index.
row() );
666 if ( index.
row() > mChangedCellBounds.
bottom() )
678 return Qt::ItemIsEnabled;
681 return Qt::NoItemFlags;
685 if (
layer()->isEditable() &&
689 flags |= Qt::ItemIsEditable;
741 fldNames << fields[fieldId].name();
752 mCachedField = fieldId;
765 return mFeatureRequest;
QgsFeatureId id() const
Get the feature ID for this feature.
void setRequest(const QgsFeatureRequest &request)
Set a request that will be used to fill this attribute table model.
Wrapper for iterator of features from vector data provider or vector layer.
bool acceptFeature(const QgsFeature &feature)
Check if a feature is accepted by this requests filter.
virtual void featuresDeleted(const QgsFeatureIds &fids)
Launched when eatures have been deleted.
QgsAttributeList mAttributes
iterator insert(const Key &key, const T &value)
const Flags & flags() const
virtual void loadLayer()
Loads the layer into the model Preferably to be called, before using this model as source for any oth...
QModelIndexList idToIndexList(QgsFeatureId id) const
bool validTextColor() const
Check if the text color is valid for render.
QHash< int, QgsFeatureId > mRowIdMap
bool isValid() const
Returns the validity of this feature.
QgsAttributeAction * actions()
void append(const T &value)
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
QColor textColor() const
The text color set for style.
bool validBackgroundColor() const
Check if the background color is valid for render.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
QSet< QgsFeatureId > QgsFeatureIds
QgsFields fields() const
Returns the list of fields of this layer.
virtual void layerDeleted()
Launched when layer has been deleted.
QFont font() const
The font for the style.
QList< QgsConditionalStyle > fieldStyles(const QString &fieldName)
Returns the conditional styles set for the field UI properties.
const T & at(int i) const
void reload(const QModelIndex &index1, const QModelIndex &index2)
Reloads the model data between indices.
#define FID_TO_STRING(fid)
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsConditionalLayerStyles * conditionalStyles() const
Return the conditional styles that are set for this layer.
QModelIndex idToIndex(QgsFeatureId id) const
Container of fields for a vector layer.
bool setAttribute(int field, const QVariant &attr)
Set an attribute's value by field index.
void fieldConditionalStyleChanged(const QString &fieldName)
Handles updating the model when the conditional style for a field changes.
QgsVectorLayer * layer()
Returns the layer to which this cache belongs.
const QgsFeatureRequest & request() const
Get the the feature request.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsEditFormConfig * editFormConfig() const
Get the configuration of the form used to represent this vector layer.
virtual bool isEditable() const override
Returns true if the provider is in editing mode.
QString tr(const char *sourceText, const char *disambiguation, int n)
void resetModel()
Resets the model.
QgsVectorLayerCache * mLayerCache
virtual void attributeValueChanged(QgsFeatureId fid, int idx, const QVariant &value)
Launched when attribute value has been changed.
virtual QVariant data(const QModelIndex &index, int role) const override
Returns data on the given index.
int indexOf(const T &value, int from) const
int count(const T &value) const
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Returns header data.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
QPixmap icon() const
The icon set for style generated from the set symbol.
Conditional styling for a rule.
void executeMapLayerAction(QgsMapLayerAction *action, const QModelIndex &idx) const
Execute a QgsMapLayerAction.
const_iterator constEnd() const
void setFeatureId(QgsFeatureId id)
Sets the feature ID for this feature.
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
#define QgsDebugMsgLevel(str, level)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of columns.
QVector< QgsEditorWidgetFactory * > mWidgetFactories
QgsExpressionContext mExpressionContext
void initAttributes(int fieldCount)
Initialize this feature with the given number of fields.
QString name() const
Gets the name of the field.
static QList< QgsConditionalStyle > matchingConditionalStyles(const QList< QgsConditionalStyle > &styles, const QVariant &value, QgsExpressionContext &context)
Find and return the matching styles for the value and feature.
void beginRemoveRows(const QModelIndex &parent, int first, int last)
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void beginRemoveColumns(const QModelIndex &parent, int first, int last)
QVector< QgsEditorWidgetConfig > mWidgetConfigs
QColor backgroundColor() const
The background color for style.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Remove rows.
int count() const
Return number of items.
virtual bool isModified() const
Returns true if the provider has been modified since the last commit.
QGis::GeometryType geometryType() const
Returns point, line or polygon.
QHash< QgsFeatureId, int > mIdRowMap
FilterType filterType() const
Return the filter type which is currently set on this request.
QgsFeatureRequest & setFlags(const QgsFeatureRequest::Flags &flags)
Set flags that affect how features will be fetched.
static QgsConditionalStyle compressStyles(const QList< QgsConditionalStyle > &styles)
Compress a list of styles into a single style.
Encapsulate a field in an attribute table or data source.
int remove(const Key &key)
QString attributeAlias(int attributeIndex) const
Returns the alias of an attribute name or an empty string if there is no alias.
void executeAction(int action, const QModelIndex &idx) const
Execute an action.
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
virtual void featureAdded(QgsFeatureId fid)
Launched when a feature has been added.
QModelIndex createIndex(int row, int column, void *ptr) const
QgsFeature feature(const QModelIndex &idx) const
Return the feature attributes at given model index.
This class caches features of a given QgsVectorLayer.
static int debugLevel()
Reads the environment variable QGIS_DEBUG and converts it to int.
void progress(int i, bool &cancel)
void beginInsertRows(const QModelIndex &parent, int first, int last)
void modelChanged()
Model has been changed.
QVector< QVariant > mAttributeWidgetCaches
const_iterator constBegin() const
QgsAttributeTableModel(QgsVectorLayerCache *layerCache, QObject *parent=nullptr)
Constructor.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows.
void insert(int i, const T &value)
int fieldCol(int idx) const
get column from field index
bool featureAtId(QgsFeatureId featureId, QgsFeature &feature, bool skipCache=false)
Gets the feature at the given feature id.
QgsVectorLayer * layer() const
Returns the layer this model uses as backend.
virtual void loadAttributes()
Gets mFieldCount, mAttributes and mValueMaps.
int idToRow(QgsFeatureId id) const
Maps feature id to table row.
void doAction(int index, const QgsFeature &feat, int defaultValueIndex=0)
Does the given values.
virtual Qt::ItemFlags flags(const QModelIndex &index) const
bool contains(const Key &key) const
int fieldIdx(int col) const
get field index from column
bool isValid() const
isValid Check if this rule is valid.
QgsFeatureId rowToId(int row) const
Maps row to feature id.
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
void swapRows(QgsFeatureId a, QgsFeatureId b)
Swaps two rows.
bool nextFeature(QgsFeature &f)
Geometry is not required. It may still be returned if e.g. required for a filter condition.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &featureRequest=QgsFeatureRequest())
Query this VectorLayerCache for features.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void beginInsertColumns(const QModelIndex &parent, int first, int last)
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Updates data on given index.
void triggerForFeature(QgsMapLayer *layer, const QgsFeature *feature)
Triggers the action with the specified layer and feature.
Allows modification of attribute values.
An action which can run on map layers.
void prefetchColumnData(int column)
Caches the entire data for one column.
QHash< int, QList< QgsConditionalStyle > > mRowStylesMap
Qt::ItemFlags flags(const QModelIndex &index) const override
Returns item flags for the index.
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.