37 , mLayerCache( layerCache )
50 if ( !
layer()->hasGeometryType() )
57 connect(
layer(), SIGNAL( attributeDeleted(
int ) ),
this, SLOT( attributeDeleted(
int ) ) );
58 connect(
layer(), SIGNAL( updatedFields() ),
this, SLOT( updatedFields() ) );
59 connect(
layer(), SIGNAL( editCommandEnded() ),
this, SLOT( editCommandEnded() ) );
64 bool QgsAttributeTableModel::loadFeatureAtId(
QgsFeatureId fid )
const
93 int currentRowCount = 0;
97 Q_FOREACH (
int row, rows )
100 qDebug() <<
"Row: " << row <<
", begin " << beginRow <<
", last " << lastRow <<
", current " << currentRowCount <<
", removed " << removedRows;
107 if ( row != lastRow + 1 && lastRow != -1 )
109 if ( rows.
count() > 100 && currentRowCount < 10 )
114 removeRows( beginRow - removedRows, currentRowCount );
117 removedRows += currentRowCount;
127 removeRows( beginRow - removedRows, currentRowCount );
141 for (
int i = row; i < row + count; i++ )
150 for (
int i = row + count; i < n; i++ )
187 featOk = loadFeatureAtId( fid );
205 void QgsAttributeTableModel::updatedFields()
212 void QgsAttributeTableModel::editCommandEnded()
217 mChangedCellBounds =
QRect();
220 void QgsAttributeTableModel::attributeDeleted(
int idx )
222 if ( idx == mCachedField )
244 if ( idx == mCachedField )
245 mFieldCache[ fid ] = value;
254 if ( loadFeatureAtId( fid ) )
289 bool ins =
false, rm =
false;
298 for (
int idx = 0; idx < fields.
count(); ++idx )
302 if ( widgetFactory && widgetType !=
"Hidden" )
426 QModelIndexList indexes;
429 for (
int column = 0; column <
columnCount(); ++column )
431 indexes.append(
index( row, column ) );
476 if ( role == Qt::DisplayRole )
478 if ( orientation == Qt::Vertical )
488 attributeName = field.
name();
494 return tr(
"feature id" );
506 ( role != Qt::TextAlignmentRole
507 && role != Qt::DisplayRole
508 && role != Qt::EditRole
522 return role == Qt::DisplayRole ? rowId :
QVariant();
531 QVariant::Type fldType = field.
type();
532 bool fldNumeric = ( fldType == QVariant::Int || fldType == QVariant::Double || fldType == QVariant::LongLong );
534 if ( role == Qt::TextAlignmentRole )
545 if ( mCachedField == fieldId )
547 val = mFieldCache[ rowId ];
553 if ( !loadFeatureAtId( rowId ) )
563 if ( role == Qt::DisplayRole )
581 if ( mChangedCellBounds.
isNull() )
587 if ( index.
column() < mChangedCellBounds.
left() )
591 if ( index.
row() < mChangedCellBounds.
top() )
593 mChangedCellBounds.
setTop( index.
row() );
599 if ( index.
row() > mChangedCellBounds.
bottom() )
611 return Qt::ItemIsEnabled;
614 return Qt::NoItemFlags;
618 if (
layer()->isEditable() &&
620 flags |= Qt::ItemIsEditable;
673 fldNames << fields[ fieldId ].name();
684 mCachedField = fieldId;
697 return mFeatureRequest;
QgsFeatureId id() const
Get the feature ID for this feature.
void setRequest(const QgsFeatureRequest &request)
Set a request that will be used to fill this attribute table model.
const QString & name() const
Gets the name of the field.
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
iterator insert(const Key &key, const T &value)
const Flags & flags() const
virtual void loadLayer()
Loads the layer into the model Preferably to be called, before using this model as source for any oth...
QModelIndexList idToIndexList(QgsFeatureId id) const
QHash< int, QgsFeatureId > mRowIdMap
bool isValid() const
Returns the validity of this feature.
QgsAttributeAction * actions()
void append(const T &value)
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
QSet< QgsFeatureId > QgsFeatureIds
virtual void layerDeleted()
Launched when layer has been deleted.
void reload(const QModelIndex &index1, const QModelIndex &index2)
Reloads the model data between indices.
#define FID_TO_STRING(fid)
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QModelIndex idToIndex(QgsFeatureId id) const
Container of fields for a vector layer.
bool setAttribute(int field, const QVariant &attr)
Set an attribute's value by field index.
QgsVectorLayer * layer()
Returns the layer to which this cache belongs.
const QgsFeatureRequest & request() const
Get the the feature request.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
virtual bool isEditable() const override
Returns true if the provider is in editing mode.
QString tr(const char *sourceText, const char *disambiguation, int n)
void resetModel()
Resets the model.
QgsVectorLayerCache * mLayerCache
virtual void attributeValueChanged(QgsFeatureId fid, int idx, const QVariant &value)
Launched when attribute value has been changed.
virtual QVariant data(const QModelIndex &index, int role) const override
Returns data on the given index.
int indexOf(const T &value, int from) const
int count(const T &value) const
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Returns header data.
void executeMapLayerAction(QgsMapLayerAction *action, const QModelIndex &idx) const
Execute a QgsMapLayerAction.
void setFeatureId(QgsFeatureId id)
Sets the feature ID for this feature.
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
#define QgsDebugMsgLevel(str, level)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of columns.
QVector< QgsEditorWidgetFactory * > mWidgetFactories
void initAttributes(int fieldCount)
Initialize this feature with the given number of fields.
const QString editorWidgetV2(int fieldIdx) const
Get the id for the editor widget used to represent the field at the given index.
void beginRemoveRows(const QModelIndex &parent, int first, int last)
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void beginRemoveColumns(const QModelIndex &parent, int first, int last)
QVector< QgsEditorWidgetConfig > mWidgetConfigs
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Remove rows.
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.
int remove(const Key &key)
virtual void featuresDeleted(QgsFeatureIds fids)
Launched when eatures have been deleted.
QString attributeAlias(int attributeIndex) const
Returns the alias of an attribute name or an empty string if there is no alias.
void executeAction(int action, const QModelIndex &idx) const
Execute an action.
virtual void featureAdded(QgsFeatureId fid)
Launched when a feature has been added.
QModelIndex createIndex(int row, int column, void *ptr) const
QgsFeature feature(const QModelIndex &idx) const
Return the feature attributes at given model index.
This class caches features of a given QgsVectorLayer.
static int debugLevel()
Reads the environment variable QGIS_DEBUG and converts it to int.
void progress(int i, bool &cancel)
void beginInsertRows(const QModelIndex &parent, int first, int last)
void modelChanged()
Model has been changed.
QVector< QVariant > mAttributeWidgetCaches
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows.
int fieldCol(int idx) const
get column from field index
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 void loadAttributes()
Gets mFieldCount, mAttributes and mValueMaps.
int idToRow(QgsFeatureId id) const
Maps feature id to table row.
void doAction(int index, const QgsFeature &feat, int defaultValueIndex=0)
virtual Qt::ItemFlags flags(const QModelIndex &index) const
bool contains(const Key &key) const
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
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.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QgsFeatureIterator getFeatures(const QgsFeatureRequest &featureRequest=QgsFeatureRequest())
Query this VectorLayerCache for features.
QgsFeatureRequest & setFlags(Flags flags)
Set flags that affect how features will be fetched.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void beginInsertColumns(const QModelIndex &parent, int first, int last)
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Updates data on given index.
void triggerForFeature(QgsMapLayer *layer, const QgsFeature *feature)
Triggers the action with the specified layer and feature.
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.
Qt::ItemFlags flags(const QModelIndex &index) const override
Returns item flags for the index.
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.