QgsFeatureIds QgsAttributeTableFilterModel::filteredFeatures() { QgsFeatureIds ids; for ( int i = 0; i < rowCount(); ++i ) { QModelIndex row = index( i, 0 ); ids << rowToId( row ); } return ids; }
QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) const { if ( !index.isValid() || ( role != Qt::TextAlignmentRole && role != Qt::DisplayRole && role != Qt::EditRole && role != SortRole && role != FeatureIdRole && role != FieldIndexRole ) ) return QVariant(); QgsFeatureId rowId = rowToId( index.row() ); if ( role == FeatureIdRole ) return rowId; if ( index.column() >= mFieldCount ) return role == Qt::DisplayRole ? rowId : QVariant(); int fieldId = mAttributes[ index.column()]; if ( role == FieldIndexRole ) return fieldId; const QgsField& field = layer()->pendingFields()[ fieldId ]; QVariant::Type fldType = field.type(); bool fldNumeric = ( fldType == QVariant::Int || fldType == QVariant::Double || fldType == QVariant::LongLong ); if ( role == Qt::TextAlignmentRole ) { if ( fldNumeric ) return QVariant( Qt::AlignRight ); else return QVariant( Qt::AlignLeft ); } QVariant val; // if we don't have the row in current cache, load it from layer first if ( mCachedField == fieldId ) { val = mFieldCache[ rowId ]; } else { if ( mFeat.id() != rowId || !mFeat.isValid() ) { if ( !loadFeatureAtId( rowId ) ) return QVariant( "ERROR" ); if ( mFeat.id() != rowId ) return QVariant( "ERROR" ); } val = mFeat.attribute( fieldId ); } if ( role == Qt::DisplayRole ) { return mWidgetFactories[ fieldId ]->representValue( layer(), fieldId, mWidgetConfigs[ fieldId ], mAttributeWidgetCaches[ fieldId ], val ); } return val; }