36 : QAbstractTableModel( parent )
37 , mLayerCache( layerCache )
49 if ( !
layer()->hasGeometryType() )
89 beginRemoveRows( QModelIndex(), row, row );
101 for (
int i = row; i < row + count; i++ )
109 for (
int i = row + count; i < n; i++ )
120 for ( QHash<QgsFeatureId, int>::iterator it =
mIdRowMap.begin(); it !=
mIdRowMap.end(); ++it )
123 QHash<QgsFeatureId, int>::iterator idit;
126 for ( QHash<int, QgsFeatureId>::iterator it =
mRowIdMap.begin(); it !=
mRowIdMap.end(); ++it )
148 beginInsertRows( QModelIndex(), n, n );
186 beginRemoveRows( QModelIndex(), 0,
rowCount() - 1 );
190 const QMap<QString, QVariant> *item;
246 bool ins =
false, rm =
false;
250 for (
int idx = 0; idx < fields.
count(); ++idx )
258 mValueMaps.insert( idx,
new QMap< QString, QVariant >(
layer()->valueMap( idx ) ) );
280 if ( ki >= 0 && vi >= 0 )
282 QSet<int> attributes;
283 attributes << ki << vi;
301 QMap< QString, QVariant > *map =
new QMap< QString, QVariant >();
305 while ( fit.nextFeature( f ) )
307 if ( e && !e->
evaluate( &f ).toBool() )
328 beginInsertColumns( QModelIndex(),
mFieldCount, attributes.size() - 1 );
333 beginRemoveColumns( QModelIndex(), attributes.size(),
mFieldCount - 1 );
353 beginRemoveRows( QModelIndex(), 0,
rowCount() - 1 );
369 if ( t.elapsed() > 1000 )
414 QgsDebugMsg( QString(
"idToRow: id %1 not in the map" ).arg(
id ) );
428 QModelIndexList indexes;
431 for (
int column = 0; column <
columnCount(); ++column )
433 indexes.append(
index( row, column ) );
443 QgsDebugMsg( QString(
"rowToId: row %1 not in the map" ).arg( row ) );
478 if ( role == Qt::DisplayRole )
480 if ( orientation == Qt::Vertical )
482 return QVariant( section );
487 if ( attributeName.isEmpty() )
490 attributeName = field.
name();
492 return QVariant( attributeName );
496 return tr(
"feature id" );
507 if ( !index.isValid() ||
508 ( role != Qt::TextAlignmentRole
509 && role != Qt::DisplayRole
510 && role != Qt::EditRole
524 return role == Qt::DisplayRole ? rowId : QVariant();
533 QVariant::Type fldType = field.
type();
534 bool fldNumeric = ( fldType == QVariant::Int || fldType == QVariant::Double );
536 if ( role == Qt::TextAlignmentRole )
539 return QVariant( Qt::AlignRight );
541 return QVariant( Qt::AlignLeft );
556 return QVariant(
"ERROR" );
559 return QVariant(
"ERROR" );
574 if ( role == Qt::EditRole )
576 return QVariant( fldType );
581 return settings.value(
"qgis/nullValue",
"NULL" );
585 if ( role == Qt::DisplayRole )
589 return mValueMaps[ fieldId ]->key( val.toString(), QString(
"(%1)" ).arg( val.toString() ) );
594 return val.toDate().toString(
layer()->dateFormat( fieldId ) );
641 if ( !index.isValid() )
642 return Qt::ItemIsEnabled;
645 return Qt::NoItemFlags;
647 Qt::ItemFlags
flags = QAbstractItemModel::flags( index );
649 if (
layer()->isEditable() &&
651 flags |= Qt::ItemIsEditable;
659 emit dataChanged( index1, index2 );
706 QStringList fldNames;
707 fldNames << fields[ fieldId ].name();
QgsFeatureId id() const
Get the feature id for this feature.
void setRequest(const QgsFeatureRequest &request)
Class for parsing and evaluation of expressions (formerly called "search strings").
const QString & name() const
Gets the name of the field.
QRect mChangedCellBounds
Holds the bounds of changed cells while an update operation is running top = min row left = min colum...
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.
QgsAttributeList mAttributes
const Flags & flags() const
virtual void loadLayer()
Loads the layer into the model Preferably to be called, before basing any other models on this model...
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
QModelIndexList idToIndexList(QgsFeatureId id) const
QHash< int, QgsFeatureId > mRowIdMap
bool isValid() const
Return the validity of this feature.
QgsAttributeAction * actions()
QgsFeatureRequest mFeatureRequest
int columnCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of columns.
QVariant evaluate(const QgsFeature *f=NULL)
Evaluate the feature and return the result.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of rows.
bool prepare(const QgsFields &fields)
Get the expression ready for evaluation - find out column indexes.
QString displayString(const QVariant &v) const
Formats string for display.
The attribute value should not be changed in the attribute form.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
Remove rows.
QHash< QgsFeatureId, QVariant > mFieldCache
Allows caching one specific column (used for sorting)
virtual void layerDeleted()
Launched when layer has been deleted.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
void reload(const QModelIndex &index1, const QModelIndex &index2)
Reloads the model data between indices.
#define FID_TO_STRING(fid)
QModelIndex idToIndex(QgsFeatureId id) const
Container of fields for a vector layer.
bool setAttribute(int field, const QVariant &attr)
Set an attribute by id.
QgsVectorLayer * layer()
Returns the layer to which this cache belongs.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void resetModel()
Resets the model.
void triggerForFeature(QgsMapLayer *layer, QgsFeature *feature)
Triggers the action with the specified layer and feature.
QgsVectorLayerCache * mLayerCache
virtual void attributeValueChanged(QgsFeatureId fid, int idx, const QVariant &value)
Launched when attribute value has been changed.
int mCachedField
The currently cached column.
virtual void editCommandEnded()
Gets called when an edit command ends This will synchronize all fields which have been changed since ...
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Updates data on given index.
void executeMapLayerAction(QgsMapLayerAction *action, const QModelIndex &idx) const
Execute a QgsMapLayerAction.
void setFeatureId(QgsFeatureId id)
Set the feature id for this feature.
QMap< int, const QMap< QString, QVariant > * > mValueMaps
#define QgsDebugMsgLevel(str, level)
The attribute value should not be shown in the attribute form.
EditType editType(int idx)
get edit type
void initAttributes(int fieldCount)
Initialize this feature with the given number of fields.
QStringList referencedColumns()
Get list of columns referenced by the expression.
void doAction(int index, QgsFeature &feat, int defaultValueIndex=0)
Qt::ItemFlags flags(const QModelIndex &index) const
Returns item flags for the index.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
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
Encapsulate a field in an attribute table or data source.
QString attributeAlias(int attributeIndex) const
Returns the alias of an attribute name or an empty string if there is no alias.
ValueRelationData & valueRelation(int idx)
access relations
void executeAction(int action, const QModelIndex &idx) const
Execute an action.
virtual void attributeDeleted(int idx)
Called whenever a column is removed;.
virtual void featureAdded(QgsFeatureId fid)
Launched when a feature has been added.
QgsFeature feature(const QModelIndex &idx) const
Return the feature attributes at given model index.
This class caches features of a given QgsVectorLayer.
bool needsGeometry()
Returns true if the expression uses feature geometry for some computation.
void progress(int i, bool &cancel)
void modelChanged()
Model has been changed.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Returns header data.
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
virtual ~QgsAttributeTableModel()
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
int fieldCol(int idx) const
get column from field index
virtual void featureDeleted(QgsFeatureId fid)
Launched when a feature has been deleted.
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 QVariant data(const QModelIndex &index, int role) const
Returns data on the given index.
QString mFilterExpression
virtual void loadAttributes()
Gets mFieldCount, mAttributes and mValueMaps.
int idToRow(QgsFeatureId id) const
Maps feature id to table row.
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
int fieldIdx(int col) const
get field index from column
QgsFeatureId rowToId(int row) const
Maps row to feature id.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
double ANALYSIS_EXPORT min(double x, double y)
returns the minimum of two doubles or the first argument if both are equal
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.
virtual bool isEditable() const
Returns true if the provider is in editing mode.
Represents a vector layer which manages a vector based data sets.
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.
QgsFeatureRequest & setFlags(Flags flags)
Set flags that affect how features will be fetched.
virtual bool loadFeatureAtId(QgsFeatureId fid) const
Load feature fid into local cache (mFeat)
QgsAttributeTableModel(QgsVectorLayerCache *layerCache, QObject *parent=0)
Constructor.
An action which can run on map layers.
void prefetchColumnData(int column)
Caches the entire data for one column.
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.
virtual void updatedFields()
Launched whenever the number of fields has changed.