QGIS API Documentation
qgscomposerattributetable.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerattributetable.cpp
3  -----------------------------
4  begin : April 2010
5  copyright : (C) 2010 by Marco Hugentobler
6  email : marco at hugis dot net
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
19 #include "qgscomposertablecolumn.h"
20 #include "qgscomposermap.h"
21 #include "qgscomposerutils.h"
22 #include "qgsmaplayerregistry.h"
23 #include "qgsvectorlayer.h"
24 
25 //QgsComposerAttributeTableCompare
26 
28  : mCurrentSortColumn( 0 ), mAscending( true )
29 {
30 }
31 
32 
34 {
35  return ( mAscending ? qgsVariantLessThan( m1[mCurrentSortColumn], m2[mCurrentSortColumn] )
36  : qgsVariantGreaterThan( m1[mCurrentSortColumn], m2[mCurrentSortColumn] ) );
37 }
38 
39 
40 //QgsComposerAttributeTable
41 
43  : QgsComposerTable( composition )
44  , mVectorLayer( nullptr )
45  , mComposerMap( nullptr )
46  , mMaximumNumberOfFeatures( 5 )
47  , mShowOnlyVisibleFeatures( false )
48  , mFilterFeatures( false )
49  , mFeatureFilter( "" )
50 {
51  //set first vector layer from layer registry as default one
54  for ( ; mapIt != layerMap.constEnd(); ++mapIt )
55  {
56  QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( mapIt.value() );
57  if ( vl )
58  {
59  mVectorLayer = vl;
60  break;
61  }
62  }
63  if ( mVectorLayer )
64  {
65  resetColumns();
66  }
67  connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( removeLayer( const QString& ) ) );
68 
69  if ( mComposition )
70  {
71  //refresh table attributes when composition is refreshed
72  connect( mComposition, SIGNAL( refreshItemsTriggered() ), this, SLOT( refreshAttributes() ) );
73 
74  //connect to atlas feature changes to update table rows
75  connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshAttributes() ) );
76  }
77 }
78 
80 {
81 }
82 
83 void QgsComposerAttributeTable::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
84 {
85  if ( mComposerMap && mComposerMap->isDrawing() )
86  {
87  return;
88  }
89  if ( !shouldDrawItem() )
90  {
91  return;
92  }
93  QgsComposerTable::paint( painter, itemStyle, pWidget );
94 }
95 
97 {
98  if ( layer == mVectorLayer )
99  {
100  //no change
101  return;
102  }
103 
104  if ( mVectorLayer )
105  {
106  //disconnect from previous layer
107  QObject::disconnect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
108  }
109 
110  mVectorLayer = layer;
111 
112  //rebuild column list to match all columns from layer
113  resetColumns();
115 
116  //listen for modifications to layer and refresh table when they occur
117  QObject::connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
118 }
119 
121 {
122  if ( !mVectorLayer )
123  {
124  return;
125  }
126 
127  //remove existing columns
128  qDeleteAll( mColumns );
129  mColumns.clear();
130 
131  //rebuild columns list from vector layer fields
132  int idx = 0;
133  Q_FOREACH ( const QgsField& field, mVectorLayer->fields() )
134  {
135  QString currentAlias = mVectorLayer->attributeDisplayName( idx );
137  col->setAttribute( field.name() );
138  col->setHeading( currentAlias );
139  mColumns.append( col );
140  idx++;
141  }
142 }
143 
145 {
146  if ( map == mComposerMap )
147  {
148  //no change
149  return;
150  }
151 
152  if ( mComposerMap )
153  {
154  //disconnect from previous map
155  QObject::disconnect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
156  }
157  mComposerMap = map;
158  if ( mComposerMap )
159  {
160  //listen out for extent changes in linked map
161  QObject::connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
162  }
164 }
165 
167 {
168  if ( features == mMaximumNumberOfFeatures )
169  {
170  return;
171  }
172 
173  mMaximumNumberOfFeatures = features;
175 }
176 
178 {
179  if ( visibleOnly == mShowOnlyVisibleFeatures )
180  {
181  return;
182  }
183 
184  mShowOnlyVisibleFeatures = visibleOnly;
186 }
187 
189 {
190  if ( filter == mFilterFeatures )
191  {
192  return;
193  }
194 
195  mFilterFeatures = filter;
197 }
198 
200 {
201  if ( expression == mFeatureFilter )
202  {
203  return;
204  }
205 
206  mFeatureFilter = expression;
208 }
209 
211 {
212  return fieldsToDisplay().toSet();
213 }
214 
216 {
217  if ( !mVectorLayer )
218  {
219  return;
220  }
221 
222  //rebuild columns list, taking only attributes with index in supplied QSet
223  qDeleteAll( mColumns );
224  mColumns.clear();
225 
226  const QgsFields& fields = mVectorLayer->fields();
227 
228  if ( !attr.empty() )
229  {
230  QSet<int>::const_iterator attIt = attr.constBegin();
231  for ( ; attIt != attr.constEnd(); ++attIt )
232  {
233  int attrIdx = ( *attIt );
234  if ( !fields.exists( attrIdx ) )
235  {
236  continue;
237  }
238  QString currentAlias = mVectorLayer->attributeDisplayName( attrIdx );
240  col->setAttribute( fields[attrIdx].name() );
241  col->setHeading( currentAlias );
242  mColumns.append( col );
243  }
244  }
245  else
246  {
247  //resetting, so add all attributes to columns
248  int idx = 0;
249  Q_FOREACH ( const QgsField& field, fields )
250  {
251  QString currentAlias = mVectorLayer->attributeDisplayName( idx );
253  col->setAttribute( field.name() );
254  col->setHeading( currentAlias );
255  mColumns.append( col );
256  idx++;
257  }
258  }
259 
260  if ( refresh )
261  {
263  }
264 }
265 
267 {
269 
271  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
272  {
273  int attrIdx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
274  fieldAliasMap.insert( attrIdx, ( *columnIt )->heading() );
275  }
276  return fieldAliasMap;
277 }
278 
279 void QgsComposerAttributeTable::restoreFieldAliasMap( const QMap<int, QString>& map )
280 {
281  if ( !mVectorLayer )
282  {
283  return;
284  }
285 
287  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
288  {
289  int attrIdx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
290  if ( map.contains( attrIdx ) )
291  {
292  ( *columnIt )->setHeading( map.value( attrIdx ) );
293  }
294  else
295  {
296  ( *columnIt )->setHeading( mVectorLayer->attributeDisplayName( attrIdx ) );
297  }
298  }
299 }
300 
301 
303 {
304  restoreFieldAliasMap( map );
306 }
307 
308 QList<int> QgsComposerAttributeTable::fieldsToDisplay() const
309 {
310  //kept for api compatibility with 2.0 only, can be removed after next api break
311  QList<int> fields;
312 
314  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
315  {
316  int idx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
317  fields.append( idx );
318  }
319  return fields;
320 }
321 
323 {
324  if ( !mVectorLayer )
325  {
326  return false;
327  }
328 
330  context->setFields( mVectorLayer->fields() );
331 
332  attributeMaps.clear();
333 
334  //prepare filter expression
335  QScopedPointer<QgsExpression> filterExpression;
336  bool activeFilter = false;
337  if ( mFilterFeatures && !mFeatureFilter.isEmpty() )
338  {
339  filterExpression.reset( new QgsExpression( mFeatureFilter ) );
340  if ( !filterExpression->hasParserError() )
341  {
342  activeFilter = true;
343  }
344  }
345 
346  QgsRectangle selectionRect;
347  if ( mComposerMap && mShowOnlyVisibleFeatures )
348  {
349  selectionRect = *mComposerMap->currentMapExtent();
351  {
352  //transform back to layer CRS
353  QgsCoordinateTransform coordTransform( mVectorLayer->crs(), mComposition->mapSettings().destinationCrs() );
354  try
355  {
356  selectionRect = coordTransform.transformBoundingBox( selectionRect, QgsCoordinateTransform::ReverseTransform );
357  }
358  catch ( QgsCsException &cse )
359  {
360  Q_UNUSED( cse );
361  return false;
362  }
363  }
364  }
365 
366  QgsFeatureRequest req;
367  if ( !selectionRect.isEmpty() )
368  req.setFilterRect( selectionRect );
369 
370  req.setFlags( mShowOnlyVisibleFeatures ? QgsFeatureRequest::ExactIntersect : QgsFeatureRequest::NoFlags );
371 
372  QgsFeature f;
373  int counter = 0;
374  QgsFeatureIterator fit = mVectorLayer->getFeatures( req );
375 
376  while ( fit.nextFeature( f ) && counter < mMaximumNumberOfFeatures )
377  {
378  context->setFeature( f );
379  //check feature against filter
380  if ( activeFilter && !filterExpression.isNull() )
381  {
382  QVariant result = filterExpression->evaluate( context.data() );
383  // skip this feature if the filter evaluation is false
384  if ( !result.toBool() )
385  {
386  continue;
387  }
388  }
389 
390  attributeMaps.push_back( QgsAttributeMap() );
391 
393  int i = 0;
394  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
395  {
396  int idx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
397  if ( idx != -1 )
398  {
399  attributeMaps.last().insert( i, f.attributes().at( idx ) );
400  }
401  else
402  {
403  // Lets assume it's an expression
404  QgsExpression* expression = new QgsExpression(( *columnIt )->attribute() );
405  context->lastScope()->setVariable( QString( "row_number" ), counter + 1 );
406  expression->prepare( context.data() );
407  QVariant value = expression->evaluate( context.data() );
408  attributeMaps.last().insert( i, value.toString() );
409  }
410 
411  i++;
412  }
413  ++counter;
414  }
415 
416  //sort the list, starting with the last attribute
418  QList< QPair<int, bool> > sortColumns = sortAttributes();
419  for ( int i = sortColumns.size() - 1; i >= 0; --i )
420  {
421  c.setSortColumn( sortColumns.at( i ).first );
422  c.setAscending( sortColumns.at( i ).second );
423  qStableSort( attributeMaps.begin(), attributeMaps.end(), c );
424  }
425 
427  return true;
428 }
429 
430 void QgsComposerAttributeTable::removeLayer( const QString& layerId )
431 {
432  if ( mVectorLayer )
433  {
434  if ( layerId == mVectorLayer->id() )
435  {
436  mVectorLayer = nullptr;
437  //remove existing columns
438  qDeleteAll( mColumns );
439  mColumns.clear();
440  }
441  }
442 }
443 
445 {
446  //update rect for data defined size and position
447  QRectF evaluatedRect = evalItemRect( rectangle );
448 
449  QgsComposerItem::setSceneRect( evaluatedRect );
450 
451  //refresh table attributes, since number of features has likely changed
453 }
454 
456 {
457  //first, clear existing sort by ranks
458  Q_FOREACH ( QgsComposerTableColumn* column, mColumns )
459  {
460  column->setSortByRank( 0 );
461  }
462 
463  //now, update sort rank of specified columns
464  QList< QPair<int, bool > >::const_iterator sortedColumnIt = att.constBegin();
465  int rank = 1;
466  for ( ; sortedColumnIt != att.constEnd(); ++sortedColumnIt )
467  {
468  if (( *sortedColumnIt ).first >= mColumns.length() )
469  {
470  continue;
471  }
472  mColumns.at(( *sortedColumnIt ).first )->setSortByRank( rank );
473  mColumns.at(( *sortedColumnIt ).first )->setSortOrder(( *sortedColumnIt ).second ? Qt::AscendingOrder : Qt::DescendingOrder );
474  rank++;
475  }
476 
478 }
479 
481 {
482  return a.second->sortByRank() < b.second->sortByRank();
483 }
484 
486 {
487  //generate list of all sorted columns
490  int idx = 0;
491  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
492  {
493  if (( *columnIt )->sortByRank() > 0 )
494  {
495  sortedColumns.append( qMakePair( idx, *columnIt ) );
496  }
497  idx++;
498  }
499 
500  //sort columns by rank
501  qSort( sortedColumns.begin(), sortedColumns.end(), columnsBySortRank );
502 
503  //generate list of column index, bool for sort direction (to match 2.0 api)
504  QList<QPair<int, bool> > attributesBySortRank;
505  QVector< QPair<int, QgsComposerTableColumn* > >::const_iterator sortedColumnIt = sortedColumns.constBegin();
506  for ( ; sortedColumnIt != sortedColumns.constEnd(); ++sortedColumnIt )
507  {
508 
509  attributesBySortRank.append( qMakePair(( *sortedColumnIt ).first,
510  ( *sortedColumnIt ).second->sortOrder() == Qt::AscendingOrder ) );
511  }
512  return attributesBySortRank;
513 }
514 
516 {
517  QDomElement composerTableElem = doc.createElement( "ComposerAttributeTable" );
518  composerTableElem.setAttribute( "showOnlyVisibleFeatures", mShowOnlyVisibleFeatures );
519  composerTableElem.setAttribute( "maxFeatures", mMaximumNumberOfFeatures );
520  composerTableElem.setAttribute( "filterFeatures", mFilterFeatures ? "true" : "false" );
521  composerTableElem.setAttribute( "featureFilter", mFeatureFilter );
522 
523  if ( mComposerMap )
524  {
525  composerTableElem.setAttribute( "composerMap", mComposerMap->id() );
526  }
527  else
528  {
529  composerTableElem.setAttribute( "composerMap", -1 );
530  }
531  if ( mVectorLayer )
532  {
533  composerTableElem.setAttribute( "vectorLayer", mVectorLayer->id() );
534  }
535 
536  elem.appendChild( composerTableElem );
537  bool ok = tableWriteXML( composerTableElem, doc );
538  return ok;
539 }
540 
542 {
543  if ( itemElem.isNull() )
544  {
545  return false;
546  }
547 
548  //read general table properties
549  if ( !tableReadXML( itemElem, doc ) )
550  {
551  return false;
552  }
553 
554  mShowOnlyVisibleFeatures = itemElem.attribute( "showOnlyVisibleFeatures", "1" ).toInt();
555  mFilterFeatures = itemElem.attribute( "filterFeatures", "false" ) == "true" ? true : false;
556  mFeatureFilter = itemElem.attribute( "featureFilter", "" );
557 
558  //composer map
559  int composerMapId = itemElem.attribute( "composerMap", "-1" ).toInt();
560  if ( composerMapId == -1 )
561  {
562  mComposerMap = nullptr;
563  }
564 
565  if ( composition() )
566  {
567  mComposerMap = composition()->getComposerMapById( composerMapId );
568  }
569  else
570  {
571  mComposerMap = nullptr;
572  }
573 
574  if ( mComposerMap )
575  {
576  //if we have found a valid map item, listen out to extent changes on it and refresh the table
577  QObject::connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
578  }
579 
580  //vector layer
581  QString layerId = itemElem.attribute( "vectorLayer", "not_existing" );
582  if ( layerId == "not_existing" )
583  {
584  mVectorLayer = nullptr;
585  }
586  else
587  {
589  if ( ml )
590  {
591  mVectorLayer = dynamic_cast<QgsVectorLayer*>( ml );
592  if ( mVectorLayer )
593  {
594  //if we have found a valid vector layer, listen for modifications on it and refresh the table
595  QObject::connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
596  }
597  }
598  }
599 
600  //restore display attribute map. This is required to upgrade pre 2.4 projects.
602  QDomNodeList displayAttributeList = itemElem.elementsByTagName( "displayAttributes" );
603  if ( !displayAttributeList.isEmpty() )
604  {
605  QDomElement displayAttributesElem = displayAttributeList.at( 0 ).toElement();
606  QDomNodeList attributeEntryList = displayAttributesElem.elementsByTagName( "attributeEntry" );
607  for ( int i = 0; i < attributeEntryList.size(); ++i )
608  {
609  QDomElement attributeEntryElem = attributeEntryList.at( i ).toElement();
610  int index = attributeEntryElem.attribute( "index", "-1" ).toInt();
611  if ( index != -1 )
612  {
613  displayAttributes.insert( index );
614  }
615  }
616  setDisplayAttributes( displayAttributes, false );
617  }
618 
619  //restore alias map. This is required to upgrade pre 2.4 projects.
621  QDomNodeList aliasMapNodeList = itemElem.elementsByTagName( "attributeAliasMap" );
622  if ( !aliasMapNodeList.isEmpty() )
623  {
624  QDomElement attributeAliasMapElem = aliasMapNodeList.at( 0 ).toElement();
625  QDomNodeList aliasMepEntryList = attributeAliasMapElem.elementsByTagName( "aliasEntry" );
626  for ( int i = 0; i < aliasMepEntryList.size(); ++i )
627  {
628  QDomElement aliasEntryElem = aliasMepEntryList.at( i ).toElement();
629  int key = aliasEntryElem.attribute( "key", "-1" ).toInt();
630  QString value = aliasEntryElem.attribute( "value", "" );
631  fieldAliasMap.insert( key, value );
632  }
633  restoreFieldAliasMap( fieldAliasMap );
634  }
635 
636  //restore sort columns. This is required to upgrade pre 2.4 projects.
637  QDomElement sortColumnsElem = itemElem.firstChildElement( "sortColumns" );
638  if ( !sortColumnsElem.isNull() && mVectorLayer )
639  {
640  QDomNodeList columns = sortColumnsElem.elementsByTagName( "column" );
641  const QgsFields& fields = mVectorLayer->fields();
642 
643  for ( int i = 0; i < columns.size(); ++i )
644  {
645  QDomElement columnElem = columns.at( i ).toElement();
646  int attribute = columnElem.attribute( "index" ).toInt();
647  Qt::SortOrder order = columnElem.attribute( "ascending" ) == "true" ? Qt::AscendingOrder : Qt::DescendingOrder;
648  //find corresponding column
649  Q_FOREACH ( QgsComposerTableColumn* column, mColumns )
650  {
651  if ( column->attribute() == fields[attribute].name() )
652  {
653  column->setSortByRank( i + 1 );
654  column->setSortOrder( order );
655  break;
656  }
657  }
658  }
659  }
660 
661  //must be done here because tableReadXML->setSceneRect changes mMaximumNumberOfFeatures
662  mMaximumNumberOfFeatures = itemElem.attribute( "maxFeatures", "5" ).toInt();
663 
665 
666  emit itemChanged();
667  return true;
668 }
Class for parsing and evaluation of expressions (formerly called "search strings").
void setSceneRect(const QRectF &rectangle) override
Adapts mMaximumNumberOfFeatures depending on the rectangle height.
void clear()
Wrapper for iterator of features from vector data provider or vector layer.
QDomNodeList elementsByTagName(const QString &tagname) const
void setAttribute(const QString &attribute)
Sets the attribute name or expression used for the column&#39;s values.
static unsigned index
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:49
QList< QPair< int, bool > > sortAttributes() const
Returns the attributes used to sort the table&#39;s features.
bool isEmpty() const
test if rectangle is empty.
void setAscending(bool asc)
Sets sort order for column sorting.
Q_DECL_DEPRECATED void setSortAttributes(const QList< QPair< int, bool > > &att)
Sets the attributes to use to sort the table&#39;s features.
bool contains(const Key &key) const
Q_DECL_DEPRECATED QVariant evaluate(const QgsFeature *f)
Evaluate the feature and return the result.
QMap< int, QVariant > QgsAttributeMap
Definition: qgsfeature.h:104
QDomNode appendChild(const QDomNode &newChild)
void append(const T &value)
Use exact geometry intersection (slower) instead of bounding boxes.
iterator begin()
void push_back(const T &value)
Q_DECL_DEPRECATED QSet< int > displayAttributes() const
Returns the attributes fields which are shown by the table.
QString attribute(const QString &name, const QString &defValue) const
int length() const
Q_DECL_DEPRECATED bool prepare(const QgsFields &fields)
Get the expression ready for evaluation - find out column indexes.
QgsFields fields() const
Returns the list of fields of this layer.
void itemChanged()
Emitted when the item changes.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
void setComposerMap(const QgsComposerMap *map)
Sets the composer map to use to limit the extent of features shown in the attribute table...
const_iterator constEnd() const
const_iterator constBegin() const
const T & at(int i) const
QRectF evalItemRect(const QRectF &newRect, const bool resizeOnly=false, const QgsExpressionContext *context=nullptr)
Evaluates an item&#39;s bounding rect to consider data defined position and size of item and reference po...
bool getFeatureAttributes(QList< QgsAttributeMap > &attributeMaps) override
Queries the attribute table&#39;s vector layer for attributes to show in the table.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
Container of fields for a vector layer.
Definition: qgsfield.h:187
QSet< T > toSet() const
QList< QgsComposerTableColumn * > * columns()
Returns a pointer to the list of QgsComposerTableColumns shown in the table.
const_iterator insert(const T &value)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is greater than the second.
Definition: qgis.cpp:331
void setDisplayAttributes(const QSet< int > &attr, bool refresh=true)
Sets the attributes to display in the table.
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
virtual QgsExpressionContext * createExpressionContext() const override
Creates an expression context relating to the item&#39;s current state.
bool operator()(const QgsAttributeMap &m1, const QgsAttributeMap &m2)
void setFilterFeatures(bool filter)
Sets whether the feature filter is active for the attribute table.
void setDisplayOnlyVisibleFeatures(bool visibleOnly)
Sets attribute table to only show features which are visible in a composer map item.
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is less than the second.
Definition: qgis.cpp:263
QMap< QString, QgsMapLayer * > mapLayers()
Retrieve the mapLayers collection (mainly intended for use by projection)
int size() const
QgsMapLayer * mapLayer(const QString &theLayerId)
Retrieve a pointer to a loaded layer by id.
A class to display feature attributes in the print composer.
void reset(T *other)
bool isDrawing() const
True if a draw is already in progress.
QDomElement toElement() const
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Reads the properties specific to an attribute table from xml.
bool isEmpty() const
const char * name() const
void setVectorLayer(QgsVectorLayer *layer)
Sets the vector layer from which to display feature attributes.
bool exists(int i) const
Return if a field index is valid.
Definition: qgsfield.cpp:375
void append(const T &value)
void setHeading(const QString &heading)
Sets the heading for a column, which is the value displayed in the columns header cell...
QString attributeDisplayName(int attributeIndex) const
Convenience function that returns the attribute alias if defined or the field name else...
QgsAttributes attributes() const
Returns the feature&#39;s attributes.
Definition: qgsfeature.cpp:110
void setAttribute(const QString &name, const QString &value)
const QgsComposition * composition() const
Returns the composition the item is attached to.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
QString name() const
Gets the name of the field.
Definition: qgsfield.cpp:84
int toInt(bool *ok, int base) const
bool isEmpty() const
const_iterator constEnd() const
static bool columnsBySortRank(QPair< int, QgsComposerTableColumn * > a, QPair< int, QgsComposerTableColumn * > b)
bool tableWriteXML(QDomElement &itemElem, QDomDocument &doc) const
Writes common table properties to xml for storage.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void setMaximumNumberOfFeatures(int features)
Sets the maximum number of features shown by the table.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
Reimplementation of QCanvasItem::paint.
QString id() const
Get this layer&#39;s unique ID, this ID is used to access this layer from map layer registry.
const_iterator constEnd() const
Q_DECL_DEPRECATED void setFieldAliasMap(const QMap< int, QString > &map)
Sets the attribute field aliases, which control how fields are named in the table&#39;s header row...
QgsFeatureRequest & setFlags(const QgsFeatureRequest::Flags &flags)
Set flags that affect how features will be fetched.
QgsComposerAttributeTable(QgsComposition *composition)
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:44
bool shouldDrawItem() const
Returns whether the item should be drawn in the current context.
Stores properties of a column in a QgsComposerTable.
Graphics scene for map printing.
void resetColumns()
Resets the attribute table&#39;s columns to match the vector layer&#39;s fields.
Object representing map window.
T * data() const
iterator end()
QList< QgsComposerTableColumn * > mColumns
const_iterator constBegin() const
bool isNull() const
void setFeatureFilter(const QString &expression)
Sets the expression used for filtering features in the table.
int id() const
Get identification number.
QgsComposition * mComposition
bool isNull() const
virtual void refreshAttributes()
Refreshes the attributes shown in the table by querying the vector layer for new data.
const T & at(int i) const
bool empty() const
const_iterator constBegin() const
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
Q_DECL_DEPRECATED QMap< int, QString > fieldAliasMap() const
Returns the attribute field aliases, which control how fields are named in the table&#39;s header row...
bool tableReadXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads the table&#39;s common properties from xml.
virtual void adjustFrameToSize()
Adapts the size of the frame to match the content.
void setSortOrder(Qt::SortOrder sortOrder)
Sets the sort order for the column.
bool writeXML(QDomElement &elem, QDomDocument &doc) const override
Writes properties specific to attribute tables.
void setSortColumn(int col)
Sets column number to sort by.
QDomElement firstChildElement(const QString &tagName) const
T & last()
virtual void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
Class for doing transforms between two map coordinate systems.
bool toBool() const
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
Reimplementation of QCanvasItem::paint.
const QgsCoordinateReferenceSystem & crs() const
Returns layer&#39;s spatial reference system.
QString attribute() const
Returns the attribute name or expression used for the column&#39;s values.
QgsAtlasComposition & atlasComposition()
iterator insert(const Key &key, const T &value)
Custom exception class for Coordinate Reference System related exceptions.
int size() const
const_iterator constEnd() const
QDomElement createElement(const QString &tagName)
bool nextFeature(QgsFeature &f)
const_iterator constBegin() const
const QgsComposerMap * getComposerMapById(const int id) const
Returns the composer map with specified id.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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.
QString toString() const
iterator end()
const QgsRectangle * currentMapExtent() const
Returns a pointer to the current map extent, which is either the original user specified extent or th...
Helper class for sorting tables, takes into account sorting column and ascending / descending...
iterator begin()
QgsFeatureRequest & setFilterRect(const QgsRectangle &rect)
Set rectangle from which features will be taken.
void setSortByRank(int sortByRank)
Sets the sort rank for the column.
QDomNode at(int index) const
const T value(const Key &key) const