QGIS API Documentation  2.3.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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"
17 #include "qgsattributetablemodel.h"
19 
20 #include "qgsfield.h"
21 #include "qgsvectorlayer.h"
22 #include "qgslogger.h"
23 #include "qgsattributeaction.h"
24 #include "qgsmapcanvas.h"
25 #include "qgsrendererv2.h"
26 #include "qgsmaplayerregistry.h"
27 #include "qgsexpression.h"
29 
30 #include <QVariant>
31 
32 #include <limits>
33 
35  : QAbstractTableModel( parent )
36  , mLayerCache( layerCache )
37  , mCachedField( -1 )
38 {
39  QgsDebugMsg( "entered." );
40 
41  if ( layerCache->layer()->geometryType() == QGis::NoGeometry )
42  {
44  }
45 
47 
48  if ( !layer()->hasGeometryType() )
50 
52 
53  connect( mLayerCache, SIGNAL( attributeValueChanged( QgsFeatureId, int, const QVariant& ) ), this, SLOT( attributeValueChanged( QgsFeatureId, int, const QVariant& ) ) );
54  connect( layer(), SIGNAL( featureDeleted( QgsFeatureId ) ), this, SLOT( featureDeleted( QgsFeatureId ) ) );
55  connect( layer(), SIGNAL( attributeDeleted( int ) ), this, SLOT( attributeDeleted( int ) ) );
56  connect( layer(), SIGNAL( updatedFields() ), this, SLOT( updatedFields() ) );
57  connect( layer(), SIGNAL( editCommandEnded() ), this, SLOT( editCommandEnded() ) );
58  connect( mLayerCache, SIGNAL( featureAdded( QgsFeatureId ) ), this, SLOT( featureAdded( QgsFeatureId ) ) );
59  connect( mLayerCache, SIGNAL( cachedLayerDeleted() ), this, SLOT( layerDeleted() ) );
60 }
61 
63 {
64  qDeleteAll( mValueMaps );
65 }
66 
68 {
69  QgsDebugMsgLevel( QString( "loading feature %1" ).arg( fid ), 3 );
70 
71  if ( fid == std::numeric_limits<int>::min() )
72  {
73  return false;
74  }
75 
76  return mLayerCache->featureAtId( fid, mFeat );
77 }
78 
80 {
81  QgsDebugMsgLevel( QString( "(%2) fid: %1" ).arg( fid ).arg( mFeatureRequest.filterType() ), 4 );
82  mFieldCache.remove( fid );
83 
84  int row = idToRow( fid );
85 
86  if ( row != -1 )
87  {
88  beginRemoveRows( QModelIndex(), row, row );
89  removeRow( row );
90  endRemoveRows();
91  }
92 }
93 
94 bool QgsAttributeTableModel::removeRows( int row, int count, const QModelIndex &parent )
95 {
96  Q_UNUSED( parent );
97  QgsDebugMsgLevel( QString( "remove %2 rows at %1 (rows %3, ids %4)" ).arg( row ).arg( count ).arg( mRowIdMap.size() ).arg( mIdRowMap.size() ), 3 );
98 
99  // clean old references
100  for ( int i = row; i < row + count; i++ )
101  {
102  mIdRowMap.remove( mRowIdMap[ i ] );
103  mRowIdMap.remove( i );
104  }
105 
106  // update maps
107  int n = mRowIdMap.size() + count;
108  for ( int i = row + count; i < n; i++ )
109  {
110  QgsFeatureId id = mRowIdMap[i];
111  mIdRowMap[ id ] -= count;
112  mRowIdMap[ i-count ] = id;
113  mRowIdMap.remove( i );
114  }
115 
116 #ifdef QGISDEBUG
117  QgsDebugMsgLevel( QString( "after removal rows %1, ids %2" ).arg( mRowIdMap.size() ).arg( mIdRowMap.size() ), 4 );
118  QgsDebugMsgLevel( "id->row", 4 );
119  for ( QHash<QgsFeatureId, int>::iterator it = mIdRowMap.begin(); it != mIdRowMap.end(); ++it )
120  QgsDebugMsgLevel( QString( "%1->%2" ).arg( FID_TO_STRING( it.key() ) ).arg( *it ), 4 );
121 
122  QHash<QgsFeatureId, int>::iterator idit;
123 
124  QgsDebugMsgLevel( "row->id", 4 );
125  for ( QHash<int, QgsFeatureId>::iterator it = mRowIdMap.begin(); it != mRowIdMap.end(); ++it )
126  QgsDebugMsgLevel( QString( "%1->%2" ).arg( it.key() ).arg( FID_TO_STRING( *it ) ), 4 );
127 #endif
128 
129  Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );
130 
131  return true;
132 }
133 
135 {
136  QgsDebugMsgLevel( QString( "(%2) fid: %1" ).arg( fid ).arg( mFeatureRequest.filterType() ), 4 );
137  bool featOk = true;
138 
139  if ( mFeat.id() != fid )
140  featOk = loadFeatureAtId( fid );
141 
142  if ( featOk && mFeatureRequest.acceptFeature( mFeat ) )
143  {
145 
146  int n = mRowIdMap.size();
147  beginInsertRows( QModelIndex(), n, n );
148 
149  mIdRowMap.insert( fid, n );
150  mRowIdMap.insert( n, fid );
151 
152  endInsertRows();
153 
154  reload( index( rowCount() - 1, 0 ), index( rowCount() - 1, columnCount() ) );
155  }
156 }
157 
159 {
160  QgsDebugMsg( "entered." );
161  loadAttributes();
162  emit modelChanged();
163 }
164 
166 {
167  reload( createIndex( mChangedCellBounds.top(), mChangedCellBounds.left() ),
168  createIndex( mChangedCellBounds.bottom(), mChangedCellBounds.right() ) );
169 
170  mChangedCellBounds = QRect();
171 }
172 
174 {
175  if ( idx == mCachedField )
176  {
177  prefetchColumnData( -1 );
178  }
179 }
180 
182 {
183  QgsDebugMsg( "entered." );
184 
185  beginRemoveRows( QModelIndex(), 0, rowCount() - 1 );
186  removeRows( 0, rowCount() );
187  endRemoveRows();
188 
189  const QMap<QString, QVariant> *item;
190  foreach ( item, mValueMaps )
191  {
192  delete item;
193  }
194 
195  mValueMaps.clear();
196 }
197 
198 void QgsAttributeTableModel::attributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value )
199 {
200  QgsDebugMsgLevel( QString( "(%4) fid: %1, idx: %2, value: %3" ).arg( fid ).arg( idx ).arg( value.toString() ).arg( mFeatureRequest.filterType() ), 3 );
201  // No filter request: skip all possibly heavy checks
203  {
204  setData( index( idToRow( fid ), fieldCol( idx ) ), value, Qt::EditRole );
205  }
206  else
207  {
208  if ( loadFeatureAtId( fid ) )
209  {
211  {
212  if ( !mIdRowMap.contains( fid ) )
213  {
214  // Feature changed in such a way, it will be shown now
215  featureAdded( fid );
216  }
217  else
218  {
219  if ( idx == mCachedField )
220  mFieldCache[ fid ] = value;
221  // Update representation
222  setData( index( idToRow( fid ), fieldCol( idx ) ), value, Qt::EditRole );
223  }
224  }
225  else
226  {
227  if ( mIdRowMap.contains( fid ) )
228  {
229  // Feature changed such, that it is no longer shown
230  featureDeleted( fid );
231  }
232  // else: we don't care
233  }
234  }
235  }
236 }
237 
239 {
240  if ( !layer() )
241  {
242  return;
243  }
244 
245  bool ins = false, rm = false;
246 
247  QgsAttributeList attributes;
248  const QgsFields& fields = layer()->pendingFields();
249  for ( int idx = 0; idx < fields.count(); ++idx )
250  {
251  switch ( layer()->editType( idx ) )
252  {
254  continue;
255 
257  mValueMaps.insert( idx, new QMap< QString, QVariant >( layer()->valueMap( idx ) ) );
258  break;
259 
261  {
263 
265  if ( !layer )
266  continue;
267 
268  int ki = layer->fieldNameIndex( data.mKey );
269  int vi = layer->fieldNameIndex( data.mValue );
270 
271  QgsExpression *e = 0;
272  if ( !data.mFilterExpression.isEmpty() )
273  {
274  e = new QgsExpression( data.mFilterExpression );
275  if ( e->hasParserError() || !e->prepare( layer->pendingFields() ) )
276  continue;
277  }
278 
279  if ( ki >= 0 && vi >= 0 )
280  {
281  QSet<int> attributes;
282  attributes << ki << vi;
283 
285 
286  if ( e )
287  {
288  if ( e->needsGeometry() )
290 
291  foreach ( const QString &field, e->referencedColumns() )
292  {
293  int idx = layer->fieldNameIndex( field );
294  if ( idx < 0 )
295  continue;
296  attributes << idx;
297  }
298  }
299 
300  QMap< QString, QVariant > *map = new QMap< QString, QVariant >();
301 
302  QgsFeatureIterator fit = layer->getFeatures( QgsFeatureRequest().setFlags( flags ).setSubsetOfAttributes( attributes.toList() ) );
303  QgsFeature f;
304  while ( fit.nextFeature( f ) )
305  {
306  if ( e && !e->evaluate( &f ).toBool() )
307  continue;
308 
309  map->insert( f.attribute( vi ).toString(), f.attribute( ki ) );
310  }
311 
312  mValueMaps.insert( idx, map );
313  }
314  }
315  break;
316 
317  default:
318  break;
319  }
320 
321  attributes << idx;
322  }
323 
324  if ( mFieldCount < attributes.size() )
325  {
326  ins = true;
327  beginInsertColumns( QModelIndex(), mFieldCount, attributes.size() - 1 );
328  }
329  else if ( attributes.size() < mFieldCount )
330  {
331  rm = true;
332  beginRemoveColumns( QModelIndex(), attributes.size(), mFieldCount - 1 );
333  }
334 
335  mFieldCount = attributes.size();
336  mAttributes = attributes;
337 
338  if ( ins )
339  {
340  endInsertColumns();
341  }
342  else if ( rm )
343  {
344  endRemoveColumns();
345  }
346 }
347 
349 {
350  QgsDebugMsg( "entered." );
351 
352  beginRemoveRows( QModelIndex(), 0, rowCount() - 1 );
353  removeRows( 0, rowCount() );
354  endRemoveRows();
355 
357 
358  int i = 0;
359 
360  QTime t;
361  t.start();
362 
363  QgsFeature feat;
364  while ( features.nextFeature( feat ) )
365  {
366  ++i;
367 
368  if ( t.elapsed() > 1000 )
369  {
370  bool cancel = false;
371  emit( progress( i, cancel ) );
372  if ( cancel )
373  break;
374 
375  t.restart();
376  }
377  mFeat = feat;
378  featureAdded( feat.id() );
379  }
380 
381  emit finished();
382 
383  mFieldCount = mAttributes.size();
384 }
385 
387 {
388  if ( a == b )
389  return;
390 
391  int rowA = idToRow( a );
392  int rowB = idToRow( b );
393 
394  //emit layoutAboutToBeChanged();
395 
396  mRowIdMap.remove( rowA );
397  mRowIdMap.remove( rowB );
398  mRowIdMap.insert( rowA, b );
399  mRowIdMap.insert( rowB, a );
400 
401  mIdRowMap.remove( a );
402  mIdRowMap.remove( b );
403  mIdRowMap.insert( a, rowB );
404  mIdRowMap.insert( b, rowA );
405 
406  //emit layoutChanged();
407 }
408 
410 {
411  if ( !mIdRowMap.contains( id ) )
412  {
413  QgsDebugMsg( QString( "idToRow: id %1 not in the map" ).arg( id ) );
414  return -1;
415  }
416 
417  return mIdRowMap[id];
418 }
419 
421 {
422  return index( idToRow( id ), 0 );
423 }
424 
426 {
427  QModelIndexList indexes;
428 
429  int row = idToRow( id );
430  for ( int column = 0; column < columnCount(); ++column )
431  {
432  indexes.append( index( row, column ) );
433  }
434 
435  return indexes;
436 }
437 
439 {
440  if ( !mRowIdMap.contains( row ) )
441  {
442  QgsDebugMsg( QString( "rowToId: row %1 not in the map" ).arg( row ) );
443  // return negative infinite (to avoid collision with newly added features)
445  }
446 
447  return mRowIdMap[row];
448 }
449 
451 {
452  return mAttributes[ col ];
453 }
454 
456 {
457  return mAttributes.indexOf( idx );
458 }
459 
460 int QgsAttributeTableModel::rowCount( const QModelIndex &parent ) const
461 {
462  Q_UNUSED( parent );
463  return mRowIdMap.size();
464 }
465 
466 int QgsAttributeTableModel::columnCount( const QModelIndex &parent ) const
467 {
468  Q_UNUSED( parent );
469  return qMax( 1, mFieldCount ); // if there are zero columns all model indices will be considered invalid
470 }
471 
472 QVariant QgsAttributeTableModel::headerData( int section, Qt::Orientation orientation, int role ) const
473 {
474  if ( !layer() )
475  return QVariant();
476 
477  if ( role == Qt::DisplayRole )
478  {
479  if ( orientation == Qt::Vertical ) //row
480  {
481  return QVariant( section );
482  }
483  else if ( section >= 0 && section < mFieldCount )
484  {
485  QString attributeName = layer()->attributeAlias( mAttributes[section] );
486  if ( attributeName.isEmpty() )
487  {
488  QgsField field = layer()->pendingFields()[ mAttributes[section] ];
489  attributeName = field.name();
490  }
491  return QVariant( attributeName );
492  }
493  else
494  {
495  return tr( "feature id" );
496  }
497  }
498  else
499  {
500  return QVariant();
501  }
502 }
503 
504 QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) const
505 {
506  if ( !index.isValid() ||
507  ( role != Qt::TextAlignmentRole
508  && role != Qt::DisplayRole
509  && role != Qt::EditRole
510  && role != SortRole
511  && role != FeatureIdRole
512  && role != FieldIndexRole
513  )
514  )
515  return QVariant();
516 
517  QgsFeatureId rowId = rowToId( index.row() );
518 
519  if ( role == FeatureIdRole )
520  return rowId;
521 
522  if ( index.column() >= mFieldCount )
523  return role == Qt::DisplayRole ? rowId : QVariant();
524 
525  int fieldId = mAttributes[ index.column()];
526 
527  if ( role == FieldIndexRole )
528  return fieldId;
529 
530  const QgsField& field = layer()->pendingFields()[ fieldId ];
531 
532  QVariant::Type fldType = field.type();
533  bool fldNumeric = ( fldType == QVariant::Int || fldType == QVariant::Double );
534 
535  if ( role == Qt::TextAlignmentRole )
536  {
537  if ( fldNumeric )
538  return QVariant( Qt::AlignRight );
539  else
540  return QVariant( Qt::AlignLeft );
541  }
542 
543  QVariant val;
544 
545  // if we don't have the row in current cache, load it from layer first
546  if ( mCachedField == fieldId )
547  {
548  val = mFieldCache[ rowId ];
549  }
550  else
551  {
552  if ( mFeat.id() != rowId || !mFeat.isValid() )
553  {
554  if ( !loadFeatureAtId( rowId ) )
555  return QVariant( "ERROR" );
556 
557  if ( mFeat.id() != rowId )
558  return QVariant( "ERROR" );
559  }
560 
561  val = mFeat.attribute( fieldId );
562  }
563 
564  // For sorting return unprocessed value
565  if ( SortRole == role )
566  {
567  return val;
568  }
569 
570  if ( val.isNull() )
571  {
572  // if the value is NULL, show that in table, but don't show "NULL" text in editor
573  if ( role == Qt::EditRole )
574  {
575  return QVariant( fldType );
576  }
577  else
578  {
579  QSettings settings;
580  return settings.value( "qgis/nullValue", "NULL" );
581  }
582  }
583 
584  if ( role == Qt::DisplayRole )
585  {
586  if ( mValueMaps.contains( fieldId ) )
587  {
588  return mValueMaps[ fieldId ]->key( val.toString(), QString( "(%1)" ).arg( val.toString() ) );
589  }
590 
591  if ( layer()->editType( fieldId ) == QgsVectorLayer::Calendar && val.canConvert( QVariant::Date ) )
592  {
593  return val.toDate().toString( layer()->dateFormat( fieldId ) );
594  }
595  }
596 
597 
598  return field.displayString( val );
599 }
600 
601 bool QgsAttributeTableModel::setData( const QModelIndex &index, const QVariant &value, int role )
602 {
603  Q_UNUSED( value )
604 
605  if ( !index.isValid() || index.column() >= mFieldCount || role != Qt::EditRole || !layer()->isEditable() )
606  return false;
607 
608  if ( !layer()->isModified() )
609  return false;
610 
611  if ( mChangedCellBounds.isNull() )
612  {
613  mChangedCellBounds = QRect( index.column(), index.row(), 0, 0 );
614  }
615  else
616  {
617  if ( index.column() < mChangedCellBounds.left() )
618  {
619  mChangedCellBounds.setLeft( index.column() );
620  }
621  if ( index.row() < mChangedCellBounds.top() )
622  {
623  mChangedCellBounds.setTop( index.row() );
624  }
625  if ( index.column() > mChangedCellBounds.right() )
626  {
627  mChangedCellBounds.setRight( index.column() );
628  }
629  if ( index.row() > mChangedCellBounds.bottom() )
630  {
631  mChangedCellBounds.setBottom( index.row() );
632  }
633  }
634 
635  return true;
636 }
637 
638 Qt::ItemFlags QgsAttributeTableModel::flags( const QModelIndex &index ) const
639 {
640  if ( !index.isValid() )
641  return Qt::ItemIsEnabled;
642 
643  if ( index.column() >= mFieldCount )
644  return Qt::NoItemFlags;
645 
646  Qt::ItemFlags flags = QAbstractItemModel::flags( index );
647 
648  if ( layer()->isEditable() &&
649  layer()->editType( mAttributes[ index.column()] ) != QgsVectorLayer::Immutable )
650  flags |= Qt::ItemIsEditable;
651 
652  return flags;
653 }
654 
655 void QgsAttributeTableModel::reload( const QModelIndex &index1, const QModelIndex &index2 )
656 {
658  emit dataChanged( index1, index2 );
659 }
660 
662 {
663  beginResetModel();
664  endResetModel();
665 }
666 
667 void QgsAttributeTableModel::executeAction( int action, const QModelIndex &idx ) const
668 {
669  QgsFeature f = feature( idx );
670  layer()->actions()->doAction( action, f, fieldIdx( idx.column() ) );
671 }
672 
673 void QgsAttributeTableModel::executeMapLayerAction( QgsMapLayerAction* action, const QModelIndex &idx ) const
674 {
675  QgsFeature f = feature( idx );
676  action->triggerForFeature( layer(), &f );
677 }
678 
679 QgsFeature QgsAttributeTableModel::feature( const QModelIndex &idx ) const
680 {
681  QgsFeature f;
682  f.initAttributes( mAttributes.size() );
683  f.setFeatureId( rowToId( idx.row() ) );
684  for ( int i = 0; i < mAttributes.size(); i++ )
685  {
686  f.setAttribute( mAttributes[i], data( index( idx.row(), i ), Qt::EditRole ) );
687  }
688 
689  return f;
690 }
691 
693 {
694  mFieldCache.clear();
695 
696  if ( column == -1 )
697  {
698  mCachedField = -1;
699  }
700  else
701  {
702  if ( column >= mAttributes.count() )
703  return;
704  int fieldId = mAttributes[ column ];
705  const QgsFields& fields = layer()->pendingFields();
706  QStringList fldNames;
707  fldNames << fields[ fieldId ].name();
708 
709  QgsFeatureIterator it = mLayerCache->getFeatures( QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry ).setSubsetOfAttributes( fldNames, fields ) );
710 
711  QgsFeature f;
712  while ( it.nextFeature( f ) )
713  {
714  mFieldCache.insert( f.id(), f.attribute( fieldId ) );
715  }
716 
717  mCachedField = fieldId;
718  }
719 }
720 
722 {
723  mFeatureRequest = request;
724  if ( layer() && !layer()->hasGeometryType() )
726 }
QgsFeatureId id() const
Get the feature id for this feature.
Definition: qgsfeature.cpp:100
void setRequest(const QgsFeatureRequest &request)
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:89
const QString & name() const
Gets the name of the field.
Definition: qgsfield.cpp:55
QRect mChangedCellBounds
Holds the bounds of changed cells while an update operation is running top = min row left = min colum...
Wrapper for iterator of features from vector data provider or vector layer.
static unsigned index
bool acceptFeature(const QgsFeature &feature)
Check if a feature is accepted by this requests filter.
const Flags & flags() const
virtual void loadLayer()
Loads the layer into the model Preferably to be called, before basing any other models on this model...
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
Definition: qgsexpression.h:96
QModelIndexList idToIndexList(QgsFeatureId id) const
QHash< int, QgsFeatureId > mRowIdMap
bool isValid() const
Return the validity of this feature.
Definition: qgsfeature.cpp:171
QgsAttributeAction * actions()
QgsFeatureRequest mFeatureRequest
int columnCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of columns.
QVariant evaluate(const QgsFeature *f=NULL)
Evaluate the feature and return the result.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of rows.
bool prepare(const QgsFields &fields)
Get the expression ready for evaluation - find out column indexes.
QString displayString(const QVariant &v) const
Formats string for display.
Definition: qgsfield.cpp:114
The attribute value should not be changed in the attribute form.
#define QgsDebugMsg(str)
Definition: qgslogger.h:36
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
Remove rows.
QHash< QgsFeatureId, QVariant > mFieldCache
Allows to cache one specific column (used for sorting)
virtual void layerDeleted()
Launched when layer has been deleted.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
void reload(const QModelIndex &index1, const QModelIndex &index2)
Reloads the model data between indices.
#define FID_TO_STRING(fid)
Definition: qgsfeature.h:83
QModelIndex idToIndex(QgsFeatureId id) const
Container of fields for a vector layer.
Definition: qgsfield.h:164
bool setAttribute(int field, const QVariant &attr)
Set an attribute by id.
Definition: qgsfeature.cpp:190
QgsVectorLayer * layer()
Returns the layer to which this cache belongs.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:114
void resetModel()
Resets the model.
void triggerForFeature(QgsMapLayer *layer, QgsFeature *feature)
Triggers the action with the specified layer and feature.
QgsVectorLayerCache * mLayerCache
virtual void attributeValueChanged(QgsFeatureId fid, int idx, const QVariant &value)
Launched when attribute value has been changed.
int mCachedField
The currently cached column.
virtual void editCommandEnded()
Gets called when an edit command ends This will synchronize all fields which have been changed since ...
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Updates data on given index.
void executeMapLayerAction(QgsMapLayerAction *action, const QModelIndex &idx) const
Execute a QgsMapLayerAction.
void setFeatureId(QgsFeatureId id)
Set the feature id for this feature.
Definition: qgsfeature.cpp:128
QMap< int, const QMap< QString, QVariant > * > mValueMaps
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:37
The attribute value should not be shown in the attribute form.
EditType editType(int idx)
get edit type
void initAttributes(int fieldCount)
Initialize this feature with the given number of fields.
Definition: qgsfeature.cpp:181
QStringList referencedColumns()
Get list of columns referenced by the expression.
void doAction(int index, QgsFeature &feat, int defaultValueIndex=0)
Qt::ItemFlags flags(const QModelIndex &index) const
Returns item flags for the index.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
int count() const
Return number of items.
Definition: qgsfield.h:198
virtual bool isModified() const
Returns true if the provider has been modified since the last commit.
QGis::GeometryType geometryType() const
Returns point, line or polygon.
QHash< QgsFeatureId, int > mIdRowMap
FilterType filterType() const
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:31
QString attributeAlias(int attributeIndex) const
Returns the alias of an attribute name or an empty string if there is no alias.
ValueRelationData & valueRelation(int idx)
access relations
void executeAction(int action, const QModelIndex &idx) const
Execute an action.
virtual void attributeDeleted(int idx)
Called whenever a column is removed;.
virtual void featureAdded(QgsFeatureId fid)
Launched when a feature has been added.
QgsFeature feature(const QModelIndex &idx) const
Return the feature attributes at given model index.
This class caches features of a given QgsVectorLayer.
bool needsGeometry()
Returns true if the expression uses feature geometry for some computation.
void progress(int i, bool &cancel)
void modelChanged()
Model has been changed.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Returns header data.
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
No filter is applied.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
Definition: qgsfeature.cpp:230
int fieldCol(int idx) const
get column from field index
virtual void featureDeleted(QgsFeatureId fid)
Launched when a feature has been deleted.
bool featureAtId(QgsFeatureId featureId, QgsFeature &feature, bool skipCache=false)
Gets the feature at the given feature id.
QgsVectorLayer * layer() const
Returns the layer this model uses as backend.
virtual QVariant data(const QModelIndex &index, int role) const
Returns data on the given index.
virtual void loadAttributes()
Gets mFieldCount, mAttributes and mValueMaps.
int idToRow(QgsFeatureId id) const
Maps feature id to table row.
qint64 QgsFeatureId
Definition: qgsfeature.h:30
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
int fieldIdx(int col) const
get field index from column
QgsFeatureId rowToId(int row) const
Maps row to feature id.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
double ANALYSIS_EXPORT min(double x, double y)
returns the minimum of two doubles or the first argument if both are equal
void swapRows(QgsFeatureId a, QgsFeatureId b)
Swaps two rows.
bool nextFeature(QgsFeature &f)
Geometry is not required. It may still be returned if e.g. required for a filter condition.
virtual bool isEditable() const
Returns true if the provider is in editing mode.
Represents a vector layer which manages a vector based data sets.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &featureRequest=QgsFeatureRequest())
Query this VectorLayerCache for features.
QgsFeatureRequest & setFlags(Flags flags)
Set flags that affect how features will be fetched.
virtual bool loadFeatureAtId(QgsFeatureId fid) const
Load feature fid into local cache (mFeat)
QgsAttributeTableModel(QgsVectorLayerCache *layerCache, QObject *parent=0)
Constructor.
value map from an table
An action which can run on map layers.
void prefetchColumnData(int column)
Caches the entire data for one column.
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.
Definition: qgsfield.cpp:60
virtual void updatedFields()
Launched whenever the number of fields has changed.
#define tr(sourceText)