22 #include <QItemSelection> 26 : QAbstractProxyModel( parent )
27 , mInjectNull( false )
34 QAbstractProxyModel::setSourceModel( sourceModel );
36 mFilterModel = sourceModel;
46 connect( mFilterModel, &QAbstractItemModel::layoutAboutToBeChanged,
this, &QAbstractItemModel::layoutAboutToBeChanged );
47 connect( mFilterModel, &QAbstractItemModel::layoutChanged,
this, &QAbstractItemModel::layoutChanged );
48 connect( mFilterModel, &QAbstractItemModel::modelAboutToBeReset,
this, &QAbstractItemModel::modelAboutToBeReset );
49 connect( mFilterModel, &QAbstractItemModel::modelReset,
this, &QAbstractItemModel::modelReset );
70 if ( mInjectNull && index.row() == 0 )
72 if ( role == Qt::DisplayRole )
78 return QVariant( QVariant::Invalid );
82 if ( role == Qt::DisplayRole || role == Qt::EditRole )
89 return mDisplayExpression.evaluate( &mExpressionContext );
106 featInfo.
isNew =
true;
114 return QVariant::fromValue( featInfo );
122 return QVariant::fromValue( feat );
124 else if ( role == Qt::TextAlignmentRole )
126 return Qt::AlignLeft;
129 if ( role == Qt::BackgroundColorRole
130 || role == Qt::TextColorRole
131 || role == Qt::DecorationRole
132 || role == Qt::FontRole )
139 QList<QgsConditionalStyle> styles;
141 if ( mRowStylesMap.contains( fid ) )
143 styles = mRowStylesMap.value( fid );
148 mRowStylesMap.insert( fid, styles );
153 if ( mDisplayExpression.isField() )
155 QString fieldName = *mDisplayExpression.referencedColumns().constBegin();
160 styles.insert( 0, rowstyle );
170 if ( role == Qt::DecorationRole )
172 if ( role == Qt::FontRole )
179 return sourceModel()->data(
mapToSource( index ), role );
184 if ( mInjectNull && index.row() == 0 )
186 return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
190 return sourceModel()->flags(
mapToSource( index ) ) & ~Qt::ItemIsEditable;
196 if ( mInjectNull != injectNull )
216 QgsExpression exp = QgsExpression( expression );
218 exp.prepare( &mExpressionContext );
220 if ( exp.hasParserError() )
222 mParserErrorString = exp.parserErrorString();
226 mDisplayExpression = exp;
234 return mParserErrorString;
239 return mDisplayExpression.expression();
249 beginRemoveRows( parent, first, last );
262 beginInsertRows( parent, first, last );
275 if ( !proxyIndex.isValid() )
276 return QModelIndex();
278 int offset = mInjectNull ? 1 : 0;
280 return mFilterModel->
mapToMaster( mFilterModel->index( proxyIndex.row() - offset, proxyIndex.column() ) );
285 if ( !sourceIndex.isValid() )
286 return QModelIndex();
288 int offset = mInjectNull ? 1 : 0;
290 return createIndex( mFilterModel->
mapFromMaster( sourceIndex ).row() + offset, 0 );
295 return mapSelectionFromSource( mFilterModel->mapSelectionFromSource( selection ) );
300 return mFilterModel->mapSelectionToSource( mapSelectionToSource( selection ) );
307 if ( !proxyIndex.isValid() )
308 return QModelIndex();
310 int offset = mInjectNull ? 1 : 0;
312 return sourceModel()->index( proxyIndex.row() - offset, proxyIndex.column() );
317 if ( !sourceIndex.isValid() )
318 return QModelIndex();
320 return createIndex( sourceIndex.row(), 0 );
327 return createIndex( row, column );
333 return QModelIndex();
346 int offset = mInjectNull ? 1 : 0;
348 return sourceModel()->rowCount() + offset;
358 return QModelIndexList() <<
fidToIndex( fid );
bool injectNull()
Returns the current state of null value injection.
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
QModelIndex fidToIndex(QgsFeatureId fid) override
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
QgsAttributeTableModel * masterModel() const
Returns the table model this filter is using.
QgsFeatureId idxToFid(const QModelIndex &index) const
bool setDisplayExpression(const QString &expression)
QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QList< QgsConditionalStyle > fieldStyles(const QString &fieldName)
Returns the conditional styles set for the field UI properties.
void onEndInsertRows(const QModelIndex &parent, int first, int last)
bool featureByIndex(const QModelIndex &index, QgsFeature &feat)
bool validBackgroundColor() const
Check if the background color is valid for render.
QPixmap icon() const
The icon set for style generated from the set symbol.
bool isFeatureAdded(QgsFeatureId id) const
Returns true if the specified feature ID has been added but not committed.
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)
virtual QModelIndex mapToMaster(const QModelIndex &proxyIndex) const
QModelIndex idToIndex(QgsFeatureId id) const
QgsConditionalLayerStyles * conditionalStyles() const
Return the conditional styles that are set for this layer.
void onBeginInsertRows(const QModelIndex &parent, int first, int last)
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
QList< QgsConditionalStyle > rowStyles()
QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on...
Conditional styling for a rule.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const override
QVariant data(const QModelIndex &index, int role) const override
bool isValid() const
isValid Check if this rule is valid.
static QList< QgsConditionalStyle > matchingConditionalStyles(const QList< QgsConditionalStyle > &styles, const QVariant &value, QgsExpressionContext &context)
Find and return the matching styles for the value and feature.
QModelIndexList fidToIndexList(QgsFeatureId fid)
QColor backgroundColor() const
The background color for style.
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
QString displayExpression() const
static QgsConditionalStyle compressStyles(const QList< QgsConditionalStyle > &styles)
Compress a list of styles into a single style.
Qt::ItemFlags flags(const QModelIndex &index) const override
bool isFeatureAttributesChanged(QgsFeatureId id) const
Returns true if the specified feature ID has had an attribute changed but not committed.
QgsAttributeTableModel * masterModel()
virtual QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
void onBeginRemoveRows(const QModelIndex &parent, int first, int last)
This class caches features of a given QgsVectorLayer.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QColor textColor() const
The text color set for style.
virtual QItemSelection mapSelectionToMaster(const QItemSelection &selection) const
bool featureAtId(QgsFeatureId featureId, QgsFeature &feature, bool skipCache=false)
Gets the feature at the given feature id.
QModelIndex fidToIdx(const QgsFeatureId fid) const
bool validTextColor() const
Check if the text color is valid for render.
QgsFeatureId rowToId(int row) const
Maps row to feature id.
void onEndRemoveRows(const QModelIndex &parent, int first, int last)
virtual QItemSelection mapSelectionFromMaster(const QItemSelection &selection) const
QgsVectorLayerCache * layerCache()
void setInjectNull(bool injectNull)
If true is specified, a NULL value will be injected.
QModelIndex parent(const QModelIndex &child) const override
QFont font() const
The font for the style.
Represents a vector layer which manages a vector based data sets.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QgsFeatureListModel(QgsAttributeTableFilterModel *sourceModel, QObject *parent=nullptr)
Constructor for QgsFeatureListModel.
QgsVectorLayerCache * layerCache() const
Returns the layerCache this filter acts on.
QModelIndex mapToMaster(const QModelIndex &proxyIndex) const