QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
qgsattributetablemodel.cpp
Go to the documentation of this file.
1/***************************************************************************
2 QgsAttributeTableModel.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 "qgsapplication.h"
18#include "moc_qgsattributetablemodel.cpp"
19
20#include "qgsactionmanager.h"
22#include "qgsexpression.h"
23#include "qgsfeatureiterator.h"
24#include "qgsconditionalstyle.h"
25#include "qgsfields.h"
26#include "qgsfieldformatter.h"
27#include "qgslogger.h"
28#include "qgsmaplayeraction.h"
29#include "qgsvectorlayer.h"
32#include "qgsgui.h"
34#include "qgsfieldmodel.h"
36#include "qgsstringutils.h"
37#include "qgsvectorlayerutils.h"
38#include "qgsvectorlayercache.h"
39
40#include <QVariant>
41#include <QUuid>
42
43#include <limits>
44
46 : QAbstractTableModel( parent )
47 , mLayer( layerCache->layer() )
48 , mLayerCache( layerCache )
49{
51
52 if ( mLayer->geometryType() == Qgis::GeometryType::Null )
53 {
55 }
56
57 mFeat.setId( std::numeric_limits<int>::min() );
58
59 if ( !mLayer->isSpatial() )
61
62 loadAttributes();
63
64 connect( mLayer, &QgsVectorLayer::featuresDeleted, this, &QgsAttributeTableModel::featuresDeleted );
65 connect( mLayer, &QgsVectorLayer::attributeDeleted, this, &QgsAttributeTableModel::attributeDeleted );
66 connect( mLayer, &QgsVectorLayer::updatedFields, this, &QgsAttributeTableModel::updatedFields );
67
68 connect( mLayer, &QgsVectorLayer::editCommandStarted, this, &QgsAttributeTableModel::bulkEditCommandStarted );
69 connect( mLayer, &QgsVectorLayer::beforeRollBack, this, &QgsAttributeTableModel::bulkEditCommandStarted );
70 connect( mLayer, &QgsVectorLayer::afterRollBack, this, [ = ]
71 {
72 mIsCleaningUpAfterRollback = true;
73 bulkEditCommandEnded();
74 mIsCleaningUpAfterRollback = false;
75 } );
76
77 connect( mLayer, &QgsVectorLayer::editCommandEnded, this, &QgsAttributeTableModel::editCommandEnded );
78 connect( mLayerCache, &QgsVectorLayerCache::attributeValueChanged, this, &QgsAttributeTableModel::attributeValueChanged );
79 connect( mLayerCache, &QgsVectorLayerCache::featureAdded, this, [ = ]( QgsFeatureId id ) { featureAdded( id ); } );
80 connect( mLayerCache, &QgsVectorLayerCache::cachedLayerDeleted, this, &QgsAttributeTableModel::layerDeleted );
81}
82
83bool QgsAttributeTableModel::loadFeatureAtId( QgsFeatureId fid ) const
84{
85 QgsDebugMsgLevel( QStringLiteral( "loading feature %1" ).arg( fid ), 3 );
86
87 if ( fid == std::numeric_limits<int>::min() )
88 {
89 return false;
90 }
91
92 return mLayerCache->featureAtId( fid, mFeat );
93}
94
95bool QgsAttributeTableModel::loadFeatureAtId( QgsFeatureId fid, int fieldIdx ) const
96{
97 QgsDebugMsgLevel( QStringLiteral( "loading feature %1 with field %2" ).arg( fid, fieldIdx ), 3 );
98
99 if ( mLayerCache->cacheSubsetOfAttributes().contains( fieldIdx ) )
100 {
101 return loadFeatureAtId( fid );
102 }
103
104 if ( fid == std::numeric_limits<int>::min() )
105 {
106 return false;
107 }
108 return mLayerCache->featureAtIdWithAllAttributes( fid, mFeat );
109}
110
112{
113 return mExtraColumns;
114}
115
117{
118 if ( extraColumns > mExtraColumns )
119 {
120 beginInsertColumns( QModelIndex(), mFieldCount + mExtraColumns, mFieldCount + extraColumns - 1 );
121 mExtraColumns = extraColumns;
122 endInsertColumns();
123 }
124 else if ( extraColumns < mExtraColumns )
125 {
126 beginRemoveColumns( QModelIndex(), mFieldCount + extraColumns, mFieldCount + mExtraColumns - 1 );
127 mExtraColumns = extraColumns;
128 endRemoveColumns();
129 }
130}
131
132void QgsAttributeTableModel::featuresDeleted( const QgsFeatureIds &fids )
133{
134 QList<int> rows;
135
136 const auto constFids = fids;
137 for ( const QgsFeatureId fid : constFids )
138 {
139 QgsDebugMsgLevel( QStringLiteral( "(%2) fid: %1, size: %3" ).arg( fid ).arg( qgsEnumValueToKey( mFeatureRequest.filterType() ) ).arg( mIdRowMap.size() ), 4 );
140
141 const int row = idToRow( fid );
142 if ( row != -1 )
143 rows << row;
144 }
145
146 std::sort( rows.begin(), rows.end() );
147
148 int lastRow = -1;
149 int beginRow = -1;
150 int currentRowCount = 0;
151 int removedRows = 0;
152 bool reset = false;
153
154 const auto constRows = rows;
155 for ( const int row : constRows )
156 {
157#if 0
158 qDebug() << "Row: " << row << ", begin " << beginRow << ", last " << lastRow << ", current " << currentRowCount << ", removed " << removedRows;
159#endif
160 if ( lastRow == -1 )
161 {
162 beginRow = row;
163 }
164
165 if ( row != lastRow + 1 && lastRow != -1 )
166 {
167 if ( rows.count() > 100 && currentRowCount < 10 )
168 {
169 reset = true;
170 break;
171 }
172 removeRows( beginRow - removedRows, currentRowCount );
173
174 beginRow = row;
175 removedRows += currentRowCount;
176 currentRowCount = 0;
177 }
178
179 currentRowCount++;
180
181 lastRow = row;
182 }
183
184 if ( !reset )
185 removeRows( beginRow - removedRows, currentRowCount );
186 else
187 resetModel();
188}
189
190bool QgsAttributeTableModel::removeRows( int row, int count, const QModelIndex &parent )
191{
192
193 if ( row < 0 || count < 1 )
194 return false;
195
196 if ( !mResettingModel )
197 {
198 beginRemoveRows( parent, row, row + count - 1 );
199 }
200
201#ifdef QGISDEBUG
202 if ( 3 <= QgsLogger::debugLevel() )
203 QgsDebugMsgLevel( QStringLiteral( "remove %2 rows at %1 (rows %3, ids %4)" ).arg( row ).arg( count ).arg( mRowIdMap.size() ).arg( mIdRowMap.size() ), 3 );
204#endif
205
206 if ( mBulkEditCommandRunning && !mResettingModel )
207 {
208 for ( int i = row; i < row + count; i++ )
209 {
210 const QgsFeatureId fid { rowToId( row ) };
211 mInsertedRowsChanges.removeOne( fid );
212 }
213 }
214
215 // clean old references
216 for ( int i = row; i < row + count; i++ )
217 {
218 for ( SortCache &cache : mSortCaches )
219 cache.sortCache.remove( mRowIdMap[i] );
220 mIdRowMap.remove( mRowIdMap[i] );
221 mRowIdMap.remove( i );
222 }
223
224 // update maps
225 const int n = mRowIdMap.size() + count;
226 for ( int i = row + count; i < n; i++ )
227 {
228 const QgsFeatureId id = mRowIdMap[i];
229 mIdRowMap[id] -= count;
230 mRowIdMap[i - count] = id;
231 mRowIdMap.remove( i );
232 }
233
234#ifdef QGISDEBUG
235 if ( 4 <= QgsLogger::debugLevel() )
236 {
237 QgsDebugMsgLevel( QStringLiteral( "after removal rows %1, ids %2" ).arg( mRowIdMap.size() ).arg( mIdRowMap.size() ), 4 );
238 QgsDebugMsgLevel( QStringLiteral( "id->row" ), 4 );
239 for ( QHash<QgsFeatureId, int>::const_iterator it = mIdRowMap.constBegin(); it != mIdRowMap.constEnd(); ++it )
240 QgsDebugMsgLevel( QStringLiteral( "%1->%2" ).arg( FID_TO_STRING( it.key() ) ).arg( *it ), 4 );
241
242 QgsDebugMsgLevel( QStringLiteral( "row->id" ), 4 );
243 for ( QHash<int, QgsFeatureId>::const_iterator it = mRowIdMap.constBegin(); it != mRowIdMap.constEnd(); ++it )
244 QgsDebugMsgLevel( QStringLiteral( "%1->%2" ).arg( it.key() ).arg( FID_TO_STRING( *it ) ), 4 );
245 }
246#endif
247
248 Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );
249
250 if ( !mResettingModel )
251 endRemoveRows();
252
253 return true;
254}
255
256void QgsAttributeTableModel::featureAdded( QgsFeatureId fid )
257{
258 QgsDebugMsgLevel( QStringLiteral( "(%2) fid: %1" ).arg( fid ).arg( qgsEnumValueToKey( mFeatureRequest.filterType() ) ), 4 );
259 bool featOk = true;
260
261 if ( mFeat.id() != fid )
262 featOk = loadFeatureAtId( fid );
263
264 if ( featOk && mFeatureRequest.acceptFeature( mFeat ) )
265 {
266 for ( SortCache &cache : mSortCaches )
267 {
268 if ( cache.sortFieldIndex >= 0 )
269 {
270 const WidgetData &widgetData = getWidgetData( cache.sortFieldIndex );
271 const QVariant sortValue = widgetData.fieldFormatter->sortValue( mLayer, cache.sortFieldIndex, widgetData.config, widgetData.cache, mFeat.attribute( cache.sortFieldIndex ) );
272 cache.sortCache.insert( mFeat.id(), sortValue );
273 }
274 else if ( cache.sortCacheExpression.isValid() )
275 {
276 mExpressionContext.setFeature( mFeat );
277 cache.sortCache[mFeat.id()] = cache.sortCacheExpression.evaluate( &mExpressionContext );
278 }
279 }
280
281 // Skip if the fid is already in the map (do not add twice)!
282 if ( ! mIdRowMap.contains( fid ) )
283 {
284 const int n = mRowIdMap.size();
285 if ( !mResettingModel )
286 beginInsertRows( QModelIndex(), n, n );
287 mIdRowMap.insert( fid, n );
288 mRowIdMap.insert( n, fid );
289 if ( !mResettingModel )
290 endInsertRows();
291 reload( index( rowCount() - 1, 0 ), index( rowCount() - 1, columnCount() ) );
292 if ( mBulkEditCommandRunning && !mResettingModel )
293 {
294 mInsertedRowsChanges.append( fid );
295 }
296 }
297 }
298}
299
300void QgsAttributeTableModel::updatedFields()
301{
302 loadAttributes();
303 emit modelChanged();
304}
305
306void QgsAttributeTableModel::editCommandEnded()
307{
308 // do not do reload(...) due would trigger (dataChanged) row sort
309 // giving issue: https://github.com/qgis/QGIS/issues/23892
310 bulkEditCommandEnded( );
311}
312
313void QgsAttributeTableModel::attributeDeleted( int idx )
314{
315 int cacheIndex = 0;
316 for ( const SortCache &cache : mSortCaches )
317 {
318 if ( cache.sortCacheAttributes.contains( idx ) )
319 {
320 prefetchSortData( QString(), cacheIndex );
321 }
322 cacheIndex++;
323 }
324}
325
326void QgsAttributeTableModel::layerDeleted()
327{
328 mLayerCache = nullptr;
329 mLayer = nullptr;
330 removeRows( 0, rowCount() );
331
332 mAttributes.clear();
333 mWidgetDatas.clear();
334}
335
336void QgsAttributeTableModel::fieldFormatterRemoved( QgsFieldFormatter *fieldFormatter )
337{
338 for ( WidgetData &widgetData : mWidgetDatas )
339 {
340 if ( widgetData.fieldFormatter == fieldFormatter )
341 widgetData.fieldFormatter = QgsApplication::fieldFormatterRegistry()->fallbackFieldFormatter();
342 }
343}
344
345void QgsAttributeTableModel::attributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value )
346{
347 // Defer all updates if a bulk edit/rollback command is running
348 if ( mBulkEditCommandRunning )
349 {
350 mAttributeValueChanges.insert( QPair<QgsFeatureId, int>( fid, idx ), value );
351 return;
352 }
353 QgsDebugMsgLevel( QStringLiteral( "(%4) fid: %1, idx: %2, value: %3" ).arg( fid ).arg( idx ).arg( value.toString() ).arg( qgsEnumValueToKey( mFeatureRequest.filterType() ) ), 2 );
354
355 for ( SortCache &cache : mSortCaches )
356 {
357 if ( cache.sortCacheAttributes.contains( idx ) )
358 {
359 if ( cache.sortFieldIndex == -1 )
360 {
361 if ( loadFeatureAtId( fid ) )
362 {
363 mExpressionContext.setFeature( mFeat );
364 cache.sortCache[fid] = cache.sortCacheExpression.evaluate( &mExpressionContext );
365 }
366 }
367 else
368 {
369 const WidgetData &widgetData = getWidgetData( cache.sortFieldIndex );
370 const QVariant sortValue = widgetData.fieldFormatter->representValue( mLayer, cache.sortFieldIndex, widgetData.config, widgetData.cache, value );
371 cache.sortCache.insert( fid, sortValue );
372 }
373 }
374 }
375 // No filter request: skip all possibly heavy checks
376 if ( mFeatureRequest.filterType() == Qgis::FeatureRequestFilterType::NoFilter )
377 {
378 if ( loadFeatureAtId( fid ) )
379 {
380 const QModelIndex modelIndex = index( idToRow( fid ), fieldCol( idx ) );
381 setData( modelIndex, value, Qt::EditRole );
382 emit dataChanged( modelIndex, modelIndex, QVector<int>() << Qt::DisplayRole );
383 }
384 }
385 else
386 {
387 if ( loadFeatureAtId( fid ) )
388 {
389 if ( mFeatureRequest.acceptFeature( mFeat ) )
390 {
391 if ( !mIdRowMap.contains( fid ) )
392 {
393 // Feature changed in such a way, it will be shown now
394 featureAdded( fid );
395 }
396 else
397 {
398 // Update representation
399 const QModelIndex modelIndex = index( idToRow( fid ), fieldCol( idx ) );
400 setData( modelIndex, value, Qt::EditRole );
401 emit dataChanged( modelIndex, modelIndex, QVector<int>() << Qt::DisplayRole );
402 }
403 }
404 else
405 {
406 if ( mIdRowMap.contains( fid ) )
407 {
408 // Feature changed such, that it is no longer shown
409 featuresDeleted( QgsFeatureIds() << fid );
410 }
411 // else: we don't care
412 }
413 }
414 }
415}
416
417void QgsAttributeTableModel::loadAttributes()
418{
419 if ( !mLayer )
420 {
421 return;
422 }
423
424 const QgsFields fields = mLayer->fields();
425 if ( mFields == fields )
426 return;
427
428 mFields = fields;
429
430 bool ins = false, rm = false;
431
432 QgsAttributeList attributes;
433
434 mWidgetDatas.clear();
435
436 for ( int idx = 0; idx < fields.count(); ++idx )
437 {
438 attributes << idx;
439 }
440
441 if ( mFieldCount + mExtraColumns < attributes.size() + mExtraColumns )
442 {
443 ins = true;
444 beginInsertColumns( QModelIndex(), mFieldCount + mExtraColumns, attributes.size() - 1 );
445 }
446 else if ( attributes.size() + mExtraColumns < mFieldCount + mExtraColumns )
447 {
448 rm = true;
449 beginRemoveColumns( QModelIndex(), attributes.size(), mFieldCount + mExtraColumns - 1 );
450 }
451
452 mFieldCount = attributes.size();
453 mAttributes = attributes;
454 mWidgetDatas.resize( mFieldCount );
455
456 for ( SortCache &cache : mSortCaches )
457 {
458 if ( cache.sortFieldIndex >= mAttributes.count() )
459 cache.sortFieldIndex = -1;
460 }
461
462 if ( ins )
463 {
464 endInsertColumns();
465 }
466 else if ( rm )
467 {
468 endRemoveColumns();
469 }
470}
471
473{
474 // make sure attributes are properly updated before caching the data
475 // (emit of progress() signal may enter event loop and thus attribute
476 // table view may be updated with inconsistent model which may assume
477 // wrong number of attributes)
478
479 loadAttributes();
480
481 mResettingModel = true;
482 beginResetModel();
483
484 if ( rowCount() != 0 )
485 {
486 removeRows( 0, rowCount() );
487 }
488
489 // Layer might have been deleted and cache set to nullptr!
490 if ( mLayerCache )
491 {
492 QgsFeatureIterator features = mLayerCache->getFeatures( mFeatureRequest );
493
494 int i = 0;
495
496 QElapsedTimer t;
497 t.start();
498
499 while ( features.nextFeature( mFeat ) )
500 {
501 ++i;
502
503 if ( t.elapsed() > 1000 )
504 {
505 bool cancel = false;
506 emit progress( i, cancel );
507 if ( cancel )
508 break;
509
510 t.restart();
511 }
512 featureAdded( mFeat.id() );
513 }
514
515 emit finished();
516 connect( mLayerCache, &QgsVectorLayerCache::invalidated, this, &QgsAttributeTableModel::loadLayer, Qt::UniqueConnection );
517 }
518
519 endResetModel();
520
521 mResettingModel = false;
522}
523
524
526{
527 if ( fieldName.isNull() )
528 {
529 mRowStylesMap.clear();
530 mConstraintStylesMap.clear();
531 emit dataChanged( index( 0, 0 ), index( rowCount() - 1, columnCount() - 1 ) );
532 return;
533 }
534
535 const int fieldIndex = mLayer->fields().lookupField( fieldName );
536 if ( fieldIndex == -1 )
537 return;
538
539 //whole column has changed
540 const int col = fieldCol( fieldIndex );
541 emit dataChanged( index( 0, col ), index( rowCount() - 1, col ) );
542}
543
545{
546 if ( a == b )
547 return;
548
549 const int rowA = idToRow( a );
550 const int rowB = idToRow( b );
551
552 //emit layoutAboutToBeChanged();
553
554 mRowIdMap.remove( rowA );
555 mRowIdMap.remove( rowB );
556 mRowIdMap.insert( rowA, b );
557 mRowIdMap.insert( rowB, a );
558
559 mIdRowMap.remove( a );
560 mIdRowMap.remove( b );
561 mIdRowMap.insert( a, rowB );
562 mIdRowMap.insert( b, rowA );
563 Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );
564
565
566 //emit layoutChanged();
567}
568
570{
571 if ( !mIdRowMap.contains( id ) )
572 {
573 QgsDebugError( QStringLiteral( "idToRow: id %1 not in the map" ).arg( id ) );
574 return -1;
575 }
576
577 return mIdRowMap[id];
578}
579
581{
582 return index( idToRow( id ), 0 );
583}
584
586{
587 QModelIndexList indexes;
588
589 const int row = idToRow( id );
590 const int columns = columnCount();
591 indexes.reserve( columns );
592 for ( int column = 0; column < columns; ++column )
593 {
594 indexes.append( index( row, column ) );
595 }
596
597 return indexes;
598}
599
601{
602 if ( !mRowIdMap.contains( row ) )
603 {
604 QgsDebugError( QStringLiteral( "rowToId: row %1 not in the map" ).arg( row ) );
605 // return negative infinite (to avoid collision with newly added features)
606 return std::numeric_limits<int>::min();
607 }
608
609 return mRowIdMap[row];
610}
611
613{
614 return mAttributes[col];
615}
616
618{
619 return mAttributes.indexOf( idx );
620}
621
622int QgsAttributeTableModel::rowCount( const QModelIndex &parent ) const
623{
624 Q_UNUSED( parent )
625 return mRowIdMap.size();
626}
627
628int QgsAttributeTableModel::columnCount( const QModelIndex &parent ) const
629{
630 Q_UNUSED( parent )
631 return std::max( 1, mFieldCount + mExtraColumns ); // if there are zero columns all model indices will be considered invalid
632}
633
634QVariant QgsAttributeTableModel::headerData( int section, Qt::Orientation orientation, int role ) const
635{
636 if ( !mLayer )
637 return QVariant();
638
639 if ( role == Qt::DisplayRole )
640 {
641 if ( orientation == Qt::Vertical ) //row
642 {
643 return QVariant( section );
644 }
645 else if ( section >= 0 && section < mFieldCount )
646 {
647 const QString attributeName = mLayer->fields().at( mAttributes.at( section ) ).displayName();
648 return QVariant( attributeName );
649 }
650 else
651 {
652 return tr( "extra column" );
653 }
654 }
655 else if ( role == Qt::ToolTipRole )
656 {
657 if ( orientation == Qt::Vertical )
658 {
659 // TODO show DisplayExpression
660 return tr( "Feature ID: %1" ).arg( rowToId( section ) );
661 }
662 else
663 {
664 const QgsField field = mLayer->fields().at( mAttributes.at( section ) );
665 return QgsFieldModel::fieldToolTipExtended( field, mLayer );
666 }
667 }
668 else
669 {
670 return QVariant();
671 }
672}
673
674QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) const
675{
676 if ( !index.isValid() || !mLayer ||
677 ( role != Qt::TextAlignmentRole
678 && role != Qt::DisplayRole
679 && role != Qt::ToolTipRole
680 && role != Qt::EditRole
681 && role != static_cast< int >( CustomRole::FeatureId )
682 && role != static_cast< int >( CustomRole::FieldIndex )
683 && role != Qt::BackgroundRole
684 && role != Qt::ForegroundRole
685 && role != Qt::DecorationRole
686 && role != Qt::FontRole
687 && role < static_cast< int >( CustomRole::Sort )
688 )
689 )
690 return QVariant();
691
692 const QgsFeatureId rowId = rowToId( index.row() );
693
694 if ( role == static_cast< int >( CustomRole::FeatureId ) )
695 return rowId;
696
697 if ( index.column() >= mFieldCount )
698 return QVariant();
699
700 const int fieldId = mAttributes.at( index.column() );
701
702 if ( role == static_cast< int >( CustomRole::FieldIndex ) )
703 return fieldId;
704
705 if ( role >= static_cast< int >( CustomRole::Sort ) )
706 {
707 const unsigned long cacheIndex = role - static_cast< int >( CustomRole::Sort );
708 if ( cacheIndex < mSortCaches.size() )
709 return mSortCaches.at( cacheIndex ).sortCache.value( rowId );
710 else
711 return QVariant();
712 }
713
714 const QgsField field = mLayer->fields().at( fieldId );
715
716 if ( role == Qt::TextAlignmentRole )
717 {
718 const WidgetData &widgetData = getWidgetData( index.column() );
719 return static_cast<Qt::Alignment::Int>( widgetData.fieldFormatter->alignmentFlag( mLayer, fieldId, widgetData.config ) | Qt::AlignVCenter );
720 }
721
722 if ( mFeat.id() != rowId || !mFeat.isValid() || ! mLayerCache->cacheSubsetOfAttributes().contains( fieldId ) )
723 {
724 if ( !loadFeatureAtId( rowId, fieldId ) )
725 return QVariant( "ERROR" );
726
727 if ( mFeat.id() != rowId )
728 return QVariant( "ERROR" );
729 }
730
731 QVariant val = mFeat.attribute( fieldId );
732
733 switch ( role )
734 {
735 case Qt::DisplayRole:
736 {
737 const WidgetData &widgetData = getWidgetData( index.column() );
738 QString s = widgetData.fieldFormatter->representValue( mLayer, fieldId, widgetData.config, widgetData.cache, val );
739 // In table view, too long strings kill performance. Just truncate them
740 constexpr int MAX_STRING_LENGTH = 10 * 1000;
741 if ( static_cast<size_t>( s.size() ) > static_cast<size_t>( MAX_STRING_LENGTH ) )
742 {
743 s.resize( MAX_STRING_LENGTH );
744 s.append( tr( "... truncated ..." ) );
745 }
746 return s;
747 }
748 case Qt::ToolTipRole:
749 {
750 const WidgetData &widgetData = getWidgetData( index.column() );
751 QString tooltip = widgetData.fieldFormatter->representValue( mLayer, fieldId, widgetData.config, widgetData.cache, val );
752 if ( val.userType() == QMetaType::Type::QString && QgsStringUtils::isUrl( val.toString() ) )
753 {
754 tooltip = tr( "%1 (Ctrl+click to open)" ).arg( tooltip );
755 }
756 return tooltip;
757 }
758 case Qt::EditRole:
759 return val;
760
761 case Qt::BackgroundRole:
762 case Qt::ForegroundRole:
763 case Qt::DecorationRole:
764 case Qt::FontRole:
765 {
766 mExpressionContext.setFeature( mFeat );
767 QList<QgsConditionalStyle> styles;
768 if ( mRowStylesMap.contains( mFeat.id() ) )
769 {
770 styles = mRowStylesMap[mFeat.id()];
771 }
772 else
773 {
774 styles = QgsConditionalStyle::matchingConditionalStyles( mLayer->conditionalStyles()->rowStyles(), QVariant(), mExpressionContext );
775 mRowStylesMap.insert( mFeat.id(), styles );
776 }
778
779 QgsConditionalStyle constraintstyle;
780 if ( mShowValidityState && QgsVectorLayerUtils::attributeHasConstraints( mLayer, fieldId ) )
781 {
782 if ( mConstraintStylesMap.contains( mFeat.id() ) &&
783 mConstraintStylesMap[mFeat.id()].contains( fieldId ) )
784 {
785 constraintstyle = mConstraintStylesMap[mFeat.id()][fieldId];
786 }
787 else
788 {
789 QStringList errors;
791 {
793 }
794 else
795 {
797 {
799 }
800 }
801 mConstraintStylesMap[mFeat.id()].insert( fieldId, constraintstyle );
802 }
803 }
804
805 styles = mLayer->conditionalStyles()->fieldStyles( field.name() );
806 styles = QgsConditionalStyle::matchingConditionalStyles( styles, val, mExpressionContext );
807 styles.insert( 0, rowstyle );
808 styles.insert( 0, constraintstyle );
810
811 if ( style.isValid() )
812 {
813 if ( role == Qt::BackgroundRole && style.validBackgroundColor() )
814 return style.backgroundColor();
815 if ( role == Qt::ForegroundRole )
816 return style.textColor();
817 if ( role == Qt::DecorationRole )
818 return style.icon();
819 if ( role == Qt::FontRole )
820 return style.font();
821 }
822 else if ( val.userType() == QMetaType::Type::QString && QgsStringUtils::isUrl( val.toString() ) )
823 {
824 if ( role == Qt::ForegroundRole )
825 {
826 return QColor( Qt::blue );
827 }
828 else if ( role == Qt::FontRole )
829 {
830 QFont font;
831 font.setUnderline( true );
832 return font;
833 }
834 }
835
836 return QVariant();
837 }
838 }
839
840 return QVariant();
841}
842
843bool QgsAttributeTableModel::setData( const QModelIndex &index, const QVariant &value, int role )
844{
845 Q_UNUSED( value )
846
847 if ( !index.isValid() || index.column() >= mFieldCount || role != Qt::EditRole || !mLayer->isEditable() )
848 return false;
849
850 mRowStylesMap.remove( mFeat.id() );
851 mConstraintStylesMap.remove( mFeat.id() );
852
853 if ( !mLayer->isModified() )
854 return false;
855
856 return true;
857}
858
859Qt::ItemFlags QgsAttributeTableModel::flags( const QModelIndex &index ) const
860{
861 if ( !index.isValid() )
862 return Qt::ItemIsEnabled;
863
864 if ( index.column() >= mFieldCount || !mLayer )
865 return Qt::NoItemFlags;
866
867 Qt::ItemFlags flags = QAbstractTableModel::flags( index );
868
869 const int fieldIndex = mAttributes[index.column()];
870 const QgsFeatureId fid = rowToId( index.row() );
871
872 if ( QgsVectorLayerUtils::fieldIsEditable( mLayer, fieldIndex, fid ) )
873 flags |= Qt::ItemIsEditable;
874
875 return flags;
876}
877
878void QgsAttributeTableModel::bulkEditCommandStarted()
879{
880 mBulkEditCommandRunning = true;
881 mAttributeValueChanges.clear();
882}
883
884void QgsAttributeTableModel::bulkEditCommandEnded()
885{
886 mBulkEditCommandRunning = false;
887 // Full model update if the changed rows are more than half the total rows
888 // or if their count is > layer cache size
889
890 const long long fullModelUpdateThreshold = std::min<long long >( mLayerCache->cacheSize(), std::ceil( rowCount() * 0.5 ) );
891 bool fullModelUpdate = false;
892
893 // try the cheaper check first
894 if ( mInsertedRowsChanges.size() > fullModelUpdateThreshold )
895 {
896 fullModelUpdate = true;
897 }
898 else
899 {
900 QSet< QgsFeatureId > changedRows;
901 changedRows.reserve( mAttributeValueChanges.size() );
902 // we need to count changed features, not the total of changed attributes (which may all apply to one feature)
903 for ( auto it = mAttributeValueChanges.constBegin(); it != mAttributeValueChanges.constEnd(); ++it )
904 {
905 changedRows.insert( it.key().first );
906 if ( changedRows.size() > fullModelUpdateThreshold )
907 {
908 fullModelUpdate = true;
909 break;
910 }
911 }
912 }
913
914 QgsDebugMsgLevel( QStringLiteral( "Bulk edit command ended modified rows over (%3), cache size is %1, starting %2 update." )
915 .arg( mLayerCache->cacheSize() )
916 .arg( fullModelUpdate ? QStringLiteral( "full" ) : QStringLiteral( "incremental" ) )
917 .arg( rowCount() ),
918 3 );
919
920 // Remove added rows on rollback
921 if ( mIsCleaningUpAfterRollback )
922 {
923 for ( const int fid : std::as_const( mInsertedRowsChanges ) )
924 {
925 const int row( idToRow( fid ) );
926 if ( row < 0 )
927 {
928 continue;
929 }
930 removeRow( row );
931 }
932 }
933
934 // Invalidates the whole model
935 if ( fullModelUpdate )
936 {
937 // Invalidates the cache (there is no API for doing this directly)
938 emit mLayer->dataChanged();
939 emit dataChanged( createIndex( 0, 0 ), createIndex( rowCount() - 1, columnCount() - 1 ) );
940 }
941 else
942 {
943
944 int minRow = rowCount();
945 int minCol = columnCount();
946 int maxRow = 0;
947 int maxCol = 0;
948 const auto keys = mAttributeValueChanges.keys();
949 for ( const auto &key : keys )
950 {
951 attributeValueChanged( key.first, key.second, mAttributeValueChanges.value( key ) );
952 const int row( idToRow( key.first ) );
953 const int col( fieldCol( key.second ) );
954 minRow = std::min<int>( row, minRow );
955 minCol = std::min<int>( col, minCol );
956 maxRow = std::max<int>( row, maxRow );
957 maxCol = std::max<int>( col, maxCol );
958 }
959
960 emit dataChanged( createIndex( minRow, minCol ), createIndex( maxRow, maxCol ) );
961 }
962 mAttributeValueChanges.clear();
963}
964
965void QgsAttributeTableModel::reload( const QModelIndex &index1, const QModelIndex &index2 )
966{
967 mFeat.setId( std::numeric_limits<int>::min() );
968 emit dataChanged( index1, index2 );
969}
970
971
972void QgsAttributeTableModel::executeAction( QUuid action, const QModelIndex &idx ) const
973{
974 const QgsFeature f = feature( idx );
975 mLayer->actions()->doAction( action, f, fieldIdx( idx.column() ) );
976}
977
978void QgsAttributeTableModel::executeMapLayerAction( QgsMapLayerAction *action, const QModelIndex &idx, const QgsMapLayerActionContext &context ) const
979{
980 const QgsFeature f = feature( idx );
982 action->triggerForFeature( mLayer, f );
984 action->triggerForFeature( mLayer, f, context );
985}
986
987QgsFeature QgsAttributeTableModel::feature( const QModelIndex &idx ) const
988{
989 QgsFeature f( mLayer->fields() );
990 f.initAttributes( mAttributes.size() );
991 f.setId( rowToId( idx.row() ) );
992 for ( int i = 0; i < mAttributes.size(); i++ )
993 {
994 f.setAttribute( mAttributes[i], data( index( idx.row(), i ), Qt::EditRole ) );
995 }
996
997 return f;
998}
999
1001{
1002 if ( column == -1 || column >= mAttributes.count() )
1003 {
1004 prefetchSortData( QString() );
1005 }
1006 else
1007 {
1008 prefetchSortData( QgsExpression::quotedColumnRef( mLayer->fields().at( mAttributes.at( column ) ).name() ) );
1009 }
1010}
1011
1012void QgsAttributeTableModel::prefetchSortData( const QString &expressionString, unsigned long cacheIndex )
1013{
1014 if ( cacheIndex >= mSortCaches.size() )
1015 {
1016 mSortCaches.resize( cacheIndex + 1 );
1017 }
1018 SortCache &cache = mSortCaches[cacheIndex];
1019 cache.sortCache.clear();
1020 cache.sortCacheAttributes.clear();
1021 cache.sortFieldIndex = -1;
1022 if ( !expressionString.isEmpty() )
1023 cache.sortCacheExpression = QgsExpression( expressionString );
1024 else
1025 {
1026 // no sorting
1027 cache.sortCacheExpression = QgsExpression();
1028 return;
1029 }
1030
1031 WidgetData widgetData;
1032
1033 if ( cache.sortCacheExpression.isField() )
1034 {
1035 const QString fieldName = static_cast<const QgsExpressionNodeColumnRef *>( cache.sortCacheExpression.rootNode() )->name();
1036 cache.sortFieldIndex = mLayer->fields().lookupField( fieldName );
1037 }
1038
1039 if ( cache.sortFieldIndex == -1 )
1040 {
1041 cache.sortCacheExpression.prepare( &mExpressionContext );
1042
1043 const QSet<QString> &referencedColumns = cache.sortCacheExpression.referencedColumns();
1044
1045 for ( const QString &col : referencedColumns )
1046 {
1047 cache.sortCacheAttributes.append( mLayer->fields().lookupField( col ) );
1048 }
1049 }
1050 else
1051 {
1052 cache.sortCacheAttributes.append( cache.sortFieldIndex );
1053
1054 widgetData = getWidgetData( cache.sortFieldIndex );
1055 }
1056
1057 const QgsFeatureRequest request = QgsFeatureRequest( mFeatureRequest ).setFlags( cache.sortCacheExpression.needsGeometry() ? Qgis::FeatureRequestFlag::NoFlags : Qgis::FeatureRequestFlag::NoGeometry ).setSubsetOfAttributes( cache.sortCacheAttributes );
1058
1059 QgsFeatureIterator it = mLayerCache->getFeatures( request );
1060
1061 QgsFeature f;
1062 while ( it.nextFeature( f ) )
1063 {
1064 if ( cache.sortFieldIndex == -1 )
1065 {
1066 mExpressionContext.setFeature( f );
1067 const QVariant cacheValue = cache.sortCacheExpression.evaluate( &mExpressionContext );
1068 cache.sortCache.insert( f.id(), cacheValue );
1069 }
1070 else
1071 {
1072 const QVariant sortValue = widgetData.fieldFormatter->sortValue( mLayer, cache.sortFieldIndex, widgetData.config, widgetData.cache, f.attribute( cache.sortFieldIndex ) );
1073 cache.sortCache.insert( f.id(), sortValue );
1074 }
1075 }
1076}
1077
1078QString QgsAttributeTableModel::sortCacheExpression( unsigned long cacheIndex ) const
1079{
1080 QString expressionString;
1081
1082 if ( cacheIndex >= mSortCaches.size() )
1083 return expressionString;
1084
1085 const QgsExpression &expression = mSortCaches[cacheIndex].sortCacheExpression;
1086
1087 if ( expression.isValid() )
1088 expressionString = expression.expression();
1089 else
1090 expressionString = QString();
1091
1092 return expressionString;
1093}
1094
1096{
1097 if ( ! mFeatureRequest.compare( request ) )
1098 {
1099 mFeatureRequest = request;
1100 if ( mLayer && !mLayer->isSpatial() )
1101 mFeatureRequest.setFlags( mFeatureRequest.flags() | Qgis::FeatureRequestFlag::NoGeometry );
1102 // Prefetch data for sorting, resetting all caches
1103 for ( unsigned long i = 0; i < mSortCaches.size(); ++i )
1104 {
1106 }
1107 }
1108}
1109
1111{
1112 return mFeatureRequest;
1113}
1114
1115const QgsAttributeTableModel::WidgetData &QgsAttributeTableModel::getWidgetData( int column ) const
1116{
1117 Q_ASSERT( column >= 0 && column < mAttributes.size() );
1118
1119 WidgetData &widgetData = mWidgetDatas[ column ];
1120 if ( !widgetData.loaded )
1121 {
1122 const int idx = fieldIdx( column );
1123 const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, mFields[ idx ].name() );
1124 widgetData.fieldFormatter = QgsApplication::fieldFormatterRegistry()->fieldFormatter( setup.type() );
1125 widgetData.config = setup.config();
1126 widgetData.cache = widgetData.fieldFormatter->createCache( mLayer, idx, setup.config() );
1127 widgetData.loaded = true;
1128 }
1129
1130 return widgetData;
1131}
@ NoFilter
No filter is applied.
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
@ NoFlags
No flags are set.
@ Null
No geometry.
void doAction(QUuid actionId, const QgsFeature &feature, int defaultValueIndex=0, const QgsExpressionContextScope &scope=QgsExpressionContextScope())
Does the given action.
static QgsFieldFormatterRegistry * fieldFormatterRegistry()
Gets the registry of available field formatters.
const QgsFeatureRequest & request() const
Gets the the feature request.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Remove rows.
Qt::ItemFlags flags(const QModelIndex &index) const override
Returns item flags for the index.
QgsFeature feature(const QModelIndex &idx) const
Returns the feature attributes at given model index.
void resetModel()
Resets the model.
void fieldConditionalStyleChanged(const QString &fieldName)
Handles updating the model when the conditional style for a field changes.
QString sortCacheExpression(unsigned long cacheIndex=0) const
The expression which was used to fill the sorting cache at index cacheIndex.
int fieldIdx(int col) const
Gets field index from column.
QgsAttributeTableModel(QgsVectorLayerCache *layerCache, QObject *parent=nullptr)
Constructor.
void swapRows(QgsFeatureId a, QgsFeatureId b)
Swaps two rows.
void modelChanged()
Emitted when the model has been changed.
void executeMapLayerAction(QgsMapLayerAction *action, const QModelIndex &idx, const QgsMapLayerActionContext &context=QgsMapLayerActionContext()) const
Execute a QgsMapLayerAction.
void progress(int i, bool &cancel)
void setRequest(const QgsFeatureRequest &request)
Set a request that will be used to fill this attribute table model.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Updates data on given index.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows.
QModelIndex idToIndex(QgsFeatureId id) const
int extraColumns() const
Empty extra columns to announce from this model.
QgsVectorLayerCache * layerCache() const
Returns the layer cache this model uses as backend.
void finished()
Emitted when the model has completely loaded all features.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of columns.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Returns header data.
QModelIndexList idToIndexList(QgsFeatureId id) const
void prefetchSortData(const QString &expression, unsigned long cacheIndex=0)
Prefetches the entire data for an expression.
QgsFeatureId rowToId(int row) const
Maps row to feature id.
int idToRow(QgsFeatureId id) const
Maps feature id to table row.
virtual void loadLayer()
Loads the layer into the model Preferably to be called, before using this model as source for any oth...
void setExtraColumns(int extraColumns)
Empty extra columns to announce from this model.
void prefetchColumnData(int column)
Caches the entire data for one column.
int fieldCol(int idx) const
Gets column from field index.
void reload(const QModelIndex &index1, const QModelIndex &index2)
Reloads the model data between indices.
@ FeatureId
Get the feature id of the feature in this row.
@ Sort
Role used for sorting start here.
@ FieldIndex
Get the field index of this column.
void executeAction(QUuid action, const QModelIndex &idx) const
Execute an action.
QVariant data(const QModelIndex &index, int role) const override
Returns data on the given index.
QgsConditionalStyles rowStyles() const
Returns a list of row styles associated with the layer.
QgsConditionalStyle constraintFailureStyles(QgsFieldConstraints::ConstraintStrength strength)
Returns a style associated to a constraint failure.
QList< QgsConditionalStyle > fieldStyles(const QString &fieldName) const
Returns the conditional styles set for the field with matching fieldName.
Conditional styling for a rule.
static QgsConditionalStyle compressStyles(const QList< QgsConditionalStyle > &styles)
Compress a list of styles into a single style.
static QList< QgsConditionalStyle > matchingConditionalStyles(const QList< QgsConditionalStyle > &styles, const QVariant &value, QgsExpressionContext &context)
Find and return the matching styles for the value and feature.
QColor backgroundColor() const
The background color for style.
QColor textColor() const
The text color set for style.
QFont font() const
The font for the style.
bool isValid() const
isValid Check if this rule is valid.
QPixmap icon() const
The icon set for style generated from the set symbol.
bool validBackgroundColor() const
Check if the background color is valid for render.
QgsEditorWidgetSetup findBest(const QgsVectorLayer *vl, const QString &fieldName) const
Find the best editor widget and its configuration for a given field.
Holder for the widget type and its configuration for a field.
QVariantMap config() const
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
An expression node which takes it value from a feature's field.
Class for parsing and evaluation of expressions (formerly called "search strings").
QString expression() const
Returns the original, unmodified expression string.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
bool isValid() const
Checks if this expression is valid.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(Qgis::FeatureRequestFlags flags)
Sets flags that affect how features will be fetched.
Qgis::FeatureRequestFilterType filterType() const
Returns the attribute/ID filter type which is currently set on this request.
Qgis::FeatureRequestFlags flags() const
Returns the flags which affect how features are fetched.
bool acceptFeature(const QgsFeature &feature)
Check if a feature is accepted by this requests filter.
bool compare(const QgsFeatureRequest &other) const
Compare two requests for equality, ignoring Expression Context, Transform Error Callback,...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Q_INVOKABLE bool setAttribute(int field, const QVariant &attr)
Sets an attribute's value by field index.
void initAttributes(int fieldCount)
Initialize this feature with the given number of fields.
QgsFeatureId id
Definition qgsfeature.h:66
void setId(QgsFeatureId id)
Sets the feature id for this feature.
bool isValid() const
Returns the validity of this feature.
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
@ ConstraintStrengthSoft
User is warned if constraint is violated but feature can still be accepted.
@ ConstraintStrengthHard
Constraint must be honored before feature can be accepted.
QgsFieldFormatter * fallbackFieldFormatter() const
Returns a basic fallback field formatter which can be used to represent any field in an unspectacular...
QgsFieldFormatter * fieldFormatter(const QString &id) const
Gets a field formatter by its id.
A field formatter helps to handle and display values for a field.
static QString fieldToolTipExtended(const QgsField &field, const QgsVectorLayer *layer)
Returns a HTML formatted tooltip string for a field, containing details like the field name,...
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:53
QString name
Definition qgsfield.h:62
QString displayName() const
Returns the name to use when displaying this field.
Definition qgsfield.cpp:95
Container of fields for a vector layer.
Definition qgsfields.h:46
int count
Definition qgsfields.h:50
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
static QgsEditorWidgetRegistry * editorWidgetRegistry()
Returns the global editor widget registry, used for managing all known edit widget factories.
Definition qgsgui.cpp:94
static int debugLevel()
Reads the environment variable QGIS_DEBUG and converts it to int.
Definition qgslogger.h:108
Encapsulates the context in which a QgsMapLayerAction action is executed.
An action which can run on map layers The class can be used in two manners:
virtual Q_DECL_DEPRECATED void triggerForFeature(QgsMapLayer *layer, const QgsFeature &feature)
Triggers the action with the specified layer and feature.
void dataChanged()
Data of layer changed.
static bool isUrl(const QString &string)
Returns whether the string is a URL (http,https,ftp,file)
This class caches features of a given QgsVectorLayer.
void invalidated()
The cache has been invalidated and cleared.
void featureAdded(QgsFeatureId fid)
Emitted when a new feature has been added to the layer and this cache.
void cachedLayerDeleted()
Is emitted when the cached layer is deleted.
void attributeValueChanged(QgsFeatureId fid, int field, const QVariant &value)
Emitted when an attribute is changed.
QgsVectorLayer * layer()
Returns the layer to which this cache belongs.
bool featureAtIdWithAllAttributes(QgsFeatureId featureId, QgsFeature &feature, bool skipCache=false)
Gets the feature at the given feature id with all attributes, if the cached feature already contains ...
int cacheSize()
Returns the maximum number of features this cache will hold.
QgsAttributeList cacheSubsetOfAttributes() const
Returns the list (possibly a subset) of cached attributes.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &featureRequest=QgsFeatureRequest())
Query this VectorLayerCache for features.
bool featureAtId(QgsFeatureId featureId, QgsFeature &feature, bool skipCache=false)
Gets the feature at the given feature id.
static bool fieldIsEditable(const QgsVectorLayer *layer, int fieldIndex, const QgsFeature &feature)
Tests whether a field is editable for a particular feature.
static bool attributeHasConstraints(const QgsVectorLayer *layer, int attributeIndex)
Returns true if a feature attribute has active constraints.
static bool validateAttribute(const QgsVectorLayer *layer, const QgsFeature &feature, int attributeIndex, QStringList &errors, QgsFieldConstraints::ConstraintStrength strength=QgsFieldConstraints::ConstraintStrengthNotSet, QgsFieldConstraints::ConstraintOrigin origin=QgsFieldConstraints::ConstraintOriginNotSet)
Tests a feature attribute value to check whether it passes all constraints which are present on the c...
bool isModified() const override
Returns true if the provider has been modified since the last commit.
void editCommandStarted(const QString &text)
Signal emitted when a new edit command has been started.
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
void featuresDeleted(const QgsFeatureIds &fids)
Emitted when features have been deleted.
bool isEditable() const FINAL
Returns true if the provider is in editing mode.
void attributeDeleted(int idx)
Will be emitted, when an attribute has been deleted from this vector layer.
QgsActionManager * actions()
Returns all layer actions defined on this layer.
void editCommandEnded()
Signal emitted, when an edit command successfully ended.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
void afterRollBack()
Emitted after changes are rolled back.
void updatedFields()
Emitted whenever the fields available from this layer have been changed.
QgsConditionalLayerStyles * conditionalStyles() const
Returns the conditional styles that are set for this layer.
void beforeRollBack()
Emitted before changes are rolled back.
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:6535
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:6149
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:6534
QSet< QgsFeatureId > QgsFeatureIds
#define FID_TO_STRING(fid)
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QList< int > QgsAttributeList
Definition qgsfield.h:27
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:39
#define QgsDebugError(str)
Definition qgslogger.h:38