8 #include <QItemSelection> 11 : QAbstractProxyModel( parent )
24 QAbstractProxyModel::setSourceModel( sourceModel );
25 mFilterModel = sourceModel;
29 connect( mFilterModel, SIGNAL( rowsAboutToBeRemoved(
const QModelIndex&,
int,
int ) ), SLOT(
onBeginRemoveRows(
const QModelIndex&,
int,
int ) ) );
30 connect( mFilterModel, SIGNAL( rowsRemoved(
const QModelIndex&,
int,
int ) ), SLOT(
onEndRemoveRows(
const QModelIndex&,
int,
int ) ) );
31 connect( mFilterModel, SIGNAL( rowsAboutToBeInserted(
const QModelIndex&,
int,
int ) ), SLOT(
onBeginInsertRows(
const QModelIndex&,
int,
int ) ) );
32 connect( mFilterModel, SIGNAL( rowsInserted(
const QModelIndex&,
int,
int ) ), SLOT(
onEndInsertRows(
const QModelIndex&,
int,
int ) ) );
34 connect( mFilterModel, SIGNAL( layoutAboutToBeChanged() ),
this, SIGNAL( layoutAboutToBeChanged() ) );
35 connect( mFilterModel, SIGNAL( layoutChanged() ),
this, SIGNAL( layoutChanged() ) );
56 if ( role == Qt::DisplayRole || role == Qt::EditRole )
64 return mExpression->
evaluate( &feat, fields );
79 const QList<QgsFeatureId> addedFeatures = editBuffer->
addedFeatures().keys();
82 if ( addedFeatures.contains( feat.
id() ) )
84 featInfo.
isNew =
true;
86 if ( changedFeatures.contains( feat.
id() ) )
92 return QVariant::fromValue( featInfo );
100 return QVariant::fromValue( feat );
103 return sourceModel()->data(
mapToSource( index ), role );
108 return sourceModel()->flags(
mapToSource( index ) ) & ~Qt::ItemIsEditable;
140 return mParserErrorString;
155 beginRemoveRows( parent, first, last );
168 beginInsertRows( parent, first, last );
181 if ( !proxyIndex.isValid() )
182 return QModelIndex();
184 return mFilterModel->
mapToMaster( mFilterModel->index( proxyIndex.row(), proxyIndex.column() ) );
189 if ( !sourceIndex.isValid() )
190 return QModelIndex();
192 return createIndex( mFilterModel->
mapFromMaster( sourceIndex ).row(), 0 );
197 return mapSelectionFromSource( mFilterModel->mapSelectionFromSource( selection ) );
202 return mFilterModel->mapSelectionToSource( mapSelectionToSource( selection ) );
209 if ( !proxyIndex.isValid() )
210 return QModelIndex();
212 return sourceModel()->index( proxyIndex.row(), proxyIndex.column() );
217 if ( !sourceIndex.isValid() )
218 return QModelIndex();
220 return createIndex( sourceIndex.row(), 0 );
226 return createIndex( row, column );
232 return QModelIndex();
244 return sourceModel()->rowCount();
254 return QModelIndexList() <<
fidToIndex( fid );
QgsFeatureId id() const
Get the feature id for this feature.
Class for parsing and evaluation of expressions (formerly called "search strings").
QModelIndex fidToIndex(QgsFeatureId fid) override
virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
const QString expression() const
Alias for dump()
QVariant evaluate(const QgsFeature *f=NULL)
Evaluate the feature and return the result.
bool prepare(const QgsFields &fields)
Get the expression ready for evaluation - find out column indexes.
virtual QModelIndex mapToMaster(const QModelIndex &proxyIndex) const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const override
const QgsChangedAttributesMap & changedAttributeValues()
Changed attributes values which are not commited.
void onEndInsertRows(const QModelIndex &parent, int first, int last)
QModelIndex idToIndex(QgsFeatureId id) const
bool featureByIndex(const QModelIndex &index, QgsFeature &feat)
Container of fields for a vector layer.
virtual QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
virtual QItemSelection mapSelectionToMaster(const QItemSelection &selection) const
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
QString parserErrorString()
Returns a detailed message about errors while parsing a QgsExpression.
virtual void setSourceModel(QgsAttributeTableFilterModel *sourceModel)
void onBeginInsertRows(const QModelIndex &parent, int first, int last)
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on...
QgsVectorLayerCache * layerCache() const
Returns the layerCache this filter acts on.
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const override
bool setDisplayExpression(const QString expression)
virtual QModelIndex mapToMaster(const QModelIndex &proxyIndex) const
virtual QVariant data(const QModelIndex &index, int role) const override
QModelIndexList fidToIndexList(QgsFeatureId fid)
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
QgsAttributeTableModel * masterModel()
void onBeginRemoveRows(const QModelIndex &parent, int first, int last)
This class caches features of a given QgsVectorLayer.
const QgsFeatureMap & addedFeatures()
New features which are not commited.
QgsAttributeTableModel * masterModel() const
Returns the table model this filter is using.
virtual const QgsFields & fields() const =0
Return a map of indexes with field names for this layer.
virtual QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
bool featureAtId(QgsFeatureId featureId, QgsFeature &feature, bool skipCache=false)
Gets the feature at the given feature id.
virtual ~QgsFeatureListModel()
QgsFeatureId idxToFid(const QModelIndex &index) const
void onEndRemoveRows(const QModelIndex &parent, int first, int last)
QgsVectorLayerCache * layerCache()
QgsFeatureId rowToId(int row) const
Maps row to feature id.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
virtual QModelIndex parent(const QModelIndex &child) const override
QgsVectorDataProvider * dataProvider()
Returns the data provider.
QModelIndex fidToIdx(const QgsFeatureId fid) const
QgsFeatureListModel(QgsAttributeTableFilterModel *sourceModel, QObject *parent=0)
QString parserErrorString() const
Returns parser error.
virtual QItemSelection mapSelectionFromMaster(const QItemSelection &selection) const
QString displayExpression() const