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