45  : QAbstractTableModel( parent )
 
   46  , mLayer( layerCache->layer() )
 
   47  , mLayerCache( layerCache )
 
   56  mFeat.
setId( std::numeric_limits<int>::min() );
 
   71    mIsCleaningUpAfterRollback = 
true;
 
   72    bulkEditCommandEnded();
 
   73    mIsCleaningUpAfterRollback = 
false;
 
 
   82bool QgsAttributeTableModel::loadFeatureAtId( 
QgsFeatureId fid )
 const 
   86  if ( fid == std::numeric_limits<int>::min() )
 
   94bool QgsAttributeTableModel::loadFeatureAtId( 
QgsFeatureId fid, 
int fieldIdx )
 const 
  100    return loadFeatureAtId( fid );
 
  103  if ( fid == std::numeric_limits<int>::min() )
 
  112  return mExtraColumns;
 
 
  119    beginInsertColumns( QModelIndex(), mFieldCount + mExtraColumns, mFieldCount + 
extraColumns - 1 );
 
  125    beginRemoveColumns( QModelIndex(), mFieldCount + 
extraColumns, mFieldCount + mExtraColumns - 1 );
 
 
  131void QgsAttributeTableModel::featuresDeleted( 
const QgsFeatureIds &fids )
 
  135  const auto constFids = fids;
 
  138    QgsDebugMsgLevel( QStringLiteral( 
"(%2) fid: %1, size: %3" ).arg( fid ).arg( mFeatureRequest.
filterType() ).arg( mIdRowMap.size() ), 4 );
 
  140    const int row = 
idToRow( fid );
 
  145  std::sort( rows.begin(), rows.end() );
 
  149  int currentRowCount = 0;
 
  153  const auto constRows = rows;
 
  154  for ( 
const int row : constRows )
 
  157    qDebug() << 
"Row: " << row << 
", begin " << beginRow << 
", last " << lastRow << 
", current " << currentRowCount << 
", removed " << removedRows;
 
  164    if ( row != lastRow + 1 && lastRow != -1 )
 
  166      if ( rows.count() > 100 && currentRowCount < 10 )
 
  171      removeRows( beginRow - removedRows, currentRowCount );
 
  174      removedRows += currentRowCount;
 
  184    removeRows( beginRow - removedRows, currentRowCount );
 
  192  if ( row < 0 || count < 1 )
 
  195  if ( !mResettingModel )
 
  197    beginRemoveRows( parent, row, row + count - 1 );
 
  202    QgsDebugMsgLevel( QStringLiteral( 
"remove %2 rows at %1 (rows %3, ids %4)" ).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( QStringLiteral( 
"after removal rows %1, ids %2" ).arg( mRowIdMap.size() ).arg( mIdRowMap.size() ), 4 );
 
  238    for ( QHash<QgsFeatureId, int>::const_iterator it = mIdRowMap.constBegin(); it != mIdRowMap.constEnd(); ++it )
 
  242    for ( QHash<int, QgsFeatureId>::const_iterator it = mRowIdMap.constBegin(); it != mRowIdMap.constEnd(); ++it )
 
  247  Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );
 
  249  if ( !mResettingModel )
 
 
  255void QgsAttributeTableModel::featureAdded( 
QgsFeatureId fid )
 
  260  if ( mFeat.
id() != fid )
 
  261    featOk = loadFeatureAtId( fid );
 
  265    for ( SortCache &cache : mSortCaches )
 
  267      if ( cache.sortFieldIndex >= 0 )
 
  269        const WidgetData &widgetData = getWidgetData( cache.sortFieldIndex );
 
  270        const QVariant sortValue = widgetData.fieldFormatter->sortValue( mLayer, cache.sortFieldIndex, widgetData.config, widgetData.cache, mFeat.
attribute( cache.sortFieldIndex ) );
 
  271        cache.sortCache.insert( mFeat.
id(), sortValue );
 
  273      else if ( cache.sortCacheExpression.isValid() )
 
  276        cache.sortCache[mFeat.
id()] = cache.sortCacheExpression.evaluate( &mExpressionContext );
 
  281    if ( ! mIdRowMap.contains( fid ) )
 
  283      const int n = mRowIdMap.size();
 
  284      if ( !mResettingModel )
 
  285        beginInsertRows( QModelIndex(), n, n );
 
  286      mIdRowMap.insert( fid, n );
 
  287      mRowIdMap.insert( n, fid );
 
  288      if ( !mResettingModel )
 
  291      if ( mBulkEditCommandRunning && !mResettingModel )
 
  293        mInsertedRowsChanges.append( fid );
 
  299void QgsAttributeTableModel::updatedFields()
 
  305void QgsAttributeTableModel::editCommandEnded()
 
  309  bulkEditCommandEnded( );
 
  312void QgsAttributeTableModel::attributeDeleted( 
int idx )
 
  315  for ( 
const SortCache &cache : mSortCaches )
 
  317    if ( cache.sortCacheAttributes.contains( idx ) )
 
  325void QgsAttributeTableModel::layerDeleted()
 
  327  mLayerCache = 
nullptr;
 
  332  mWidgetDatas.clear();
 
  335void QgsAttributeTableModel::fieldFormatterRemoved( 
QgsFieldFormatter *fieldFormatter )
 
  337  for ( WidgetData &widgetData : mWidgetDatas )
 
  339    if ( widgetData.fieldFormatter == fieldFormatter )
 
  344void QgsAttributeTableModel::attributeValueChanged( 
QgsFeatureId fid, 
int idx, 
const QVariant &value )
 
  347  if ( mBulkEditCommandRunning )
 
  349    mAttributeValueChanges.insert( QPair<QgsFeatureId, int>( fid, idx ), value );
 
  352  QgsDebugMsgLevel( QStringLiteral( 
"(%4) fid: %1, idx: %2, value: %3" ).arg( fid ).arg( idx ).arg( value.toString() ).arg( mFeatureRequest.
filterType() ), 2 );
 
  354  for ( SortCache &cache : mSortCaches )
 
  356    if ( cache.sortCacheAttributes.contains( idx ) )
 
  358      if ( cache.sortFieldIndex == -1 )
 
  360        if ( loadFeatureAtId( fid ) )
 
  363          cache.sortCache[fid] = cache.sortCacheExpression.evaluate( &mExpressionContext );
 
  368        const WidgetData &widgetData = getWidgetData( cache.sortFieldIndex );
 
  369        const QVariant sortValue = widgetData.fieldFormatter->representValue( mLayer, cache.sortFieldIndex, widgetData.config, widgetData.cache, value );
 
  370        cache.sortCache.insert( fid, sortValue );
 
  377    if ( loadFeatureAtId( fid ) )
 
  379      const QModelIndex modelIndex = index( 
idToRow( fid ), 
fieldCol( idx ) );
 
  380      setData( modelIndex, value, Qt::EditRole );
 
  381      emit dataChanged( modelIndex, modelIndex, QVector<int>() << Qt::DisplayRole );
 
  386    if ( loadFeatureAtId( fid ) )
 
  390        if ( !mIdRowMap.contains( fid ) )
 
  398          const QModelIndex modelIndex = index( 
idToRow( fid ), 
fieldCol( idx ) );
 
  399          setData( modelIndex, value, Qt::EditRole );
 
  400          emit dataChanged( modelIndex, modelIndex, QVector<int>() << Qt::DisplayRole );
 
  405        if ( mIdRowMap.contains( fid ) )
 
  416void QgsAttributeTableModel::loadAttributes()
 
  424  if ( mFields == fields )
 
  429  bool ins = 
false, rm = 
false;
 
  433  mWidgetDatas.clear();
 
  435  for ( 
int idx = 0; idx < fields.
count(); ++idx )
 
  440  if ( mFieldCount + mExtraColumns < attributes.size() + mExtraColumns )
 
  443    beginInsertColumns( QModelIndex(), mFieldCount + mExtraColumns, attributes.size() - 1 );
 
  445  else if ( attributes.size() + mExtraColumns < mFieldCount + mExtraColumns )
 
  448    beginRemoveColumns( QModelIndex(), attributes.size(), mFieldCount + mExtraColumns - 1 );
 
  451  mFieldCount = attributes.size();
 
  452  mAttributes = attributes;
 
  453  mWidgetDatas.resize( mFieldCount );
 
  455  for ( SortCache &cache : mSortCaches )
 
  457    if ( cache.sortFieldIndex >= mAttributes.count() )
 
  458      cache.sortFieldIndex = -1;
 
  480  mResettingModel = 
true;
 
  502      if ( t.elapsed() > 1000 )
 
  511      featureAdded( mFeat.
id() );
 
  520  mResettingModel = 
false;
 
 
  526  if ( fieldName.isNull() )
 
  528    mRowStylesMap.clear();
 
  529    mConstraintStylesMap.clear();
 
  535  if ( fieldIndex == -1 )
 
  539  const int col = 
fieldCol( fieldIndex );
 
  540  emit dataChanged( index( 0, col ), index( 
rowCount() - 1, col ) );
 
 
  553  mRowIdMap.remove( rowA );
 
  554  mRowIdMap.remove( rowB );
 
  555  mRowIdMap.insert( rowA, b );
 
  556  mRowIdMap.insert( rowB, a );
 
  558  mIdRowMap.remove( a );
 
  559  mIdRowMap.remove( b );
 
  560  mIdRowMap.insert( a, rowB );
 
  561  mIdRowMap.insert( b, rowA );
 
  562  Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );
 
 
  570  if ( !mIdRowMap.contains( 
id ) )
 
  572    QgsDebugError( QStringLiteral( 
"idToRow: id %1 not in the map" ).arg( 
id ) );
 
  576  return mIdRowMap[id];
 
 
  581  return index( 
idToRow( 
id ), 0 );
 
 
  586  QModelIndexList indexes;
 
  590  indexes.reserve( columns );
 
  591  for ( 
int column = 0; column < columns; ++column )
 
  593    indexes.append( index( row, column ) );
 
 
  601  if ( !mRowIdMap.contains( row ) )
 
  603    QgsDebugError( QStringLiteral( 
"rowToId: row %1 not in the map" ).arg( row ) );
 
  605    return std::numeric_limits<int>::min();
 
  608  return mRowIdMap[row];
 
 
  613  return mAttributes[col];
 
 
  618  return mAttributes.indexOf( idx );
 
 
  624  return mRowIdMap.size();
 
 
  630  return std::max( 1, mFieldCount + mExtraColumns );  
 
 
  638  if ( role == Qt::DisplayRole )
 
  640    if ( orientation == Qt::Vertical ) 
 
  642      return QVariant( section );
 
  644    else if ( section >= 0 && section < mFieldCount )
 
  646      const QString attributeName = mLayer->
fields().
at( mAttributes.at( section ) ).
displayName();
 
  647      return QVariant( attributeName );
 
  651      return tr( 
"extra column" );
 
  654  else if ( role == Qt::ToolTipRole )
 
  656    if ( orientation == Qt::Vertical )
 
  659      return tr( 
"Feature ID: %1" ).arg( 
rowToId( section ) );
 
 
  675  if ( !index.isValid() || !mLayer ||
 
  676       ( role != Qt::TextAlignmentRole
 
  677         && role != Qt::DisplayRole
 
  678         && role != Qt::ToolTipRole
 
  679         && role != Qt::EditRole
 
  682         && role != Qt::BackgroundRole
 
  683         && role != Qt::ForegroundRole
 
  684         && role != Qt::DecorationRole
 
  685         && role != Qt::FontRole
 
  696  if ( index.column() >= mFieldCount )
 
  699  const int fieldId = mAttributes.at( index.column() );
 
  706    const unsigned long cacheIndex = role - 
SortRole;
 
  707    if ( cacheIndex < mSortCaches.size() )
 
  708      return mSortCaches.at( cacheIndex ).sortCache.value( rowId );
 
  715  if ( role == Qt::TextAlignmentRole )
 
  717    const WidgetData &widgetData = getWidgetData( index.column() );
 
  718    return static_cast<Qt::Alignment::Int
>( widgetData.fieldFormatter->alignmentFlag( mLayer, fieldId, widgetData.config ) | Qt::AlignVCenter );
 
  723    if ( !loadFeatureAtId( rowId, fieldId ) )
 
  724      return QVariant( 
"ERROR" );
 
  726    if ( mFeat.
id() != rowId )
 
  727      return QVariant( 
"ERROR" );
 
  730  QVariant val = mFeat.
attribute( fieldId );
 
  734    case Qt::DisplayRole:
 
  736      const WidgetData &widgetData = getWidgetData( index.column() );
 
  737      return widgetData.fieldFormatter->representValue( mLayer, fieldId, widgetData.config, widgetData.cache, val );
 
  739    case Qt::ToolTipRole:
 
  741      const WidgetData &widgetData = getWidgetData( index.column() );
 
  742      QString tooltip = widgetData.fieldFormatter->representValue( mLayer, fieldId, widgetData.config, widgetData.cache, val );
 
  745        tooltip = tr( 
"%1 (Ctrl+click to open)" ).arg( tooltip );
 
  752    case Qt::BackgroundRole:
 
  753    case Qt::ForegroundRole:
 
  754    case Qt::DecorationRole:
 
  758      QList<QgsConditionalStyle> styles;
 
  759      if ( mRowStylesMap.contains( mFeat.
id() ) )
 
  761        styles = mRowStylesMap[mFeat.
id()];
 
  766        mRowStylesMap.insert( mFeat.
id(), styles );
 
  773        if ( mConstraintStylesMap.contains( mFeat.
id() ) &&
 
  774             mConstraintStylesMap[mFeat.
id()].contains( fieldId ) )
 
  776          constraintstyle = mConstraintStylesMap[mFeat.
id()][fieldId];
 
  792          mConstraintStylesMap[mFeat.
id()].insert( fieldId, constraintstyle );
 
  798      styles.insert( 0, rowstyle );
 
  799      styles.insert( 0, constraintstyle );
 
  806        if ( role == Qt::ForegroundRole )
 
  808        if ( role == Qt::DecorationRole )
 
  810        if ( role == Qt::FontRole )
 
  815        if ( role == Qt::ForegroundRole )
 
  817          return QColor( Qt::blue );
 
  819        else if ( role == Qt::FontRole )
 
  822          font.setUnderline( 
true );
 
 
  838  if ( !index.isValid() || index.column() >= mFieldCount || role != Qt::EditRole || !mLayer->
isEditable() )
 
  841  mRowStylesMap.remove( mFeat.
id() );
 
  842  mConstraintStylesMap.remove( mFeat.
id() );
 
 
  852  if ( !index.isValid() )
 
  853    return Qt::ItemIsEnabled;
 
  855  if ( index.column() >= mFieldCount || !mLayer )
 
  856    return Qt::NoItemFlags;
 
  858  Qt::ItemFlags 
flags = QAbstractTableModel::flags( index );
 
  860  const int fieldIndex = mAttributes[index.column()];
 
  864    flags |= Qt::ItemIsEditable;
 
 
  869void QgsAttributeTableModel::bulkEditCommandStarted()
 
  871  mBulkEditCommandRunning = 
true;
 
  872  mAttributeValueChanges.clear();
 
  875void QgsAttributeTableModel::bulkEditCommandEnded()
 
  877  mBulkEditCommandRunning = 
false;
 
  881  const long long fullModelUpdateThreshold = std::min<long long >( mLayerCache->
cacheSize(), std::ceil( 
rowCount() * 0.5 ) );
 
  882  bool fullModelUpdate = 
false;
 
  885  if ( mInsertedRowsChanges.size() > fullModelUpdateThreshold )
 
  887    fullModelUpdate = 
true;
 
  891    QSet< QgsFeatureId > changedRows;
 
  892    changedRows.reserve( mAttributeValueChanges.size() );
 
  894    for ( 
auto it = mAttributeValueChanges.constBegin(); it != mAttributeValueChanges.constEnd(); ++it )
 
  896      changedRows.insert( it.key().first );
 
  897      if ( changedRows.size() > fullModelUpdateThreshold )
 
  899        fullModelUpdate = 
true;
 
  905  QgsDebugMsgLevel( QStringLiteral( 
"Bulk edit command ended modified rows over (%3), cache size is %1, starting %2 update." )
 
  907                    .arg( fullModelUpdate ? QStringLiteral( 
"full" ) :  QStringLiteral( 
"incremental" ) )
 
  912  if ( mIsCleaningUpAfterRollback )
 
  914    for ( 
const int fid : std::as_const( mInsertedRowsChanges ) )
 
  916      const int row( 
idToRow( fid ) );
 
  926  if ( fullModelUpdate )
 
  939    const auto keys = mAttributeValueChanges.keys();
 
  940    for ( 
const auto &key : keys )
 
  942      attributeValueChanged( key.first, key.second, mAttributeValueChanges.value( key ) );
 
  943      const int row( 
idToRow( key.first ) );
 
  944      const int col( 
fieldCol( key.second ) );
 
  945      minRow = std::min<int>( row, minRow );
 
  946      minCol = std::min<int>( col, minCol );
 
  947      maxRow = std::max<int>( row, maxRow );
 
  948      maxCol = std::max<int>( col, maxCol );
 
  951    emit dataChanged( createIndex( minRow, minCol ), createIndex( maxRow, maxCol ) );
 
  953  mAttributeValueChanges.clear();
 
  958  mFeat.
setId( std::numeric_limits<int>::min() );
 
  959  emit dataChanged( index1, index2 );
 
 
  983  for ( 
int i = 0; i < mAttributes.size(); i++ )
 
  985    f.
setAttribute( mAttributes[i], 
data( index( idx.row(), i ), Qt::EditRole ) );
 
 
  993  if ( column == -1 || column >= mAttributes.count() )
 
 
 1005  if ( cacheIndex >= mSortCaches.size() )
 
 1007    mSortCaches.resize( cacheIndex + 1 );
 
 1009  SortCache &cache = mSortCaches[cacheIndex];
 
 1010  cache.sortCache.clear();
 
 1011  cache.sortCacheAttributes.clear();
 
 1012  cache.sortFieldIndex = -1;
 
 1013  if ( !expressionString.isEmpty() )
 
 1014    cache.sortCacheExpression = 
QgsExpression( expressionString );
 
 1022  WidgetData widgetData;
 
 1024  if ( cache.sortCacheExpression.isField() )
 
 1030  if ( cache.sortFieldIndex == -1 )
 
 1032    cache.sortCacheExpression.prepare( &mExpressionContext );
 
 1034    const QSet<QString> &referencedColumns = cache.sortCacheExpression.referencedColumns();
 
 1036    for ( 
const QString &col : referencedColumns )
 
 1043    cache.sortCacheAttributes.append( cache.sortFieldIndex );
 
 1045    widgetData = getWidgetData( cache.sortFieldIndex );
 
 1056    if ( cache.sortFieldIndex == -1 )
 
 1059      const QVariant cacheValue = cache.sortCacheExpression.evaluate( &mExpressionContext );
 
 1060      cache.sortCache.insert( f.
id(), cacheValue );
 
 1064      const QVariant sortValue = widgetData.fieldFormatter->sortValue( mLayer, cache.sortFieldIndex, widgetData.config, widgetData.cache, f.
attribute( cache.sortFieldIndex ) );
 
 1065      cache.sortCache.insert( f.
id(), sortValue );
 
 
 1072  QString expressionString;
 
 1074  if ( cacheIndex >= mSortCaches.size() )
 
 1075    return expressionString;
 
 1077  const QgsExpression &expression = mSortCaches[cacheIndex].sortCacheExpression;
 
 1082    expressionString = QString();
 
 1084  return expressionString;
 
 
 1096  return mFeatureRequest;
 
 
 1099const QgsAttributeTableModel::WidgetData &QgsAttributeTableModel::getWidgetData( 
int column )
 const 
 1101  Q_ASSERT( column >= 0 && column < mAttributes.size() );
 
 1103  WidgetData &widgetData = mWidgetDatas[ column ];
 
 1104  if ( !widgetData.loaded )
 
 1106    const int idx = 
fieldIdx( column );
 
 1109    widgetData.config = setup.
config();
 
 1110    widgetData.cache = widgetData.fieldFormatter->createCache( mLayer, idx, setup.
config() );
 
 1111    widgetData.loaded = 
true;
 
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()
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.
 
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...
 
@ SortRole
Role used for sorting start here.
 
@ FeatureIdRole
Get the feature id of the feature in this row.
 
@ FieldIndexRole
Get the field index of this column.
 
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.
 
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)
 
This class wraps a request for features to a vector layer (or directly its vector data provider).
 
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
 
Flags flags() const
Returns the flags which affect how features are fetched.
 
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
 
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
 
bool acceptFeature(const QgsFeature &feature)
Check if a feature is accepted by this requests filter.
 
FilterType filterType() const
Returns the attribute/ID filter type which is currently set on this request.
 
@ FilterNone
No filter is applied.
 
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
 
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.
 
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.
 
int count() const
Returns number of items.
 
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
 
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...
 
QgsFields fields() const FINAL
Returns the list of fields of this layer.
 
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
 
#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)