23 #include <QItemSelection> 27 : QSortFilterProxyModel( parent )
34 QSortFilterProxyModel::setSourceModel( sourceModel );
36 mFilterModel = sourceModel;
57 if ( mInjectNull && index.row() == 0 )
59 if ( role == Qt::DisplayRole )
65 return QVariant( QVariant::Invalid );
69 if ( role == Qt::DisplayRole || role == Qt::EditRole )
76 return mDisplayExpression.
evaluate( &mExpressionContext );
93 featInfo.
isNew =
true;
101 return QVariant::fromValue( featInfo );
109 return QVariant::fromValue( feat );
111 else if ( role == Qt::TextAlignmentRole )
113 return Qt::AlignLeft;
116 if ( role == Qt::BackgroundColorRole
117 || role == Qt::TextColorRole
118 || role == Qt::DecorationRole
119 || role == Qt::FontRole )
126 QList<QgsConditionalStyle> styles;
128 if ( mRowStylesMap.contains( fid ) )
130 styles = mRowStylesMap.value( fid );
135 mRowStylesMap.insert( fid, styles );
140 if ( mDisplayExpression.
isField() )
147 styles.insert( 0, rowstyle );
157 if ( role == Qt::DecorationRole )
159 if ( role == Qt::FontRole )
166 return sourceModel()->data(
mapToSource( index ), role );
171 if ( mInjectNull && index.row() == 0 )
173 return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
177 return sourceModel()->flags(
mapToSource( index ) ) & ~Qt::ItemIsEditable;
183 if ( mInjectNull == injectNull )
208 exp.
prepare( &mExpressionContext );
216 mDisplayExpression = exp;
218 if ( mSortByDisplayExpression )
221 emit dataChanged( index( 0, 0 ), index(
rowCount() - 1, 0 ) );
229 return mParserErrorString;
244 beginRemoveRows( parent, first, last );
257 beginInsertRows( parent, first, last );
270 return mSortByDisplayExpression;
278 if ( sortByDisplayExpression )
282 setDynamicSortFilter( mSortByDisplayExpression );
288 QModelIndex masterIndex;
290 if ( proxyIndex.isValid() )
292 if ( mSortByDisplayExpression )
298 int offset = mInjectNull ? 1 : 0;
300 masterIndex = mFilterModel->
mapToMaster( mFilterModel->index( proxyIndex.row() - offset, proxyIndex.column() ) );
308 QModelIndex proxyIndex;
310 if ( masterIndex.isValid() )
312 if ( mSortByDisplayExpression )
318 int offset = mInjectNull ? 1 : 0;
320 return createIndex( mFilterModel->
mapFromMaster( masterIndex ).row() + offset, 0 );
329 return mapSelectionFromSource( mFilterModel->mapSelectionFromSource( selection ) );
334 return mFilterModel->mapSelectionToSource( mapSelectionToSource( selection ) );
341 QModelIndex sourceIndex;
343 if ( mSortByDisplayExpression )
345 sourceIndex = QSortFilterProxyModel::mapToSource( proxyIndex );
349 if ( !proxyIndex.isValid() )
350 return QModelIndex();
352 int offset = mInjectNull ? 1 : 0;
354 sourceIndex = sourceModel()->index( proxyIndex.row() - offset, proxyIndex.column() );
362 QModelIndex proxyIndex;
364 if ( mSortByDisplayExpression )
366 proxyIndex = QSortFilterProxyModel::mapFromSource( sourceIndex );
370 if ( sourceIndex.isValid() )
371 proxyIndex = createIndex( sourceIndex.row(), 0 );
380 return QModelIndex();
393 int offset = mInjectNull ? 1 : 0;
395 return sourceModel()->rowCount() + offset;
405 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").
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
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
Returns the feature ID corresponding to an index from the model.
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 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()
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.
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
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() const
Returns parser error.
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
Returns the conditional styles that are set for this layer.
Q_DECL_DEPRECATED void onBeginInsertRows(const QModelIndex &parent, int first, int last)
Does nothing except for calling beginInsertRows()
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.
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.
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...
bool sortByDisplayExpression() const
Sort this model by its display expression.
QgsAttributeTableModel * masterModel()
virtual QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
Q_DECL_DEPRECATED void onBeginRemoveRows(const QModelIndex &parent, int first, int last)
Does nothing except for calling beginRemoveRows()
QString expression() const
Returns the original, unmodified expression string.
This class caches features of a given QgsVectorLayer.
QColor textColor() const
The text color set for style.
virtual QItemSelection mapSelectionToMaster(const QItemSelection &selection) 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.
bool validTextColor() const
Check if the text color is valid for render.
bool isField() const
Checks whether an expression consists only of a single field reference.
QgsFeatureId rowToId(int row) const
Maps row to feature id.
Q_DECL_DEPRECATED void onEndRemoveRows(const QModelIndex &parent, int first, int last)
Does nothing except for calling endRemoveRows()
virtual QItemSelection mapSelectionFromMaster(const QItemSelection &selection) const
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.
void setSortByDisplayExpression(bool sortByDisplayExpression)
Sort this model by its display expression.
QModelIndex fidToIdx(QgsFeatureId fid) const
Returns the model index corresponding to a feature ID.
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