24#include <QItemSelection>
28 : QSortFilterProxyModel( parent )
38 QSortFilterProxyModel::setSourceModel( sourceModel );
40 mFilterModel = sourceModel;
42 mSourceLayer = sourceModel->
layer();
63 if ( mInjectNull && index.row() == 0 )
65 if ( role == Qt::DisplayRole )
71 return QVariant( QVariant::Invalid );
75 if ( role == Qt::DisplayRole || role == Qt::EditRole )
82 return mDisplayExpression.
evaluate( &mExpressionContext );
99 featInfo.
isNew =
true;
107 return QVariant::fromValue( featInfo );
115 return QVariant::fromValue( feat );
117 else if ( role == Qt::TextAlignmentRole )
119 return static_cast<Qt::Alignment::Int
>( Qt::AlignLeft );
122 if ( role == Qt::BackgroundRole
123 || role == Qt::ForegroundRole
124 || role == Qt::DecorationRole
125 || role == Qt::FontRole )
132 QList<QgsConditionalStyle> styles;
134 if ( mRowStylesMap.contains( fid ) )
136 styles = mRowStylesMap.value( fid );
141 mRowStylesMap.insert( fid, styles );
146 if ( mDisplayExpression.
isField() )
153 styles.insert( 0, rowstyle );
163 if ( role == Qt::DecorationRole )
164 return style.
icon().isNull() ? QVariant() : style.
icon();
165 if ( role == Qt::FontRole )
172 return sourceModel()->data(
mapToSource( index ), role );
177 if ( mInjectNull && index.row() == 0 )
179 return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
183 return sourceModel()->flags(
mapToSource( index ) ) & ~Qt::ItemIsEditable;
214 exp.
prepare( &mExpressionContext );
222 mDisplayExpression = exp;
224 if ( mSortByDisplayExpression )
227 emit dataChanged( index( 0, 0 ), index(
rowCount() - 1, 0 ) );
235 return mParserErrorString;
250 beginRemoveRows(
parent, first, last );
263 beginInsertRows(
parent, first, last );
274void QgsFeatureListModel::conditionalStylesChanged()
276 mRowStylesMap.clear();
282 return mSortByDisplayExpression;
290 if ( mSortByDisplayExpression )
294 setDynamicSortFilter( mSortByDisplayExpression );
300 QModelIndex masterIndex;
302 if ( proxyIndex.isValid() )
304 if ( mSortByDisplayExpression )
310 const int offset = mInjectNull ? 1 : 0;
312 masterIndex = mFilterModel->
mapToMaster( mFilterModel->index( proxyIndex.row() - offset, proxyIndex.column() ) );
320 QModelIndex proxyIndex;
322 if ( masterIndex.isValid() )
324 if ( mSortByDisplayExpression )
330 const int offset = mInjectNull ? 1 : 0;
332 return createIndex( mFilterModel->
mapFromMaster( masterIndex ).row() + offset, 0 );
341 return mapSelectionFromSource( mFilterModel->mapSelectionFromSource( selection ) );
346 return mFilterModel->mapSelectionToSource( mapSelectionToSource( selection ) );
353 QModelIndex sourceIndex;
355 if ( mSortByDisplayExpression )
357 sourceIndex = QSortFilterProxyModel::mapToSource( proxyIndex );
361 if ( !proxyIndex.isValid() )
362 return QModelIndex();
364 const int offset = mInjectNull ? 1 : 0;
366 sourceIndex = sourceModel()->index( proxyIndex.row() - offset, proxyIndex.column() );
374 QModelIndex proxyIndex;
376 if ( mSortByDisplayExpression )
378 proxyIndex = QSortFilterProxyModel::mapFromSource( sourceIndex );
382 if ( sourceIndex.isValid() )
383 proxyIndex = createIndex( sourceIndex.row(), 0 );
392 return QModelIndex();
405 const int offset = mInjectNull ? 1 : 0;
407 return sourceModel()->rowCount() + offset;
417 return QModelIndexList() <<
fidToIndex( fid );
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
QgsVectorLayerCache * layerCache() const
Returns the layerCache this filter acts on.
QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
QgsAttributeTableModel * masterModel() const
Returns the table model this filter is using.
QModelIndex mapToMaster(const QModelIndex &proxyIndex) const
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
QModelIndex idToIndex(QgsFeatureId id) const
void prefetchSortData(const QString &expression, unsigned long cacheIndex=0)
Prefetches the entire data for an expression.
QgsFeatureId rowToId(int row) const
Maps row to feature id.
@ SortRole
Role used for sorting start here.
void changed()
Emitted when the conditional styles are changed.
QgsConditionalStyles rowStyles() const
Returns a list of row styles associated with the layer.
QList< QgsConditionalStyle > fieldStyles(const QString &fieldName) const
Returns the conditional styles set for the field with matching fieldName.
Conditional styling for a rule.
static QgsConditionalStyle compressStyles(const QList< QgsConditionalStyle > &styles)
Compress a list of styles into a single style.
static QList< QgsConditionalStyle > matchingConditionalStyles(const QList< QgsConditionalStyle > &styles, const QVariant &value, QgsExpressionContext &context)
Find and return the matching styles for the value and feature.
QColor backgroundColor() const
The background color for style.
QColor textColor() const
The text color set for style.
QFont font() const
The font for the style.
bool validTextColor() const
Check if the text color is valid for render.
bool isValid() const
isValid Check if this rule is valid.
QPixmap icon() const
The icon set for style generated from the set symbol.
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.
Class for parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
QString expression() const
Returns the original, unmodified expression string.
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
QString parserErrorString() const
Returns parser error.
bool isField() const
Checks whether an expression consists only of a single field reference.
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
QVariant evaluate()
Evaluate the feature and return the result.
QgsFeatureId idxToFid(const QModelIndex &index) const
Returns the feature ID corresponding to an index from the model.
virtual void setSourceModel(QgsAttributeTableFilterModel *sourceModel)
void setInjectNull(bool injectNull)
If true is specified, a NULL value will be injected.
Q_DECL_DEPRECATED void onEndRemoveRows(const QModelIndex &parent, int first, int last)
Does nothing except for calling endRemoveRows()
Q_DECL_DEPRECATED void onBeginInsertRows(const QModelIndex &parent, int first, int last)
Does nothing except for calling beginInsertRows()
Qt::ItemFlags flags(const QModelIndex &index) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QModelIndexList fidToIndexList(QgsFeatureId fid)
bool featureByIndex(const QModelIndex &index, QgsFeature &feat)
virtual QModelIndex mapToMaster(const QModelIndex &proxyIndex) const
void setSortByDisplayExpression(bool sortByDisplayExpression, Qt::SortOrder order=Qt::AscendingOrder)
Sort this model by its display expression.
QModelIndex fidToIdx(QgsFeatureId fid) const
Returns the model index corresponding to a feature ID.
QString parserErrorString()
Returns a detailed message about errors while parsing a QgsExpression.
Q_DECL_DEPRECATED void onBeginRemoveRows(const QModelIndex &parent, int first, int last)
Does nothing except for calling beginRemoveRows()
QVariant data(const QModelIndex &index, int role) const override
bool injectNull()
Returns the current state of null value injection.
virtual QItemSelection mapSelectionToMaster(const QItemSelection &selection) const
bool sortByDisplayExpression() const
Sort this model by its display expression.
QModelIndex parent(const QModelIndex &child) const override
bool setDisplayExpression(const QString &expression)
virtual QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
QString displayExpression() const
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
QgsVectorLayerCache * layerCache()
Returns the vector layer cache which is being used to populate the model.
QModelIndex fidToIndex(QgsFeatureId fid) override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QgsFeatureListModel(QgsAttributeTableFilterModel *sourceModel, QObject *parent=nullptr)
Constructor for QgsFeatureListModel.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const override
Q_DECL_DEPRECATED void onEndInsertRows(const QModelIndex &parent, int first, int last)
Does nothing except for calling endInsertRows()
virtual QItemSelection mapSelectionFromMaster(const QItemSelection &selection) const
QgsAttributeTableModel * masterModel()
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
This class caches features of a given QgsVectorLayer.
bool featureAtIdWithAllAttributes(QgsFeatureId featureId, QgsFeature &feature, bool skipCache=false)
Gets the feature at the given feature id with all attributes, if the cached feature already contains ...
bool isFeatureAdded(QgsFeatureId id) const
Returns true if the specified feature ID has been added but not committed.
bool isFeatureAttributesChanged(QgsFeatureId id) const
Returns true if the specified feature ID has had an attribute changed but not committed.
Represents a vector layer which manages a vector based data sets.
QgsExpressionContext createExpressionContext() const FINAL
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Q_INVOKABLE QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on.
QgsConditionalLayerStyles * conditionalStyles() const
Returns the conditional styles that are set for this layer.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
bool isEdited
True if feature has been edited.
bool isNew
True if feature is a newly added feature.