QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
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 QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
123 if ( role == Qt::BackgroundColorRole
124 || role == Qt::TextColorRole
126 if ( role == Qt::BackgroundRole
127 || role == Qt::ForegroundRole
129 || role == Qt::DecorationRole
130 || role == Qt::FontRole )
137 QList<QgsConditionalStyle> styles;
139 if ( mRowStylesMap.contains( fid ) )
141 styles = mRowStylesMap.value( fid );
146 mRowStylesMap.insert( fid, styles );
151 if ( mDisplayExpression.
isField() )
158 styles.insert( 0, rowstyle );
164 #if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
170 #if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
176 if ( role == Qt::DecorationRole )
177 return style.
icon().isNull() ? QVariant() : style.
icon();
178 if ( role == Qt::FontRole )
185 return sourceModel()->data(
mapToSource( index ), role );
190 if ( mInjectNull && index.row() == 0 )
192 return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
196 return sourceModel()->flags(
mapToSource( index ) ) & ~Qt::ItemIsEditable;
227 exp.
prepare( &mExpressionContext );
235 mDisplayExpression = exp;
237 if ( mSortByDisplayExpression )
240 emit dataChanged( index( 0, 0 ), index(
rowCount() - 1, 0 ) );
248 return mParserErrorString;
263 beginRemoveRows(
parent, first, last );
276 beginInsertRows(
parent, first, last );
287 void QgsFeatureListModel::conditionalStylesChanged()
289 mRowStylesMap.clear();
295 return mSortByDisplayExpression;
303 if ( mSortByDisplayExpression )
307 setDynamicSortFilter( mSortByDisplayExpression );
313 QModelIndex masterIndex;
315 if ( proxyIndex.isValid() )
317 if ( mSortByDisplayExpression )
323 const int offset = mInjectNull ? 1 : 0;
325 masterIndex = mFilterModel->
mapToMaster( mFilterModel->index( proxyIndex.row() - offset, proxyIndex.column() ) );
333 QModelIndex proxyIndex;
335 if ( masterIndex.isValid() )
337 if ( mSortByDisplayExpression )
343 const int offset = mInjectNull ? 1 : 0;
345 return createIndex( mFilterModel->
mapFromMaster( masterIndex ).row() + offset, 0 );
354 return mapSelectionFromSource( mFilterModel->mapSelectionFromSource( selection ) );
359 return mFilterModel->mapSelectionToSource( mapSelectionToSource( selection ) );
366 QModelIndex sourceIndex;
368 if ( mSortByDisplayExpression )
370 sourceIndex = QSortFilterProxyModel::mapToSource( proxyIndex );
374 if ( !proxyIndex.isValid() )
375 return QModelIndex();
377 const int offset = mInjectNull ? 1 : 0;
379 sourceIndex = sourceModel()->index( proxyIndex.row() - offset, proxyIndex.column() );
387 QModelIndex proxyIndex;
389 if ( mSortByDisplayExpression )
391 proxyIndex = QSortFilterProxyModel::mapFromSource( sourceIndex );
395 if ( sourceIndex.isValid() )
396 proxyIndex = createIndex( sourceIndex.row(), 0 );
405 return QModelIndex();
418 const int offset = mInjectNull ? 1 : 0;
420 return sourceModel()->rowCount() + offset;
430 return QModelIndexList() <<
fidToIndex( fid );
bool setDisplayExpression(const QString &expression)
Q_INVOKABLE QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on.
bool isFeatureAttributesChanged(QgsFeatureId id) const
Returns true if the specified feature ID has had an attribute changed but not committed.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
bool isValid() const
isValid Check if this rule is valid.
This class caches features of a given QgsVectorLayer.
bool featureByIndex(const QModelIndex &index, QgsFeature &feat)
QModelIndex mapToSource(const QModelIndex &proxyIndex) const override
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
void setInjectNull(bool injectNull)
If true is specified, a NULL value will be injected.
virtual QModelIndex mapToMaster(const QModelIndex &proxyIndex) const
QModelIndexList fidToIndexList(QgsFeatureId fid)
Conditional styling for a rule.
QVariant data(const QModelIndex &index, int role) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
bool sortByDisplayExpression() const
Sort this model by its display expression.
static QgsConditionalStyle compressStyles(const QList< QgsConditionalStyle > &styles)
Compress a list of styles into a single style.
bool isEdited
True if feature has been edited.
virtual QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
QPixmap icon() const
The icon set for style generated from the set symbol.
Q_DECL_DEPRECATED void onBeginInsertRows(const QModelIndex &parent, int first, int last)
Does nothing except for calling beginInsertRows()
QgsFeatureId idxToFid(const QModelIndex &index) const
Returns the feature ID corresponding to an index from the model.
Qt::ItemFlags flags(const QModelIndex &index) const override
QString parserErrorString()
Returns a detailed message about errors while parsing a QgsExpression.
QString parserErrorString() const
Returns parser error.
QString displayExpression() const
Q_DECL_DEPRECATED void onEndInsertRows(const QModelIndex &parent, int first, int last)
Does nothing except for calling endInsertRows()
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
QgsFeatureId rowToId(int row) const
Maps row to feature id.
bool validBackgroundColor() const
Check if the background color is valid for render.
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
QColor backgroundColor() const
The background color for style.
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
QgsVectorLayerCache * layerCache() const
Returns the layerCache this filter acts on.
QgsAttributeTableModel * masterModel() const
Returns the table model this filter is using.
bool isNew
True if feature is a newly added feature.
QModelIndex mapToMaster(const QModelIndex &proxyIndex) const
void prefetchSortData(const QString &expression, unsigned long cacheIndex=0)
Prefetches the entire data for an expression.
QModelIndex fidToIdx(QgsFeatureId fid) const
Returns the model index corresponding to a feature ID.
QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
QModelIndex parent(const QModelIndex &child) const override
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
static QList< QgsConditionalStyle > matchingConditionalStyles(const QList< QgsConditionalStyle > &styles, const QVariant &value, QgsExpressionContext &context)
Find and return the matching styles for the value and feature.
bool featureAtId(QgsFeatureId featureId, QgsFeature &feature, bool skipCache=false)
Gets the feature at the given feature id.
virtual QItemSelection mapSelectionToMaster(const QItemSelection &selection) const
QVariant evaluate()
Evaluate the feature and return the result.
QFont font() const
The font for the style.
QgsAttributeTableModel * masterModel()
QgsConditionalStyles rowStyles() const
Returns a list of row styles associated with the layer.
bool isFeatureAdded(QgsFeatureId id) const
Returns true if the specified feature ID has been added but not committed.
bool injectNull()
Returns the current state of null value injection.
QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
QgsVectorLayerCache * layerCache()
Returns the vector layer cache which is being used to populate the model.
Q_DECL_DEPRECATED void onEndRemoveRows(const QModelIndex &parent, int first, int last)
Does nothing except for calling endRemoveRows()
QColor textColor() const
The text color set for style.
Represents a vector layer which manages a vector based data sets.
Q_DECL_DEPRECATED void onBeginRemoveRows(const QModelIndex &parent, int first, int last)
Does nothing except for calling beginRemoveRows()
QgsConditionalLayerStyles * conditionalStyles() const
Returns the conditional styles that are set for this layer.
QgsFeatureListModel(QgsAttributeTableFilterModel *sourceModel, QObject *parent=nullptr)
Constructor for QgsFeatureListModel.
QList< QgsConditionalStyle > fieldStyles(const QString &fieldName) const
Returns the conditional styles set for the field with matching fieldName.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setSortByDisplayExpression(bool sortByDisplayExpression, Qt::SortOrder order=Qt::AscendingOrder)
Sort this model by its display expression.
bool isField() const
Checks whether an expression consists only of a single field reference.
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
@ SortRole
Role used for sorting start here.
virtual QItemSelection mapSelectionFromMaster(const QItemSelection &selection) const
QgsExpressionContext createExpressionContext() const FINAL
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QModelIndex idToIndex(QgsFeatureId id) const
Class for parsing and evaluation of expressions (formerly called "search strings")....
bool validTextColor() const
Check if the text color is valid for render.
QString expression() const
Returns the original, unmodified expression string.
void changed()
Emitted when the conditional styles are changed.
QModelIndex fidToIndex(QgsFeatureId fid) override
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
virtual void setSourceModel(QgsAttributeTableFilterModel *sourceModel)