QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 "qgsfeatureiterator.h"
22 #include "qgsvectorlayer.h"
23 #include "qgsfeature.h"
24 #include "qgsmapcanvas.h"
25 #include "qgslogger.h"
26 #include "qgsrenderer.h"
29 #include "qgsapplication.h"
30 
32 // Filter Model //
34 
36  : QSortFilterProxyModel( parent )
37  , mCanvas( canvas )
38 {
39  setSourceModel( sourceModel );
40  setDynamicSortFilter( true );
41  setSortRole( QgsAttributeTableModel::SortRole );
42  connect( layer(), &QgsVectorLayer::selectionChanged, this, &QgsAttributeTableFilterModel::selectionChanged );
43 
44  mReloadVisibleTimer.setSingleShot( true );
45  connect( &mReloadVisibleTimer, &QTimer::timeout, this, &QgsAttributeTableFilterModel::reloadVisible );
46  mFilterFeaturesTimer.setSingleShot( true );
47  connect( &mFilterFeaturesTimer, &QTimer::timeout, this, &QgsAttributeTableFilterModel::filterFeatures );
48 }
49 
50 bool QgsAttributeTableFilterModel::lessThan( const QModelIndex &left, const QModelIndex &right ) const
51 {
52  if ( mSelectedOnTop )
53  {
54  bool leftSelected = layer()->selectedFeatureIds().contains( masterModel()->rowToId( left.row() ) );
55  bool rightSelected = layer()->selectedFeatureIds().contains( masterModel()->rowToId( right.row() ) );
56 
57  if ( leftSelected && !rightSelected )
58  {
59  return sortOrder() == Qt::AscendingOrder;
60  }
61  else if ( rightSelected && !leftSelected )
62  {
63  return sortOrder() == Qt::DescendingOrder;
64  }
65  }
66 
67  if ( mTableModel->sortCacheExpression().isEmpty() )
68  {
69  //shortcut when no sort order set
70  return false;
71  }
72 
74  right.data( QgsAttributeTableModel::SortRole ) );
75 }
76 
77 void QgsAttributeTableFilterModel::sort( int column, Qt::SortOrder order )
78 {
79  if ( order != Qt::AscendingOrder && order != Qt::DescendingOrder )
80  order = Qt::AscendingOrder;
81  if ( column < 0 || column >= mColumnMapping.size() )
82  {
83  sort( QString() );
84  }
85  else
86  {
87  int myColumn = mColumnMapping.at( column );
88  masterModel()->prefetchColumnData( myColumn );
89  QSortFilterProxyModel::sort( myColumn, order );
90  }
91  emit sortColumnChanged( column, order );
92 }
93 
94 QVariant QgsAttributeTableFilterModel::data( const QModelIndex &index, int role ) const
95 {
96  if ( mapColumnToSource( index.column() ) == -1 ) // actions
97  {
98  if ( role == TypeRole )
100  else if ( role == QgsAttributeTableModel::FeatureIdRole )
101  {
102  QModelIndex fieldIndex = QSortFilterProxyModel::mapToSource( QSortFilterProxyModel::index( index.row(), 0, index.parent() ) );
103  return sourceModel()->data( fieldIndex, QgsAttributeTableModel::FeatureIdRole );
104  }
105  }
106  else if ( role == TypeRole )
107  return ColumnTypeField;
108 
109  return QSortFilterProxyModel::data( index, role );
110 }
111 
112 QVariant QgsAttributeTableFilterModel::headerData( int section, Qt::Orientation orientation, int role ) const
113 {
114  if ( orientation == Qt::Horizontal )
115  {
116  if ( mColumnMapping.at( section ) == -1 && role == Qt::DisplayRole )
117  return tr( "Actions" );
118  else
119  return QSortFilterProxyModel::headerData( section, orientation, role );
120  }
121  else
122  {
123  if ( role == Qt::DisplayRole )
124  return section + 1;
125  else
126  {
127  int sourceSection = mapToSource( index( section, ( !mColumnMapping.isEmpty() && mColumnMapping.at( 0 ) == -1 ) ? 1 : 0 ) ).row();
128  return sourceModel()->headerData( sourceSection, orientation, role );
129  }
130  }
131 }
132 
134 {
135  return mColumnMapping.indexOf( -1 );
136 }
137 
138 int QgsAttributeTableFilterModel::columnCount( const QModelIndex &parent ) const
139 {
140  Q_UNUSED( parent )
141  return mColumnMapping.count();
142 }
143 
145 {
146  QgsAttributeTableConfig oldConfig = mConfig;
147  mConfig = config;
148  mConfig.update( layer()->fields() );
149 
150  if ( mConfig.hasSameColumns( oldConfig ) )
151  {
152  return;
153  }
154 
155  QVector<int> newColumnMapping;
156  const auto constColumns = mConfig.columns();
157  for ( const QgsAttributeTableConfig::ColumnConfig &columnConfig : constColumns )
158  {
159  // Hidden? Forget about this column
160  if ( columnConfig.hidden )
161  continue;
162 
163  // The new value for the mapping (field index or -1 for action column)
164  int newValue = ( columnConfig.type == QgsAttributeTableConfig::Action ) ? -1 : layer()->fields().lookupField( columnConfig.name );
165  newColumnMapping << newValue;
166  }
167 
168  if ( newColumnMapping != mColumnMapping )
169  {
170  bool requiresReset = false;
171  int firstRemovedColumn = -1;
172  int removedColumnCount = 0;
173 
174  // Check if there have a contiguous set of columns have been removed or if we require a full reset
175  for ( int i = 0; i < std::min( newColumnMapping.size(), mColumnMapping.size() - removedColumnCount ); ++i )
176  {
177  if ( newColumnMapping.at( i ) == mColumnMapping.at( i + removedColumnCount ) )
178  continue;
179 
180  if ( firstRemovedColumn == -1 )
181  {
182  firstRemovedColumn = i;
183 
184  while ( i < mColumnMapping.size() - removedColumnCount && mColumnMapping.at( i + removedColumnCount ) != newColumnMapping.at( i ) )
185  {
186  ++removedColumnCount;
187  }
188  }
189  else
190  {
191  requiresReset = true;
192  break;
193  }
194  }
195 
196  // No difference found so far
197  if ( firstRemovedColumn == -1 )
198  {
199  if ( newColumnMapping.size() > mColumnMapping.size() )
200  {
201  // More columns: appended to the end
202  beginInsertColumns( QModelIndex(), mColumnMapping.size(), newColumnMapping.size() - 1 );
203  mColumnMapping = newColumnMapping;
204  endInsertColumns();
205  }
206  else
207  {
208  // Less columns: removed from the end
209  beginRemoveColumns( QModelIndex(), newColumnMapping.size(), mColumnMapping.size() - 1 );
210  mColumnMapping = newColumnMapping;
211  endRemoveColumns();
212  }
213  }
214  else
215  {
216  if ( newColumnMapping.size() == mColumnMapping.size() - removedColumnCount )
217  {
218  //the amount of removed column in the model need to be equal removedColumnCount
219  beginRemoveColumns( QModelIndex(), firstRemovedColumn, firstRemovedColumn + removedColumnCount - 1 );
220  mColumnMapping = newColumnMapping;
221  endRemoveColumns();
222  }
223  else
224  {
225  requiresReset = true;
226  }
227  }
228 
229  if ( requiresReset )
230  {
231  beginResetModel();
232  mColumnMapping = newColumnMapping;
233  endResetModel();
234  }
235  }
236 
237  if ( !config.sortExpression().isEmpty() )
238  sort( config.sortExpression(), config.sortOrder() );
239 }
240 
242 {
243  mFilterExpression = expression;
244  mFilterExpressionContext = context;
245 }
246 
247 void QgsAttributeTableFilterModel::sort( const QString &expression, Qt::SortOrder order )
248 {
249  if ( order != Qt::AscendingOrder && order != Qt::DescendingOrder )
250  order = Qt::AscendingOrder;
251 
252  QSortFilterProxyModel::sort( -1 );
253  masterModel()->prefetchSortData( expression );
254  QSortFilterProxyModel::sort( 0, order );
255 }
256 
258 {
259  return masterModel()->sortCacheExpression();
260 }
261 
263 {
264  if ( mSelectedOnTop != selectedOnTop )
265  {
266  mSelectedOnTop = selectedOnTop;
267  int column = sortColumn();
268  Qt::SortOrder order = sortOrder();
269 
270  // set default sort values if they are not correctly set
271  if ( column < 0 )
272  column = 0;
273 
274  if ( order != Qt::AscendingOrder && order != Qt::DescendingOrder )
275  order = Qt::AscendingOrder;
276 
277  sort( 0, Qt::AscendingOrder );
278  invalidate();
279  }
280 }
281 
283 {
284  mTableModel = sourceModel;
285 
286  for ( int i = 0; i < mTableModel->columnCount() - mTableModel->extraColumns(); ++i )
287  {
288  mColumnMapping.append( i );
289  }
290 
291  QSortFilterProxyModel::setSourceModel( sourceModel );
292 
293  // Disconnect any code to update columns in the parent, we handle this manually
294  disconnect( mTableModel, SIGNAL( columnsAboutToBeInserted( QModelIndex, int, int ) ), this, SLOT( _q_sourceColumnsAboutToBeInserted( QModelIndex, int, int ) ) );
295  disconnect( mTableModel, SIGNAL( columnsInserted( QModelIndex, int, int ) ), this, SLOT( _q_sourceColumnsInserted( QModelIndex, int, int ) ) );
296  disconnect( mTableModel, SIGNAL( columnsAboutToBeRemoved( QModelIndex, int, int ) ), this, SLOT( _q_sourceColumnsAboutToBeRemoved( QModelIndex, int, int ) ) );
297  disconnect( mTableModel, SIGNAL( columnsRemoved( QModelIndex, int, int ) ), this, SLOT( _q_sourceColumnsRemoved( QModelIndex, int, int ) ) );
298  // The following connections are needed in order to keep the filter model in sync, see: regression #15974
299  connect( mTableModel, &QAbstractItemModel::columnsAboutToBeInserted, this, &QgsAttributeTableFilterModel::onColumnsChanged );
300  connect( mTableModel, &QAbstractItemModel::columnsAboutToBeRemoved, this, &QgsAttributeTableFilterModel::onColumnsChanged );
301 
302 }
303 
305 {
306  return mSelectedOnTop;
307 }
308 
310 {
311  mFilteredFeatures = ids;
313  invalidateFilter();
314 }
315 
317 {
318  QgsFeatureIds ids;
319  ids.reserve( rowCount() );
320  for ( int i = 0; i < rowCount(); ++i )
321  {
322  QModelIndex row = index( i, 0 );
323  ids << rowToId( row );
324  }
325  return ids;
326 }
327 
329 {
330  if ( filterMode != mFilterMode )
331  {
334  mFilterMode = filterMode;
335  invalidateFilter();
336  }
337 }
338 
340 {
341  // cleanup existing connections
342  switch ( mFilterMode )
343  {
344  case ShowVisible:
345  disconnect( mCanvas, &QgsMapCanvas::extentsChanged, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
346  disconnect( layer(), &QgsVectorLayer::featureAdded, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
347  disconnect( layer(), &QgsVectorLayer::geometryChanged, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
348  break;
349  case ShowAll:
350  case ShowEdited:
351  case ShowSelected:
352  break;
353  case ShowFilteredList:
354  disconnect( layer(), &QgsVectorLayer::featureAdded, this, &QgsAttributeTableFilterModel::startTimedFilterFeatures );
355  disconnect( layer(), &QgsVectorLayer::attributeValueChanged, this, &QgsAttributeTableFilterModel::onAttributeValueChanged );
356  disconnect( layer(), &QgsVectorLayer::geometryChanged, this, &QgsAttributeTableFilterModel::onGeometryChanged );
357  break;
358  }
359 }
360 
362 {
363  // setup new connections
364  switch ( filterMode )
365  {
366  case ShowVisible:
367  connect( mCanvas, &QgsMapCanvas::extentsChanged, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
368  connect( layer(), &QgsVectorLayer::featureAdded, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
369  connect( layer(), &QgsVectorLayer::geometryChanged, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
371  break;
372  case ShowAll:
373  case ShowEdited:
374  case ShowSelected:
375  break;
376  case ShowFilteredList:
377  connect( layer(), &QgsVectorLayer::featureAdded, this, &QgsAttributeTableFilterModel::startTimedFilterFeatures );
378  connect( layer(), &QgsVectorLayer::attributeValueChanged, this, &QgsAttributeTableFilterModel::onAttributeValueChanged );
379  connect( layer(), &QgsVectorLayer::geometryChanged, this, &QgsAttributeTableFilterModel::onGeometryChanged );
380  break;
381  }
382 }
383 
384 bool QgsAttributeTableFilterModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
385 {
386  Q_UNUSED( sourceParent )
387  switch ( mFilterMode )
388  {
389  case ShowAll:
390  return true;
391 
392  case ShowFilteredList:
393  return mFilteredFeatures.contains( masterModel()->rowToId( sourceRow ) );
394 
395  case ShowSelected:
396  return layer()->selectedFeatureIds().contains( masterModel()->rowToId( sourceRow ) );
397 
398  case ShowVisible:
399  return mFilteredFeatures.contains( masterModel()->rowToId( sourceRow ) );
400 
401  case ShowEdited:
402  {
403  QgsVectorLayerEditBuffer *editBuffer = layer()->editBuffer();
404  if ( editBuffer )
405  {
406  QgsFeatureId fid = masterModel()->rowToId( sourceRow );
407 
408  if ( editBuffer->isFeatureAdded( fid ) )
409  return true;
410 
411  if ( editBuffer->isFeatureAttributesChanged( fid ) )
412  return true;
413 
414  if ( editBuffer->isFeatureGeometryChanged( fid ) )
415  return true;
416 
417  return false;
418  }
419  return false;
420  }
421 
422  default:
423  Q_ASSERT( false ); // In debug mode complain
424  return true; // In release mode accept row
425  }
426  // returns are handled in their respective case statement above
427 }
428 
430 {
431  reloadVisible();
432 }
433 
434 void QgsAttributeTableFilterModel::reloadVisible()
435 {
437  invalidateFilter();
438  emit visibleReloaded();
439 }
440 
441 void QgsAttributeTableFilterModel::onAttributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value )
442 {
443  Q_UNUSED( fid );
444  Q_UNUSED( value );
445 
446  if ( mFilterExpression.referencedAttributeIndexes( layer()->fields() ).contains( idx ) )
447  {
448  startTimedFilterFeatures();
449  }
450 }
451 
452 void QgsAttributeTableFilterModel::onGeometryChanged()
453 {
454  if ( mFilterExpression.needsGeometry() )
455  {
456  startTimedFilterFeatures();
457  }
458 }
459 
460 void QgsAttributeTableFilterModel::startTimedReloadVisible()
461 {
462  mReloadVisibleTimer.start( 10 );
463 }
464 
465 void QgsAttributeTableFilterModel::startTimedFilterFeatures()
466 {
467  mFilterFeaturesTimer.start( 10 );
468 }
469 
471 {
472  if ( !mFilterExpression.isValid() )
473  return;
474 
476  QgsDistanceArea distanceArea;
477 
478  distanceArea.setSourceCrs( mTableModel->layer()->crs(), QgsProject::instance()->transformContext() );
479  distanceArea.setEllipsoid( QgsProject::instance()->ellipsoid() );
480 
481  const bool fetchGeom = mFilterExpression.needsGeometry();
482 
483  QApplication::setOverrideCursor( Qt::WaitCursor );
484 
485  mFilterExpression.setGeomCalculator( &distanceArea );
486  mFilterExpression.setDistanceUnits( QgsProject::instance()->distanceUnits() );
487  mFilterExpression.setAreaUnits( QgsProject::instance()->areaUnits() );
488  QgsFeatureRequest request( mTableModel->request() );
489  request.setSubsetOfAttributes( mFilterExpression.referencedColumns(), mTableModel->layer()->fields() );
490  if ( !fetchGeom )
491  {
493  }
494  else
495  {
496  // force geometry extraction if the filter requests it
497  request.setFlags( request.flags() & ~QgsFeatureRequest::NoGeometry );
498  }
499  QgsFeatureIterator featIt = mTableModel->layer()->getFeatures( request );
500 
501  QgsFeature f;
502 
503  while ( featIt.nextFeature( f ) )
504  {
505  mFilterExpressionContext.setFeature( f );
506  if ( mFilterExpression.evaluate( &mFilterExpressionContext ).toInt() != 0 )
507  filteredFeatures << f.id();
508 
509  // check if there were errors during evaluating
510  if ( mFilterExpression.hasEvalError() )
511  break;
512  }
513 
514  featIt.close();
515 
517 
518  QApplication::restoreOverrideCursor();
519 
520  emit featuresFiltered();
521 }
522 
523 
524 void QgsAttributeTableFilterModel::selectionChanged()
525 {
526  if ( ShowSelected == mFilterMode )
527  {
528  invalidateFilter();
529  }
530  else if ( mSelectedOnTop )
531  {
532  invalidate();
533  }
534 }
535 
536 void QgsAttributeTableFilterModel::onColumnsChanged()
537 {
538  setAttributeTableConfig( mConfig );
539 }
540 
541 int QgsAttributeTableFilterModel::mapColumnToSource( int column ) const
542 {
543  if ( mColumnMapping.isEmpty() )
544  return column;
545  if ( column < 0 || column >= mColumnMapping.size() )
546  return -1;
547  else
548  return mColumnMapping.at( column );
549 }
550 
551 int QgsAttributeTableFilterModel::mapColumnFromSource( int column ) const
552 {
553  if ( mColumnMapping.isEmpty() )
554  return column;
555  else
556  return mColumnMapping.indexOf( column );
557 }
558 
560 {
561  if ( !layer() )
562  return;
563 
564  bool filter = false;
565  QgsRectangle rect = mCanvas->mapSettings().mapToLayerCoordinates( layer(), mCanvas->extent() );
566  QgsRenderContext renderContext;
568 
569  mFilteredFeatures.clear();
570  if ( !layer()->renderer() )
571  {
572  QgsDebugMsg( QStringLiteral( "Cannot get renderer" ) );
573  return;
574  }
575 
576  std::unique_ptr< QgsFeatureRenderer > renderer( layer()->renderer()->clone() );
577 
578  const QgsMapSettings &ms = mCanvas->mapSettings();
579  if ( !layer()->isInScaleRange( ms.scale() ) )
580  {
581  QgsDebugMsg( QStringLiteral( "Out of scale limits" ) );
582  }
583  else
584  {
585  if ( renderer->capabilities() & QgsFeatureRenderer::ScaleDependent )
586  {
587  // setup scale
588  // mapRenderer()->renderContext()->scale is not automatically updated when
589  // render extent changes (because it's scale is used to identify if changed
590  // since last render) -> use local context
591  renderContext.setExtent( ms.visibleExtent() );
592  renderContext.setMapToPixel( ms.mapToPixel() );
593  renderContext.setRendererScale( ms.scale() );
594  }
595 
596  filter = renderer->capabilities() & QgsFeatureRenderer::Filter;
597  }
598 
599  renderer->startRender( renderContext, layer()->fields() );
600 
601  QgsFeatureRequest r( masterModel()->request() );
602  if ( !r.filterRect().isNull() )
603  {
604  r.setFilterRect( r.filterRect().intersect( rect ) );
605  }
606  else
607  {
608  r.setFilterRect( rect );
609  }
611 
612  QgsFeature f;
613 
614  while ( features.nextFeature( f ) )
615  {
616  renderContext.expressionContext().setFeature( f );
617  if ( !filter || renderer->willRenderFeature( f, renderContext ) )
618  {
619  mFilteredFeatures << f.id();
620  }
621 #if 0
622  if ( t.elapsed() > 5000 )
623  {
624  bool cancel = false;
625  emit progress( i, cancel );
626  if ( cancel )
627  break;
628 
629  t.restart();
630  }
631 #endif
632  }
633 
634  features.close();
635 
636  if ( renderer->capabilities() & QgsFeatureRenderer::ScaleDependent )
637  {
638  renderer->stopRender( renderContext );
639  }
640 }
641 
643 {
644  return masterModel()->rowToId( mapToSource( row ).row() );
645 }
646 
648 {
649  return mapFromMaster( masterModel()->idToIndex( fid ) );
650 }
651 
653 {
654  QModelIndexList indexes;
655  const auto constIdToIndexList = masterModel()->idToIndexList( fid );
656  for ( const QModelIndex &idx : constIdToIndexList )
657  {
658  indexes.append( mapFromMaster( idx ) );
659  }
660 
661  return indexes;
662 }
663 
664 QModelIndex QgsAttributeTableFilterModel::mapToSource( const QModelIndex &proxyIndex ) const
665 {
666  if ( !proxyIndex.isValid() )
667  return QModelIndex();
668 
669  int sourceColumn = mapColumnToSource( proxyIndex.column() );
670 
671  // For the action column there is no matching column in the source model, just return the first one
672  // so we are still able to query for the feature id, the feature...
673  if ( sourceColumn == -1 )
674  sourceColumn = 0;
675 
676  return QSortFilterProxyModel::mapToSource( index( proxyIndex.row(), sourceColumn, proxyIndex.parent() ) );
677 }
678 
679 QModelIndex QgsAttributeTableFilterModel::mapFromSource( const QModelIndex &sourceIndex ) const
680 {
681  QModelIndex proxyIndex = QSortFilterProxyModel::mapFromSource( sourceIndex );
682 
683  if ( proxyIndex.column() < 0 )
684  return QModelIndex();
685 
686  int col = mapColumnFromSource( proxyIndex.column() );
687 
688  if ( col == -1 )
689  col = 0;
690 
691  return index( proxyIndex.row(), col, proxyIndex.parent() );
692 }
693 
694 Qt::ItemFlags QgsAttributeTableFilterModel::flags( const QModelIndex &index ) const
695 {
696  // Handle the action column flags here, the master model doesn't know it
697  if ( mapColumnToSource( index.column() ) == -1 )
698  return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
699 
700  QModelIndex source_index = mapToSource( index );
701  return masterModel()->flags( source_index );
702 }
QgsFeatureRequest::NoGeometry
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
Definition: qgsfeaturerequest.h:107
QgsAttributeTableConfig::sortOrder
Qt::SortOrder sortOrder() const
Gets the sort order.
Definition: qgsattributetableconfig.cpp:233
QgsVectorLayer::getFeatures
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
Definition: qgsvectorlayer.cpp:993
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
QgsMapLayer::crs
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:88
QgsVectorLayer::editBuffer
Q_INVOKABLE QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on.
Definition: qgsvectorlayer.h:1942
QgsAttributeTableFilterModel::ShowAll
@ ShowAll
Show all features.
Definition: qgsattributetablefiltermodel.h:46
qgsexpressioncontextutils.h
QgsFeatureRenderer::Filter
@ Filter
Features may be filtered, i.e. some features may not be rendered (categorized, rule based ....
Definition: qgsrenderer.h:256
QgsVectorLayerEditBuffer::isFeatureAttributesChanged
bool isFeatureAttributesChanged(QgsFeatureId id) const
Returns true if the specified feature ID has had an attribute changed but not committed.
Definition: qgsvectorlayereditbuffer.h:138
QgsExpressionContext::appendScopes
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
Definition: qgsexpressioncontext.cpp:495
QgsMapCanvas::extent
QgsRectangle extent() const
Returns the current zoom extent of the map canvas.
Definition: qgsmapcanvas.cpp:1049
QgsAttributeTableConfig::sortExpression
QString sortExpression() const
Gets the expression used for sorting.
Definition: qgsattributetableconfig.cpp:198
QgsMapSettings::mapToLayerCoordinates
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer's CRS
Definition: qgsmapsettings.cpp:516
QgsAttributeTableModel::idToIndexList
QModelIndexList idToIndexList(QgsFeatureId id) const
Definition: qgsattributetablemodel.cpp:547
QgsExpression::setDistanceUnits
void setDistanceUnits(QgsUnitTypes::DistanceUnit unit)
Sets the desired distance units for calculations involving geomCalculator(), e.g.,...
Definition: qgsexpression.cpp:415
QgsAttributeTableFilterModel::sortExpression
QString sortExpression() const
The expression which is used to sort the attribute table.
Definition: qgsattributetablefiltermodel.cpp:257
QgsRenderContext::expressionContext
QgsExpressionContext & expressionContext()
Gets the expression context.
Definition: qgsrendercontext.h:580
QgsAttributeTableFilterModel::visibleReloaded
void visibleReloaded()
Emitted when the the visible features on extend are reloaded (the list is created)
qgsmapcanvas.h
QgsExpression::referencedColumns
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
Definition: qgsexpression.cpp:217
QgsAttributeTableFilterModel::connectFilterModeConnections
void connectFilterModeConnections(FilterMode filterMode)
Disconnect the connections set for the new filterMode.
Definition: qgsattributetablefiltermodel.cpp:361
QgsMapCanvas::mapSettings
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
Definition: qgsmapcanvas.cpp:390
qgsVariantLessThan
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:121
QgsFeatureRequest::flags
const Flags & flags() const
Definition: qgsfeaturerequest.h:516
QgsFeatureRequest::filterRect
const QgsRectangle & filterRect() const
Returns the rectangle from which features will be taken.
Definition: qgsfeaturerequest.h:348
QgsAttributeTableFilterModel::setSourceModel
void setSourceModel(QgsAttributeTableModel *sourceModel)
Set the attribute table model that backs this model.
Definition: qgsattributetablefiltermodel.cpp:282
QgsAttributeTableFilterModel::ShowFilteredList
@ ShowFilteredList
Show only features whose ids are on the filter list. {.
Definition: qgsattributetablefiltermodel.h:49
QgsAttributeTableFilterModel::extentsChanged
Q_DECL_DEPRECATED void extentsChanged()
Is called upon every change of the visible extents on the map canvas.
Definition: qgsattributetablefiltermodel.cpp:429
qgsfeatureiterator.h
QgsExpression::referencedAttributeIndexes
QSet< int > referencedAttributeIndexes(const QgsFields &fields) const
Returns a list of field name indexes obtained from the provided fields.
Definition: qgsexpression.cpp:241
QgsMapCanvas
Definition: qgsmapcanvas.h:83
QgsExpression::isValid
bool isValid() const
Checks if this expression is valid.
Definition: qgsexpression.cpp:197
QgsAttributeTableConfig::ColumnConfig
Defines the configuration of a column in the attribute table.
Definition: qgsattributetableconfig.h:52
qgsfeature.h
QgsAttributeTableFilterModel::sort
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder) override
Sort by the given column using the given order.
Definition: qgsattributetablefiltermodel.cpp:77
QgsProject::transformContext
QgsCoordinateTransformContext transformContext
Definition: qgsproject.h:99
qgis.h
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:458
QgsAttributeTableFilterModel::ShowEdited
@ ShowEdited
Show only features which have unsaved changes.
Definition: qgsattributetablefiltermodel.h:50
QgsExpressionContextUtils::globalProjectLayerScopes
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Definition: qgsexpressioncontextutils.cpp:306
QgsFeatureRequest::setSubsetOfAttributes
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
Definition: qgsfeaturerequest.cpp:190
QgsVectorLayerCache::getFeatures
QgsFeatureIterator getFeatures(const QgsFeatureRequest &featureRequest=QgsFeatureRequest())
Query this VectorLayerCache for features.
Definition: qgsvectorlayercache.cpp:378
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsRectangle::intersect
QgsRectangle intersect(const QgsRectangle &rect) const
Returns the intersection with the given rectangle.
Definition: qgsrectangle.h:312
QgsAttributeTableFilterModel::filteredFeatures
QgsFeatureIds filteredFeatures()
Gets a list of currently filtered feature ids.
Definition: qgsattributetablefiltermodel.cpp:316
QgsRectangle
Definition: qgsrectangle.h:41
QgsAttributeTableFilterModel::columnCount
int columnCount(const QModelIndex &parent) const override
Definition: qgsattributetablefiltermodel.cpp:138
QgsAttributeTableFilterModel::ColumnTypeField
@ ColumnTypeField
This column shows a field.
Definition: qgsattributetablefiltermodel.h:59
QgsVectorLayerEditBuffer::isFeatureGeometryChanged
bool isFeatureGeometryChanged(QgsFeatureId id) const
Returns true if the specified feature ID has had its geometry changed but not committed.
Definition: qgsvectorlayereditbuffer.h:171
QgsExpression::setAreaUnits
void setAreaUnits(QgsUnitTypes::AreaUnit unit)
Sets the desired areal units for calculations involving geomCalculator(), e.g., "$area".
Definition: qgsexpression.cpp:425
qgsapplication.h
QgsFeatureRequest::setFilterRect
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
Definition: qgsfeaturerequest.cpp:97
QgsExpression::setGeomCalculator
void setGeomCalculator(const QgsDistanceArea *calc)
Sets the geometry calculator used for distance and area calculations in expressions.
Definition: qgsexpression.cpp:314
QgsAttributeTableConfig
Definition: qgsattributetableconfig.h:36
QgsVectorLayer::fields
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Definition: qgsvectorlayer.cpp:3280
QgsFeature::id
QgsFeatureId id
Definition: qgsfeature.h:68
QgsDistanceArea::setEllipsoid
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
Definition: qgsdistancearea.cpp:66
QgsFeatureRequest
Definition: qgsfeaturerequest.h:75
QgsExpression::hasEvalError
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
Definition: qgsexpression.cpp:374
QgsAttributeTableModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Returns item flags for the index.
Definition: qgsattributetablemodel.cpp:764
QgsAttributeTableFilterModel::featuresFiltered
void featuresFiltered()
Emitted when the filtering of the features has been done.
QgsAttributeTableConfig::Action
@ Action
This column represents an action widget.
Definition: qgsattributetableconfig.h:46
QgsVectorLayer::selectionChanged
void selectionChanged(const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect)
Emitted when selection was changed.
QgsAttributeTableModel::rowToId
QgsFeatureId rowToId(int row) const
Maps row to feature id.
Definition: qgsattributetablemodel.cpp:562
QgsAttributeTableFilterModel::generateListOfVisibleFeatures
void generateListOfVisibleFeatures()
Updates the list of currently visible features on the map canvas.
Definition: qgsattributetablefiltermodel.cpp:559
QgsFeatureIterator::close
bool close()
Definition: qgsfeatureiterator.h:386
QgsAttributeTableFilterModel::sortColumnChanged
void sortColumnChanged(int column, Qt::SortOrder order)
Emitted whenever the sort column is changed.
QgsRenderContext::setExtent
void setExtent(const QgsRectangle &extent)
When rendering a map layer, calling this method sets the "clipping" extent for the layer (in the laye...
Definition: qgsrendercontext.h:418
QgsAttributeTableFilterModel::layer
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
Definition: qgsattributetablefiltermodel.h:150
QgsAttributeTableFilterModel::fidToIndexList
QModelIndexList fidToIndexList(QgsFeatureId fid)
Definition: qgsattributetablefiltermodel.cpp:652
QgsAttributeTableModel
Is able to generate editor widgets for its QModelIndexes as well. Is mostly referred to as "master mo...
Definition: qgsattributetablemodel.h:49
QgsVectorLayer::attributeValueChanged
void attributeValueChanged(QgsFeatureId fid, int idx, const QVariant &value)
Emitted whenever an attribute value change is done in the edit buffer.
qgsattributetablefiltermodel.h
QgsAttributeTableConfig::columns
QVector< QgsAttributeTableConfig::ColumnConfig > columns() const
Gets the list with all columns and their configuration.
Definition: qgsattributetableconfig.cpp:20
QgsVectorLayer::selectedFeatureIds
const Q_INVOKABLE QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in this layer.
Definition: qgsvectorlayer.cpp:3433
QgsMapCanvas::extentsChanged
void extentsChanged()
Emitted when the extents of the map change.
QgsAttributeTableFilterModel::setAttributeTableConfig
void setAttributeTableConfig(const QgsAttributeTableConfig &config)
Set the attribute table configuration to control which fields are shown, in which order they are show...
Definition: qgsattributetablefiltermodel.cpp:144
QgsAttributeTableFilterModel::fidToIndex
QModelIndex fidToIndex(QgsFeatureId fid) override
Definition: qgsattributetablefiltermodel.cpp:647
QgsAttributeTableFilterModel::masterModel
QgsAttributeTableModel * masterModel() const
Returns the table model this filter is using.
Definition: qgsattributetablefiltermodel.h:164
QgsRenderContext::setMapToPixel
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
Definition: qgsrendercontext.h:404
QgsAttributeTableModel::prefetchSortData
void prefetchSortData(const QString &expression, unsigned long cacheIndex=0)
Prefetches the entire data for an expression.
Definition: qgsattributetablemodel.cpp:877
QgsAttributeTableFilterModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: qgsattributetablefiltermodel.cpp:694
QgsAttributeTableFilterModel::setSelectedOnTop
void setSelectedOnTop(bool selectedOnTop)
Changes the sort order of the features.
Definition: qgsattributetablefiltermodel.cpp:262
QgsAttributeTableFilterModel::rowToId
QgsFeatureId rowToId(const QModelIndex &row)
Returns the feature id for a given model index.
Definition: qgsattributetablefiltermodel.cpp:642
QgsAttributeTableFilterModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition: qgsattributetablefiltermodel.cpp:94
QgsMapSettings::scale
double scale() const
Returns the calculated map scale.
Definition: qgsmapsettings.cpp:395
qgsattributetablemodel.h
QgsAttributeTableModel::extraColumns
int extraColumns() const
Empty extra columns to announce from this model.
Definition: qgsattributetablemodel.cpp:94
QgsAttributeTableModel::layer
QgsVectorLayer * layer() const
Returns the layer this model uses as backend.
Definition: qgsattributetablemodel.h:168
qgsrenderer.h
QgsDistanceArea::setSourceCrs
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
Definition: qgsdistancearea.cpp:60
QgsAttributeTableFilterModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Definition: qgsattributetablefiltermodel.cpp:112
QgsAttributeTableModel::prefetchColumnData
void prefetchColumnData(int column)
Caches the entire data for one column.
Definition: qgsattributetablemodel.cpp:865
QgsAttributeTableFilterModel::TypeRole
@ TypeRole
The type of a given column.
Definition: qgsattributetablefiltermodel.h:71
QgsAttributeTableFilterModel::filterAcceptsRow
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Returns true if the source row will be accepted.
Definition: qgsattributetablefiltermodel.cpp:384
QgsFeatureIds
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:34
QgsAttributeTableFilterModel::selectedOnTop
bool selectedOnTop()
Returns if selected features are currently shown on top.
Definition: qgsattributetablefiltermodel.cpp:304
QgsExpression::evaluate
QVariant evaluate()
Evaluate the feature and return the result.
Definition: qgsexpression.cpp:346
QgsAttributeTableModel::sortCacheExpression
QString sortCacheExpression(unsigned long cacheIndex=0) const
The expression which was used to fill the sorting cache at index cacheIndex.
Definition: qgsattributetablemodel.cpp:948
QgsRenderContext::setRendererScale
void setRendererScale(double scale)
Sets the renderer map scale.
Definition: qgsrendercontext.h:467
qgsvectorlayer.h
QgsAttributeTableModel::FeatureIdRole
@ FeatureIdRole
Get the feature id of the feature in this row.
Definition: qgsattributetablemodel.h:56
QgsAttributeTableFilterModel::setFilterMode
void setFilterMode(FilterMode filterMode)
Set the filter mode the filter will use.
Definition: qgsattributetablefiltermodel.cpp:328
QgsAttributeTableFilterModel::disconnectFilterModeConnections
void disconnectFilterModeConnections()
Disconnect the connections set for the current filterMode.
Definition: qgsattributetablefiltermodel.cpp:339
QgsVectorLayerEditBuffer::isFeatureAdded
bool isFeatureAdded(QgsFeatureId id) const
Returns true if the specified feature ID has been added but not committed.
Definition: qgsvectorlayereditbuffer.h:124
QgsAttributeTableFilterModel::mapToSource
QModelIndex mapToSource(const QModelIndex &proxyIndex) const override
Definition: qgsattributetablefiltermodel.cpp:664
QgsAttributeTableFilterModel::mapFromMaster
QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
Definition: qgsattributetablefiltermodel.h:181
QgsAttributeTableFilterModel::ColumnTypeActionButton
@ ColumnTypeActionButton
This column shows action buttons.
Definition: qgsattributetablefiltermodel.h:60
QgsAttributeTableFilterModel::ShowSelected
@ ShowSelected
Show only selected features.
Definition: qgsattributetablefiltermodel.h:47
QgsAttributeTableFilterModel::mapFromSource
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
Definition: qgsattributetablefiltermodel.cpp:679
QgsFeatureIterator::nextFeature
bool nextFeature(QgsFeature &f)
Definition: qgsfeatureiterator.h:373
QgsAttributeTableFilterModel::setFilterExpression
void setFilterExpression(const QgsExpression &expression, const QgsExpressionContext &context)
Set the expression and the context to be stored in case of the features need to be filtered again (li...
Definition: qgsattributetablefiltermodel.cpp:241
QgsVectorLayerEditBuffer
Definition: qgsvectorlayereditbuffer.h:36
QgsAttributeTableFilterModel::filterFeatures
void filterFeatures()
Updates the filtered features in the filter model.
Definition: qgsattributetablefiltermodel.cpp:470
QgsFeatureRenderer::ScaleDependent
@ ScaleDependent
Depends on scale if feature will be rendered (rule based )
Definition: qgsrenderer.h:257
QgsVectorLayer::geometryChanged
void geometryChanged(QgsFeatureId fid, const QgsGeometry &geometry)
Emitted whenever a geometry change is done in the edit buffer.
QgsAttributeTableFilterModel::lessThan
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
Used by the sorting algorithm.
Definition: qgsattributetablefiltermodel.cpp:50
QgsAttributeTableFilterModel::QgsAttributeTableFilterModel
QgsAttributeTableFilterModel(QgsMapCanvas *canvas, QgsAttributeTableModel *sourceModel, QObject *parent=nullptr)
Make sure, the master model is already loaded, so the selection will get synchronized.
Definition: qgsattributetablefiltermodel.cpp:35
QgsAttributeTableFilterModel::setFilteredFeatures
virtual void setFilteredFeatures(const QgsFeatureIds &ids)
Specify a list of features, which the filter will accept.
Definition: qgsattributetablefiltermodel.cpp:309
QgsAttributeTableFilterModel::actionColumnIndex
int actionColumnIndex() const
Gets the index of the first column that contains an action widget.
Definition: qgsattributetablefiltermodel.cpp:133
QgsExpression::needsGeometry
bool needsGeometry() const
Returns true if the expression uses feature geometry for some computation.
Definition: qgsexpression.cpp:266
QgsDistanceArea
Definition: qgsdistancearea.h:49
QgsFeature
Definition: qgsfeature.h:55
QgsAttributeTableFilterModel::filterMode
FilterMode filterMode()
The current filterModel.
Definition: qgsattributetablefiltermodel.h:143
QgsAttributeTableModel::SortRole
@ SortRole
Role used for sorting start here.
Definition: qgsattributetablemodel.h:60
qgslogger.h
QgsAttributeTableModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of columns.
Definition: qgsattributetablemodel.cpp:590
QgsFields::lookupField
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
Definition: qgsfields.cpp:324
QgsAttributeTableModel::request
const QgsFeatureRequest & request() const
Gets the the feature request.
Definition: qgsattributetablemodel.cpp:972
QgsExpression
Definition: qgsexpression.h:113
QgsMapSettings
Definition: qgsmapsettings.h:86
QgsMapSettings::visibleExtent
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
Definition: qgsmapsettings.cpp:370
QgsAttributeTableConfig::hasSameColumns
bool hasSameColumns(const QgsAttributeTableConfig &other) const
Compare this configuration's columns name, type, and order to other.
Definition: qgsattributetableconfig.cpp:288
QgsAttributeTableFilterModel::FilterMode
FilterMode
The filter mode defines how the rows should be filtered.
Definition: qgsattributetablefiltermodel.h:44
QgsFeatureIterator
Definition: qgsfeatureiterator.h:263
QgsFeatureRequest::setFlags
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
Definition: qgsfeaturerequest.cpp:184
QgsMapSettings::mapToPixel
const QgsMapToPixel & mapToPixel() const
Definition: qgsmapsettings.h:433
QgsRectangle::isNull
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Definition: qgsrectangle.h:447
qgsvectorlayereditbuffer.h
QgsAttributeTableModel::layerCache
QgsVectorLayerCache * layerCache() const
Returns the layer cache this model uses as backend.
Definition: qgsattributetablemodel.h:173
QgsAttributeTableFilterModel::ShowVisible
@ ShowVisible
Show only visible features (depends on the map canvas)
Definition: qgsattributetablefiltermodel.h:48
QgsFeatureId
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25
QgsExpressionContext::setFeature
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Definition: qgsexpressioncontext.cpp:521
QgsAttributeTableConfig::update
void update(const QgsFields &fields)
Update the configuration with the given fields.
Definition: qgsattributetableconfig.cpp:50
QgsVectorLayer::featureAdded
void featureAdded(QgsFeatureId fid)
Emitted when a new feature has been added to the layer.