QGIS API Documentation  2.13.0-Master
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  QVariant v1 = m1[mCurrentSortColumn];
36  QVariant v2 = m2[mCurrentSortColumn];
37 
38  bool less = false;
39 
40  //sort null values first
41  if ( v1.isNull() && v2.isNull() )
42  {
43  less = false;
44  }
45  else if ( v1.isNull() )
46  {
47  less = true;
48  }
49  else if ( v2.isNull() )
50  {
51  less = false;
52  }
53  else
54  {
55  //otherwise sort by converting to corresponding type and comparing
56  switch ( v1.type() )
57  {
58  case QVariant::Int:
59  case QVariant::UInt:
60  case QVariant::LongLong:
61  case QVariant::ULongLong:
62  less = v1.toLongLong() < v2.toLongLong();
63  break;
64 
65  case QVariant::Double:
66  less = v1.toDouble() < v2.toDouble();
67  break;
68 
69  case QVariant::Date:
70  less = v1.toDate() < v2.toDate();
71  break;
72 
73  case QVariant::DateTime:
74  less = v1.toDateTime() < v2.toDateTime();
75  break;
76 
77  case QVariant::Time:
78  less = v1.toTime() < v2.toTime();
79  break;
80 
81  default:
82  //use locale aware compare for strings
83  less = v1.toString().localeAwareCompare( v2.toString() ) < 0;
84  break;
85  }
86  }
87 
88  return ( mAscending ? less : !less );
89 }
90 
91 
92 //QgsComposerAttributeTable
93 
95  : QgsComposerTable( composition )
96  , mVectorLayer( nullptr )
97  , mComposerMap( nullptr )
98  , mMaximumNumberOfFeatures( 5 )
99  , mShowOnlyVisibleFeatures( false )
100  , mFilterFeatures( false )
101  , mFeatureFilter( "" )
102 {
103  //set first vector layer from layer registry as default one
106  for ( ; mapIt != layerMap.constEnd(); ++mapIt )
107  {
108  QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( mapIt.value() );
109  if ( vl )
110  {
111  mVectorLayer = vl;
112  break;
113  }
114  }
115  if ( mVectorLayer )
116  {
117  resetColumns();
118  }
119  connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( removeLayer( const QString& ) ) );
120 
121  if ( mComposition )
122  {
123  //refresh table attributes when composition is refreshed
124  connect( mComposition, SIGNAL( refreshItemsTriggered() ), this, SLOT( refreshAttributes() ) );
125 
126  //connect to atlas feature changes to update table rows
127  connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshAttributes() ) );
128  }
129 }
130 
132 {
133 }
134 
135 void QgsComposerAttributeTable::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
136 {
137  if ( mComposerMap && mComposerMap->isDrawing() )
138  {
139  return;
140  }
141  if ( !shouldDrawItem() )
142  {
143  return;
144  }
145  QgsComposerTable::paint( painter, itemStyle, pWidget );
146 }
147 
149 {
150  if ( layer == mVectorLayer )
151  {
152  //no change
153  return;
154  }
155 
156  if ( mVectorLayer )
157  {
158  //disconnect from previous layer
159  QObject::disconnect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
160  }
161 
162  mVectorLayer = layer;
163 
164  //rebuild column list to match all columns from layer
165  resetColumns();
167 
168  //listen for modifications to layer and refresh table when they occur
169  QObject::connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
170 }
171 
173 {
174  if ( !mVectorLayer )
175  {
176  return;
177  }
178 
179  //remove existing columns
180  qDeleteAll( mColumns );
181  mColumns.clear();
182 
183  //rebuild columns list from vector layer fields
184  const QgsFields& fields = mVectorLayer->fields();
185  for ( int idx = 0; idx < fields.count(); ++idx )
186  {
187  QString currentAlias = mVectorLayer->attributeDisplayName( idx );
189  col->setAttribute( fields[idx].name() );
190  col->setHeading( currentAlias );
191  mColumns.append( col );
192  }
193 }
194 
196 {
197  if ( map == mComposerMap )
198  {
199  //no change
200  return;
201  }
202 
203  if ( mComposerMap )
204  {
205  //disconnect from previous map
206  QObject::disconnect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
207  }
208  mComposerMap = map;
209  if ( mComposerMap )
210  {
211  //listen out for extent changes in linked map
212  QObject::connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
213  }
215 }
216 
218 {
219  if ( features == mMaximumNumberOfFeatures )
220  {
221  return;
222  }
223 
224  mMaximumNumberOfFeatures = features;
226 }
227 
229 {
230  if ( visibleOnly == mShowOnlyVisibleFeatures )
231  {
232  return;
233  }
234 
235  mShowOnlyVisibleFeatures = visibleOnly;
237 }
238 
240 {
241  if ( filter == mFilterFeatures )
242  {
243  return;
244  }
245 
246  mFilterFeatures = filter;
248 }
249 
251 {
252  if ( expression == mFeatureFilter )
253  {
254  return;
255  }
256 
257  mFeatureFilter = expression;
259 }
260 
262 {
263  return fieldsToDisplay().toSet();
264 }
265 
267 {
268  if ( !mVectorLayer )
269  {
270  return;
271  }
272 
273  //rebuild columns list, taking only attributes with index in supplied QSet
274  qDeleteAll( mColumns );
275  mColumns.clear();
276 
277  const QgsFields& fields = mVectorLayer->fields();
278 
279  if ( !attr.empty() )
280  {
281  QSet<int>::const_iterator attIt = attr.constBegin();
282  for ( ; attIt != attr.constEnd(); ++attIt )
283  {
284  int attrIdx = ( *attIt );
285  if ( !fields.exists( attrIdx ) )
286  {
287  continue;
288  }
289  QString currentAlias = mVectorLayer->attributeDisplayName( attrIdx );
291  col->setAttribute( fields[attrIdx].name() );
292  col->setHeading( currentAlias );
293  mColumns.append( col );
294  }
295  }
296  else
297  {
298  //resetting, so add all attributes to columns
299  for ( int idx = 0; idx < fields.count(); ++idx )
300  {
301  QString currentAlias = mVectorLayer->attributeDisplayName( idx );
303  col->setAttribute( fields[idx].name() );
304  col->setHeading( currentAlias );
305  mColumns.append( col );
306  }
307  }
308 
309  if ( refresh )
310  {
312  }
313 }
314 
316 {
318 
320  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
321  {
322  int attrIdx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
323  fieldAliasMap.insert( attrIdx, ( *columnIt )->heading() );
324  }
325  return fieldAliasMap;
326 }
327 
328 void QgsComposerAttributeTable::restoreFieldAliasMap( const QMap<int, QString>& map )
329 {
330  if ( !mVectorLayer )
331  {
332  return;
333  }
334 
336  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
337  {
338  int attrIdx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
339  if ( map.contains( attrIdx ) )
340  {
341  ( *columnIt )->setHeading( map.value( attrIdx ) );
342  }
343  else
344  {
345  ( *columnIt )->setHeading( mVectorLayer->attributeDisplayName( attrIdx ) );
346  }
347  }
348 }
349 
350 
352 {
353  restoreFieldAliasMap( map );
355 }
356 
357 QList<int> QgsComposerAttributeTable::fieldsToDisplay() const
358 {
359  //kept for api compatibility with 2.0 only, can be removed after next api break
360  QList<int> fields;
361 
363  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
364  {
365  int idx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
366  fields.append( idx );
367  }
368  return fields;
369 }
370 
372 {
373  if ( !mVectorLayer )
374  {
375  return false;
376  }
377 
379  context->setFields( mVectorLayer->fields() );
380 
381  attributeMaps.clear();
382 
383  //prepare filter expression
384  QScopedPointer<QgsExpression> filterExpression;
385  bool activeFilter = false;
386  if ( mFilterFeatures && !mFeatureFilter.isEmpty() )
387  {
388  filterExpression.reset( new QgsExpression( mFeatureFilter ) );
389  if ( !filterExpression->hasParserError() )
390  {
391  activeFilter = true;
392  }
393  }
394 
395  QgsRectangle selectionRect;
396  if ( mComposerMap && mShowOnlyVisibleFeatures )
397  {
398  selectionRect = *mComposerMap->currentMapExtent();
400  {
401  //transform back to layer CRS
402  QgsCoordinateTransform coordTransform( mVectorLayer->crs(), mComposition->mapSettings().destinationCrs() );
403  try
404  {
405  selectionRect = coordTransform.transformBoundingBox( selectionRect, QgsCoordinateTransform::ReverseTransform );
406  }
407  catch ( QgsCsException &cse )
408  {
409  Q_UNUSED( cse );
410  return false;
411  }
412  }
413  }
414 
415  QgsFeatureRequest req;
416  if ( !selectionRect.isEmpty() )
417  req.setFilterRect( selectionRect );
418 
419  req.setFlags( mShowOnlyVisibleFeatures ? QgsFeatureRequest::ExactIntersect : QgsFeatureRequest::NoFlags );
420 
421  QgsFeature f;
422  int counter = 0;
423  QgsFeatureIterator fit = mVectorLayer->getFeatures( req );
424 
425  while ( fit.nextFeature( f ) && counter < mMaximumNumberOfFeatures )
426  {
427  context->setFeature( f );
428  //check feature against filter
429  if ( activeFilter && !filterExpression.isNull() )
430  {
431  QVariant result = filterExpression->evaluate( context.data() );
432  // skip this feature if the filter evaluation is false
433  if ( !result.toBool() )
434  {
435  continue;
436  }
437  }
438 
439  attributeMaps.push_back( QgsAttributeMap() );
440 
442  int i = 0;
443  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
444  {
445  int idx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
446  if ( idx != -1 )
447  {
448  attributeMaps.last().insert( i, f.attributes().at( idx ) );
449  }
450  else
451  {
452  // Lets assume it's an expression
453  QgsExpression* expression = new QgsExpression(( *columnIt )->attribute() );
454  context->lastScope()->setVariable( QString( "row_number" ), counter + 1 );
455  expression->prepare( context.data() );
456  QVariant value = expression->evaluate( context.data() );
457  attributeMaps.last().insert( i, value.toString() );
458  }
459 
460  i++;
461  }
462  ++counter;
463  }
464 
465  //sort the list, starting with the last attribute
467  QList< QPair<int, bool> > sortColumns = sortAttributes();
468  for ( int i = sortColumns.size() - 1; i >= 0; --i )
469  {
470  c.setSortColumn( sortColumns.at( i ).first );
471  c.setAscending( sortColumns.at( i ).second );
472  qStableSort( attributeMaps.begin(), attributeMaps.end(), c );
473  }
474 
476  return true;
477 }
478 
479 void QgsComposerAttributeTable::removeLayer( const QString& layerId )
480 {
481  if ( mVectorLayer )
482  {
483  if ( layerId == mVectorLayer->id() )
484  {
485  mVectorLayer = nullptr;
486  //remove existing columns
487  qDeleteAll( mColumns );
488  mColumns.clear();
489  }
490  }
491 }
492 
494 {
495  //update rect for data defined size and position
496  QRectF evaluatedRect = evalItemRect( rectangle );
497 
498  QgsComposerItem::setSceneRect( evaluatedRect );
499 
500  //refresh table attributes, since number of features has likely changed
502 }
503 
505 {
506  //first, clear existing sort by ranks
507  Q_FOREACH ( QgsComposerTableColumn* column, mColumns )
508  {
509  column->setSortByRank( 0 );
510  }
511 
512  //now, update sort rank of specified columns
513  QList< QPair<int, bool > >::const_iterator sortedColumnIt = att.constBegin();
514  int rank = 1;
515  for ( ; sortedColumnIt != att.constEnd(); ++sortedColumnIt )
516  {
517  if (( *sortedColumnIt ).first >= mColumns.length() )
518  {
519  continue;
520  }
521  mColumns.at(( *sortedColumnIt ).first )->setSortByRank( rank );
522  mColumns.at(( *sortedColumnIt ).first )->setSortOrder(( *sortedColumnIt ).second ? Qt::AscendingOrder : Qt::DescendingOrder );
523  rank++;
524  }
525 
527 }
528 
530 {
531  return a.second->sortByRank() < b.second->sortByRank();
532 }
533 
535 {
536  //generate list of all sorted columns
539  int idx = 0;
540  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
541  {
542  if (( *columnIt )->sortByRank() > 0 )
543  {
544  sortedColumns.append( qMakePair( idx, *columnIt ) );
545  }
546  idx++;
547  }
548 
549  //sort columns by rank
550  qSort( sortedColumns.begin(), sortedColumns.end(), columnsBySortRank );
551 
552  //generate list of column index, bool for sort direction (to match 2.0 api)
553  QList<QPair<int, bool> > attributesBySortRank;
554  QVector< QPair<int, QgsComposerTableColumn* > >::const_iterator sortedColumnIt = sortedColumns.constBegin();
555  for ( ; sortedColumnIt != sortedColumns.constEnd(); ++sortedColumnIt )
556  {
557 
558  attributesBySortRank.append( qMakePair(( *sortedColumnIt ).first,
559  ( *sortedColumnIt ).second->sortOrder() == Qt::AscendingOrder ) );
560  }
561  return attributesBySortRank;
562 }
563 
565 {
566  QDomElement composerTableElem = doc.createElement( "ComposerAttributeTable" );
567  composerTableElem.setAttribute( "showOnlyVisibleFeatures", mShowOnlyVisibleFeatures );
568  composerTableElem.setAttribute( "maxFeatures", mMaximumNumberOfFeatures );
569  composerTableElem.setAttribute( "filterFeatures", mFilterFeatures ? "true" : "false" );
570  composerTableElem.setAttribute( "featureFilter", mFeatureFilter );
571 
572  if ( mComposerMap )
573  {
574  composerTableElem.setAttribute( "composerMap", mComposerMap->id() );
575  }
576  else
577  {
578  composerTableElem.setAttribute( "composerMap", -1 );
579  }
580  if ( mVectorLayer )
581  {
582  composerTableElem.setAttribute( "vectorLayer", mVectorLayer->id() );
583  }
584 
585  elem.appendChild( composerTableElem );
586  bool ok = tableWriteXML( composerTableElem, doc );
587  return ok;
588 }
589 
591 {
592  if ( itemElem.isNull() )
593  {
594  return false;
595  }
596 
597  //read general table properties
598  if ( !tableReadXML( itemElem, doc ) )
599  {
600  return false;
601  }
602 
603  mShowOnlyVisibleFeatures = itemElem.attribute( "showOnlyVisibleFeatures", "1" ).toInt();
604  mFilterFeatures = itemElem.attribute( "filterFeatures", "false" ) == "true" ? true : false;
605  mFeatureFilter = itemElem.attribute( "featureFilter", "" );
606 
607  //composer map
608  int composerMapId = itemElem.attribute( "composerMap", "-1" ).toInt();
609  if ( composerMapId == -1 )
610  {
611  mComposerMap = nullptr;
612  }
613 
614  if ( composition() )
615  {
616  mComposerMap = composition()->getComposerMapById( composerMapId );
617  }
618  else
619  {
620  mComposerMap = nullptr;
621  }
622 
623  if ( mComposerMap )
624  {
625  //if we have found a valid map item, listen out to extent changes on it and refresh the table
626  QObject::connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
627  }
628 
629  //vector layer
630  QString layerId = itemElem.attribute( "vectorLayer", "not_existing" );
631  if ( layerId == "not_existing" )
632  {
633  mVectorLayer = nullptr;
634  }
635  else
636  {
638  if ( ml )
639  {
640  mVectorLayer = dynamic_cast<QgsVectorLayer*>( ml );
641  if ( mVectorLayer )
642  {
643  //if we have found a valid vector layer, listen for modifications on it and refresh the table
644  QObject::connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
645  }
646  }
647  }
648 
649  //restore display attribute map. This is required to upgrade pre 2.4 projects.
651  QDomNodeList displayAttributeList = itemElem.elementsByTagName( "displayAttributes" );
652  if ( !displayAttributeList.isEmpty() )
653  {
654  QDomElement displayAttributesElem = displayAttributeList.at( 0 ).toElement();
655  QDomNodeList attributeEntryList = displayAttributesElem.elementsByTagName( "attributeEntry" );
656  for ( int i = 0; i < attributeEntryList.size(); ++i )
657  {
658  QDomElement attributeEntryElem = attributeEntryList.at( i ).toElement();
659  int index = attributeEntryElem.attribute( "index", "-1" ).toInt();
660  if ( index != -1 )
661  {
662  displayAttributes.insert( index );
663  }
664  }
665  setDisplayAttributes( displayAttributes, false );
666  }
667 
668  //restore alias map. This is required to upgrade pre 2.4 projects.
670  QDomNodeList aliasMapNodeList = itemElem.elementsByTagName( "attributeAliasMap" );
671  if ( !aliasMapNodeList.isEmpty() )
672  {
673  QDomElement attributeAliasMapElem = aliasMapNodeList.at( 0 ).toElement();
674  QDomNodeList aliasMepEntryList = attributeAliasMapElem.elementsByTagName( "aliasEntry" );
675  for ( int i = 0; i < aliasMepEntryList.size(); ++i )
676  {
677  QDomElement aliasEntryElem = aliasMepEntryList.at( i ).toElement();
678  int key = aliasEntryElem.attribute( "key", "-1" ).toInt();
679  QString value = aliasEntryElem.attribute( "value", "" );
680  fieldAliasMap.insert( key, value );
681  }
682  restoreFieldAliasMap( fieldAliasMap );
683  }
684 
685  //restore sort columns. This is required to upgrade pre 2.4 projects.
686  QDomElement sortColumnsElem = itemElem.firstChildElement( "sortColumns" );
687  if ( !sortColumnsElem.isNull() && mVectorLayer )
688  {
689  QDomNodeList columns = sortColumnsElem.elementsByTagName( "column" );
690  const QgsFields& fields = mVectorLayer->fields();
691 
692  for ( int i = 0; i < columns.size(); ++i )
693  {
694  QDomElement columnElem = columns.at( i ).toElement();
695  int attribute = columnElem.attribute( "index" ).toInt();
696  Qt::SortOrder order = columnElem.attribute( "ascending" ) == "true" ? Qt::AscendingOrder : Qt::DescendingOrder;
697  //find corresponding column
698  Q_FOREACH ( QgsComposerTableColumn* column, mColumns )
699  {
700  if ( column->attribute() == fields[attribute].name() )
701  {
702  column->setSortByRank( i + 1 );
703  column->setSortOrder( order );
704  break;
705  }
706  }
707  }
708  }
709 
710  //must be done here because tableReadXML->setSceneRect changes mMaximumNumberOfFeatures
711  mMaximumNumberOfFeatures = itemElem.attribute( "maxFeatures", "5" ).toInt();
712 
714 
715  emit itemChanged();
716  return true;
717 }
Class for parsing and evaluation of expressions (formerly called "search strings").
qlonglong toLongLong(bool *ok) const
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.
int localeAwareCompare(const QString &other) const
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.
QDateTime toDateTime() const
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
QTime toTime() 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:189
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
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 objects&#39; 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.
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:373
void append(const T &value)
bool isNull() const
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
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
int count() const
Return number of items.
Definition: qgsfield.cpp:363
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)
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()
QgsRectangle * currentMapExtent()
Returns a pointer to the current map extent, which is either the original user specified extent or th...
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
QDate toDate() 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...
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
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()
double toDouble(bool *ok) const
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
Type type() 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()
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