18#include "moc_qgsattributetablemodel.cpp"
46 : QAbstractTableModel( parent )
47 , mLayer( layerCache->layer() )
48 , mLayerCache( layerCache )
57 mFeat.
setId( std::numeric_limits<int>::min() );
72 mIsCleaningUpAfterRollback =
true;
73 bulkEditCommandEnded();
74 mIsCleaningUpAfterRollback =
false;
83bool QgsAttributeTableModel::loadFeatureAtId(
QgsFeatureId fid )
const
87 if ( fid == std::numeric_limits<int>::min() )
95bool QgsAttributeTableModel::loadFeatureAtId(
QgsFeatureId fid,
int fieldIdx )
const
101 return loadFeatureAtId( fid );
104 if ( fid == std::numeric_limits<int>::min() )
113 return mExtraColumns;
120 beginInsertColumns( QModelIndex(), mFieldCount + mExtraColumns, mFieldCount +
extraColumns - 1 );
126 beginRemoveColumns( QModelIndex(), mFieldCount +
extraColumns, mFieldCount + mExtraColumns - 1 );
132void QgsAttributeTableModel::featuresDeleted(
const QgsFeatureIds &fids )
136 const auto constFids = fids;
141 const int row =
idToRow( fid );
146 std::sort( rows.begin(), rows.end() );
150 int currentRowCount = 0;
154 const auto constRows = rows;
155 for (
const int row : constRows )
158 qDebug() <<
"Row: " << row <<
", begin " << beginRow <<
", last " << lastRow <<
", current " << currentRowCount <<
", removed " << removedRows;
165 if ( row != lastRow + 1 && lastRow != -1 )
167 if ( rows.count() > 100 && currentRowCount < 10 )
172 removeRows( beginRow - removedRows, currentRowCount );
175 removedRows += currentRowCount;
185 removeRows( beginRow - removedRows, currentRowCount );
193 if ( row < 0 || count < 1 )
196 if ( !mResettingModel )
198 beginRemoveRows( parent, row, row + count - 1 );
203 QgsDebugMsgLevel( QStringLiteral(
"remove %2 rows at %1 (rows %3, ids %4)" ).arg( row ).arg( count ).arg( mRowIdMap.size() ).arg( mIdRowMap.size() ), 3 );
206 if ( mBulkEditCommandRunning && !mResettingModel )
208 for (
int i = row; i < row + count; i++ )
211 mInsertedRowsChanges.removeOne( fid );
216 for (
int i = row; i < row + count; i++ )
218 for ( SortCache &cache : mSortCaches )
219 cache.sortCache.remove( mRowIdMap[i] );
220 mIdRowMap.remove( mRowIdMap[i] );
221 mRowIdMap.remove( i );
225 const int n = mRowIdMap.size() + count;
226 for (
int i = row + count; i < n; i++ )
229 mIdRowMap[id] -= count;
230 mRowIdMap[i - count] = id;
231 mRowIdMap.remove( i );
237 QgsDebugMsgLevel( QStringLiteral(
"after removal rows %1, ids %2" ).arg( mRowIdMap.size() ).arg( mIdRowMap.size() ), 4 );
239 for ( QHash<QgsFeatureId, int>::const_iterator it = mIdRowMap.constBegin(); it != mIdRowMap.constEnd(); ++it )
243 for ( QHash<int, QgsFeatureId>::const_iterator it = mRowIdMap.constBegin(); it != mRowIdMap.constEnd(); ++it )
248 Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );
250 if ( !mResettingModel )
256void QgsAttributeTableModel::featureAdded(
QgsFeatureId fid )
261 if ( mFeat.
id() != fid )
262 featOk = loadFeatureAtId( fid );
266 for ( SortCache &cache : mSortCaches )
268 if ( cache.sortFieldIndex >= 0 )
270 const WidgetData &widgetData = getWidgetData( cache.sortFieldIndex );
271 const QVariant sortValue = widgetData.fieldFormatter->sortValue( mLayer, cache.sortFieldIndex, widgetData.config, widgetData.cache, mFeat.
attribute( cache.sortFieldIndex ) );
272 cache.sortCache.insert( mFeat.
id(), sortValue );
274 else if ( cache.sortCacheExpression.isValid() )
277 cache.sortCache[mFeat.
id()] = cache.sortCacheExpression.evaluate( &mExpressionContext );
282 if ( ! mIdRowMap.contains( fid ) )
284 const int n = mRowIdMap.size();
285 if ( !mResettingModel )
286 beginInsertRows( QModelIndex(), n, n );
287 mIdRowMap.insert( fid, n );
288 mRowIdMap.insert( n, fid );
289 if ( !mResettingModel )
292 if ( mBulkEditCommandRunning && !mResettingModel )
294 mInsertedRowsChanges.append( fid );
300void QgsAttributeTableModel::updatedFields()
306void QgsAttributeTableModel::editCommandEnded()
310 bulkEditCommandEnded( );
313void QgsAttributeTableModel::attributeDeleted(
int idx )
316 for (
const SortCache &cache : mSortCaches )
318 if ( cache.sortCacheAttributes.contains( idx ) )
326void QgsAttributeTableModel::layerDeleted()
328 mLayerCache =
nullptr;
333 mWidgetDatas.clear();
336void QgsAttributeTableModel::fieldFormatterRemoved(
QgsFieldFormatter *fieldFormatter )
338 for ( WidgetData &widgetData : mWidgetDatas )
340 if ( widgetData.fieldFormatter == fieldFormatter )
345void QgsAttributeTableModel::attributeValueChanged(
QgsFeatureId fid,
int idx,
const QVariant &value )
348 if ( mBulkEditCommandRunning )
350 mAttributeValueChanges.insert( QPair<QgsFeatureId, int>( fid, idx ), value );
355 for ( SortCache &cache : mSortCaches )
357 if ( cache.sortCacheAttributes.contains( idx ) )
359 if ( cache.sortFieldIndex == -1 )
361 if ( loadFeatureAtId( fid ) )
364 cache.sortCache[fid] = cache.sortCacheExpression.evaluate( &mExpressionContext );
369 const WidgetData &widgetData = getWidgetData( cache.sortFieldIndex );
370 const QVariant sortValue = widgetData.fieldFormatter->representValue( mLayer, cache.sortFieldIndex, widgetData.config, widgetData.cache, value );
371 cache.sortCache.insert( fid, sortValue );
378 if ( loadFeatureAtId( fid ) )
380 const QModelIndex modelIndex = index(
idToRow( fid ),
fieldCol( idx ) );
381 setData( modelIndex, value, Qt::EditRole );
382 emit dataChanged( modelIndex, modelIndex, QVector<int>() << Qt::DisplayRole );
387 if ( loadFeatureAtId( fid ) )
391 if ( !mIdRowMap.contains( fid ) )
399 const QModelIndex modelIndex = index(
idToRow( fid ),
fieldCol( idx ) );
400 setData( modelIndex, value, Qt::EditRole );
401 emit dataChanged( modelIndex, modelIndex, QVector<int>() << Qt::DisplayRole );
406 if ( mIdRowMap.contains( fid ) )
417void QgsAttributeTableModel::loadAttributes()
425 if ( mFields == fields )
430 bool ins =
false, rm =
false;
434 mWidgetDatas.clear();
436 for (
int idx = 0; idx < fields.
count(); ++idx )
441 if ( mFieldCount + mExtraColumns < attributes.size() + mExtraColumns )
444 beginInsertColumns( QModelIndex(), mFieldCount + mExtraColumns, attributes.size() - 1 );
446 else if ( attributes.size() + mExtraColumns < mFieldCount + mExtraColumns )
449 beginRemoveColumns( QModelIndex(), attributes.size(), mFieldCount + mExtraColumns - 1 );
452 mFieldCount = attributes.size();
453 mAttributes = attributes;
454 mWidgetDatas.resize( mFieldCount );
456 for ( SortCache &cache : mSortCaches )
458 if ( cache.sortFieldIndex >= mAttributes.count() )
459 cache.sortFieldIndex = -1;
481 mResettingModel =
true;
503 if ( t.elapsed() > 1000 )
512 featureAdded( mFeat.
id() );
521 mResettingModel =
false;
527 if ( fieldName.isNull() )
529 mRowStylesMap.clear();
530 mConstraintStylesMap.clear();
536 if ( fieldIndex == -1 )
540 const int col =
fieldCol( fieldIndex );
541 emit dataChanged( index( 0, col ), index(
rowCount() - 1, col ) );
554 mRowIdMap.remove( rowA );
555 mRowIdMap.remove( rowB );
556 mRowIdMap.insert( rowA, b );
557 mRowIdMap.insert( rowB, a );
559 mIdRowMap.remove( a );
560 mIdRowMap.remove( b );
561 mIdRowMap.insert( a, rowB );
562 mIdRowMap.insert( b, rowA );
563 Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );
571 if ( !mIdRowMap.contains(
id ) )
573 QgsDebugError( QStringLiteral(
"idToRow: id %1 not in the map" ).arg(
id ) );
577 return mIdRowMap[id];
582 return index(
idToRow(
id ), 0 );
587 QModelIndexList indexes;
591 indexes.reserve( columns );
592 for (
int column = 0; column < columns; ++column )
594 indexes.append( index( row, column ) );
602 if ( !mRowIdMap.contains( row ) )
604 QgsDebugError( QStringLiteral(
"rowToId: row %1 not in the map" ).arg( row ) );
606 return std::numeric_limits<int>::min();
609 return mRowIdMap[row];
614 return mAttributes[col];
619 return mAttributes.indexOf( idx );
625 return mRowIdMap.size();
631 return std::max( 1, mFieldCount + mExtraColumns );
639 if ( role == Qt::DisplayRole )
641 if ( orientation == Qt::Vertical )
643 return QVariant( section );
645 else if ( section >= 0 && section < mFieldCount )
647 const QString attributeName = mLayer->
fields().
at( mAttributes.at( section ) ).
displayName();
648 return QVariant( attributeName );
652 return tr(
"extra column" );
655 else if ( role == Qt::ToolTipRole )
657 if ( orientation == Qt::Vertical )
660 return tr(
"Feature ID: %1" ).arg(
rowToId( section ) );
676 if ( !index.isValid() || !mLayer ||
677 ( role != Qt::TextAlignmentRole
678 && role != Qt::DisplayRole
679 && role != Qt::ToolTipRole
680 && role != Qt::EditRole
683 && role != Qt::BackgroundRole
684 && role != Qt::ForegroundRole
685 && role != Qt::DecorationRole
686 && role != Qt::FontRole
697 if ( index.column() >= mFieldCount )
700 const int fieldId = mAttributes.at( index.column() );
707 const unsigned long cacheIndex = role -
static_cast< int >(
CustomRole::Sort );
708 if ( cacheIndex < mSortCaches.size() )
709 return mSortCaches.at( cacheIndex ).sortCache.value( rowId );
716 if ( role == Qt::TextAlignmentRole )
718 const WidgetData &widgetData = getWidgetData( index.column() );
719 return static_cast<Qt::Alignment::Int
>( widgetData.fieldFormatter->alignmentFlag( mLayer, fieldId, widgetData.config ) | Qt::AlignVCenter );
724 if ( !loadFeatureAtId( rowId, fieldId ) )
725 return QVariant(
"ERROR" );
727 if ( mFeat.
id() != rowId )
728 return QVariant(
"ERROR" );
731 QVariant val = mFeat.
attribute( fieldId );
735 case Qt::DisplayRole:
737 const WidgetData &widgetData = getWidgetData( index.column() );
738 QString s = widgetData.fieldFormatter->representValue( mLayer, fieldId, widgetData.config, widgetData.cache, val );
740 constexpr int MAX_STRING_LENGTH = 10 * 1000;
741 if (
static_cast<size_t>( s.size() ) >
static_cast<size_t>( MAX_STRING_LENGTH ) )
743 s.resize( MAX_STRING_LENGTH );
744 s.append( tr(
"... truncated ..." ) );
748 case Qt::ToolTipRole:
750 const WidgetData &widgetData = getWidgetData( index.column() );
751 QString tooltip = widgetData.fieldFormatter->representValue( mLayer, fieldId, widgetData.config, widgetData.cache, val );
754 tooltip = tr(
"%1 (Ctrl+click to open)" ).arg( tooltip );
761 case Qt::BackgroundRole:
762 case Qt::ForegroundRole:
763 case Qt::DecorationRole:
767 QList<QgsConditionalStyle> styles;
768 if ( mRowStylesMap.contains( mFeat.
id() ) )
770 styles = mRowStylesMap[mFeat.
id()];
775 mRowStylesMap.insert( mFeat.
id(), styles );
782 if ( mConstraintStylesMap.contains( mFeat.
id() ) &&
783 mConstraintStylesMap[mFeat.
id()].contains( fieldId ) )
785 constraintstyle = mConstraintStylesMap[mFeat.
id()][fieldId];
801 mConstraintStylesMap[mFeat.
id()].insert( fieldId, constraintstyle );
807 styles.insert( 0, rowstyle );
808 styles.insert( 0, constraintstyle );
815 if ( role == Qt::ForegroundRole )
817 if ( role == Qt::DecorationRole )
819 if ( role == Qt::FontRole )
824 if ( role == Qt::ForegroundRole )
826 return QColor( Qt::blue );
828 else if ( role == Qt::FontRole )
831 font.setUnderline(
true );
847 if ( !index.isValid() || index.column() >= mFieldCount || role != Qt::EditRole || !mLayer->
isEditable() )
850 mRowStylesMap.remove( mFeat.
id() );
851 mConstraintStylesMap.remove( mFeat.
id() );
861 if ( !index.isValid() )
862 return Qt::ItemIsEnabled;
864 if ( index.column() >= mFieldCount || !mLayer )
865 return Qt::NoItemFlags;
867 Qt::ItemFlags
flags = QAbstractTableModel::flags( index );
869 const int fieldIndex = mAttributes[index.column()];
873 flags |= Qt::ItemIsEditable;
878void QgsAttributeTableModel::bulkEditCommandStarted()
880 mBulkEditCommandRunning =
true;
881 mAttributeValueChanges.clear();
884void QgsAttributeTableModel::bulkEditCommandEnded()
886 mBulkEditCommandRunning =
false;
890 const long long fullModelUpdateThreshold = std::min<long long >( mLayerCache->
cacheSize(), std::ceil(
rowCount() * 0.5 ) );
891 bool fullModelUpdate =
false;
894 if ( mInsertedRowsChanges.size() > fullModelUpdateThreshold )
896 fullModelUpdate =
true;
900 QSet< QgsFeatureId > changedRows;
901 changedRows.reserve( mAttributeValueChanges.size() );
903 for (
auto it = mAttributeValueChanges.constBegin(); it != mAttributeValueChanges.constEnd(); ++it )
905 changedRows.insert( it.key().first );
906 if ( changedRows.size() > fullModelUpdateThreshold )
908 fullModelUpdate =
true;
914 QgsDebugMsgLevel( QStringLiteral(
"Bulk edit command ended modified rows over (%3), cache size is %1, starting %2 update." )
916 .arg( fullModelUpdate ? QStringLiteral(
"full" ) : QStringLiteral(
"incremental" ) )
921 if ( mIsCleaningUpAfterRollback )
923 for (
const int fid : std::as_const( mInsertedRowsChanges ) )
925 const int row(
idToRow( fid ) );
935 if ( fullModelUpdate )
948 const auto keys = mAttributeValueChanges.keys();
949 for (
const auto &key : keys )
951 attributeValueChanged( key.first, key.second, mAttributeValueChanges.value( key ) );
952 const int row(
idToRow( key.first ) );
953 const int col(
fieldCol( key.second ) );
954 minRow = std::min<int>( row, minRow );
955 minCol = std::min<int>( col, minCol );
956 maxRow = std::max<int>( row, maxRow );
957 maxCol = std::max<int>( col, maxCol );
960 emit dataChanged( createIndex( minRow, minCol ), createIndex( maxRow, maxCol ) );
962 mAttributeValueChanges.clear();
967 mFeat.
setId( std::numeric_limits<int>::min() );
968 emit dataChanged( index1, index2 );
992 for (
int i = 0; i < mAttributes.size(); i++ )
994 f.
setAttribute( mAttributes[i],
data( index( idx.row(), i ), Qt::EditRole ) );
1002 if ( column == -1 || column >= mAttributes.count() )
1014 if ( cacheIndex >= mSortCaches.size() )
1016 mSortCaches.resize( cacheIndex + 1 );
1018 SortCache &cache = mSortCaches[cacheIndex];
1019 cache.sortCache.clear();
1020 cache.sortCacheAttributes.clear();
1021 cache.sortFieldIndex = -1;
1022 if ( !expressionString.isEmpty() )
1023 cache.sortCacheExpression =
QgsExpression( expressionString );
1031 WidgetData widgetData;
1033 if ( cache.sortCacheExpression.isField() )
1039 if ( cache.sortFieldIndex == -1 )
1041 cache.sortCacheExpression.prepare( &mExpressionContext );
1043 const QSet<QString> &referencedColumns = cache.sortCacheExpression.referencedColumns();
1045 for (
const QString &col : referencedColumns )
1052 cache.sortCacheAttributes.append( cache.sortFieldIndex );
1054 widgetData = getWidgetData( cache.sortFieldIndex );
1064 if ( cache.sortFieldIndex == -1 )
1067 const QVariant cacheValue = cache.sortCacheExpression.evaluate( &mExpressionContext );
1068 cache.sortCache.insert( f.
id(), cacheValue );
1072 const QVariant sortValue = widgetData.fieldFormatter->sortValue( mLayer, cache.sortFieldIndex, widgetData.config, widgetData.cache, f.
attribute( cache.sortFieldIndex ) );
1073 cache.sortCache.insert( f.
id(), sortValue );
1080 QString expressionString;
1082 if ( cacheIndex >= mSortCaches.size() )
1083 return expressionString;
1085 const QgsExpression &expression = mSortCaches[cacheIndex].sortCacheExpression;
1090 expressionString = QString();
1092 return expressionString;
1103 for (
unsigned long i = 0; i < mSortCaches.size(); ++i )
1112 return mFeatureRequest;
1115const QgsAttributeTableModel::WidgetData &QgsAttributeTableModel::getWidgetData(
int column )
const
1117 Q_ASSERT( column >= 0 && column < mAttributes.size() );
1119 WidgetData &widgetData = mWidgetDatas[ column ];
1120 if ( !widgetData.loaded )
1122 const int idx =
fieldIdx( column );
1125 widgetData.config = setup.
config();
1126 widgetData.cache = widgetData.fieldFormatter->createCache( mLayer, idx, setup.
config() );
1127 widgetData.loaded =
true;
@ NoFilter
No filter is applied.
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
@ NoFlags
No flags are set.
void doAction(QUuid actionId, const QgsFeature &feature, int defaultValueIndex=0, const QgsExpressionContextScope &scope=QgsExpressionContextScope())
Does the given action.
static QgsFieldFormatterRegistry * fieldFormatterRegistry()
Gets the registry of available field formatters.
const QgsFeatureRequest & request() const
Gets the the feature request.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Remove rows.
Qt::ItemFlags flags(const QModelIndex &index) const override
Returns item flags for the index.
QgsFeature feature(const QModelIndex &idx) const
Returns the feature attributes at given model index.
void resetModel()
Resets the model.
void fieldConditionalStyleChanged(const QString &fieldName)
Handles updating the model when the conditional style for a field changes.
QString sortCacheExpression(unsigned long cacheIndex=0) const
The expression which was used to fill the sorting cache at index cacheIndex.
int fieldIdx(int col) const
Gets field index from column.
QgsAttributeTableModel(QgsVectorLayerCache *layerCache, QObject *parent=nullptr)
Constructor.
void swapRows(QgsFeatureId a, QgsFeatureId b)
Swaps two rows.
void modelChanged()
Emitted when the model has been changed.
void executeMapLayerAction(QgsMapLayerAction *action, const QModelIndex &idx, const QgsMapLayerActionContext &context=QgsMapLayerActionContext()) const
Execute a QgsMapLayerAction.
void progress(int i, bool &cancel)
void setRequest(const QgsFeatureRequest &request)
Set a request that will be used to fill this attribute table model.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Updates data on given index.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows.
QModelIndex idToIndex(QgsFeatureId id) const
int extraColumns() const
Empty extra columns to announce from this model.
QgsVectorLayerCache * layerCache() const
Returns the layer cache this model uses as backend.
void finished()
Emitted when the model has completely loaded all features.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of columns.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Returns header data.
QModelIndexList idToIndexList(QgsFeatureId id) const
void prefetchSortData(const QString &expression, unsigned long cacheIndex=0)
Prefetches the entire data for an expression.
QgsFeatureId rowToId(int row) const
Maps row to feature id.
int idToRow(QgsFeatureId id) const
Maps feature id to table row.
virtual void loadLayer()
Loads the layer into the model Preferably to be called, before using this model as source for any oth...
void setExtraColumns(int extraColumns)
Empty extra columns to announce from this model.
void prefetchColumnData(int column)
Caches the entire data for one column.
int fieldCol(int idx) const
Gets column from field index.
void reload(const QModelIndex &index1, const QModelIndex &index2)
Reloads the model data between indices.
@ FeatureId
Get the feature id of the feature in this row.
@ Sort
Role used for sorting start here.
@ FieldIndex
Get the field index of this column.
void executeAction(QUuid action, const QModelIndex &idx) const
Execute an action.
QVariant data(const QModelIndex &index, int role) const override
Returns data on the given index.
QgsConditionalStyles rowStyles() const
Returns a list of row styles associated with the layer.
QgsConditionalStyle constraintFailureStyles(QgsFieldConstraints::ConstraintStrength strength)
Returns a style associated to a constraint failure.
QList< QgsConditionalStyle > fieldStyles(const QString &fieldName) const
Returns the conditional styles set for the field with matching fieldName.
Conditional styling for a rule.
static QgsConditionalStyle compressStyles(const QList< QgsConditionalStyle > &styles)
Compress a list of styles into a single style.
static QList< QgsConditionalStyle > matchingConditionalStyles(const QList< QgsConditionalStyle > &styles, const QVariant &value, QgsExpressionContext &context)
Find and return the matching styles for the value and feature.
QColor backgroundColor() const
The background color for style.
QColor textColor() const
The text color set for style.
QFont font() const
The font for the style.
bool isValid() const
isValid Check if this rule is valid.
QPixmap icon() const
The icon set for style generated from the set symbol.
bool validBackgroundColor() const
Check if the background color is valid for render.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
An expression node which takes it value from a feature's field.
Class for parsing and evaluation of expressions (formerly called "search strings").
QString expression() const
Returns the original, unmodified expression string.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
bool isValid() const
Checks if this expression is valid.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
This class 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.
Qgis::FeatureRequestFilterType filterType() const
Returns the attribute/ID filter type which is currently set on this request.
Qgis::FeatureRequestFlags flags() const
Returns the flags which affect how features are fetched.
bool acceptFeature(const QgsFeature &feature)
Check if a feature is accepted by this requests filter.
bool compare(const QgsFeatureRequest &other) const
Compare two requests for equality, ignoring Expression Context, Transform Error Callback,...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Q_INVOKABLE bool setAttribute(int field, const QVariant &attr)
Sets an attribute's value by field index.
void initAttributes(int fieldCount)
Initialize this feature with the given number of fields.
void setId(QgsFeatureId id)
Sets the feature id for this feature.
bool isValid() const
Returns the validity of this feature.
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
@ ConstraintStrengthSoft
User is warned if constraint is violated but feature can still be accepted.
@ ConstraintStrengthHard
Constraint must be honored before feature can be accepted.
static QString fieldToolTipExtended(const QgsField &field, const QgsVectorLayer *layer)
Returns a HTML formatted tooltip string for a field, containing details like the field name,...
Encapsulate a field in an attribute table or data source.
QString displayName() const
Returns the name to use when displaying this field.
Container of fields for a vector layer.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
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.
static int debugLevel()
Reads the environment variable QGIS_DEBUG and converts it to int.
Encapsulates the context in which a QgsMapLayerAction action is executed.
An action which can run on map layers The class can be used in two manners:
virtual Q_DECL_DEPRECATED void triggerForFeature(QgsMapLayer *layer, const QgsFeature &feature)
Triggers the action with the specified layer and feature.
void dataChanged()
Data of layer changed.
static bool isUrl(const QString &string)
Returns whether the string is a URL (http,https,ftp,file)
This class caches features of a given QgsVectorLayer.
void invalidated()
The cache has been invalidated and cleared.
void featureAdded(QgsFeatureId fid)
Emitted when a new feature has been added to the layer and this cache.
void cachedLayerDeleted()
Is emitted when the cached layer is deleted.
void attributeValueChanged(QgsFeatureId fid, int field, const QVariant &value)
Emitted when an attribute is changed.
QgsVectorLayer * layer()
Returns the layer to which this cache belongs.
bool featureAtIdWithAllAttributes(QgsFeatureId featureId, QgsFeature &feature, bool skipCache=false)
Gets the feature at the given feature id with all attributes, if the cached feature already contains ...
int cacheSize()
Returns the maximum number of features this cache will hold.
QgsAttributeList cacheSubsetOfAttributes() const
Returns the list (possibly a subset) of cached attributes.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &featureRequest=QgsFeatureRequest())
Query this VectorLayerCache for features.
bool featureAtId(QgsFeatureId featureId, QgsFeature &feature, bool skipCache=false)
Gets the feature at the given feature id.
static bool fieldIsEditable(const QgsVectorLayer *layer, int fieldIndex, const QgsFeature &feature)
Tests whether a field is editable for a particular feature.
static bool attributeHasConstraints(const QgsVectorLayer *layer, int attributeIndex)
Returns true if a feature attribute has active constraints.
static bool validateAttribute(const QgsVectorLayer *layer, const QgsFeature &feature, int attributeIndex, QStringList &errors, QgsFieldConstraints::ConstraintStrength strength=QgsFieldConstraints::ConstraintStrengthNotSet, QgsFieldConstraints::ConstraintOrigin origin=QgsFieldConstraints::ConstraintOriginNotSet)
Tests a feature attribute value to check whether it passes all constraints which are present on the c...
bool isModified() const override
Returns true if the provider has been modified since the last commit.
void editCommandStarted(const QString &text)
Signal emitted when a new edit command has been started.
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
void featuresDeleted(const QgsFeatureIds &fids)
Emitted when features have been deleted.
bool isEditable() const FINAL
Returns true if the provider is in editing mode.
void attributeDeleted(int idx)
Will be emitted, when an attribute has been deleted from this vector layer.
QgsActionManager * actions()
Returns all layer actions defined on this layer.
void editCommandEnded()
Signal emitted, when an edit command successfully ended.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
void afterRollBack()
Emitted after changes are rolled back.
void updatedFields()
Emitted whenever the fields available from this layer have been changed.
QgsConditionalLayerStyles * conditionalStyles() const
Returns the conditional styles that are set for this layer.
void beforeRollBack()
Emitted before changes are rolled back.
#define Q_NOWARN_DEPRECATED_POP
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
#define Q_NOWARN_DEPRECATED_PUSH
QSet< QgsFeatureId > QgsFeatureIds
#define FID_TO_STRING(fid)
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QList< int > QgsAttributeList
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)