QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsfeaturepickermodelbase.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfeaturepickermodelbase.cpp - QgsFeaturePickerModelBase
3  ---------------------
4  begin : 10.3.2017
5  copyright : (C) 2017 by Matthias Kuhn
6  email : [email protected]
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 
18 
19 #include "qgsvectorlayer.h"
20 #include "qgsconditionalstyle.h"
21 #include "qgsapplication.h"
22 #include "qgssettings.h"
24 
26  : QAbstractItemModel( parent )
27 {
28  mReloadTimer.setInterval( 100 );
29  mReloadTimer.setSingleShot( true );
30  connect( &mReloadTimer, &QTimer::timeout, this, &QgsFeaturePickerModelBase::scheduledReload );
31 
32  // The fact that the feature changed is a combination of the 2 signals:
33  // If the extra value is set to a feature currently not fetched, it will go through an intermediate step while the extra value does not exist (as it call reloadFeature)
36 }
37 
38 
40 {
41  if ( mGatherer )
42  connect( mGatherer, &QgsFeatureExpressionValuesGatherer::finished, mGatherer, &QgsFeatureExpressionValuesGatherer::deleteLater );
43 }
44 
45 
47 {
48  return mSourceLayer;
49 }
50 
51 
53 {
54  if ( mSourceLayer == sourceLayer )
55  return;
56 
57  mSourceLayer = sourceLayer;
58  if ( mSourceLayer )
59  mExpressionContext = mSourceLayer->createExpressionContext();
60 
61  reload();
62  emit sourceLayerChanged();
63 
64  if ( mSourceLayer )
65  setDisplayExpression( mSourceLayer->displayExpression() );
66 }
67 
68 
70 {
71  return mDisplayExpression.expression();
72 }
73 
74 
75 void QgsFeaturePickerModelBase::setDisplayExpression( const QString &displayExpression )
76 {
77  if ( mDisplayExpression.expression() == displayExpression )
78  return;
79 
80  mDisplayExpression = QgsExpression( displayExpression );
81  reload();
83 }
84 
85 
87 {
88  return mFilterValue;
89 }
90 
91 
92 void QgsFeaturePickerModelBase::setFilterValue( const QString &filterValue )
93 {
94  if ( mFilterValue == filterValue )
95  return;
96 
97  mFilterValue = filterValue;
98  reload();
99  emit filterValueChanged();
100 }
101 
102 
104 {
105  return mFilterExpression;
106 }
107 
108 
109 void QgsFeaturePickerModelBase::setFilterExpression( const QString &filterExpression )
110 {
111  if ( mFilterExpression == filterExpression )
112  return;
113 
114  mFilterExpression = filterExpression;
115  reload();
117 }
118 
119 
121 {
122  return mGatherer;
123 }
124 
126 {
127  return mExtraIdentifierValue;
128 }
129 
130 
131 QModelIndex QgsFeaturePickerModelBase::index( int row, int column, const QModelIndex &parent ) const
132 {
133  Q_UNUSED( parent )
134  return createIndex( row, column, nullptr );
135 }
136 
137 
138 QModelIndex QgsFeaturePickerModelBase::parent( const QModelIndex &child ) const
139 {
140  Q_UNUSED( child )
141  return QModelIndex();
142 }
143 
144 
145 int QgsFeaturePickerModelBase::rowCount( const QModelIndex &parent ) const
146 {
147  Q_UNUSED( parent )
148  return mEntries.size();
149 }
150 
151 
152 
153 QVariant QgsFeaturePickerModelBase::data( const QModelIndex &index, int role ) const
154 {
155  if ( !index.isValid() )
156  return QVariant();
157 
158  switch ( role )
159  {
160  case Qt::DisplayRole:
161  case Qt::EditRole:
162  case ValueRole:
163  return mEntries.value( index.row() ).value;
164 
165  case FeatureIdRole:
166  return mEntries.value( index.row() ).featureId;
167 
168  case FeatureRole:
169  return mEntries.value( index.row() ).feature;
170 
171  case IdentifierValueRole:
172  {
173  const QVariantList values = mEntries.value( index.row() ).identifierFields;
174  return values.value( 0 );
175  }
176 
178  return mEntries.value( index.row() ).identifierFields;
179 
180 #if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
181  case Qt::BackgroundColorRole:
182  case Qt::TextColorRole:
183 #else
184  case Qt::BackgroundRole:
185  case Qt::ForegroundRole:
186 #endif
187  case Qt::DecorationRole:
188  case Qt::FontRole:
189  {
190  const bool isNull = identifierIsNull( entryIdentifier( mEntries.value( index.row() ) ) );
191  if ( isNull )
192  {
193  // Representation for NULL value
194 #if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
195  if ( role == Qt::TextColorRole )
196 #else
197  if ( role == Qt::ForegroundRole )
198 #endif
199  {
200  return QBrush( QColor( Qt::gray ) );
201  }
202  if ( role == Qt::FontRole )
203  {
204  QFont font = QFont();
205  if ( index.row() == mExtraValueIndex )
206  font.setBold( true );
207  else
208  font.setItalic( true );
209  return font;
210  }
211  }
212  else
213  {
214  // Respect conditional style
215  const QgsConditionalStyle style = featureStyle( mEntries.value( index.row() ).feature );
216 
217  if ( style.isValid() )
218  {
219 #if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
220  if ( role == Qt::BackgroundColorRole && style.validBackgroundColor() )
221 #else
222  if ( role == Qt::BackgroundRole && style.validBackgroundColor() )
223 #endif
224  return style.backgroundColor();
225 #if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
226  if ( role == Qt::TextColorRole && style.validTextColor() )
227 #else
228  if ( role == Qt::ForegroundRole && style.validTextColor() )
229 #endif
230  return style.textColor();
231  if ( role == Qt::DecorationRole )
232  return style.icon();
233  if ( role == Qt::FontRole )
234  return style.font();
235  }
236  }
237  break;
238  }
239  }
240 
241  return QVariant();
242 }
243 
244 
245 void QgsFeaturePickerModelBase::updateCompleter()
246 {
247  emit beginUpdate();
248 
249  QgsFeatureExpressionValuesGatherer *gatherer = qobject_cast<QgsFeatureExpressionValuesGatherer *>( sender() );
250  if ( gatherer->wasCanceled() )
251  {
252  delete gatherer;
253  return;
254  }
255 
256  QVector<QgsFeatureExpressionValuesGatherer::Entry> entries = mGatherer->entries();
257 
258  if ( mExtraValueIndex == -1 )
259  {
261  }
262 
263  // Only reloading the current entry?
264  const bool reloadCurrentFeatureOnly = mGatherer->data().toBool();
265  if ( reloadCurrentFeatureOnly )
266  {
267  if ( !entries.isEmpty() )
268  {
269  mEntries.replace( mExtraValueIndex, entries.at( 0 ) );
270  emit dataChanged( index( mExtraValueIndex, 0, QModelIndex() ), index( mExtraValueIndex, 0, QModelIndex() ) );
271  mShouldReloadCurrentFeature = false;
272  setExtraValueDoesNotExist( false );
273  }
274  else
275  {
276  setExtraValueDoesNotExist( true );
277  }
278 
279  mKeepCurrentEntry = true;
280  mShouldReloadCurrentFeature = false;
281 
282  if ( mFilterValue.isEmpty() )
283  reload();
284  }
285  else
286  {
287  // We got strings for a filter selection
288  std::sort( entries.begin(), entries.end(), []( const QgsFeatureExpressionValuesGatherer::Entry & a, const QgsFeatureExpressionValuesGatherer::Entry & b ) { return a.value.localeAwareCompare( b.value ) < 0; } );
289 
290  if ( mAllowNull && mSourceLayer )
291  {
292  entries.prepend( QgsFeatureExpressionValuesGatherer::nullEntry( mSourceLayer ) );
293  }
294 
295  const int newEntriesSize = entries.size();
296 
297  // fixed entry is either NULL or extra value
298  const int nbFixedEntry = ( mKeepCurrentEntry ? 1 : 0 ) + ( mAllowNull ? 1 : 0 );
299 
300  // Find the index of the current entry in the new list
301  int currentEntryInNewList = -1;
302  if ( mExtraValueIndex != -1 && mExtraValueIndex < mEntries.count() )
303  {
304  for ( int i = 0; i < newEntriesSize; ++i )
305  {
306  if ( compareEntries( entries.at( i ), mEntries.at( mExtraValueIndex ) ) )
307  {
308  mEntries.replace( mExtraValueIndex, entries.at( i ) );
309  currentEntryInNewList = i;
310  setExtraValueDoesNotExist( false );
311  break;
312  }
313  }
314  }
315 
316  int firstRow = 0;
317 
318  // Move current entry to the first position if this is a fixed entry or because
319  // the entry exists in the new list
320  if ( mExtraValueIndex > -1 && ( mExtraValueIndex < nbFixedEntry || currentEntryInNewList != -1 ) )
321  {
322  if ( mExtraValueIndex != 0 )
323  {
324  beginMoveRows( QModelIndex(), mExtraValueIndex, mExtraValueIndex, QModelIndex(), 0 );
325  mEntries.move( mExtraValueIndex, 0 );
326  endMoveRows();
327  }
328  firstRow = 1;
329  }
330 
331  // Remove all entries (except for extra entry if existent)
332  beginRemoveRows( QModelIndex(), firstRow, mEntries.size() - firstRow );
333  mEntries.remove( firstRow, mEntries.size() - firstRow );
334 
335  // if we remove all rows before endRemoveRows, setExtraIdentifierValuesUnguarded will be called
336  // and a null value will be added to mEntries, so we block setExtraIdentifierValuesUnguarded call
337 
338  mIsSettingExtraIdentifierValue = true;
339  endRemoveRows();
340  mIsSettingExtraIdentifierValue = false;
341 
342  if ( currentEntryInNewList == -1 )
343  {
344  beginInsertRows( QModelIndex(), firstRow, entries.size() + 1 );
345  mEntries += entries;
346  endInsertRows();
347 
348  // if all entries have been cleaned (firstRow == 0)
349  // and there is a value in entries, prefer this value over NULL
350  // else chose the first one (the previous one)
351  setExtraIdentifierValueIndex( firstRow == 0 && mAllowNull && !entries.isEmpty() ? 1 : 0, firstRow == 0 );
352  }
353  else
354  {
355  if ( currentEntryInNewList != 0 )
356  {
357  beginInsertRows( QModelIndex(), 0, currentEntryInNewList - 1 );
358  mEntries = entries.mid( 0, currentEntryInNewList ) + mEntries;
359  endInsertRows();
360  }
361  else
362  {
363  mEntries.replace( 0, entries.at( 0 ) );
364  }
365 
366  // don't notify for a change if it's a fixed entry
367  if ( currentEntryInNewList >= nbFixedEntry )
368  {
369  emit dataChanged( index( currentEntryInNewList, 0, QModelIndex() ), index( currentEntryInNewList, 0, QModelIndex() ) );
370  }
371 
372  beginInsertRows( QModelIndex(), currentEntryInNewList + 1, newEntriesSize - currentEntryInNewList - 1 );
373  mEntries += entries.mid( currentEntryInNewList + 1 );
374  endInsertRows();
375  setExtraIdentifierValueIndex( currentEntryInNewList );
376  }
377 
378  emit filterJobCompleted();
379 
380  mKeepCurrentEntry = false;
381  }
382  emit endUpdate();
383 
384  // scheduleReload and updateCompleter lives in the same thread so if the gatherer hasn't been stopped
385  // (checked before), mGatherer still references the current gatherer
386  Q_ASSERT( gatherer == mGatherer );
387  delete mGatherer;
388  mGatherer = nullptr;
389  emit isLoadingChanged();
390 }
391 
392 
393 void QgsFeaturePickerModelBase::scheduledReload()
394 {
395  if ( !mSourceLayer )
396  return;
397 
398  bool wasLoading = false;
399 
400  if ( mGatherer )
401  {
402  mGatherer->stop();
403  wasLoading = true;
404  }
405 
406  QgsFeatureRequest request;
407 
408  if ( mShouldReloadCurrentFeature )
409  {
411  }
412  else
413  {
414  QString filterClause;
415 
416  if ( mFilterValue.isEmpty() && !mFilterExpression.isEmpty() )
417  filterClause = mFilterExpression;
418  else if ( mFilterExpression.isEmpty() && !mFilterValue.isEmpty() )
419  filterClause = QStringLiteral( "(%1) ILIKE '%%2%'" ).arg( mDisplayExpression, mFilterValue );
420  else if ( !mFilterExpression.isEmpty() && !mFilterValue.isEmpty() )
421  filterClause = QStringLiteral( "(%1) AND ((%2) ILIKE '%%3%')" ).arg( mFilterExpression, mDisplayExpression, mFilterValue );
422 
423  if ( !filterClause.isEmpty() )
424  {
425  request.setFilterExpression( filterClause );
427  }
428  }
429  QSet<QString> attributes = requestedAttributes();
430  if ( !attributes.isEmpty() )
431  {
432  if ( auto *lFilterExpression = request.filterExpression() )
433  attributes += lFilterExpression->referencedColumns();
434  attributes += requestedAttributesForStyle();
435 
436  request.setSubsetOfAttributes( attributes, mSourceLayer->fields() );
437  }
438 
439  if ( !mFetchGeometry )
441  if ( mFetchLimit > 0 )
442  request.setLimit( mFetchLimit );
443 
444  mGatherer = createValuesGatherer( request );
445  mGatherer->setData( mShouldReloadCurrentFeature );
446  connect( mGatherer, &QgsFeatureExpressionValuesGatherer::finished, this, &QgsFeaturePickerModelBase::updateCompleter );
447 
448  mGatherer->start();
449  if ( !wasLoading )
450  emit isLoadingChanged();
451 }
452 
453 
454 QSet<QString> QgsFeaturePickerModelBase::requestedAttributesForStyle() const
455 {
456  QSet<QString> requestedAttrs;
457 
458  const auto rowStyles = mSourceLayer->conditionalStyles()->rowStyles();
459 
460  for ( const QgsConditionalStyle &style : rowStyles )
461  {
462  const QgsExpression exp( style.rule() );
463  requestedAttrs += exp.referencedColumns();
464  }
465 
466  if ( mDisplayExpression.isField() )
467  {
468  const QString fieldName = *mDisplayExpression.referencedColumns().constBegin();
469  const auto constFieldStyles = mSourceLayer->conditionalStyles()->fieldStyles( fieldName );
470  for ( const QgsConditionalStyle &style : constFieldStyles )
471  {
472  const QgsExpression exp( style.rule() );
473  requestedAttrs += exp.referencedColumns();
474  }
475  }
476 
477  return requestedAttrs;
478 }
479 
480 
481 void QgsFeaturePickerModelBase::setExtraIdentifierValueIndex( int index, bool force )
482 {
483  if ( mExtraValueIndex == index && !force )
484  return;
485 
488 }
489 
490 
491 void QgsFeaturePickerModelBase::reloadCurrentFeature()
492 {
493  mShouldReloadCurrentFeature = true;
494  mReloadTimer.start();
495 }
496 
497 
498 void QgsFeaturePickerModelBase::setExtraIdentifierValueUnguarded( const QVariant &identifierValue )
499 {
500  const QVector<QgsFeatureExpressionValuesGatherer::Entry> entries = mEntries;
501 
502  int index = 0;
503  for ( const QgsFeatureExpressionValuesGatherer::Entry &entry : entries )
504  {
505  if ( compareEntries( entry, createEntry( identifierValue ) ) )
506  {
507  setExtraIdentifierValueIndex( index );
508  break;
509  }
510 
511  index++;
512  }
513 
514  // Value not found in current entries
515  if ( mExtraValueIndex != index )
516  {
517  const bool isNull = identifierIsNull( identifierValue );
518  if ( !isNull || mAllowNull )
519  {
520  beginInsertRows( QModelIndex(), 0, 0 );
521  if ( !isNull )
522  {
523  mEntries.prepend( createEntry( identifierValue ) );
524  setExtraValueDoesNotExist( true );
525  reloadCurrentFeature();
526  }
527  else
528  {
529  mEntries.prepend( QgsFeatureExpressionValuesGatherer::nullEntry( mSourceLayer ) );
530  setExtraValueDoesNotExist( false );
531  }
532  endInsertRows();
533 
534  setExtraIdentifierValueIndex( 0, true );
535  }
536  }
537 }
538 
539 
540 QgsConditionalStyle QgsFeaturePickerModelBase::featureStyle( const QgsFeature &feature ) const
541 {
542  if ( !mSourceLayer )
543  return QgsConditionalStyle();
544 
545  QgsVectorLayer *layer = mSourceLayer;
546  const QgsFeatureId fid = feature.id();
547  mExpressionContext.setFeature( feature );
548 
549  auto styles = QgsConditionalStyle::matchingConditionalStyles( layer->conditionalStyles()->rowStyles(), QVariant(), mExpressionContext );
550 
551  if ( mDisplayExpression.referencedColumns().count() == 1 )
552  {
553  // Style specific for this field
554  const QString fieldName = *mDisplayExpression.referencedColumns().constBegin();
555  const auto allStyles = layer->conditionalStyles()->fieldStyles( fieldName );
556  const auto matchingFieldStyles = QgsConditionalStyle::matchingConditionalStyles( allStyles, feature.attribute( fieldName ), mExpressionContext );
557 
558  styles += matchingFieldStyles;
559  }
560 
561  QgsConditionalStyle style;
562  style = QgsConditionalStyle::compressStyles( styles );
563  mEntryStylesMap.insert( fid, style );
564 
565  return style;
566 }
567 
568 
570 {
571  return mAllowNull;
572 }
573 
574 
576 {
577  if ( mAllowNull == allowNull )
578  return;
579 
580  mAllowNull = allowNull;
581  emit allowNullChanged();
582 
583  reload();
584 }
585 
587 {
588  return mFetchGeometry;
589 }
590 
592 {
593  if ( mFetchGeometry == fetchGeometry )
594  return;
595 
596  mFetchGeometry = fetchGeometry;
597  reload();
598 }
599 
601 {
602  return mFetchLimit;
603 }
604 
606 {
607  if ( fetchLimit == mFetchLimit )
608  return;
609 
610  mFetchLimit = fetchLimit;
611  emit fetchLimitChanged();
612 }
613 
614 
616 {
617  return mExtraValueDoesNotExist;
618 }
619 
620 
621 void QgsFeaturePickerModelBase::setExtraValueDoesNotExist( bool extraValueDoesNotExist )
622 {
623  if ( mExtraValueDoesNotExist == extraValueDoesNotExist )
624  return;
625 
626  mExtraValueDoesNotExist = extraValueDoesNotExist;
628 }
629 
630 
632 {
633  return mExtraValueIndex;
634 }
635 
636 
637 void QgsFeaturePickerModelBase::reload()
638 {
639  mReloadTimer.start();
640 }
641 
642 
643 void QgsFeaturePickerModelBase::setExtraIdentifierValue( const QVariant &extraIdentifierValue )
644 {
646  return;
647 
648  if ( mIsSettingExtraIdentifierValue )
649  return;
650 
651  mIsSettingExtraIdentifierValue = true;
652 
654 
656 
657  mIsSettingExtraIdentifierValue = false;
658 
660 }
661 
QgsFeatureRequest::NoGeometry
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
Definition: qgsfeaturerequest.h:115
QgsFeaturePickerModelBase::IdentifierValueRole
@ IdentifierValueRole
Definition: qgsfeaturepickermodelbase.h:65
QgsFeaturePickerModelBase::nullIdentifier
virtual QVariant nullIdentifier() const =0
Returns a null identifier.
qgsexpressioncontextutils.h
QgsExpressionContext::appendScopes
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
Definition: qgsexpressioncontext.cpp:499
qgsconditionalstyle.h
QgsFeaturePickerModelBase::isLoading
bool isLoading() const
Indicator if the model is currently performing any feature iteration in the background.
Definition: qgsfeaturepickermodelbase.cpp:120
QgsConditionalStyle::isValid
bool isValid() const
isValid Check if this rule is valid.
Definition: qgsconditionalstyle.h:252
QgsFeaturePickerModelBase::filterValue
QString filterValue
Definition: qgsfeaturepickermodelbase.h:51
QgsFeaturePickerModelBase::extraIdentifierValueIndex
int extraIdentifierValueIndex
Definition: qgsfeaturepickermodelbase.h:56
QgsFeaturePickerModelBase::displayExpressionChanged
void displayExpressionChanged()
The display expression will be used for.
QgsFeaturePickerModelBase::compareEntries
virtual bool compareEntries(const QgsFeatureExpressionValuesGatherer::Entry &a, const QgsFeatureExpressionValuesGatherer::Entry &b) const =0
Returns true if the 2 entries refers to the same feature.
QgsFeaturePickerModelBase::filterExpression
QString filterExpression
Definition: qgsfeaturepickermodelbase.h:52
QgsExpression::referencedColumns
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
Definition: qgsexpression.cpp:221
QgsFeaturePickerModelBase::IdentifierValuesRole
@ IdentifierValuesRole
Used to retrieve the identifierValues (primary keys) of a feature.
Definition: qgsfeaturepickermodelbase.h:66
QgsFeaturePickerModelBase::setExtraIdentifierValue
void setExtraIdentifierValue(const QVariant &extraIdentifierValue)
Allows specifying one value that does not need to match the filter criteria but will still be availab...
Definition: qgsfeaturepickermodelbase.cpp:643
qgsfeaturepickermodelbase.h
QgsExpressionContextUtils::globalProjectLayerScopes
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Definition: qgsexpressioncontextutils.cpp:377
QgsFeaturePickerModelBase::identifierIsNull
virtual bool identifierIsNull(const QVariant &identifier) const =0
Returns true if the entry is null The identifier can be either the feature ID or the list of identifi...
QgsFeatureRequest::setSubsetOfAttributes
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
Definition: qgsfeaturerequest.cpp:228
QgsFeaturePickerModelBase::setExtraIdentifierValueUnguarded
void setExtraIdentifierValueUnguarded(const QVariant &identifierValue)
This will set the identifier value to be set in the model even if it doesn't exist currently in the d...
Definition: qgsfeaturepickermodelbase.cpp:498
QgsFeaturePickerModelBase::ValueRole
@ ValueRole
Used to retrieve the displayExpression of a feature.
Definition: qgsfeaturepickermodelbase.h:67
QgsFeaturePickerModelBase::~QgsFeaturePickerModelBase
~QgsFeaturePickerModelBase() override
Definition: qgsfeaturepickermodelbase.cpp:39
QgsConditionalStyle
Conditional styling for a rule.
Definition: qgsconditionalstyle.h:120
QgsFeaturePickerModelBase::currentFeatureChanged
void currentFeatureChanged()
Emitted when the current feature in the model has changed This emitted both when the extra value chan...
QgsFeaturePickerModelBase::filterJobCompleted
void filterJobCompleted()
Indicates that a filter job has been completed and new data may be available.
QgsFeaturePickerModelBase::mExtraIdentifierValue
QVariant mExtraIdentifierValue
The current identifier value.
Definition: qgsfeaturepickermodelbase.h:337
QgsConditionalStyle::compressStyles
static QgsConditionalStyle compressStyles(const QList< QgsConditionalStyle > &styles)
Compress a list of styles into a single style.
Definition: qgsconditionalstyle.cpp:276
QgsFeatureRequest::expressionContext
QgsExpressionContext * expressionContext()
Returns the expression context used to evaluate filter expressions.
Definition: qgsfeaturerequest.h:581
QgsFeaturePickerModelBase::endUpdate
void endUpdate()
Notification that the model change is finished.
QgsFeaturePickerModelBase::QgsFeaturePickerModelBase
QgsFeaturePickerModelBase(QObject *parent=nullptr)
Create a new QgsFeaturePickerModelBase, optionally specifying a parent.
Definition: qgsfeaturepickermodelbase.cpp:25
QgsFeaturePickerModelBase::isLoadingChanged
void isLoadingChanged()
Indicator if the model is currently performing any feature iteration in the background.
QgsFeaturePickerModelBase::fetchGeometry
bool fetchGeometry
Definition: qgsfeaturepickermodelbase.h:54
QgsFeatureRequest::setFilterExpression
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
Definition: qgsfeaturerequest.cpp:167
qgsapplication.h
QgsFeaturePickerModelBase::allowNull
bool allowNull
Definition: qgsfeaturepickermodelbase.h:53
QgsVectorLayer::fields
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Definition: qgsvectorlayer.cpp:3436
QgsFeature::id
QgsFeatureId id
Definition: qgsfeature.h:68
QgsFeatureRequest
This class wraps a request for features to a vector layer (or directly its vector data provider).
Definition: qgsfeaturerequest.h:83
QgsFeaturePickerModelBase::createEntry
virtual QgsFeatureExpressionValuesGatherer::Entry createEntry(const QVariant &identifier) const =0
Creates an entry with just the identifier so the feature can be retrieved in a next iteration.
QgsConditionalStyle::icon
QPixmap icon() const
The icon set for style generated from the set symbol.
Definition: qgsconditionalstyle.h:200
QgsFeaturePickerModelBase::sourceLayer
QgsVectorLayer sourceLayer
Definition: qgsfeaturepickermodelbase.h:49
QgsFeaturePickerModelBase::mEntries
QVector< QgsFeatureExpressionValuesGatherer::Entry > mEntries
Definition: qgsfeaturepickermodelbase.h:333
QgsFeaturePickerModelBase::extraValueDoesNotExist
bool extraValueDoesNotExist() const
Flag indicating that the extraIdentifierValue does not exist in the data.
Definition: qgsfeaturepickermodelbase.cpp:615
qgsfeatureexpressionvaluesgatherer.h
QgsFeaturePickerModelBase::data
QVariant data(const QModelIndex &index, int role) const override
Definition: qgsfeaturepickermodelbase.cpp:153
QgsFeaturePickerModelBase::extraIdentifierValueIndexChanged
void extraIdentifierValueIndexChanged(int index)
The index at which the extra identifier value is available within the model.
QgsConditionalStyle::validBackgroundColor
bool validBackgroundColor() const
Check if the background color is valid for render.
Definition: qgsconditionalstyle.cpp:243
QgsConditionalStyle::backgroundColor
QColor backgroundColor() const
The background color for style.
Definition: qgsconditionalstyle.h:225
QgsFeatureRequest::filterExpression
QgsExpression * filterExpression() const
Returns the filter expression (if set).
Definition: qgsfeaturerequest.h:562
QgsFeaturePickerModelBase::extraValueDoesNotExistChanged
void extraValueDoesNotExistChanged()
Flag indicating that the extraIdentifierValue does not exist in the data.
QgsFeaturePickerModelBase::extraIdentifierValue
QVariant extraIdentifierValue() const
Allows specifying one value that does not need to match the filter criteria but will still be availab...
Definition: qgsfeaturepickermodelbase.cpp:125
QgsFeaturePickerModelBase::fetchLimitChanged
void fetchLimitChanged()
Emitted when the fetching limit for the feature request changes.
QgsFeaturePickerModelBase::index
QModelIndex index(int row, int column, const QModelIndex &parent) const override
Definition: qgsfeaturepickermodelbase.cpp:131
QgsFeaturePickerModelBase::requestedAttributes
virtual QSet< QString > requestedAttributes() const
Returns the attributes to be fetched in the request.
Definition: qgsfeaturepickermodelbase.h:310
QgsFeaturePickerModelBase::displayExpression
QString displayExpression
Definition: qgsfeaturepickermodelbase.h:50
QgsFeature::attribute
QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
Definition: qgsfeature.cpp:327
QgsFeaturePickerModelBase::requestToReloadCurrentFeature
virtual void requestToReloadCurrentFeature(QgsFeatureRequest &request)=0
Update the request to match the current feature to be reloaded.
QgsFeaturePickerModelBase::rowCount
int rowCount(const QModelIndex &parent) const override
Definition: qgsfeaturepickermodelbase.cpp:145
QgsConditionalStyle::matchingConditionalStyles
static QList< QgsConditionalStyle > matchingConditionalStyles(const QList< QgsConditionalStyle > &styles, const QVariant &value, QgsExpressionContext &context)
Find and return the matching styles for the value and feature.
Definition: qgsconditionalstyle.cpp:253
QgsFeaturePickerModelBase::setAllowNull
void setAllowNull(bool allowNull)
Add a NULL entry to the list.
Definition: qgsfeaturepickermodelbase.cpp:575
QgsConditionalStyle::font
QFont font() const
The font for the style.
Definition: qgsconditionalstyle.h:238
qgsvectorlayer.h
QgsFeaturePickerModelBase::FeatureRole
@ FeatureRole
Used to retrieve the feature, it might be incomplete if the request doesn't fetch all attributes or g...
Definition: qgsfeaturepickermodelbase.h:68
QgsConditionalLayerStyles::rowStyles
QgsConditionalStyles rowStyles() const
Returns a list of row styles associated with the layer.
Definition: qgsconditionalstyle.cpp:28
QgsFeaturePickerModelBase::setDisplayExpression
void setDisplayExpression(const QString &displayExpression)
The display expression will be used for.
Definition: qgsfeaturepickermodelbase.cpp:75
QgsFeaturePickerModelBase::entryIdentifier
virtual QVariant entryIdentifier(const QgsFeatureExpressionValuesGatherer::Entry &entry) const =0
Returns the identifier of the given entry.
QgsFeaturePickerModelBase::fetchLimit
int fetchLimit
Definition: qgsfeaturepickermodelbase.h:55
QgsConditionalStyle::textColor
QColor textColor() const
The text color set for style.
Definition: qgsconditionalstyle.h:212
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsFeatureRequest::setLimit
QgsFeatureRequest & setLimit(long long limit)
Set the maximum number of features to request.
Definition: qgsfeaturerequest.cpp:216
QgsFeaturePickerModelBase::allowNullChanged
void allowNullChanged()
Add a NULL entry to the list.
qgssettings.h
QgsFeaturePickerModelBase::createValuesGatherer
virtual QgsFeatureExpressionValuesGatherer * createValuesGatherer(const QgsFeatureRequest &request) const =0
Creates the value gatherer.
QgsVectorLayer::conditionalStyles
QgsConditionalLayerStyles * conditionalStyles() const
Returns the conditional styles that are set for this layer.
Definition: qgsvectorlayer.cpp:1047
QgsFeaturePickerModelBase::extraIdentifierValueChanged
void extraIdentifierValueChanged()
Allows specifying one value that does not need to match the filter criteria but will still be availab...
QgsConditionalLayerStyles::fieldStyles
QList< QgsConditionalStyle > fieldStyles(const QString &fieldName) const
Returns the conditional styles set for the field with matching fieldName.
Definition: qgsconditionalstyle.cpp:51
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsExpression::isField
bool isField() const
Checks whether an expression consists only of a single field reference.
Definition: qgsexpression.cpp:1360
QgsFeaturePickerModelBase::mExtraValueIndex
int mExtraValueIndex
The current index.
Definition: qgsfeaturepickermodelbase.h:340
QgsFeaturePickerModelBase::setFetchLimit
void setFetchLimit(int fetchLimit)
Defines the feature request fetch limit If set to 0, no limit is applied when fetching.
Definition: qgsfeaturepickermodelbase.cpp:605
QgsFeaturePickerModelBase::setFetchGeometry
void setFetchGeometry(bool fetchGeometry)
Defines if the geometry will be fetched.
Definition: qgsfeaturepickermodelbase.cpp:591
QgsVectorLayer::createExpressionContext
QgsExpressionContext createExpressionContext() const FINAL
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Definition: qgsvectorlayer.cpp:5203
QgsExpression
Class for parsing and evaluation of expressions (formerly called "search strings")....
Definition: qgsexpression.h:102
QgsFeaturePickerModelBase::setSourceLayer
void setSourceLayer(QgsVectorLayer *sourceLayer)
The source layer from which features will be fetched.
Definition: qgsfeaturepickermodelbase.cpp:52
QgsVectorLayer::displayExpression
QString displayExpression
Definition: qgsvectorlayer.h:396
QgsFeaturePickerModelBase::parent
QModelIndex parent(const QModelIndex &child) const override
Definition: qgsfeaturepickermodelbase.cpp:138
QgsFeaturePickerModelBase::FeatureIdRole
@ FeatureIdRole
Used to retrieve the id of a feature.
Definition: qgsfeaturepickermodelbase.h:69
QgsConditionalStyle::validTextColor
bool validTextColor() const
Check if the text color is valid for render.
Definition: qgsconditionalstyle.cpp:248
QgsFeaturePickerModelBase::setFilterExpression
void setFilterExpression(const QString &filterExpression)
An additional filter expression to apply, next to the filterValue.
Definition: qgsfeaturepickermodelbase.cpp:109
QgsFeatureRequest::setFlags
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
Definition: qgsfeaturerequest.cpp:222
QgsFeaturePickerModelBase::sourceLayerChanged
void sourceLayerChanged()
The source layer from which features will be fetched.
QgsExpression::expression
QString expression() const
Returns the original, unmodified expression string.
Definition: qgsexpression.cpp:60
QgsFeaturePickerModelBase::setFilterValue
void setFilterValue(const QString &filterValue)
This value will be used to filter the features available from this model.
Definition: qgsfeaturepickermodelbase.cpp:92
QgsFeaturePickerModelBase::filterValueChanged
void filterValueChanged()
This value will be used to filter the features available from this model.
QgsFeaturePickerModelBase::beginUpdate
void beginUpdate()
Notification that the model is about to be changed because a job was completed.
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28
QgsExpressionContext::setFeature
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Definition: qgsexpressioncontext.cpp:525
QgsFeaturePickerModelBase::filterExpressionChanged
void filterExpressionChanged()
An additional filter expression to apply, next to the filterValue.