QGIS API Documentation  2.12.0-Lyon
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( 0 )
97  , mComposerMap( 0 )
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 = 0;
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
508  for ( ; columnIt != mColumns.end(); ++columnIt )
509  {
510  ( *columnIt )->setSortByRank( 0 );
511  }
512 
513  //now, update sort rank of specified columns
514  QList< QPair<int, bool > >::const_iterator sortedColumnIt = att.constBegin();
515  int rank = 1;
516  for ( ; sortedColumnIt != att.constEnd(); ++sortedColumnIt )
517  {
518  if (( *sortedColumnIt ).first >= mColumns.length() )
519  {
520  continue;
521  }
522  mColumns[( *sortedColumnIt ).first ]->setSortByRank( rank );
523  mColumns[( *sortedColumnIt ).first ]->setSortOrder(( *sortedColumnIt ).second ? Qt::AscendingOrder : Qt::DescendingOrder );
524  rank++;
525  }
526 
528 }
529 
531 {
532  return a.second->sortByRank() < b.second->sortByRank();
533 }
534 
536 {
537  //generate list of all sorted columns
540  int idx = 0;
541  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
542  {
543  if (( *columnIt )->sortByRank() > 0 )
544  {
545  sortedColumns.append( qMakePair( idx, *columnIt ) );
546  }
547  idx++;
548  }
549 
550  //sort columns by rank
551  qSort( sortedColumns.begin(), sortedColumns.end(), columnsBySortRank );
552 
553  //generate list of column index, bool for sort direction (to match 2.0 api)
554  QList<QPair<int, bool> > attributesBySortRank;
555  QList< QPair<int, QgsComposerTableColumn* > >::const_iterator sortedColumnIt = sortedColumns.constBegin();
556  for ( ; sortedColumnIt != sortedColumns.constEnd(); ++sortedColumnIt )
557  {
558 
559  attributesBySortRank.append( qMakePair(( *sortedColumnIt ).first,
560  ( *sortedColumnIt ).second->sortOrder() == Qt::AscendingOrder ) );
561  }
562  return attributesBySortRank;
563 }
564 
566 {
567  QDomElement composerTableElem = doc.createElement( "ComposerAttributeTable" );
568  composerTableElem.setAttribute( "showOnlyVisibleFeatures", mShowOnlyVisibleFeatures );
569  composerTableElem.setAttribute( "maxFeatures", mMaximumNumberOfFeatures );
570  composerTableElem.setAttribute( "filterFeatures", mFilterFeatures ? "true" : "false" );
571  composerTableElem.setAttribute( "featureFilter", mFeatureFilter );
572 
573  if ( mComposerMap )
574  {
575  composerTableElem.setAttribute( "composerMap", mComposerMap->id() );
576  }
577  else
578  {
579  composerTableElem.setAttribute( "composerMap", -1 );
580  }
581  if ( mVectorLayer )
582  {
583  composerTableElem.setAttribute( "vectorLayer", mVectorLayer->id() );
584  }
585 
586  elem.appendChild( composerTableElem );
587  bool ok = tableWriteXML( composerTableElem, doc );
588  return ok;
589 }
590 
592 {
593  if ( itemElem.isNull() )
594  {
595  return false;
596  }
597 
598  //read general table properties
599  if ( !tableReadXML( itemElem, doc ) )
600  {
601  return false;
602  }
603 
604  mShowOnlyVisibleFeatures = itemElem.attribute( "showOnlyVisibleFeatures", "1" ).toInt();
605  mFilterFeatures = itemElem.attribute( "filterFeatures", "false" ) == "true" ? true : false;
606  mFeatureFilter = itemElem.attribute( "featureFilter", "" );
607 
608  //composer map
609  int composerMapId = itemElem.attribute( "composerMap", "-1" ).toInt();
610  if ( composerMapId == -1 )
611  {
612  mComposerMap = 0;
613  }
614 
615  if ( composition() )
616  {
617  mComposerMap = composition()->getComposerMapById( composerMapId );
618  }
619  else
620  {
621  mComposerMap = 0;
622  }
623 
624  if ( mComposerMap )
625  {
626  //if we have found a valid map item, listen out to extent changes on it and refresh the table
627  QObject::connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
628  }
629 
630  //vector layer
631  QString layerId = itemElem.attribute( "vectorLayer", "not_existing" );
632  if ( layerId == "not_existing" )
633  {
634  mVectorLayer = 0;
635  }
636  else
637  {
639  if ( ml )
640  {
641  mVectorLayer = dynamic_cast<QgsVectorLayer*>( ml );
642  if ( mVectorLayer )
643  {
644  //if we have found a valid vector layer, listen for modifications on it and refresh the table
645  QObject::connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
646  }
647  }
648  }
649 
650  //restore display attribute map. This is required to upgrade pre 2.4 projects.
652  QDomNodeList displayAttributeList = itemElem.elementsByTagName( "displayAttributes" );
653  if ( displayAttributeList.size() > 0 )
654  {
655  QDomElement displayAttributesElem = displayAttributeList.at( 0 ).toElement();
656  QDomNodeList attributeEntryList = displayAttributesElem.elementsByTagName( "attributeEntry" );
657  for ( int i = 0; i < attributeEntryList.size(); ++i )
658  {
659  QDomElement attributeEntryElem = attributeEntryList.at( i ).toElement();
660  int index = attributeEntryElem.attribute( "index", "-1" ).toInt();
661  if ( index != -1 )
662  {
663  displayAttributes.insert( index );
664  }
665  }
666  setDisplayAttributes( displayAttributes, false );
667  }
668 
669  //restore alias map. This is required to upgrade pre 2.4 projects.
671  QDomNodeList aliasMapNodeList = itemElem.elementsByTagName( "attributeAliasMap" );
672  if ( aliasMapNodeList.size() > 0 )
673  {
674  QDomElement attributeAliasMapElem = aliasMapNodeList.at( 0 ).toElement();
675  QDomNodeList aliasMepEntryList = attributeAliasMapElem.elementsByTagName( "aliasEntry" );
676  for ( int i = 0; i < aliasMepEntryList.size(); ++i )
677  {
678  QDomElement aliasEntryElem = aliasMepEntryList.at( i ).toElement();
679  int key = aliasEntryElem.attribute( "key", "-1" ).toInt();
680  QString value = aliasEntryElem.attribute( "value", "" );
681  fieldAliasMap.insert( key, value );
682  }
683  restoreFieldAliasMap( fieldAliasMap );
684  }
685 
686  //restore sort columns. This is required to upgrade pre 2.4 projects.
687  QDomElement sortColumnsElem = itemElem.firstChildElement( "sortColumns" );
688  if ( !sortColumnsElem.isNull() && mVectorLayer )
689  {
690  QDomNodeList columns = sortColumnsElem.elementsByTagName( "column" );
691  const QgsFields& fields = mVectorLayer->fields();
692 
693  for ( int i = 0; i < columns.size(); ++i )
694  {
695  QDomElement columnElem = columns.at( i ).toElement();
696  int attribute = columnElem.attribute( "index" ).toInt();
697  Qt::SortOrder order = columnElem.attribute( "ascending" ) == "true" ? Qt::AscendingOrder : Qt::DescendingOrder;
698  //find corresponding column
700  for ( ; columnIt != mColumns.end(); ++columnIt )
701  {
702  if (( *columnIt )->attribute() == fields[attribute].name() )
703  {
704  ( *columnIt )->setSortByRank( i + 1 );
705  ( *columnIt )->setSortOrder( order );
706  break;
707  }
708  }
709  }
710  }
711 
712  //must be done here because tableReadXML->setSceneRect changes mMaximumNumberOfFeatures
713  mMaximumNumberOfFeatures = itemElem.attribute( "maxFeatures", "5" ).toInt();
714 
716 
717  emit itemChanged();
718  return true;
719 }
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:92
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'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'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'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)
Use exact geometry intersection (slower) instead of bounding boxes.
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 constBegin() const
const T & at(int i) const
QTime toTime() const
bool getFeatureAttributes(QList< QgsAttributeMap > &attributeMaps) override
Queries the attribute table'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:177
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:176
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'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.
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.
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:321
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's attributes.
Definition: qgsfeature.cpp:92
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
QRectF evalItemRect(const QRectF &newRect, const bool resizeOnly=false, const QgsExpressionContext *context=0)
Evaluates an item's bounding rect to consider data defined position and size of item and reference po...
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'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:311
Q_DECL_DEPRECATED void setFieldAliasMap(const QMap< int, QString > &map)
Sets the attribute field aliases, which control how fields are named in the table'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's columns to match the vector layer'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
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's header row...
bool tableReadXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads the table's common properties from xml.
virtual void adjustFrameToSize()
Adapts the size of the frame to match the content.
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's spatial reference system.
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
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.
QDomNode at(int index) const
const T value(const Key &key) const