22 #include <QItemSelection> 26 : QSortFilterProxyModel( parent )
33 QSortFilterProxyModel::setSourceModel( sourceModel );
35 mFilterModel = sourceModel;
56 if ( mInjectNull && index.row() == 0 )
58 if ( role == Qt::DisplayRole )
64 return QVariant( QVariant::Invalid );
68 if ( role == Qt::DisplayRole || role == Qt::EditRole )
75 return mDisplayExpression.
evaluate( &mExpressionContext );
92 featInfo.
isNew =
true;
100 return QVariant::fromValue( featInfo );
108 return QVariant::fromValue( feat );
110 else if ( role == Qt::TextAlignmentRole )
112 return Qt::AlignLeft;
115 if ( role == Qt::BackgroundColorRole
116 || role == Qt::TextColorRole
117 || role == Qt::DecorationRole
118 || role == Qt::FontRole )
125 QList<QgsConditionalStyle> styles;
127 if ( mRowStylesMap.contains( fid ) )
129 styles = mRowStylesMap.value( fid );
134 mRowStylesMap.insert( fid, styles );
139 if ( mDisplayExpression.
isField() )
146 styles.insert( 0, rowstyle );
156 if ( role == Qt::DecorationRole )
158 if ( role == Qt::FontRole )
165 return sourceModel()->data(
mapToSource( index ), role );
170 if ( mInjectNull && index.row() == 0 )
172 return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
176 return sourceModel()->flags(
mapToSource( index ) ) & ~Qt::ItemIsEditable;
182 if ( mInjectNull == injectNull )
207 exp.
prepare( &mExpressionContext );
215 mDisplayExpression = exp;
217 if ( mSortByDisplayExpression )
220 emit dataChanged( index( 0, 0 ), index(
rowCount() - 1, 0 ) );
228 return mParserErrorString;
243 beginRemoveRows( parent, first, last );
256 beginInsertRows( parent, first, last );
269 return mSortByDisplayExpression;
277 if ( sortByDisplayExpression )
281 setDynamicSortFilter( mSortByDisplayExpression );
287 QModelIndex masterIndex;
289 if ( proxyIndex.isValid() )
291 if ( mSortByDisplayExpression )
297 int offset = mInjectNull ? 1 : 0;
299 masterIndex = mFilterModel->
mapToMaster( mFilterModel->index( proxyIndex.row() - offset, proxyIndex.column() ) );
307 QModelIndex proxyIndex;
309 if ( masterIndex.isValid() )
311 if ( mSortByDisplayExpression )
317 int offset = mInjectNull ? 1 : 0;
319 return createIndex( mFilterModel->
mapFromMaster( masterIndex ).row() + offset, 0 );
328 return mapSelectionFromSource( mFilterModel->mapSelectionFromSource( selection ) );
333 return mFilterModel->mapSelectionToSource( mapSelectionToSource( selection ) );
340 QModelIndex sourceIndex;
342 if ( mSortByDisplayExpression )
344 sourceIndex = QSortFilterProxyModel::mapToSource( proxyIndex );
348 if ( !proxyIndex.isValid() )
349 return QModelIndex();
351 int offset = mInjectNull ? 1 : 0;
353 sourceIndex = sourceModel()->index( proxyIndex.row() - offset, proxyIndex.column() );
361 QModelIndex proxyIndex;
363 if ( mSortByDisplayExpression )
365 proxyIndex = QSortFilterProxyModel::mapFromSource( sourceIndex );
369 if ( sourceIndex.isValid() )
370 proxyIndex = createIndex( sourceIndex.row(), 0 );
379 return QModelIndex();
392 int offset = mInjectNull ? 1 : 0;
394 return sourceModel()->rowCount() + offset;
404 return QModelIndexList() <<
fidToIndex( fid );
bool injectNull()
Returns the current state of null value injection.
Class for parsing and evaluation of expressions (formerly called "search strings").
QModelIndex fidToIndex(QgsFeatureId fid) override
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
bool validTextColor() const
Check if the text color is valid for render.
bool setDisplayExpression(const QString &expression)
QColor textColor() const
The text color set for style.
bool validBackgroundColor() const
Check if the background color is valid for render.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
QFont font() const
The font for the style.
virtual QModelIndex mapToMaster(const QModelIndex &proxyIndex) const
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
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 prefetchSortData(const QString &expression, unsigned long cacheIndex=0)
Prefetches the entire data for an expression.
QVariant evaluate()
Evaluate the feature and return the result.
Q_DECL_DEPRECATED void onEndInsertRows(const QModelIndex &parent, int first, int last)
Does nothing except for calling endInsertRows()
QgsConditionalLayerStyles * conditionalStyles() const
Returns the conditional styles that are set for this layer.
QModelIndex idToIndex(QgsFeatureId id) const
bool featureByIndex(const QModelIndex &index, QgsFeature &feat)
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)
Q_DECL_DEPRECATED void onBeginInsertRows(const QModelIndex &parent, int first, int last)
Does nothing except for calling beginInsertRows()
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
QList< QgsConditionalStyle > rowStyles()
Roles used for sorting start here.
QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on...
bool isEdited
True if feature has been edited.
QPixmap icon() const
The icon set for style generated from the set symbol.
Conditional styling for a rule.
QgsVectorLayerCache * layerCache() const
Returns the layerCache this filter acts on.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const override
QModelIndex mapToMaster(const QModelIndex &proxyIndex) const
QVariant data(const QModelIndex &index, int role) const override
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)
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
QColor backgroundColor() const
The background color for style.
bool isField() const
Checks whether an expression consists only of a single field reference.
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 isNew
True if feature is a newly added feature.
QgsExpressionContext createExpressionContext() const FINAL
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QgsAttributeTableModel * masterModel()
QModelIndex fidToIdx(QgsFeatureId fid) const
Returns the model index corresponding to a feature ID.
bool sortByDisplayExpression() const
Sort this model by its display expression.
Q_DECL_DEPRECATED void onBeginRemoveRows(const QModelIndex &parent, int first, int last)
Does nothing except for calling beginRemoveRows()
This class caches features of a given QgsVectorLayer.
QgsAttributeTableModel * masterModel() const
Returns the table model this filter is using.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
bool featureAtId(QgsFeatureId featureId, QgsFeature &feature, bool skipCache=false)
Gets the feature at the given feature id.
QgsFeatureId idxToFid(const QModelIndex &index) const
Returns the feature ID corresponding to an index from the model.
Q_DECL_DEPRECATED void onEndRemoveRows(const QModelIndex &parent, int first, int last)
Does nothing except for calling endRemoveRows()
QString expression() const
Returns the original, unmodified expression string.
QgsVectorLayerCache * layerCache()
Returns the vector layer cache which is being used to populate the model.
void setInjectNull(bool injectNull)
If true is specified, a NULL value will be injected.
bool isValid() const
isValid Check if this rule is valid.
QgsFeatureId rowToId(int row) const
Maps row to feature id.
void setSortByDisplayExpression(bool sortByDisplayExpression)
Sort this model by its display expression.
bool isFeatureAttributesChanged(QgsFeatureId id) const
Returns true if the specified feature ID has had an attribute changed but not committed.
QModelIndex parent(const QModelIndex &child) const override
bool isFeatureAdded(QgsFeatureId id) const
Returns true if the specified feature ID has been added but not committed.
Represents a vector layer which manages a vector based data sets.
QString parserErrorString() const
Returns parser error.
virtual QItemSelection mapSelectionFromMaster(const QItemSelection &selection) const
QgsFeatureListModel(QgsAttributeTableFilterModel *sourceModel, QObject *parent=nullptr)
Constructor for QgsFeatureListModel.
QString displayExpression() const