QGIS API Documentation  2.14.11-Essen
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  const QgsFields& fields = mVectorLayer->fields();
133  for ( int idx = 0; idx < fields.count(); ++idx )
134  {
135  QString currentAlias = mVectorLayer->attributeDisplayName( idx );
137  col->setAttribute( fields[idx].name() );
138  col->setHeading( currentAlias );
139  mColumns.append( col );
140  }
141 }
142 
144 {
145  if ( map == mComposerMap )
146  {
147  //no change
148  return;
149  }
150 
151  if ( mComposerMap )
152  {
153  //disconnect from previous map
154  QObject::disconnect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
155  }
156  mComposerMap = map;
157  if ( mComposerMap )
158  {
159  //listen out for extent changes in linked map
160  QObject::connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
161  }
163 }
164 
166 {
167  if ( features == mMaximumNumberOfFeatures )
168  {
169  return;
170  }
171 
172  mMaximumNumberOfFeatures = features;
174 }
175 
177 {
178  if ( visibleOnly == mShowOnlyVisibleFeatures )
179  {
180  return;
181  }
182 
183  mShowOnlyVisibleFeatures = visibleOnly;
185 }
186 
188 {
189  if ( filter == mFilterFeatures )
190  {
191  return;
192  }
193 
194  mFilterFeatures = filter;
196 }
197 
199 {
200  if ( expression == mFeatureFilter )
201  {
202  return;
203  }
204 
205  mFeatureFilter = expression;
207 }
208 
210 {
211  return fieldsToDisplay().toSet();
212 }
213 
215 {
216  if ( !mVectorLayer )
217  {
218  return;
219  }
220 
221  //rebuild columns list, taking only attributes with index in supplied QSet
222  qDeleteAll( mColumns );
223  mColumns.clear();
224 
225  const QgsFields& fields = mVectorLayer->fields();
226 
227  if ( !attr.empty() )
228  {
229  QSet<int>::const_iterator attIt = attr.constBegin();
230  for ( ; attIt != attr.constEnd(); ++attIt )
231  {
232  int attrIdx = ( *attIt );
233  if ( !fields.exists( attrIdx ) )
234  {
235  continue;
236  }
237  QString currentAlias = mVectorLayer->attributeDisplayName( attrIdx );
239  col->setAttribute( fields[attrIdx].name() );
240  col->setHeading( currentAlias );
241  mColumns.append( col );
242  }
243  }
244  else
245  {
246  //resetting, so add all attributes to columns
247  for ( int idx = 0; idx < fields.count(); ++idx )
248  {
249  QString currentAlias = mVectorLayer->attributeDisplayName( idx );
251  col->setAttribute( fields[idx].name() );
252  col->setHeading( currentAlias );
253  mColumns.append( col );
254  }
255  }
256 
257  if ( refresh )
258  {
260  }
261 }
262 
264 {
266 
268  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
269  {
270  int attrIdx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
271  fieldAliasMap.insert( attrIdx, ( *columnIt )->heading() );
272  }
273  return fieldAliasMap;
274 }
275 
276 void QgsComposerAttributeTable::restoreFieldAliasMap( const QMap<int, QString>& map )
277 {
278  if ( !mVectorLayer )
279  {
280  return;
281  }
282 
284  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
285  {
286  int attrIdx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
287  if ( map.contains( attrIdx ) )
288  {
289  ( *columnIt )->setHeading( map.value( attrIdx ) );
290  }
291  else
292  {
293  ( *columnIt )->setHeading( mVectorLayer->attributeDisplayName( attrIdx ) );
294  }
295  }
296 }
297 
298 
300 {
301  restoreFieldAliasMap( map );
303 }
304 
305 QList<int> QgsComposerAttributeTable::fieldsToDisplay() const
306 {
307  //kept for api compatibility with 2.0 only, can be removed after next api break
308  QList<int> fields;
309 
311  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
312  {
313  int idx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
314  fields.append( idx );
315  }
316  return fields;
317 }
318 
320 {
321  if ( !mVectorLayer )
322  {
323  return false;
324  }
325 
327  context->setFields( mVectorLayer->fields() );
328 
329  attributeMaps.clear();
330 
331  //prepare filter expression
332  QScopedPointer<QgsExpression> filterExpression;
333  bool activeFilter = false;
334  if ( mFilterFeatures && !mFeatureFilter.isEmpty() )
335  {
336  filterExpression.reset( new QgsExpression( mFeatureFilter ) );
337  if ( !filterExpression->hasParserError() )
338  {
339  activeFilter = true;
340  }
341  }
342 
343  QgsRectangle selectionRect;
344  if ( mComposerMap && mShowOnlyVisibleFeatures )
345  {
346  selectionRect = *mComposerMap->currentMapExtent();
348  {
349  //transform back to layer CRS
350  QgsCoordinateTransform coordTransform( mVectorLayer->crs(), mComposition->mapSettings().destinationCrs() );
351  try
352  {
353  selectionRect = coordTransform.transformBoundingBox( selectionRect, QgsCoordinateTransform::ReverseTransform );
354  }
355  catch ( QgsCsException &cse )
356  {
357  Q_UNUSED( cse );
358  return false;
359  }
360  }
361  }
362 
363  QgsFeatureRequest req;
364  if ( !selectionRect.isEmpty() )
365  req.setFilterRect( selectionRect );
366 
367  req.setFlags( mShowOnlyVisibleFeatures ? QgsFeatureRequest::ExactIntersect : QgsFeatureRequest::NoFlags );
368 
369  QgsFeature f;
370  int counter = 0;
371  QgsFeatureIterator fit = mVectorLayer->getFeatures( req );
372 
373  while ( fit.nextFeature( f ) && counter < mMaximumNumberOfFeatures )
374  {
375  context->setFeature( f );
376  //check feature against filter
377  if ( activeFilter && !filterExpression.isNull() )
378  {
379  QVariant result = filterExpression->evaluate( context.data() );
380  // skip this feature if the filter evaluation is false
381  if ( !result.toBool() )
382  {
383  continue;
384  }
385  }
386 
387  attributeMaps.push_back( QgsAttributeMap() );
388 
390  int i = 0;
391  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
392  {
393  int idx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
394  if ( idx != -1 )
395  {
396  attributeMaps.last().insert( i, f.attributes().at( idx ) );
397  }
398  else
399  {
400  // Lets assume it's an expression
401  QgsExpression* expression = new QgsExpression(( *columnIt )->attribute() );
402  context->lastScope()->setVariable( QString( "row_number" ), counter + 1 );
403  expression->prepare( context.data() );
404  QVariant value = expression->evaluate( context.data() );
405  attributeMaps.last().insert( i, value.toString() );
406  }
407 
408  i++;
409  }
410  ++counter;
411  }
412 
413  //sort the list, starting with the last attribute
415  QList< QPair<int, bool> > sortColumns = sortAttributes();
416  for ( int i = sortColumns.size() - 1; i >= 0; --i )
417  {
418  c.setSortColumn( sortColumns.at( i ).first );
419  c.setAscending( sortColumns.at( i ).second );
420  qStableSort( attributeMaps.begin(), attributeMaps.end(), c );
421  }
422 
424  return true;
425 }
426 
427 void QgsComposerAttributeTable::removeLayer( const QString& layerId )
428 {
429  if ( mVectorLayer )
430  {
431  if ( layerId == mVectorLayer->id() )
432  {
433  mVectorLayer = nullptr;
434  //remove existing columns
435  qDeleteAll( mColumns );
436  mColumns.clear();
437  }
438  }
439 }
440 
442 {
443  //update rect for data defined size and position
444  QRectF evaluatedRect = evalItemRect( rectangle );
445 
446  QgsComposerItem::setSceneRect( evaluatedRect );
447 
448  //refresh table attributes, since number of features has likely changed
450 }
451 
453 {
454  //first, clear existing sort by ranks
455  Q_FOREACH ( QgsComposerTableColumn* column, mColumns )
456  {
457  column->setSortByRank( 0 );
458  }
459 
460  //now, update sort rank of specified columns
461  QList< QPair<int, bool > >::const_iterator sortedColumnIt = att.constBegin();
462  int rank = 1;
463  for ( ; sortedColumnIt != att.constEnd(); ++sortedColumnIt )
464  {
465  if (( *sortedColumnIt ).first >= mColumns.length() )
466  {
467  continue;
468  }
469  mColumns.at(( *sortedColumnIt ).first )->setSortByRank( rank );
470  mColumns.at(( *sortedColumnIt ).first )->setSortOrder(( *sortedColumnIt ).second ? Qt::AscendingOrder : Qt::DescendingOrder );
471  rank++;
472  }
473 
475 }
476 
478 {
479  return a.second->sortByRank() < b.second->sortByRank();
480 }
481 
483 {
484  //generate list of all sorted columns
487  int idx = 0;
488  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
489  {
490  if (( *columnIt )->sortByRank() > 0 )
491  {
492  sortedColumns.append( qMakePair( idx, *columnIt ) );
493  }
494  idx++;
495  }
496 
497  //sort columns by rank
498  qSort( sortedColumns.begin(), sortedColumns.end(), columnsBySortRank );
499 
500  //generate list of column index, bool for sort direction (to match 2.0 api)
501  QList<QPair<int, bool> > attributesBySortRank;
502  QVector< QPair<int, QgsComposerTableColumn* > >::const_iterator sortedColumnIt = sortedColumns.constBegin();
503  for ( ; sortedColumnIt != sortedColumns.constEnd(); ++sortedColumnIt )
504  {
505 
506  attributesBySortRank.append( qMakePair(( *sortedColumnIt ).first,
507  ( *sortedColumnIt ).second->sortOrder() == Qt::AscendingOrder ) );
508  }
509  return attributesBySortRank;
510 }
511 
513 {
514  QDomElement composerTableElem = doc.createElement( "ComposerAttributeTable" );
515  composerTableElem.setAttribute( "showOnlyVisibleFeatures", mShowOnlyVisibleFeatures );
516  composerTableElem.setAttribute( "maxFeatures", mMaximumNumberOfFeatures );
517  composerTableElem.setAttribute( "filterFeatures", mFilterFeatures ? "true" : "false" );
518  composerTableElem.setAttribute( "featureFilter", mFeatureFilter );
519 
520  if ( mComposerMap )
521  {
522  composerTableElem.setAttribute( "composerMap", mComposerMap->id() );
523  }
524  else
525  {
526  composerTableElem.setAttribute( "composerMap", -1 );
527  }
528  if ( mVectorLayer )
529  {
530  composerTableElem.setAttribute( "vectorLayer", mVectorLayer->id() );
531  }
532 
533  elem.appendChild( composerTableElem );
534  bool ok = tableWriteXML( composerTableElem, doc );
535  return ok;
536 }
537 
539 {
540  if ( itemElem.isNull() )
541  {
542  return false;
543  }
544 
545  //read general table properties
546  if ( !tableReadXML( itemElem, doc ) )
547  {
548  return false;
549  }
550 
551  mShowOnlyVisibleFeatures = itemElem.attribute( "showOnlyVisibleFeatures", "1" ).toInt();
552  mFilterFeatures = itemElem.attribute( "filterFeatures", "false" ) == "true" ? true : false;
553  mFeatureFilter = itemElem.attribute( "featureFilter", "" );
554 
555  //composer map
556  int composerMapId = itemElem.attribute( "composerMap", "-1" ).toInt();
557  if ( composerMapId == -1 )
558  {
559  mComposerMap = nullptr;
560  }
561 
562  if ( composition() )
563  {
564  mComposerMap = composition()->getComposerMapById( composerMapId );
565  }
566  else
567  {
568  mComposerMap = nullptr;
569  }
570 
571  if ( mComposerMap )
572  {
573  //if we have found a valid map item, listen out to extent changes on it and refresh the table
574  QObject::connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
575  }
576 
577  //vector layer
578  QString layerId = itemElem.attribute( "vectorLayer", "not_existing" );
579  if ( layerId == "not_existing" )
580  {
581  mVectorLayer = nullptr;
582  }
583  else
584  {
586  if ( ml )
587  {
588  mVectorLayer = dynamic_cast<QgsVectorLayer*>( ml );
589  if ( mVectorLayer )
590  {
591  //if we have found a valid vector layer, listen for modifications on it and refresh the table
592  QObject::connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
593  }
594  }
595  }
596 
597  //restore display attribute map. This is required to upgrade pre 2.4 projects.
599  QDomNodeList displayAttributeList = itemElem.elementsByTagName( "displayAttributes" );
600  if ( !displayAttributeList.isEmpty() )
601  {
602  QDomElement displayAttributesElem = displayAttributeList.at( 0 ).toElement();
603  QDomNodeList attributeEntryList = displayAttributesElem.elementsByTagName( "attributeEntry" );
604  for ( int i = 0; i < attributeEntryList.size(); ++i )
605  {
606  QDomElement attributeEntryElem = attributeEntryList.at( i ).toElement();
607  int index = attributeEntryElem.attribute( "index", "-1" ).toInt();
608  if ( index != -1 )
609  {
610  displayAttributes.insert( index );
611  }
612  }
613  setDisplayAttributes( displayAttributes, false );
614  }
615 
616  //restore alias map. This is required to upgrade pre 2.4 projects.
618  QDomNodeList aliasMapNodeList = itemElem.elementsByTagName( "attributeAliasMap" );
619  if ( !aliasMapNodeList.isEmpty() )
620  {
621  QDomElement attributeAliasMapElem = aliasMapNodeList.at( 0 ).toElement();
622  QDomNodeList aliasMepEntryList = attributeAliasMapElem.elementsByTagName( "aliasEntry" );
623  for ( int i = 0; i < aliasMepEntryList.size(); ++i )
624  {
625  QDomElement aliasEntryElem = aliasMepEntryList.at( i ).toElement();
626  int key = aliasEntryElem.attribute( "key", "-1" ).toInt();
627  QString value = aliasEntryElem.attribute( "value", "" );
628  fieldAliasMap.insert( key, value );
629  }
630  restoreFieldAliasMap( fieldAliasMap );
631  }
632 
633  //restore sort columns. This is required to upgrade pre 2.4 projects.
634  QDomElement sortColumnsElem = itemElem.firstChildElement( "sortColumns" );
635  if ( !sortColumnsElem.isNull() && mVectorLayer )
636  {
637  QDomNodeList columns = sortColumnsElem.elementsByTagName( "column" );
638  const QgsFields& fields = mVectorLayer->fields();
639 
640  for ( int i = 0; i < columns.size(); ++i )
641  {
642  QDomElement columnElem = columns.at( i ).toElement();
643  int attribute = columnElem.attribute( "index" ).toInt();
644  Qt::SortOrder order = columnElem.attribute( "ascending" ) == "true" ? Qt::AscendingOrder : Qt::DescendingOrder;
645  //find corresponding column
646  Q_FOREACH ( QgsComposerTableColumn* column, mColumns )
647  {
648  if ( column->attribute() == fields[attribute].name() )
649  {
650  column->setSortByRank( i + 1 );
651  column->setSortOrder( order );
652  break;
653  }
654  }
655  }
656  }
657 
658  //must be done here because tableReadXML->setSceneRect changes mMaximumNumberOfFeatures
659  mMaximumNumberOfFeatures = itemElem.attribute( "maxFeatures", "5" ).toInt();
660 
662 
663  emit itemChanged();
664  return true;
665 }
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
QgsAttributes attributes() const
Returns the feature&#39;s attributes.
Definition: qgsfeature.cpp:110
void setAscending(bool asc)
Sets sort order for column sorting.
const QgsComposerMap * getComposerMapById(const int id) const
Returns the composer map with specified id.
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
bool shouldDrawItem() const
Returns whether the item should be drawn in the current context.
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)
QString attribute(const QString &name, const QString &defValue) const
int length() const
bool tableWriteXML(QDomElement &itemElem, QDomDocument &doc) const
Writes common table properties to xml for storage.
Q_DECL_DEPRECATED bool prepare(const QgsFields &fields)
Get the expression ready for evaluation - find out column indexes.
bool exists(int i) const
Return if a field index is valid.
Definition: qgsfield.cpp:375
void itemChanged()
Emitted when the item changes.
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
const QgsCoordinateReferenceSystem & crs() const
Returns layer&#39;s spatial reference system.
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 hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
bool getFeatureAttributes(QList< QgsAttributeMap > &attributeMaps) override
Queries the attribute table&#39;s vector layer for attributes to show in the table.
int id() const
Get identification number.
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:335
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.
int count() const
Return number of items.
Definition: qgsfield.cpp:365
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:267
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)
QgsFields fields() const
Returns the list of fields of this layer.
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
QList< QPair< int, bool > > sortAttributes() const
Returns the attributes used to sort the table&#39;s features.
const char * name() const
void setVectorLayer(QgsVectorLayer *layer)
Sets the vector layer from which to display feature attributes.
void append(const T &value)
QString id() const
Get this layer&#39;s unique ID, this ID is used to access this layer from map layer registry.
void setHeading(const QString &heading)
Sets the heading for a column, which is the value displayed in the columns header cell...
bool isEmpty() const
test if rectangle is empty.
void setAttribute(const QString &name, const QString &value)
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)
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.
const T & value() const
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)
Stores properties of a column in a QgsComposerTable.
bool isDrawing() const
True if a draw is already in progress.
Graphics scene for map printing.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
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.
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.
const QgsComposition * composition() const
Returns the composition the item is attached to.
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...
const QMap< QString, QgsMapLayer * > & mapLayers()
Retrieve the mapLayers collection (mainly intended for use by projection)
Class for doing transforms between two map coordinate systems.
bool toBool() const
QString attribute() const
Returns the attribute name or expression used for the column&#39;s values.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
Reimplementation of QCanvasItem::paint.
QgsAtlasComposition & atlasComposition()
iterator insert(const Key &key, const T &value)
Custom exception class for Coordinate Reference System related exceptions.
int size() const
Q_DECL_DEPRECATED QSet< int > displayAttributes() const
Returns the attributes fields which are shown by the table.
const_iterator constEnd() const
QDomElement createElement(const QString &tagName)
bool nextFeature(QgsFeature &f)
const_iterator constBegin() const
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.
QString toString() const
iterator end()
QString attributeDisplayName(int attributeIndex) const
Convenience function that returns the attribute alias if defined or the field name else...
Helper class for sorting tables, takes into account sorting column and ascending / descending...
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...
const QgsRectangle * currentMapExtent() const
Returns a pointer to the current map extent, which is either the original user specified extent or th...
iterator begin()
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
QgsFeatureRequest & setFilterRect(const QgsRectangle &rect)
Set rectangle from which features will be taken.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
void setSortByRank(int sortByRank)
Sets the sort rank for the column.
QDomNode at(int index) const
const T value(const Key &key) const