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