QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
104  QMap<QString, QgsMapLayer*> layerMap = QgsMapLayerRegistry::instance()->mapLayers();
105  QMap<QString, QgsMapLayer*>::const_iterator mapIt = layerMap.constBegin();
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  QgsComposerTable::paint( painter, itemStyle, pWidget );
142 }
143 
145 {
146  if ( layer == mVectorLayer )
147  {
148  //no change
149  return;
150  }
151 
152  if ( mVectorLayer )
153  {
154  //disconnect from previous layer
155  QObject::disconnect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
156  }
157 
158  mVectorLayer = layer;
159 
160  //rebuild column list to match all columns from layer
161  resetColumns();
163 
164  //listen for modifications to layer and refresh table when they occur
165  QObject::connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
166 }
167 
169 {
170  if ( !mVectorLayer )
171  {
172  return;
173  }
174 
175  //remove existing columns
176  qDeleteAll( mColumns );
177  mColumns.clear();
178 
179  //rebuild columns list from vector layer fields
180  const QgsFields& fields = mVectorLayer->pendingFields();
181  for ( int idx = 0; idx < fields.count(); ++idx )
182  {
183  QString currentAlias = mVectorLayer->attributeDisplayName( idx );
185  col->setAttribute( fields[idx].name() );
186  col->setHeading( currentAlias );
187  mColumns.append( col );
188  }
189 }
190 
192 {
193  if ( map == mComposerMap )
194  {
195  //no change
196  return;
197  }
198 
199  if ( mComposerMap )
200  {
201  //disconnect from previous map
202  QObject::disconnect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
203  }
204  mComposerMap = map;
205  if ( mComposerMap )
206  {
207  //listen out for extent changes in linked map
208  QObject::connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
209  }
211 }
212 
214 {
215  if ( features == mMaximumNumberOfFeatures )
216  {
217  return;
218  }
219 
220  mMaximumNumberOfFeatures = features;
222 }
223 
225 {
226  if ( visibleOnly == mShowOnlyVisibleFeatures )
227  {
228  return;
229  }
230 
231  mShowOnlyVisibleFeatures = visibleOnly;
233 }
234 
236 {
237  if ( filter == mFilterFeatures )
238  {
239  return;
240  }
241 
242  mFilterFeatures = filter;
244 }
245 
246 void QgsComposerAttributeTable::setFeatureFilter( const QString& expression )
247 {
248  if ( expression == mFeatureFilter )
249  {
250  return;
251  }
252 
253  mFeatureFilter = expression;
255 }
256 
258 {
259  return fieldsToDisplay().toSet();
260 }
261 
262 void QgsComposerAttributeTable::setDisplayAttributes( const QSet<int>& attr, bool refresh )
263 {
264  if ( !mVectorLayer )
265  {
266  return;
267  }
268 
269  //rebuild columns list, taking only attributes with index in supplied QSet
270  qDeleteAll( mColumns );
271  mColumns.clear();
272 
273  const QgsFields& fields = mVectorLayer->pendingFields();
274 
275  if ( !attr.empty() )
276  {
277  QSet<int>::const_iterator attIt = attr.constBegin();
278  for ( ; attIt != attr.constEnd(); ++attIt )
279  {
280  int attrIdx = ( *attIt );
281  if ( !fields.exists( attrIdx ) )
282  {
283  continue;
284  }
285  QString currentAlias = mVectorLayer->attributeDisplayName( attrIdx );
287  col->setAttribute( fields[attrIdx].name() );
288  col->setHeading( currentAlias );
289  mColumns.append( col );
290  }
291  }
292  else
293  {
294  //resetting, so add all attributes to columns
295  for ( int idx = 0; idx < fields.count(); ++idx )
296  {
297  QString currentAlias = mVectorLayer->attributeDisplayName( idx );
299  col->setAttribute( fields[idx].name() );
300  col->setHeading( currentAlias );
301  mColumns.append( col );
302  }
303  }
304 
305  if ( refresh )
306  {
308  }
309 }
310 
312 {
313  QMap<int, QString> fieldAliasMap;
314 
315  QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin();
316  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
317  {
318  int attrIdx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
319  fieldAliasMap.insert( attrIdx, ( *columnIt )->heading() );
320  }
321  return fieldAliasMap;
322 }
323 
324 void QgsComposerAttributeTable::restoreFieldAliasMap( const QMap<int, QString>& map )
325 {
326  if ( !mVectorLayer )
327  {
328  return;
329  }
330 
331  QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin();
332  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
333  {
334  int attrIdx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
335  if ( map.contains( attrIdx ) )
336  {
337  ( *columnIt )->setHeading( map.value( attrIdx ) );
338  }
339  else
340  {
341  ( *columnIt )->setHeading( mVectorLayer->attributeDisplayName( attrIdx ) );
342  }
343  }
344 }
345 
346 
347 void QgsComposerAttributeTable::setFieldAliasMap( const QMap<int, QString>& map )
348 {
349  restoreFieldAliasMap( map );
351 }
352 
354 {
355  //kept for api compatibility with 2.0 only, can be removed after next api break
356  QList<int> fields;
357 
358  QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin();
359  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
360  {
361  int idx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
362  fields.append( idx );
363  }
364  return fields;
365 }
366 
367 bool QgsComposerAttributeTable::getFeatureAttributes( QList<QgsAttributeMap> &attributeMaps )
368 {
369  if ( !mVectorLayer )
370  {
371  return false;
372  }
373 
374  attributeMaps.clear();
375 
376  //prepare filter expression
377  std::auto_ptr<QgsExpression> filterExpression;
378  bool activeFilter = false;
379  if ( mFilterFeatures && !mFeatureFilter.isEmpty() )
380  {
381  filterExpression = std::auto_ptr<QgsExpression>( new QgsExpression( mFeatureFilter ) );
382  if ( !filterExpression->hasParserError() )
383  {
384  activeFilter = true;
385  }
386  }
387 
388  QgsRectangle selectionRect;
390  {
391  selectionRect = *mComposerMap->currentMapExtent();
393  {
394  //transform back to layer CRS
396  try
397  {
398  selectionRect = coordTransform.transformBoundingBox( selectionRect, QgsCoordinateTransform::ReverseTransform );
399  }
400  catch ( QgsCsException &cse )
401  {
402  Q_UNUSED( cse );
403  return false;
404  }
405  }
406  }
407 
408  QgsFeatureRequest req;
409  if ( !selectionRect.isEmpty() )
410  req.setFilterRect( selectionRect );
411 
413 
414  QgsFeature f;
415  int counter = 0;
417 
418  while ( fit.nextFeature( f ) && counter < mMaximumNumberOfFeatures )
419  {
420  //check feature against filter
421  if ( activeFilter )
422  {
423  QVariant result = filterExpression->evaluate( &f, mVectorLayer->pendingFields() );
424  // skip this feature if the filter evaluation is false
425  if ( !result.toBool() )
426  {
427  continue;
428  }
429  }
430 
431  attributeMaps.push_back( QgsAttributeMap() );
432 
433  QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin();
434  int i = 0;
435  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
436  {
437  int idx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
438  if ( idx != -1 )
439  {
440  attributeMaps.last().insert( i, f.attributes()[idx] );
441  }
442  else
443  {
444  // Lets assume it's an expression
445  QgsExpression* expression = new QgsExpression(( *columnIt )->attribute() );
446  expression->setCurrentRowNumber( counter + 1 );
447  expression->prepare( mVectorLayer->pendingFields() );
448  QVariant value = expression->evaluate( f ) ;
449  attributeMaps.last().insert( i, value.toString() );
450  }
451 
452  i++;
453  }
454  ++counter;
455  }
456 
457  //sort the list, starting with the last attribute
459  QList< QPair<int, bool> > sortColumns = sortAttributes();
460  for ( int i = sortColumns.size() - 1; i >= 0; --i )
461  {
462  c.setSortColumn( sortColumns.at( i ).first );
463  c.setAscending( sortColumns.at( i ).second );
464  qStableSort( attributeMaps.begin(), attributeMaps.end(), c );
465  }
466 
468  return true;
469 }
470 
472 {
473  if ( mVectorLayer )
474  {
475  if ( layerId == mVectorLayer->id() )
476  {
477  mVectorLayer = 0;
478  //remove existing columns
479  qDeleteAll( mColumns );
480  mColumns.clear();
481  }
482  }
483 }
484 
485 void QgsComposerAttributeTable::setSceneRect( const QRectF& rectangle )
486 {
487  //update rect for data defined size and position
488  QRectF evaluatedRect = evalItemRect( rectangle );
489 
490  QgsComposerItem::setSceneRect( evaluatedRect );
491 
492  //refresh table attributes, since number of features has likely changed
494 }
495 
496 void QgsComposerAttributeTable::setSortAttributes( const QList<QPair<int, bool> > att )
497 {
498  //first, clear existing sort by ranks
499  QList<QgsComposerTableColumn*>::iterator columnIt = mColumns.begin();
500  for ( ; columnIt != mColumns.end(); ++columnIt )
501  {
502  ( *columnIt )->setSortByRank( 0 );
503  }
504 
505  //now, update sort rank of specified columns
506  QList< QPair<int, bool > >::const_iterator sortedColumnIt = att.constBegin();
507  int rank = 1;
508  for ( ; sortedColumnIt != att.constEnd(); ++sortedColumnIt )
509  {
510  if (( *sortedColumnIt ).first >= mColumns.length() )
511  {
512  continue;
513  }
514  mColumns[( *sortedColumnIt ).first ]->setSortByRank( rank );
515  mColumns[( *sortedColumnIt ).first ]->setSortOrder(( *sortedColumnIt ).second ? Qt::AscendingOrder : Qt::DescendingOrder );
516  rank++;
517  }
518 
520 }
521 
522 static bool columnsBySortRank( QPair<int, QgsComposerTableColumn* > a, QPair<int, QgsComposerTableColumn* > b )
523 {
524  return a.second->sortByRank() < b.second->sortByRank();
525 }
526 
527 QList<QPair<int, bool> > QgsComposerAttributeTable::sortAttributes() const
528 {
529  //generate list of all sorted columns
530  QList< QPair<int, QgsComposerTableColumn* > > sortedColumns;
531  QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin();
532  int idx = 0;
533  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
534  {
535  if (( *columnIt )->sortByRank() > 0 )
536  {
537  sortedColumns.append( qMakePair( idx, *columnIt ) );
538  }
539  idx++;
540  }
541 
542  //sort columns by rank
543  qSort( sortedColumns.begin(), sortedColumns.end(), columnsBySortRank );
544 
545  //generate list of column index, bool for sort direction (to match 2.0 api)
546  QList<QPair<int, bool> > attributesBySortRank;
547  QList< QPair<int, QgsComposerTableColumn* > >::const_iterator sortedColumnIt = sortedColumns.constBegin();
548  for ( ; sortedColumnIt != sortedColumns.constEnd(); ++sortedColumnIt )
549  {
550 
551  attributesBySortRank.append( qMakePair(( *sortedColumnIt ).first,
552  ( *sortedColumnIt ).second->sortOrder() == Qt::AscendingOrder ) );
553  }
554  return attributesBySortRank;
555 }
556 
557 bool QgsComposerAttributeTable::writeXML( QDomElement& elem, QDomDocument & doc ) const
558 {
559  QDomElement composerTableElem = doc.createElement( "ComposerAttributeTable" );
560  composerTableElem.setAttribute( "showOnlyVisibleFeatures", mShowOnlyVisibleFeatures );
561  composerTableElem.setAttribute( "maxFeatures", mMaximumNumberOfFeatures );
562  composerTableElem.setAttribute( "filterFeatures", mFilterFeatures ? "true" : "false" );
563  composerTableElem.setAttribute( "featureFilter", mFeatureFilter );
564 
565  if ( mComposerMap )
566  {
567  composerTableElem.setAttribute( "composerMap", mComposerMap->id() );
568  }
569  else
570  {
571  composerTableElem.setAttribute( "composerMap", -1 );
572  }
573  if ( mVectorLayer )
574  {
575  composerTableElem.setAttribute( "vectorLayer", mVectorLayer->id() );
576  }
577 
578  elem.appendChild( composerTableElem );
579  bool ok = tableWriteXML( composerTableElem, doc );
580  return ok;
581 }
582 
583 bool QgsComposerAttributeTable::readXML( const QDomElement& itemElem, const QDomDocument& doc )
584 {
585  if ( itemElem.isNull() )
586  {
587  return false;
588  }
589 
590  //read general table properties
591  if ( !tableReadXML( itemElem, doc ) )
592  {
593  return false;
594  }
595 
596  mShowOnlyVisibleFeatures = itemElem.attribute( "showOnlyVisibleFeatures", "1" ).toInt();
597  mFilterFeatures = itemElem.attribute( "filterFeatures", "false" ) == "true" ? true : false;
598  mFeatureFilter = itemElem.attribute( "featureFilter", "" );
599 
600  //composer map
601  int composerMapId = itemElem.attribute( "composerMap", "-1" ).toInt();
602  if ( composerMapId == -1 )
603  {
604  mComposerMap = 0;
605  }
606 
607  if ( composition() )
608  {
609  mComposerMap = composition()->getComposerMapById( composerMapId );
610  }
611  else
612  {
613  mComposerMap = 0;
614  }
615 
616  if ( mComposerMap )
617  {
618  //if we have found a valid map item, listen out to extent changes on it and refresh the table
619  QObject::connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
620  }
621 
622  //vector layer
623  QString layerId = itemElem.attribute( "vectorLayer", "not_existing" );
624  if ( layerId == "not_existing" )
625  {
626  mVectorLayer = 0;
627  }
628  else
629  {
631  if ( ml )
632  {
633  mVectorLayer = dynamic_cast<QgsVectorLayer*>( ml );
634  if ( mVectorLayer )
635  {
636  //if we have found a valid vector layer, listen for modifications on it and refresh the table
637  QObject::connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
638  }
639  }
640  }
641 
642  //restore display attribute map. This is required to upgrade pre 2.4 projects.
643  QSet<int> displayAttributes;
644  QDomNodeList displayAttributeList = itemElem.elementsByTagName( "displayAttributes" );
645  if ( displayAttributeList.size() > 0 )
646  {
647  QDomElement displayAttributesElem = displayAttributeList.at( 0 ).toElement();
648  QDomNodeList attributeEntryList = displayAttributesElem.elementsByTagName( "attributeEntry" );
649  for ( int i = 0; i < attributeEntryList.size(); ++i )
650  {
651  QDomElement attributeEntryElem = attributeEntryList.at( i ).toElement();
652  int index = attributeEntryElem.attribute( "index", "-1" ).toInt();
653  if ( index != -1 )
654  {
655  displayAttributes.insert( index );
656  }
657  }
658  setDisplayAttributes( displayAttributes, false );
659  }
660 
661  //restore alias map. This is required to upgrade pre 2.4 projects.
662  QMap<int, QString> fieldAliasMap;
663  QDomNodeList aliasMapNodeList = itemElem.elementsByTagName( "attributeAliasMap" );
664  if ( aliasMapNodeList.size() > 0 )
665  {
666  QDomElement attributeAliasMapElem = aliasMapNodeList.at( 0 ).toElement();
667  QDomNodeList aliasMepEntryList = attributeAliasMapElem.elementsByTagName( "aliasEntry" );
668  for ( int i = 0; i < aliasMepEntryList.size(); ++i )
669  {
670  QDomElement aliasEntryElem = aliasMepEntryList.at( i ).toElement();
671  int key = aliasEntryElem.attribute( "key", "-1" ).toInt();
672  QString value = aliasEntryElem.attribute( "value", "" );
673  fieldAliasMap.insert( key, value );
674  }
675  restoreFieldAliasMap( fieldAliasMap );
676  }
677 
678  //restore sort columns. This is required to upgrade pre 2.4 projects.
679  QDomElement sortColumnsElem = itemElem.firstChildElement( "sortColumns" );
680  if ( !sortColumnsElem.isNull() && mVectorLayer )
681  {
682  QDomNodeList columns = sortColumnsElem.elementsByTagName( "column" );
683  const QgsFields& fields = mVectorLayer->pendingFields();
684 
685  for ( int i = 0; i < columns.size(); ++i )
686  {
687  QDomElement columnElem = columns.at( i ).toElement();
688  int attribute = columnElem.attribute( "index" ).toInt();
689  Qt::SortOrder order = columnElem.attribute( "ascending" ) == "true" ? Qt::AscendingOrder : Qt::DescendingOrder;
690  //find corresponding column
691  QList<QgsComposerTableColumn*>::iterator columnIt = mColumns.begin();
692  for ( ; columnIt != mColumns.end(); ++columnIt )
693  {
694  if (( *columnIt )->attribute() == fields[attribute].name() )
695  {
696  ( *columnIt )->setSortByRank( i + 1 );
697  ( *columnIt )->setSortOrder( order );
698  break;
699  }
700  }
701  }
702  }
703 
704  //must be done here because tableReadXML->setSceneRect changes mMaximumNumberOfFeatures
705  mMaximumNumberOfFeatures = itemElem.attribute( "maxFeatures", "5" ).toInt();
706 
708 
709  emit itemChanged();
710  return true;
711 }
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:89
Wrapper for iterator of features from vector data provider or vector layer.
static unsigned index
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:48
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.
QMap< int, QVariant > QgsAttributeMap
Definition: qgsfeature.h:98
void setAttribute(QString attribute)
Sets the attribute name or expression used for the column's values.
Use exact geometry intersection (slower) instead of bounding boxes.
QVariant evaluate(const QgsFeature *f=NULL)
Evaluate the feature and return the result.
bool getFeatureAttributes(QList< QgsAttributeMap > &attributeMaps)
Queries the attribute table's vector layer for attributes to show in the table.
Q_DECL_DEPRECATED QSet< int > displayAttributes() const
Returns the attributes fields which are shown by the table.
bool prepare(const QgsFields &fields)
Get the expression ready for evaluation - find out column indexes.
QString mFeatureFilter
Feature filter expression.
void itemChanged()
Emitted when the item changes.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
void setComposerMap(const QgsComposerMap *map)
Sets the composer map to use to limit the extent of features shown in the attribute table...
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads the properties specific to an attribute table from xml.
bool writeXML(QDomElement &elem, QDomDocument &doc) const
Writes properties specific to attribute tables.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
Container of fields for a vector layer.
Definition: qgsfield.h:163
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
Definition: qgsfield.h:213
QList< QgsComposerTableColumn * > * columns()
Returns a pointer to the list of QgsComposerTableColumns shown in the table.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
void setHeading(QString heading)
Sets the heading for a column, which is the value displayed in the columns header cell...
void setDisplayAttributes(const QSet< int > &attr, bool refresh=true)
Sets the attributes to display in the table.
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.
const QgsComposerMap * mComposerMap
Associated composer map (used to display the visible features)
A class to display feature attributes in the print composer.
bool isDrawing() const
True if a draw is already in progress.
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.h:206
Q_DECL_DEPRECATED void setSortAttributes(const QList< QPair< int, bool > > att)
Sets the attributes to use to sort the table's features.
QgsVectorLayer * mVectorLayer
Associated vector layer.
QString attributeDisplayName(int attributeIndex) const
Convenience function that returns the attribute alias if defined or the field name else...
void setSceneRect(const QRectF &rectangle)
Adapts mMaximumNumberOfFeatures depending on the rectangle height.
const QgsComposition * composition() const
Returns the composition the item is attached to.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
static bool columnsBySortRank(QPair< int, QgsComposerTableColumn * > a, QPair< int, QgsComposerTableColumn * > b)
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget)
Reimplementation of QCanvasItem::paint.
bool tableWriteXML(QDomElement &itemElem, QDomDocument &doc) const
Writes common table properties to xml for storage.
void restoreFieldAliasMap(const QMap< int, QString > &map)
Restores a field alias map from a pre 2.4 format project file format.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget)
Reimplementation of QCanvasItem::paint.
void setMaximumNumberOfFeatures(int features)
Sets the maximum number of features shown by the table.
const QgsAttributes & attributes() const
Definition: qgsfeature.h:142
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
Definition: qgsmaplayer.cpp:95
int count() const
Return number of items.
Definition: qgsfield.h:200
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...
QgsComposerAttributeTable(QgsComposition *composition)
QList< int > fieldsToDisplay() const
Returns a list of attribute indices corresponding to displayed fields in the table.
Stores properties of a column in a QgsComposerTable.
void setCurrentRowNumber(int rowNumber)
Set the number for $rownum special column.
QRectF evalItemRect(const QRectF &newRect)
Update an item rect to consider data defined position and size of item.
Graphics scene for map printing.
void resetColumns()
Resets the attribute table's columns to match the vector layer's fields.
Object representing map window.
QgsRectangle * currentMapExtent()
Returns a pointer to the current map extent, which is either the original user specified extent or th...
QList< QgsComposerTableColumn * > mColumns
void setFeatureFilter(const QString &expression)
Sets the expression used for filtering features in the table.
int id() const
Get identification number.
QgsComposition * mComposition
virtual void refreshAttributes()
Refreshes the attributes shown in the table by querying the vector layer for new data.
void removeLayer(QString layerId)
Checks if this vector layer will be removed (and sets mVectorLayer to 0 if yes)
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
bool mFilterFeatures
True if feature filtering enabled.
int mMaximumNumberOfFeatures
Maximum number of features that is displayed.
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.
void setSortColumn(int col)
Sets column number to sort by.
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.
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
QgsAtlasComposition & atlasComposition()
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
Custom exception class for Coordinate Reference System related exceptions.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
bool nextFeature(QgsFeature &f)
bool mShowOnlyVisibleFeatures
Shows only the features that are visible in the associated composer map (true by default) ...
const QgsComposerMap * getComposerMapById(const int id) const
Returns the composer map with specified id.
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.
QgsFeatureRequest & setFlags(Flags flags)
Set flags that affect how features will be fetched.
Helper class for sorting tables, takes into account sorting column and ascending / descending...
QgsFeatureRequest & setFilterRect(const QgsRectangle &rect)
Set rectangle from which features will be taken.