QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsattributetablefiltermodel.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  QgsAttributeTableFilterModel.cpp
3  --------------------------------------
4  Date : Feb 2009
5  Copyright : (C) 2009 Vita Cizek
6  Email : weetya (at) gmail.com
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 
16 #include <QItemSelectionModel>
17 
18 #include "qgis.h"
20 #include "qgsattributetablemodel.h"
21 #include "qgsvectorlayer.h"
22 #include "qgsfeature.h"
23 #include "qgsmapcanvas.h"
24 #include "qgslogger.h"
25 #include "qgsrendererv2.h"
28 // Filter Model //
30 
32  : QSortFilterProxyModel( parent )
33  , mCanvas( canvas )
34  , mFilterMode( ShowAll )
35  , mSelectedOnTop( false )
36 {
37  setSourceModel( sourceModel );
38  setDynamicSortFilter( true );
40  connect( layer(), SIGNAL( selectionChanged() ), SLOT( selectionChanged() ) );
41 }
42 
43 bool QgsAttributeTableFilterModel::lessThan( const QModelIndex &left, const QModelIndex &right ) const
44 {
45  if ( mSelectedOnTop )
46  {
47  bool leftSelected = layer()->selectedFeaturesIds().contains( masterModel()->rowToId( left.row() ) );
48  bool rightSelected = layer()->selectedFeaturesIds().contains( masterModel()->rowToId( right.row() ) );
49 
50  if ( leftSelected && !rightSelected )
51  {
52  return sortOrder() == Qt::AscendingOrder;
53  }
54  else if ( rightSelected && !leftSelected )
55  {
56  return sortOrder() == Qt::DescendingOrder;
57  }
58  }
59 
60  if ( mTableModel->sortCacheExpression().isEmpty() )
61  {
62  //shortcut when no sort order set
63  return false;
64  }
65 
68 }
69 
70 void QgsAttributeTableFilterModel::sort( int column, Qt::SortOrder order )
71 {
72  if ( order != Qt::AscendingOrder && order != Qt::DescendingOrder )
73  order = Qt::AscendingOrder;
74 
75  int myColumn = mColumnMapping.at( column );
76  masterModel()->prefetchColumnData( myColumn );
77  QSortFilterProxyModel::sort( myColumn, order );
78  emit sortColumnChanged( column, order );
79 }
80 
82 {
83  if ( mapColumnToSource( index.column() ) == -1 ) // actions
84  {
85  if ( role == TypeRole )
87  else if ( role == QgsAttributeTableModel::FeatureIdRole )
88  {
91  }
92  }
93  else if ( role == TypeRole )
94  return ColumnTypeField;
95 
96  return QSortFilterProxyModel::data( index, role );
97 }
98 
99 QVariant QgsAttributeTableFilterModel::headerData( int section, Qt::Orientation orientation, int role ) const
100 {
101  if ( orientation == Qt::Horizontal )
102  {
103  if ( mColumnMapping.at( section ) == -1 && role == Qt::DisplayRole )
104  return tr( "Actions" );
105  else
106  return QSortFilterProxyModel::headerData( section, orientation, role );
107  }
108  else
109  {
110  if ( role == Qt::DisplayRole )
111  return section + 1;
112  else
113  {
114  int sourceSection = mapToSource( index( section, ( !mColumnMapping.isEmpty() && mColumnMapping.at( 0 ) == -1 ) ? 1 : 0 ) ).row();
115  return sourceModel()->headerData( sourceSection, orientation, role );
116  }
117  }
118 }
119 
121 {
122  return mColumnMapping.indexOf( -1 );
123 }
124 
126 {
127  Q_UNUSED( parent );
128  return mColumnMapping.count();
129 }
130 
132 {
133  mConfig = config;
134  mConfig.update( layer()->fields() );
135 
136  QVector<int> newColumnMapping;
137 
138  Q_FOREACH ( const QgsAttributeTableConfig::ColumnConfig& columnConfig, mConfig.columns() )
139  {
140  // Hidden? Forget about this column
141  if ( columnConfig.hidden )
142  continue;
143 
144  // The new value for the mapping (field index or -1 for action column)
145  int newValue = ( columnConfig.type == QgsAttributeTableConfig::Action ) ? -1 : layer()->fieldNameIndex( columnConfig.name );
146  newColumnMapping << newValue;
147  }
148 
149  if ( newColumnMapping != mColumnMapping )
150  {
151  bool requiresReset = false;
152  int firstRemovedColumn = -1;
153  int removedColumnCount = 0;
154 
155  // Check if there have a contiguous set of columns have been removed or if we require a full reset
156  for ( int i = 0; i < qMin( newColumnMapping.size(), mColumnMapping.size() - removedColumnCount ); ++i )
157  {
158  if ( newColumnMapping.at( i ) == mColumnMapping.at( i + removedColumnCount ) )
159  continue;
160 
161  if ( firstRemovedColumn == -1 )
162  {
163  firstRemovedColumn = i;
164 
165  while ( i < mColumnMapping.size() - removedColumnCount && mColumnMapping.at( i + removedColumnCount ) != newColumnMapping.at( i ) )
166  {
167  ++removedColumnCount;
168  }
169  }
170  else
171  {
172  requiresReset = true;
173  break;
174  }
175  }
176 
177  // No difference found so far
178  if ( firstRemovedColumn == -1 )
179  {
180  if ( newColumnMapping.size() > mColumnMapping.size() )
181  {
182  // More columns: appended to the end
183  beginInsertColumns( QModelIndex(), mColumnMapping.size(), newColumnMapping.size() - 1 );
184  mColumnMapping = newColumnMapping;
186  }
187  else
188  {
189  // Less columns: removed from the end
190  beginRemoveColumns( QModelIndex(), newColumnMapping.size(), mColumnMapping.size() - 1 );
191  mColumnMapping = newColumnMapping;
193  }
194  }
195  else
196  {
197  if ( newColumnMapping.size() == mColumnMapping.size() - removedColumnCount )
198  {
199  //the amount of removed column in the model need to be equal removedColumnCount
200  beginRemoveColumns( QModelIndex(), firstRemovedColumn, firstRemovedColumn + removedColumnCount - 1 );
201  mColumnMapping = newColumnMapping;
203  }
204  else
205  {
206  requiresReset = true;
207  }
208  }
209 
210  if ( requiresReset )
211  {
212  beginResetModel();
213  mColumnMapping = newColumnMapping;
214  endResetModel();
215  }
216  }
217 
218  if ( !config.sortExpression().isEmpty() )
219  sort( config.sortExpression(), config.sortOrder() );
220 }
221 
222 void QgsAttributeTableFilterModel::sort( QString expression, Qt::SortOrder order )
223 {
224  if ( order != Qt::AscendingOrder && order != Qt::DescendingOrder )
225  order = Qt::AscendingOrder;
226 
228  masterModel()->prefetchSortData( expression );
229  QSortFilterProxyModel::sort( 0, order ) ;
230 }
231 
233 {
234  return masterModel()->sortCacheExpression();
235 }
236 
238 {
239  if ( mSelectedOnTop != selectedOnTop )
240  {
241  mSelectedOnTop = selectedOnTop;
242  int column = sortColumn();
243  Qt::SortOrder order = sortOrder();
244 
245  // set default sort values if they are not correctly set
246  if ( column < 0 )
247  column = 0;
248 
249  if ( order != Qt::AscendingOrder && order != Qt::DescendingOrder )
250  order = Qt::AscendingOrder;
251 
252  sort( column, order );
253  invalidate();
254  }
255 }
256 
258 {
259  mTableModel = sourceModel;
260 
261  for ( int i = 0; i < mTableModel->columnCount() - mTableModel->extraColumns(); ++i )
262  {
263  mColumnMapping.append( i );
264  }
265 
267 
268  // Disconnect any code to update columns in the parent, we handle this manually
269  disconnect( sourceModel, SIGNAL( columnsAboutToBeInserted( QModelIndex, int, int ) ), this, SLOT( _q_sourceColumnsAboutToBeInserted( QModelIndex, int, int ) ) );
270  disconnect( sourceModel, SIGNAL( columnsInserted( QModelIndex, int, int ) ), this, SLOT( _q_sourceColumnsInserted( QModelIndex, int, int ) ) );
271  disconnect( sourceModel, SIGNAL( columnsAboutToBeRemoved( QModelIndex, int, int ) ), this, SLOT( _q_sourceColumnsAboutToBeRemoved( QModelIndex, int, int ) ) );
272  disconnect( sourceModel, SIGNAL( columnsRemoved( QModelIndex, int, int ) ), this, SLOT( _q_sourceColumnsRemoved( QModelIndex, int, int ) ) );
273 
274  connect( mTableModel, SIGNAL( columnsAboutToBeInserted( QModelIndex, int, int ) ), this, SLOT( onColumnsChanged() ) );
275  connect( mTableModel, SIGNAL( columnsAboutToBeRemoved( QModelIndex, int, int ) ), this, SLOT( onColumnsChanged() ) );
276 }
277 
279 {
280  return mSelectedOnTop;
281 }
282 
284 {
285  mFilteredFeatures = ids;
288 }
289 
291 {
292  QgsFeatureIds ids;
293  for ( int i = 0; i < rowCount(); ++i )
294  {
295  QModelIndex row = index( i, 0 );
296  ids << rowToId( row );
297  }
298  return ids;
299 }
300 
302 {
303  if ( filterMode != mFilterMode )
304  {
305  if ( filterMode == ShowVisible )
306  {
307  connect( mCanvas, SIGNAL( extentsChanged() ), this, SLOT( extentsChanged() ) );
309  }
310  else
311  {
312  disconnect( mCanvas, SIGNAL( extentsChanged() ), this, SLOT( extentsChanged() ) );
313  }
314 
315  mFilterMode = filterMode;
317  }
318 }
319 
320 bool QgsAttributeTableFilterModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
321 {
322  Q_UNUSED( sourceParent );
323  switch ( mFilterMode )
324  {
325  case ShowAll:
326  return true;
327 
328  case ShowFilteredList:
329  return mFilteredFeatures.contains( masterModel()->rowToId( sourceRow ) );
330 
331  case ShowSelected:
332  return layer()->selectedFeaturesIds().isEmpty() || layer()->selectedFeaturesIds().contains( masterModel()->rowToId( sourceRow ) );
333 
334  case ShowVisible:
335  return mFilteredFeatures.contains( masterModel()->rowToId( sourceRow ) );
336 
337  case ShowEdited:
338  {
339  QgsVectorLayerEditBuffer* editBuffer = layer()->editBuffer();
340  if ( editBuffer )
341  {
342  const QList<QgsFeatureId> addedFeatures = editBuffer->addedFeatures().keys();
343  const QList<QgsFeatureId> changedFeatures = editBuffer->changedAttributeValues().keys();
344  const QList<QgsFeatureId> changedGeometries = editBuffer->changedGeometries().keys();
345  const QgsFeatureId fid = masterModel()->rowToId( sourceRow );
346  return addedFeatures.contains( fid ) || changedFeatures.contains( fid ) || changedGeometries.contains( fid );
347  }
348  return false;
349  }
350 
351  default:
352  Q_ASSERT( false ); // In debug mode complain
353  return true; // In release mode accept row
354  }
355  // returns are handled in their respective case statement above
356 }
357 
359 {
362 }
363 
364 void QgsAttributeTableFilterModel::selectionChanged()
365 {
366  if ( ShowSelected == mFilterMode )
367  {
369  }
370  else if ( mSelectedOnTop )
371  {
372  sort( sortColumn(), sortOrder() );
373  invalidate();
374  }
375 }
376 
377 void QgsAttributeTableFilterModel::onColumnsChanged()
378 {
379  setAttributeTableConfig( mConfig );
380 }
381 
382 int QgsAttributeTableFilterModel::mapColumnToSource( int column ) const
383 {
384  if ( mColumnMapping.isEmpty() )
385  return column;
386  if ( column < 0 || column >= mColumnMapping.size() )
387  return -1;
388  else
389  return mColumnMapping.at( column );
390 }
391 
393 {
394  if ( !layer() )
395  return;
396 
397  bool filter = false;
398  QgsRectangle rect = mCanvas->mapSettings().mapToLayerCoordinates( layer(), mCanvas->extent() );
399  QgsRenderContext renderContext;
403  QgsFeatureRendererV2* renderer = layer()->rendererV2();
404 
405  mFilteredFeatures.clear();
406 
407  if ( !renderer )
408  {
409  QgsDebugMsg( "Cannot get renderer" );
410  return;
411  }
412 
413  const QgsMapSettings& ms = mCanvas->mapSettings();
414  if ( !layer()->isInScaleRange( ms.scale() ) )
415  {
416  QgsDebugMsg( "Out of scale limits" );
417  }
418  else
419  {
420  if ( renderer && renderer->capabilities() & QgsFeatureRendererV2::ScaleDependent )
421  {
422  // setup scale
423  // mapRenderer()->renderContext()->scale is not automaticaly updated when
424  // render extent changes (because it's scale is used to identify if changed
425  // since last render) -> use local context
426  renderContext.setExtent( ms.visibleExtent() );
427  renderContext.setMapToPixel( ms.mapToPixel() );
428  renderContext.setRendererScale( ms.scale() );
429  }
430 
431  filter = renderer && renderer->capabilities() & QgsFeatureRendererV2::Filter;
432  }
433 
434  renderer->startRender( renderContext, layer()->fields() );
435 
436  QgsFeatureRequest r( masterModel()->request() );
437  if ( !r.filterRect().isNull() )
438  {
439  r.setFilterRect( r.filterRect().intersect( &rect ) );
440  }
441  else
442  {
443  r.setFilterRect( rect );
444  }
446 
447  QgsFeature f;
448 
449  while ( features.nextFeature( f ) )
450  {
451  renderContext.expressionContext().setFeature( f );
452  if ( !filter || renderer->willRenderFeature( f, renderContext ) )
453  {
454  mFilteredFeatures << f.id();
455  }
456 #if 0
457  if ( t.elapsed() > 5000 )
458  {
459  bool cancel = false;
460  emit progress( i, cancel );
461  if ( cancel )
462  break;
463 
464  t.restart();
465  }
466 #endif
467  }
468 
469  features.close();
470 
471  if ( renderer && renderer->capabilities() & QgsFeatureRendererV2::ScaleDependent )
472  {
473  renderer->stopRender( renderContext );
474  }
475 }
476 
478 {
479  return masterModel()->rowToId( mapToSource( row ).row() );
480 }
481 
483 {
484  return mapFromMaster( masterModel()->idToIndex( fid ) );
485 }
486 
488 {
489  QModelIndexList indexes;
490  Q_FOREACH ( const QModelIndex& idx, masterModel()->idToIndexList( fid ) )
491  {
492  indexes.append( mapFromMaster( idx ) );
493  }
494 
495  return indexes;
496 }
497 
499 {
500  if ( !proxyIndex.isValid() )
501  return QModelIndex();
502 
503  int sourceColumn = mapColumnToSource( proxyIndex.column() );
504 
505  // For the action column there is no matching column in the source model, just return the first one
506  // so we are still able to query for the feature id, the feature...
507  if ( sourceColumn == -1 )
508  sourceColumn = 0;
509 
510  return QSortFilterProxyModel::mapToSource( index( proxyIndex.row(), sourceColumn, proxyIndex.parent() ) );
511 }
512 
514 {
515  QModelIndex proxyIndex = QSortFilterProxyModel::mapFromSource( sourceIndex );
516 
517  if ( proxyIndex.column() < 0 )
518  return QModelIndex();
519 
520  int col = mapColumnToSource( proxyIndex.column() );
521  if ( col == -1 )
522  col = 0;
523 
524  return index( proxyIndex.row(), col , proxyIndex.parent() );
525 }
526 
528 {
529  // Handle the action column flags here, the master model doesn't know it
530  if ( mapColumnToSource( index.column() ) == -1 )
531  return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
532 
533  QModelIndex source_index = mapToSource( index );
534  return masterModel()->flags( source_index );
535 }
536 
void generateListOfVisibleFeatures()
Updates the list of currently visible features on the map canvas.
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
const QgsGeometryMap & changedGeometries()
Changed geometries which are not commited.
QgsFeatureId rowToId(const QModelIndex &row)
Returns the feature id for a given model index.
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
Wrapper for iterator of features from vector data provider or vector layer.
virtual QVariant data(const QModelIndex &index, int role) const override
void setSortRole(int role)
int extraColumns() const
Empty extra columns to announce from this model.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
void update(const QgsFields &fields)
Update the configuration with the given fields.
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Returns true if the source row will be accepted.
bool selectedOnTop()
Returns if selected features are currently shown on top.
void setAttributeTableConfig(const QgsAttributeTableConfig &config)
Set the attribute table configuration to control which fields are shown, in which order they are show...
QgsAttributeTableModel * masterModel() const
Returns the table model this filter is using.
void setSelectedOnTop(bool selectedOnTop)
Changes the sort order of the features.
virtual void sort(int column, Qt::SortOrder order)
void setFilterMode(FilterMode filterMode)
Set the filter mode the filter will use.
void append(const T &value)
QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
virtual void setSourceModel(QAbstractItemModel *sourceModel)
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
int indexOf(const T &value, int from) const
void setRendererScale(double scale)
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
Used by the sorting algorithm.
const QgsChangedAttributesMap & changedAttributeValues()
Changed attributes values which are not commited.
void columnsRemoved(const QModelIndex &parent, int start, int end)
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const override
QgsRectangle intersect(const QgsRectangle *rect) const
return the intersection with the given rectangle
This column represents an action widget.
depends on scale if feature will be rendered (rule based )
virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
Show only visible features (depends on the map canvas)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
const QgsRectangle & filterRect() const
Get the rectangle from which features will be taken.
virtual Q_DECL_DEPRECATED bool willRenderFeature(QgsFeature &feat)
Returns whether the renderer will render a feature or not.
QString tr(const char *sourceText, const char *disambiguation, int n)
void setExtent(const QgsRectangle &extent)
QgsRectangle visibleExtent() const
Return the actual extent derived from requested extent that takes takes output image size into accoun...
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:109
virtual int rowCount(const QModelIndex &parent) const
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is less than the second.
Definition: qgis.cpp:269
QgsAttributeTableFilterModel(QgsMapCanvas *canvas, QgsAttributeTableModel *sourceModel, QObject *parent=nullptr)
Make sure, the master model is already loaded, so the selection will get synchronized.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
Needs to be called when a new render cycle is started.
virtual void setFilteredFeatures(const QgsFeatureIds &ids)
Specify a list of features, which the filter will accept.
The QgsMapSettings class contains configuration for rendering of the map.
virtual void stopRender(QgsRenderContext &context)=0
Needs to be called when a render cycle has finished to clean up.
Get the feature id of the feature in this row.
int actionColumnIndex() const
Get the index of the first column that contains an action widget.
QList< Key > keys() const
bool isValid() const
QgsFeatureRendererV2 * rendererV2()
Return renderer V2.
QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on...
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
FilterMode filterMode()
The current filterModel.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of columns.
FilterMode
The filter mode defines how the rows should be filtered.
double scale() const
Return the calculated scale of the map.
bool isEmpty() const
QgsRectangle extent() const
Returns the current zoom exent of the map canvas.
int row() const
bool hidden
Flag that controls if the column is hidden.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QgsVectorLayerCache * layerCache() const
Returns the layer cache this model uses as backend.
void beginRemoveColumns(const QModelIndex &parent, int first, int last)
void setDynamicSortFilter(bool enable)
virtual QVariant data(const QModelIndex &index, int role) const=0
Show only features which have unsaved changes.
QModelIndex parent() const
void columnsInserted(const QModelIndex &parent, int start, int end)
const QgsMapToPixel & mapToPixel() const
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
QString name
The name of the attribute if this column represents a field.
void setSourceModel(QgsAttributeTableModel *sourceModel)
Set the attribute table model that backs this model.
QgsFeatureId id() const
Get the feature ID for this feature.
Definition: qgsfeature.cpp:65
void extentsChanged()
Is called upon every change of the visible extents on the map canvas.
QString sortExpression() const
The expression which is used to sort the attribute table.
void columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
bool contains(const T &value) const
QgsExpressionContext & expressionContext()
Gets the expression context.
Show only features whose ids are on the filter list. {.
bool contains(const T &value) const
QVector< ColumnConfig > columns() const
Get the list with all columns and their configuration.
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
const QgsFeatureIds & selectedFeaturesIds() const
Return reference to identifiers of selected features.
const QgsFeatureMap & addedFeatures()
New features which are not commited.
const T & at(int i) const
Contains information about the context of a rendering operation.
QAbstractItemModel * sourceModel() const
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Qt::SortOrder sortOrder() const
QVariant data(int role) const
QgsPoint mapToLayerCoordinates(QgsMapLayer *theLayer, QgsPoint point) const
transform point coordinates from output CRS to layer&#39;s CRS
virtual void sort(int column, Qt::SortOrder order=Qt::AscendingOrder) override
Sort by the given column using the given order.
virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
bool isEmpty() const
int columnCount(const QModelIndex &parent) const override
int count(const T &value) const
void setMapToPixel(const QgsMapToPixel &mtp)
bool isNull() const
test if the rectangle is null (all coordinates zero or after call to setMinimal()).
int column() const
bool isEmpty() const
Defines the configuration of a column in the attribute table.
QgsFeatureId rowToId(int row) const
Maps row to feature id.
qint64 QgsFeatureId
Definition: qgsfeature.h:31
QString sortCacheExpression() const
The expression which was used to fill the sorting cache.
QgsFeatureIds filteredFeatures()
Get a list of currently filtered feature ids.
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
bool nextFeature(QgsFeature &f)
features may be filtered, i.e. some features may not be rendered (categorized, rule based ...
void clear()
This is a container for configuration of the attribute table.
Qt::SortOrder sortOrder() const
Get the sort order.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const
int size() const
QString sortExpression() const
Get the expression used for sorting.
void sortColumnChanged(int column, Qt::SortOrder order)
Is emitted whenever the sort column is changed.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &featureRequest=QgsFeatureRequest())
Query this VectorLayerCache for features.
QModelIndexList fidToIndexList(QgsFeatureId fid)
int sortColumn() const
void beginInsertColumns(const QModelIndex &parent, int first, int last)
void prefetchColumnData(int column)
Caches the entire data for one column.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rect)
Set rectangle from which features will be taken.
void prefetchSortData(const QString &expression)
Prefetches the entire data for one expression.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
virtual QVariant data(const QModelIndex &index, int role) const
Qt::ItemFlags flags(const QModelIndex &index) const override
Returns item flags for the index.
QModelIndex fidToIndex(QgsFeatureId fid) override
void columnsAboutToBeInserted(const QModelIndex &parent, int start, int end)
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
typedef ItemFlags