QGIS API Documentation 3.43.0-Master (32433f7016e)
qgsfeaturelistmodel.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsfeaturelistmodel.h
3 ---------------------
4 begin : February 2013
5 copyright : (C) 2013 by Matthias Kuhn
6 email : matthias at opengis dot ch
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSATTRIBUTEEDITORMODEL_H
16#define QGSATTRIBUTEEDITORMODEL_H
17
18#include "qgsexpression.h"
19
20#include <QSortFilterProxyModel>
21#include <QVariant>
22#include <QItemSelectionModel>
23#include <QPointer>
24
25#include "qgsfeaturemodel.h"
26#include "qgsfeature.h" // QgsFeatureId
28#include "qgsconditionalstyle.h"
29#include "qgis_gui.h"
30
34
40class GUI_EXPORT QgsFeatureListModel : public QSortFilterProxyModel, public QgsFeatureModel
41{
42 Q_OBJECT
43
44 public:
46 {
47 public:
48 FeatureInfo() = default;
49
51 bool isNew = false;
52
54 bool isEdited = false;
55 };
56
57 enum Role
58 {
59 FeatureInfoRole = 0x1000, // Make sure no collisions with roles on QgsAttributeTableModel
62 };
63
64 public:
66 explicit QgsFeatureListModel( QgsAttributeTableFilterModel *sourceModel, QObject *parent SIP_TRANSFERTHIS = nullptr );
67
68#ifdef __clang__
69#pragma clang diagnostic push
70#pragma clang diagnostic ignored "-Woverloaded-virtual"
71#endif
72 virtual void setSourceModel( QgsAttributeTableFilterModel *sourceModel );
73#ifdef __clang__
74#pragma clang diagnostic pop
75#endif
76
80 QgsVectorLayerCache *layerCache();
81
82 QVariant data( const QModelIndex &index, int role ) const override;
83 Qt::ItemFlags flags( const QModelIndex &index ) const override;
84
90 void setInjectNull( bool injectNull );
91
96 bool injectNull();
97
98 QgsAttributeTableModel *masterModel();
99
108 bool setDisplayExpression( const QString &expression );
109
114 QString parserErrorString();
115
116 QString displayExpression() const;
117 bool featureByIndex( const QModelIndex &index, QgsFeature &feat );
118
123 QgsFeatureId idxToFid( const QModelIndex &index ) const;
124
129 QModelIndex fidToIdx( QgsFeatureId fid ) const;
130
131 QModelIndex mapToSource( const QModelIndex &proxyIndex ) const override;
132 QModelIndex mapFromSource( const QModelIndex &sourceIndex ) const override;
133
134 virtual QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const;
135 virtual QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const;
136
137 virtual QItemSelection mapSelectionFromMaster( const QItemSelection &selection ) const;
138 virtual QItemSelection mapSelectionToMaster( const QItemSelection &selection ) const;
139
140 QModelIndex parent( const QModelIndex &child ) const override;
141 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
142 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
143
144 QModelIndex fidToIndex( QgsFeatureId fid ) override;
145 QModelIndexList fidToIndexList( QgsFeatureId fid );
146
152 bool sortByDisplayExpression() const;
153
162 void setSortByDisplayExpression( bool sortByDisplayExpression, Qt::SortOrder order = Qt::AscendingOrder );
163
164 public slots:
165
171 Q_DECL_DEPRECATED void onBeginRemoveRows( const QModelIndex &parent, int first, int last );
172
178 Q_DECL_DEPRECATED void onEndRemoveRows( const QModelIndex &parent, int first, int last );
179
185 Q_DECL_DEPRECATED void onBeginInsertRows( const QModelIndex &parent, int first, int last );
186
192 Q_DECL_DEPRECATED void onEndInsertRows( const QModelIndex &parent, int first, int last );
193
194 private slots:
195
196 void conditionalStylesChanged();
197
198 private:
199 mutable QgsExpression mDisplayExpression;
200 QgsAttributeTableFilterModel *mFilterModel = nullptr;
201 QString mParserErrorString;
202 bool mInjectNull = false;
203 mutable QgsExpressionContext mExpressionContext;
204 mutable QMap<QgsFeatureId, QList<QgsConditionalStyle>> mRowStylesMap;
205 bool mSortByDisplayExpression = false;
206 QPointer<QgsVectorLayer> mSourceLayer;
207};
208
210
211#endif // QGSATTRIBUTEEDITORMODEL_H
A proxy model for filtering an attribute table model.
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Handles parsing and evaluation of expressions (formerly called "search strings").
A proxy model for feature lists.
@ FeatureWithGeometryRole
Feature with all attributes and geometry,.
@ FeatureRole
Feature with all attributes and no geometry.
Base class for feature models.
virtual QModelIndex fidToIndex(QgsFeatureId fid)=0
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Caches features for a given QgsVectorLayer.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features