45#include "moc_qgsattributetablemodel.cpp"
47using namespace Qt::StringLiterals;
50 : QAbstractTableModel( parent )
58 mFeatureRequest.setFlags( Qgis::FeatureRequestFlag::NoGeometry );
61 mFeat.setId( std::numeric_limits<int>::min() );
63 if ( !mLayer->isSpatial() )
75 mIsCleaningUpAfterRollback =
true;
76 bulkEditCommandEnded();
77 mIsCleaningUpAfterRollback =
false;
86bool QgsAttributeTableModel::loadFeatureAtId(
QgsFeatureId fid )
const
90 if ( fid == std::numeric_limits<int>::min() )
95 return mLayerCache->featureAtId( fid, mFeat );
98bool QgsAttributeTableModel::loadFeatureAtId(
QgsFeatureId fid,
int fieldIdx )
const
102 if ( mLayerCache->cacheSubsetOfAttributes().contains(
fieldIdx ) )
104 return loadFeatureAtId( fid );
107 if ( fid == std::numeric_limits<int>::min() )
111 return mLayerCache->featureAtIdWithAllAttributes( fid, mFeat );
116 return mExtraColumns;
123 beginInsertColumns( QModelIndex(), mFieldCount + mExtraColumns, mFieldCount +
extraColumns - 1 );
129 beginRemoveColumns( QModelIndex(), mFieldCount +
extraColumns, mFieldCount + mExtraColumns - 1 );
135void QgsAttributeTableModel::featuresDeleted(
const QgsFeatureIds &fids )
139 const auto constFids = fids;
144 const int row =
idToRow( fid );
149 std::sort( rows.begin(), rows.end() );
153 int currentRowCount = 0;
157 const auto constRows = rows;
158 for (
const int row : constRows )
161 qDebug() <<
"Row: " << row <<
", begin " << beginRow <<
", last " << lastRow <<
", current " << currentRowCount <<
", removed " << removedRows;
168 if ( row != lastRow + 1 && lastRow != -1 )
170 if ( rows.count() > 100 && currentRowCount < 10 )
175 removeRows( beginRow - removedRows, currentRowCount );
178 removedRows += currentRowCount;
188 removeRows( beginRow - removedRows, currentRowCount );
195 if ( row < 0 || count < 1 )
198 if ( !mResettingModel )
200 beginRemoveRows( parent, row, row + count - 1 );
203 QgsDebugMsgLevel( u
"remove %2 rows at %1 (rows %3, ids %4)"_s.arg( row ).arg( count ).arg( mRowIdMap.size() ).arg( mIdRowMap.size() ), 3 );
205 if ( mBulkEditCommandRunning && !mResettingModel )
207 for (
int i = row; i < row + count; i++ )
210 mInsertedRowsChanges.removeOne( fid );
215 for (
int i = row; i < row + count; i++ )
217 for ( SortCache &cache : mSortCaches )
218 cache.sortCache.remove( mRowIdMap[i] );
219 mIdRowMap.remove( mRowIdMap[i] );
220 mRowIdMap.remove( i );
224 const int n = mRowIdMap.size() + count;
225 for (
int i = row + count; i < n; i++ )
228 mIdRowMap[id] -= count;
229 mRowIdMap[i - count] = id;
230 mRowIdMap.remove( i );
236 QgsDebugMsgLevel( u
"after removal rows %1, ids %2"_s.arg( mRowIdMap.size() ).arg( mIdRowMap.size() ), 4 );
238 for ( QHash<QgsFeatureId, int>::const_iterator it = mIdRowMap.constBegin(); it != mIdRowMap.constEnd(); ++it )
244 for ( QHash<int, QgsFeatureId>::const_iterator it = mRowIdMap.constBegin(); it != mRowIdMap.constEnd(); ++it )
251 Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );
253 if ( !mResettingModel )
259void QgsAttributeTableModel::featureAdded(
QgsFeatureId fid )
264 if ( mFeat.
id() != fid )
265 featOk = loadFeatureAtId( fid );
269 for ( SortCache &cache : mSortCaches )
271 if ( cache.sortFieldIndex >= 0 )
273 const WidgetData &widgetData = getWidgetData( cache.sortFieldIndex );
274 const QVariant sortValue = widgetData.fieldFormatter->sortValue( mLayer, cache.sortFieldIndex, widgetData.config, widgetData.cache, mFeat.
attribute( cache.sortFieldIndex ) );
275 cache.sortCache.insert( mFeat.
id(), sortValue );
277 else if ( cache.sortCacheExpression.isValid() )
279 mExpressionContext.setFeature( mFeat );
280 cache.sortCache[mFeat.id()] = cache.sortCacheExpression.evaluate( &mExpressionContext );
285 if ( !mIdRowMap.contains( fid ) )
287 const int n = mRowIdMap.size();
288 if ( !mResettingModel )
289 beginInsertRows( QModelIndex(), n, n );
290 mIdRowMap.insert( fid, n );
291 mRowIdMap.insert( n, fid );
292 if ( !mResettingModel )
295 if ( mBulkEditCommandRunning && !mResettingModel )
297 mInsertedRowsChanges.append( fid );
303void QgsAttributeTableModel::updatedFields()
309void QgsAttributeTableModel::editCommandEnded()
313 bulkEditCommandEnded();
316void QgsAttributeTableModel::attributeDeleted(
int idx )
319 for (
const SortCache &cache : mSortCaches )
321 if ( cache.sortCacheAttributes.contains( idx ) )
329void QgsAttributeTableModel::layerDeleted()
331 mLayerCache =
nullptr;
336 mWidgetDatas.clear();
339void QgsAttributeTableModel::fieldFormatterRemoved(
QgsFieldFormatter *fieldFormatter )
341 for ( WidgetData &widgetData : mWidgetDatas )
343 if ( widgetData.fieldFormatter == fieldFormatter )
348void QgsAttributeTableModel::attributeValueChanged(
QgsFeatureId fid,
int idx,
const QVariant &value )
351 if ( mBulkEditCommandRunning )
353 mAttributeValueChanges.insert( QPair<QgsFeatureId, int>( fid, idx ), value );
356 QgsDebugMsgLevel( u
"(%4) fid: %1, idx: %2, value: %3"_s.arg( fid ).arg( idx ).arg( value.toString() ).arg(
qgsEnumValueToKey( mFeatureRequest.filterType() ) ), 2 );
358 for ( SortCache &cache : mSortCaches )
360 if ( cache.sortCacheAttributes.contains( idx ) )
362 if ( cache.sortFieldIndex == -1 )
364 if ( loadFeatureAtId( fid ) )
366 mExpressionContext.setFeature( mFeat );
367 cache.sortCache[fid] = cache.sortCacheExpression.evaluate( &mExpressionContext );
372 const WidgetData &widgetData = getWidgetData( cache.sortFieldIndex );
373 const QVariant sortValue = widgetData.fieldFormatter->representValue( mLayer, cache.sortFieldIndex, widgetData.config, widgetData.cache, value );
374 cache.sortCache.insert( fid, sortValue );
381 if ( loadFeatureAtId( fid ) )
383 const QModelIndex modelIndex = index(
idToRow( fid ),
fieldCol( idx ) );
384 setData( modelIndex, value, Qt::EditRole );
385 emit dataChanged( modelIndex, modelIndex, QVector<int>() << Qt::DisplayRole );
390 if ( loadFeatureAtId( fid ) )
392 if ( mFeatureRequest.acceptFeature( mFeat ) )
394 if ( !mIdRowMap.contains( fid ) )
402 const QModelIndex modelIndex = index(
idToRow( fid ),
fieldCol( idx ) );
403 setData( modelIndex, value, Qt::EditRole );
404 emit dataChanged( modelIndex, modelIndex, QVector<int>() << Qt::DisplayRole );
409 if ( mIdRowMap.contains( fid ) )
420void QgsAttributeTableModel::loadAttributes()
427 const QgsFields fields = mLayer->fields();
428 if ( mFields == fields )
433 bool ins =
false, rm =
false;
437 mWidgetDatas.
clear();
439 for (
int idx = 0; idx < fields.
count(); ++idx )
444 if ( mFieldCount + mExtraColumns < attributes.size() + mExtraColumns )
447 beginInsertColumns( QModelIndex(), mFieldCount + mExtraColumns, attributes.size() - 1 );
449 else if ( attributes.size() + mExtraColumns < mFieldCount + mExtraColumns )
452 beginRemoveColumns( QModelIndex(), attributes.size(), mFieldCount + mExtraColumns - 1 );
455 mFieldCount = attributes.size();
456 mAttributes = attributes;
457 mWidgetDatas.resize( mFieldCount );
459 for ( SortCache &cache : mSortCaches )
461 if ( cache.sortFieldIndex >= mAttributes.count() )
462 cache.sortFieldIndex = -1;
484 mResettingModel =
true;
506 if ( t.elapsed() > 1000 )
515 featureAdded( mFeat.id() );
524 mResettingModel =
false;
530 if ( fieldName.isNull() )
532 mRowStylesMap.clear();
533 mConstraintStylesMap.clear();
538 const int fieldIndex = mLayer->fields().lookupField( fieldName );
539 if ( fieldIndex == -1 )
543 const int col =
fieldCol( fieldIndex );
544 emit dataChanged( index( 0, col ), index(
rowCount() - 1, col ) );
557 mRowIdMap.remove( rowA );
558 mRowIdMap.remove( rowB );
559 mRowIdMap.insert( rowA, b );
560 mRowIdMap.insert( rowB, a );
562 mIdRowMap.remove( a );
563 mIdRowMap.remove( b );
564 mIdRowMap.insert( a, rowB );
565 mIdRowMap.insert( b, rowA );
566 Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );
574 if ( !mIdRowMap.contains(
id ) )
576 QgsDebugError( u
"idToRow: id %1 not in the map"_s.arg(
id ) );
580 return mIdRowMap[id];
585 return index(
idToRow(
id ), 0 );
590 QModelIndexList indexes;
594 indexes.reserve( columns );
595 for (
int column = 0; column < columns; ++column )
597 indexes.append( index( row, column ) );
605 if ( !mRowIdMap.contains( row ) )
607 QgsDebugError( u
"rowToId: row %1 not in the map"_s.arg( row ) );
609 return std::numeric_limits<int>::min();
612 return mRowIdMap[row];
617 return mAttributes[col];
622 return mAttributes.indexOf( idx );
628 return mRowIdMap.size();
634 return std::max( 1, mFieldCount + mExtraColumns );
642 if ( role == Qt::DisplayRole )
644 if ( orientation == Qt::Vertical )
646 return QVariant( section );
648 else if ( section >= 0 && section < mFieldCount )
650 const QString attributeName = mLayer->fields().at( mAttributes.at( section ) ).displayName();
651 return QVariant( attributeName );
655 return tr(
"extra column" );
658 else if ( role == Qt::ToolTipRole )
660 if ( orientation == Qt::Vertical )
663 return tr(
"Feature ID: %1" ).arg(
rowToId( section ) );
667 const QgsField field = mLayer->fields().at( mAttributes.at( section ) );
679 if ( !index.isValid() || !mLayer || ( role != Qt::TextAlignmentRole && role != Qt::DisplayRole && role != Qt::ToolTipRole && role != Qt::EditRole && role !=
static_cast<int>(
CustomRole::FeatureId ) && role !=
static_cast<int>(
CustomRole::FieldIndex ) && role != Qt::BackgroundRole && role != Qt::ForegroundRole && role != Qt::DecorationRole && role != Qt::FontRole && role <
static_cast<int>(
CustomRole::Sort ) ) )
687 if ( index.column() >= mFieldCount )
690 const int fieldId = mAttributes.at( index.column() );
697 const unsigned long cacheIndex = role -
static_cast<int>(
CustomRole::Sort );
698 if ( cacheIndex < mSortCaches.size() )
700 return mSortCaches.at( cacheIndex ).sortCache.value( rowId );
708 const QgsField field = mLayer->fields().at( fieldId );
710 if ( role == Qt::TextAlignmentRole )
712 const WidgetData &widgetData = getWidgetData( index.column() );
713 return static_cast<Qt::Alignment::Int
>( widgetData.fieldFormatter->
alignmentFlag( mLayer, fieldId, widgetData.config ) | Qt::AlignVCenter );
716 if ( mFeat.id() != rowId || !mFeat.isValid() || !mLayerCache->cacheSubsetOfAttributes().contains( fieldId ) )
718 if ( !loadFeatureAtId( rowId, fieldId ) )
719 return QVariant(
"ERROR" );
721 if ( mFeat.id() != rowId )
722 return QVariant(
"ERROR" );
725 QVariant val = mFeat.attribute( fieldId );
729 case Qt::DisplayRole:
731 const WidgetData &widgetData = getWidgetData( index.column() );
732 QString s = widgetData.fieldFormatter->
representValue( mLayer, fieldId, widgetData.config, widgetData.cache, val );
734 constexpr int MAX_STRING_LENGTH = 10 * 1000;
735 if (
static_cast<size_t>( s.size() ) >
static_cast<size_t>( MAX_STRING_LENGTH ) )
737 s.resize( MAX_STRING_LENGTH );
738 s.append( tr(
"... truncated ..." ) );
742 case Qt::ToolTipRole:
744 const WidgetData &widgetData = getWidgetData( index.column() );
745 QString tooltip = widgetData.fieldFormatter->
representValue( mLayer, fieldId, widgetData.config, widgetData.cache, val );
746 if ( tooltip != val.toString() )
748 tooltip = tr(
"%1 (%2)" ).arg( tooltip, val.toString() );
752 tooltip = tr(
"%1 (Ctrl+click to open)" ).arg( tooltip );
759 case Qt::BackgroundRole:
760 case Qt::ForegroundRole:
761 case Qt::DecorationRole:
764 mExpressionContext.setFeature( mFeat );
765 QList<QgsConditionalStyle> styles;
766 if ( mRowStylesMap.contains( mFeat.id() ) )
768 styles = mRowStylesMap[mFeat.id()];
773 mRowStylesMap.insert( mFeat.id(), styles );
780 if ( mConstraintStylesMap.contains( mFeat.id() ) && mConstraintStylesMap[mFeat.id()].contains( fieldId ) )
782 constraintstyle = mConstraintStylesMap[mFeat.id()][fieldId];
798 mConstraintStylesMap[mFeat.id()].insert( fieldId, constraintstyle );
802 styles = mLayer->conditionalStyles()->fieldStyles( field.
name() );
804 styles.insert( 0, rowstyle );
805 styles.insert( 0, constraintstyle );
812 if ( role == Qt::ForegroundRole )
814 if ( role == Qt::DecorationRole )
816 if ( role == Qt::FontRole )
821 if ( role == Qt::ForegroundRole )
823 return QColor( Qt::blue );
825 else if ( role == Qt::FontRole )
828 font.setUnderline(
true );
844 if ( !index.isValid() || index.column() >= mFieldCount || role != Qt::EditRole || !mLayer->isEditable() )
847 mRowStylesMap.remove( mFeat.id() );
848 mConstraintStylesMap.remove( mFeat.id() );
850 if ( !mLayer->isModified() )
858 if ( !index.isValid() )
859 return Qt::ItemIsEnabled;
861 if ( index.column() >= mFieldCount || !mLayer )
862 return Qt::NoItemFlags;
864 Qt::ItemFlags
flags = QAbstractTableModel::flags( index );
866 const int fieldIndex = mAttributes[index.column()];
870 flags |= Qt::ItemIsEditable;
875void QgsAttributeTableModel::bulkEditCommandStarted()
877 mBulkEditCommandRunning =
true;
878 mAttributeValueChanges.clear();
881void QgsAttributeTableModel::bulkEditCommandEnded()
883 mBulkEditCommandRunning =
false;
887 const long long fullModelUpdateThreshold = std::min<long long>( mLayerCache->cacheSize(), std::ceil(
rowCount() * 0.5 ) );
888 bool fullModelUpdate =
false;
891 if ( mInsertedRowsChanges.size() > fullModelUpdateThreshold )
893 fullModelUpdate =
true;
897 QSet<QgsFeatureId> changedRows;
898 changedRows.reserve( mAttributeValueChanges.size() );
900 for (
auto it = mAttributeValueChanges.constBegin(); it != mAttributeValueChanges.constEnd(); ++it )
902 changedRows.insert( it.key().first );
903 if ( changedRows.size() > fullModelUpdateThreshold )
905 fullModelUpdate =
true;
911 QgsDebugMsgLevel( u
"Bulk edit command ended modified rows over (%3), cache size is %1, starting %2 update."_s.arg( mLayerCache->cacheSize() ).arg( fullModelUpdate ? u
"full"_s : u
"incremental"_s ).arg(
rowCount() ), 3 );
914 if ( mIsCleaningUpAfterRollback )
916 for (
const int fid : std::as_const( mInsertedRowsChanges ) )
918 const int row(
idToRow( fid ) );
928 if ( fullModelUpdate )
931 emit mLayer->dataChanged();
940 const auto keys = mAttributeValueChanges.keys();
941 for (
const auto &key : keys )
943 attributeValueChanged( key.first, key.second, mAttributeValueChanges.value( key ) );
944 const int row(
idToRow( key.first ) );
945 const int col(
fieldCol( key.second ) );
946 minRow = std::min<int>( row, minRow );
947 minCol = std::min<int>( col, minCol );
948 maxRow = std::max<int>( row, maxRow );
949 maxCol = std::max<int>( col, maxCol );
952 emit dataChanged( createIndex( minRow, minCol ), createIndex( maxRow, maxCol ) );
954 mAttributeValueChanges.clear();
959 mFeat.setId( std::numeric_limits<int>::min() );
960 emit dataChanged( index1, index2 );
967 mLayer->actions()->doAction( action, f,
fieldIdx( idx.column() ) );
984 for (
int i = 0; i < mAttributes.size(); i++ )
986 f.
setAttribute( mAttributes[i],
data( index( idx.row(), i ), Qt::EditRole ) );
994 if ( column == -1 || column >= mAttributes.count() )
1009 if ( cacheIndex >= mSortCaches.size() )
1011 mSortCaches.resize( cacheIndex + 1 );
1013 SortCache &cache = mSortCaches[cacheIndex];
1014 cache.sortCache.clear();
1015 cache.sortCacheAttributes.clear();
1016 cache.sortFieldIndex = -1;
1017 if ( !expressionString.isEmpty() )
1018 cache.sortCacheExpression =
QgsExpression( expressionString );
1026 WidgetData widgetData;
1028 if ( cache.sortCacheExpression.
isField() )
1031 cache.sortFieldIndex = mLayer->fields().lookupField( fieldName );
1034 if ( cache.sortFieldIndex == -1 )
1036 cache.sortCacheExpression.
prepare( &mExpressionContext );
1038 const QSet<QString> &referencedColumns = cache.sortCacheExpression.
referencedColumns();
1040 for (
const QString &col : referencedColumns )
1042 cache.sortCacheAttributes.append( mLayer->fields().lookupField( col ) );
1047 cache.sortCacheAttributes.append( cache.sortFieldIndex );
1049 widgetData = getWidgetData( cache.sortFieldIndex );
1059 if ( cache.sortFieldIndex == -1 )
1061 mExpressionContext.setFeature( f );
1062 const QVariant cacheValue = cache.sortCacheExpression.
evaluate( &mExpressionContext );
1063 cache.sortCache.insert( f.
id(), cacheValue );
1067 const QVariant sortValue = widgetData.fieldFormatter->
sortValue( mLayer, cache.sortFieldIndex, widgetData.config, widgetData.cache, f.
attribute( cache.sortFieldIndex ) );
1068 cache.sortCache.insert( f.
id(), sortValue );
1075 QString expressionString;
1077 if ( cacheIndex >= mSortCaches.size() )
1078 return expressionString;
1080 const QgsExpression &expression = mSortCaches[cacheIndex].sortCacheExpression;
1085 expressionString = QString();
1087 return expressionString;
1092 if ( !mFeatureRequest.compare(
request ) )
1095 if ( mLayer && !mLayer->isSpatial() )
1098 for (
unsigned long i = 0; i < mSortCaches.size(); ++i )
1107 return mFeatureRequest;
1110const QgsAttributeTableModel::WidgetData &QgsAttributeTableModel::getWidgetData(
int column )
const
1112 Q_ASSERT( column >= 0 && column < mAttributes.size() );
1114 WidgetData &widgetData = mWidgetDatas[column];
1115 if ( !widgetData.loaded )
1117 const int idx =
fieldIdx( column );
1120 widgetData.config = setup.
config();
1121 widgetData.cache = widgetData.fieldFormatter->createCache( mLayer, idx, setup.
config() );
1122 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.
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
QgsVectorLayer * layer() const
Returns the layer this model uses as backend.
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.
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.
An expression node which takes its value from a feature's field.
QString name() const
The name of the column.
Handles parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
QString expression() const
Returns the original, unmodified expression string.
bool isField() const
Checks whether an expression consists only of a single field reference.
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes).
const QgsExpressionNode * rootNode() const
Returns the root node of the expression.
bool needsGeometry() const
Returns true if the expression uses feature geometry for some computation.
QVariant evaluate()
Evaluate the feature and return the result.
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.
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.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
bool acceptFeature(const QgsFeature &feature)
Check if a feature is accepted by this requests filter.
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.
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.
void clear()
Removes all fields.
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.
virtual Q_DECL_DEPRECATED void triggerForFeature(QgsMapLayer *layer, const QgsFeature &feature)
Triggers the action with the specified layer and feature.
static bool isUrl(const QString &string)
Returns whether the string is a URL (http,https,ftp,file).
Caches features for 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.
static bool fieldIsEditable(const QgsVectorLayer *layer, int fieldIndex, const QgsFeature &feature, QgsVectorLayerUtils::FieldIsEditableFlags flags=QgsVectorLayerUtils::FieldIsEditableFlags())
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...
void editCommandStarted(const QString &text)
Signal emitted when a new edit command has been started.
void featuresDeleted(const QgsFeatureIds &fids)
Emitted when features have been deleted.
void attributeDeleted(int idx)
Will be emitted, when an attribute has been deleted from this vector layer.
void editCommandEnded()
Signal emitted, when an edit command successfully ended.
void afterRollBack()
Emitted after changes are rolled back.
void updatedFields()
Emitted whenever the fields available from this layer have been changed.
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)