QGIS API Documentation  2.14.11-Essen
qgscomposerattributetablev2.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  QgsComposerAttributeTableV2.cpp
3  -----------------------------
4  begin : September 2014
5  copyright : (C) 2014 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 #include "qgscomposerframe.h"
25 #include "qgsatlascomposition.h"
26 #include "qgsproject.h"
27 #include "qgsrelationmanager.h"
28 #include "qgsgeometry.h"
29 
30 //QgsComposerAttributeTableCompareV2
31 
33  : mCurrentSortColumn( 0 ), mAscending( true )
34 {
35 }
36 
37 
39 {
40  return ( mAscending ? qgsVariantLessThan( m1[mCurrentSortColumn], m2[mCurrentSortColumn] )
41  : qgsVariantGreaterThan( m1[mCurrentSortColumn], m2[mCurrentSortColumn] ) );
42 }
43 
44 //
45 // QgsComposerAttributeTableV2
46 //
47 
49  : QgsComposerTableV2( composition, createUndoCommands )
50  , mSource( LayerAttributes )
51  , mVectorLayer( nullptr )
52  , mCurrentAtlasLayer( nullptr )
53  , mComposerMap( nullptr )
54  , mMaximumNumberOfFeatures( 30 )
55  , mShowUniqueRowsOnly( false )
56  , mShowOnlyVisibleFeatures( false )
57  , mFilterToAtlasIntersection( false )
58  , mFilterFeatures( false )
59  , mFeatureFilter( "" )
60 {
61  //set first vector layer from layer registry as default one
64  for ( ; mapIt != layerMap.constEnd(); ++mapIt )
65  {
66  QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( mapIt.value() );
67  if ( vl )
68  {
69  mVectorLayer = vl;
70  break;
71  }
72  }
73  if ( mVectorLayer )
74  {
75  resetColumns();
76  //listen for modifications to layer and refresh table when they occur
77  connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
78  }
79  connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( removeLayer( const QString& ) ) );
80 
81  if ( mComposition )
82  {
83  //refresh table attributes when composition is refreshed
84  connect( mComposition, SIGNAL( refreshItemsTriggered() ), this, SLOT( refreshAttributes() ) );
85 
86  //connect to atlas feature changes to update table rows
87  connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshAttributes() ) );
88 
89  //atlas coverage layer change = regenerate columns
90  connect( &mComposition->atlasComposition(), SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( atlasLayerChanged( QgsVectorLayer* ) ) );
91  }
93 }
94 
96 {
97 }
98 
100 {
101  return tr( "<attribute table>" );
102 }
103 
105 {
106  if ( layer == mVectorLayer )
107  {
108  //no change
109  return;
110  }
111 
112  QgsVectorLayer* prevLayer = sourceLayer();
113  mVectorLayer = layer;
114 
115  if ( mSource == QgsComposerAttributeTableV2::LayerAttributes && layer != prevLayer )
116  {
117  if ( prevLayer )
118  {
119  //disconnect from previous layer
120  disconnect( prevLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
121  }
122 
123  //rebuild column list to match all columns from layer
124  resetColumns();
125 
126  //listen for modifications to layer and refresh table when they occur
127  connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
128  }
129 
131  emit changed();
132 }
133 
135 {
136  if ( relationId == mRelationId )
137  {
138  //no change
139  return;
140  }
141 
142  QgsVectorLayer* prevLayer = sourceLayer();
143  mRelationId = relationId;
144  QgsRelation relation = QgsProject::instance()->relationManager()->relation( mRelationId );
145  QgsVectorLayer* newLayer = relation.referencingLayer();
146 
147  if ( mSource == QgsComposerAttributeTableV2::RelationChildren && newLayer != prevLayer )
148  {
149  if ( prevLayer )
150  {
151  //disconnect from previous layer
152  disconnect( prevLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
153  }
154 
155  //rebuild column list to match all columns from layer
156  resetColumns();
157 
158  //listen for modifications to layer and refresh table when they occur
159  connect( newLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
160  }
161 
163  emit changed();
164 }
165 
166 void QgsComposerAttributeTableV2::atlasLayerChanged( QgsVectorLayer *layer )
167 {
168  if ( mSource != QgsComposerAttributeTableV2::AtlasFeature || layer == mCurrentAtlasLayer )
169  {
170  //nothing to do
171  return;
172  }
173 
174  //atlas feature mode, atlas layer changed, so we need to reset columns
175  if ( mCurrentAtlasLayer )
176  {
177  //disconnect from previous layer
178  disconnect( mCurrentAtlasLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
179  }
180 
181  mCurrentAtlasLayer = layer;
182 
183  //rebuild column list to match all columns from layer
184  resetColumns();
186 
187  //listen for modifications to layer and refresh table when they occur
188  connect( layer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
189 }
190 
192 {
194  if ( !source )
195  {
196  return;
197  }
198 
199  //remove existing columns
200  qDeleteAll( mColumns );
201  mColumns.clear();
202 
203  //rebuild columns list from vector layer fields
204  const QgsFields& fields = source->fields();
205  for ( int idx = 0; idx < fields.count(); ++idx )
206  {
207  QString currentAlias = source->attributeDisplayName( idx );
209  col->setAttribute( fields[idx].name() );
210  col->setHeading( currentAlias );
211  mColumns.append( col );
212  }
213 }
214 
216 {
217  if ( map == mComposerMap )
218  {
219  //no change
220  return;
221  }
222 
223  if ( mComposerMap )
224  {
225  //disconnect from previous map
226  disconnect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
227  }
228  mComposerMap = map;
229  if ( mComposerMap )
230  {
231  //listen out for extent changes in linked map
232  connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
233  }
235  emit changed();
236 }
237 
239 {
240  if ( features == mMaximumNumberOfFeatures )
241  {
242  return;
243  }
244 
245  mMaximumNumberOfFeatures = features;
247  emit changed();
248 }
249 
251 {
252  if ( uniqueOnly == mShowUniqueRowsOnly )
253  {
254  return;
255  }
256 
257  mShowUniqueRowsOnly = uniqueOnly;
259  emit changed();
260 }
261 
263 {
264  if ( visibleOnly == mShowOnlyVisibleFeatures )
265  {
266  return;
267  }
268 
269  mShowOnlyVisibleFeatures = visibleOnly;
271  emit changed();
272 }
273 
275 {
276  if ( filterToAtlas == mFilterToAtlasIntersection )
277  {
278  return;
279  }
280 
281  mFilterToAtlasIntersection = filterToAtlas;
283  emit changed();
284 }
285 
287 {
288  if ( filter == mFilterFeatures )
289  {
290  return;
291  }
292 
293  mFilterFeatures = filter;
295  emit changed();
296 }
297 
299 {
300  if ( expression == mFeatureFilter )
301  {
302  return;
303  }
304 
305  mFeatureFilter = expression;
307  emit changed();
308 }
309 
311 {
313  if ( !source )
314  {
315  return;
316  }
317 
318  //rebuild columns list, taking only attributes with index in supplied QSet
319  qDeleteAll( mColumns );
320  mColumns.clear();
321 
322  const QgsFields& fields = source->fields();
323 
324  if ( !attr.empty() )
325  {
326  QSet<int>::const_iterator attIt = attr.constBegin();
327  for ( ; attIt != attr.constEnd(); ++attIt )
328  {
329  int attrIdx = ( *attIt );
330  if ( !fields.exists( attrIdx ) )
331  {
332  continue;
333  }
334  QString currentAlias = source->attributeDisplayName( attrIdx );
336  col->setAttribute( fields[attrIdx].name() );
337  col->setHeading( currentAlias );
338  mColumns.append( col );
339  }
340  }
341  else
342  {
343  //resetting, so add all attributes to columns
344  for ( int idx = 0; idx < fields.count(); ++idx )
345  {
346  QString currentAlias = source->attributeDisplayName( idx );
348  col->setAttribute( fields[idx].name() );
349  col->setHeading( currentAlias );
350  mColumns.append( col );
351  }
352  }
353 
354  if ( refresh )
355  {
357  }
358 }
359 
360 void QgsComposerAttributeTableV2::restoreFieldAliasMap( const QMap<int, QString>& map )
361 {
363  if ( !source )
364  {
365  return;
366  }
367 
369  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
370  {
371  int attrIdx = source->fieldNameIndex(( *columnIt )->attribute() );
372  if ( map.contains( attrIdx ) )
373  {
374  ( *columnIt )->setHeading( map.value( attrIdx ) );
375  }
376  else
377  {
378  ( *columnIt )->setHeading( source->attributeDisplayName( attrIdx ) );
379  }
380  }
381 }
382 
384 {
385  contents.clear();
386 
389  {
390  //source mode requires atlas, but atlas disabled
391  return false;
392  }
393 
394  QgsVectorLayer* layer = sourceLayer();
395 
396  if ( !layer )
397  {
398  //no source layer
399  return false;
400  }
401 
403  context->setFields( layer->fields() );
404 
405  //prepare filter expression
406  QScopedPointer<QgsExpression> filterExpression;
407  bool activeFilter = false;
408  if ( mFilterFeatures && !mFeatureFilter.isEmpty() )
409  {
410  filterExpression.reset( new QgsExpression( mFeatureFilter ) );
411  if ( !filterExpression->hasParserError() )
412  {
413  activeFilter = true;
414  }
415  }
416 
417  QgsRectangle selectionRect;
418  if ( mComposerMap && mShowOnlyVisibleFeatures )
419  {
420  selectionRect = *mComposerMap->currentMapExtent();
421  if ( layer && mComposition->mapSettings().hasCrsTransformEnabled() )
422  {
423  //transform back to layer CRS
424  QgsCoordinateTransform coordTransform( layer->crs(), mComposition->mapSettings().destinationCrs() );
425  try
426  {
427  selectionRect = coordTransform.transformBoundingBox( selectionRect, QgsCoordinateTransform::ReverseTransform );
428  }
429  catch ( QgsCsException &cse )
430  {
431  Q_UNUSED( cse );
432  return false;
433  }
434  }
435  }
436 
437  QgsFeatureRequest req;
438 
440  {
441  QgsRelation relation = QgsProject::instance()->relationManager()->relation( mRelationId );
442  QgsFeature atlasFeature = mComposition->atlasComposition().feature();
443  req = relation.getRelatedFeaturesRequest( atlasFeature );
444  }
445 
446  if ( !selectionRect.isEmpty() )
447  req.setFilterRect( selectionRect );
448 
449  req.setFlags( mShowOnlyVisibleFeatures ? QgsFeatureRequest::ExactIntersect : QgsFeatureRequest::NoFlags );
450 
453  {
454  //source mode is current atlas feature
455  QgsFeature atlasFeature = mComposition->atlasComposition().feature();
456  req.setFilterFid( atlasFeature.id() );
457  }
458 
459  QgsFeature f;
460  int counter = 0;
461  QgsFeatureIterator fit = layer->getFeatures( req );
462 
463  while ( fit.nextFeature( f ) && counter < mMaximumNumberOfFeatures )
464  {
465  context->setFeature( f );
466  //check feature against filter
467  if ( activeFilter && !filterExpression.isNull() )
468  {
469  QVariant result = filterExpression->evaluate( context.data() );
470  // skip this feature if the filter evaluation is false
471  if ( !result.toBool() )
472  {
473  continue;
474  }
475  }
476  //check against atlas feature intersection
477  if ( mFilterToAtlasIntersection )
478  {
479  if ( !f.constGeometry() || ! mComposition->atlasComposition().enabled() )
480  {
481  continue;
482  }
483  QgsFeature atlasFeature = mComposition->atlasComposition().feature();
484  if ( !atlasFeature.constGeometry() ||
485  !f.constGeometry()->intersects( atlasFeature.constGeometry() ) )
486  {
487  //feature falls outside current atlas feature
488  continue;
489  }
490  }
491 
492  QgsComposerTableRow currentRow;
493 
495  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
496  {
497  int idx = layer->fieldNameIndex(( *columnIt )->attribute() );
498  if ( idx != -1 )
499  {
500  currentRow << replaceWrapChar( f.attributes().at( idx ) );
501  }
502  else
503  {
504  // Lets assume it's an expression
505  QgsExpression* expression = new QgsExpression(( *columnIt )->attribute() );
506  context->lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QString( "row_number" ), counter + 1, true ) );
507  expression->prepare( context.data() );
508  QVariant value = expression->evaluate( context.data() );
509  currentRow << value;
510  }
511  }
512 
513  if ( !mShowUniqueRowsOnly || !contentsContainsRow( contents, currentRow ) )
514  {
515  contents << currentRow;
516  ++counter;
517  }
518  }
519 
520  //sort the list, starting with the last attribute
522  QList< QPair<int, bool> > sortColumns = sortAttributes();
523  for ( int i = sortColumns.size() - 1; i >= 0; --i )
524  {
525  c.setSortColumn( sortColumns.at( i ).first );
526  c.setAscending( sortColumns.at( i ).second );
527  qStableSort( contents.begin(), contents.end(), c );
528  }
529 
531  return true;
532 }
533 
535 {
537 
538  if ( mSource == LayerAttributes )
539  {
540  context->appendScope( QgsExpressionContextUtils::layerScope( mVectorLayer ) );
541  }
542 
543  return context;
544 }
545 
546 QVariant QgsComposerAttributeTableV2::replaceWrapChar( const QVariant &variant ) const
547 {
548  //avoid converting variants to string if not required (try to maintain original type for sorting)
549  if ( mWrapString.isEmpty() || !variant.toString().contains( mWrapString ) )
550  return variant;
551 
552  QString replaced = variant.toString();
553  replaced.replace( mWrapString, "\n" );
554  return replaced;
555 }
556 
558 {
559  switch ( mSource )
560  {
564  return mVectorLayer;
566  {
567  QgsRelation relation = QgsProject::instance()->relationManager()->relation( mRelationId );
568  return relation.referencingLayer();
569  }
570  }
571  return nullptr;
572 }
573 
574 void QgsComposerAttributeTableV2::removeLayer( const QString& layerId )
575 {
576  if ( mVectorLayer && mSource == QgsComposerAttributeTableV2::LayerAttributes )
577  {
578  if ( layerId == mVectorLayer->id() )
579  {
580  mVectorLayer = nullptr;
581  //remove existing columns
582  qDeleteAll( mColumns );
583  mColumns.clear();
584  }
585  }
586 }
587 
589 {
590  return a.second->sortByRank() < b.second->sortByRank();
591 }
592 
594 {
595  //generate list of all sorted columns
598  int idx = 0;
599  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
600  {
601  if (( *columnIt )->sortByRank() > 0 )
602  {
603  sortedColumns.append( qMakePair( idx, *columnIt ) );
604  }
605  idx++;
606  }
607 
608  //sort columns by rank
609  qSort( sortedColumns.begin(), sortedColumns.end(), columnsBySortRank );
610 
611  //generate list of column index, bool for sort direction (to match 2.0 api)
612  QList<QPair<int, bool> > attributesBySortRank;
613  QVector< QPair<int, QgsComposerTableColumn* > >::const_iterator sortedColumnIt = sortedColumns.constBegin();
614  for ( ; sortedColumnIt != sortedColumns.constEnd(); ++sortedColumnIt )
615  {
616 
617  attributesBySortRank.append( qMakePair(( *sortedColumnIt ).first,
618  ( *sortedColumnIt ).second->sortOrder() == Qt::AscendingOrder ) );
619  }
620  return attributesBySortRank;
621 }
622 
624 {
625  if ( wrapString == mWrapString )
626  {
627  return;
628  }
629 
630  mWrapString = wrapString;
632  emit changed();
633 }
634 
635 bool QgsComposerAttributeTableV2::writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames ) const
636 {
637  QDomElement composerTableElem = doc.createElement( "ComposerAttributeTableV2" );
638  composerTableElem.setAttribute( "source", QString::number( static_cast< int >( mSource ) ) );
639  composerTableElem.setAttribute( "relationId", mRelationId );
640  composerTableElem.setAttribute( "showUniqueRowsOnly", mShowUniqueRowsOnly );
641  composerTableElem.setAttribute( "showOnlyVisibleFeatures", mShowOnlyVisibleFeatures );
642  composerTableElem.setAttribute( "filterToAtlasIntersection", mFilterToAtlasIntersection );
643  composerTableElem.setAttribute( "maxFeatures", mMaximumNumberOfFeatures );
644  composerTableElem.setAttribute( "filterFeatures", mFilterFeatures ? "true" : "false" );
645  composerTableElem.setAttribute( "featureFilter", mFeatureFilter );
646  composerTableElem.setAttribute( "wrapString", mWrapString );
647 
648  if ( mComposerMap )
649  {
650  composerTableElem.setAttribute( "composerMap", mComposerMap->id() );
651  }
652  else
653  {
654  composerTableElem.setAttribute( "composerMap", -1 );
655  }
656  if ( mVectorLayer )
657  {
658  composerTableElem.setAttribute( "vectorLayer", mVectorLayer->id() );
659  }
660 
661  bool ok = QgsComposerTableV2::writeXML( composerTableElem, doc, ignoreFrames );
662 
663  elem.appendChild( composerTableElem );
664 
665  return ok;
666 }
667 
668 bool QgsComposerAttributeTableV2::readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames )
669 {
670  if ( itemElem.isNull() )
671  {
672  return false;
673  }
674 
675  //read general table properties
676  if ( !QgsComposerTableV2::readXML( itemElem, doc, ignoreFrames ) )
677  {
678  return false;
679  }
680 
681  QgsVectorLayer* prevLayer = sourceLayer();
682  if ( prevLayer )
683  {
684  //disconnect from previous layer
685  disconnect( prevLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
686  }
687 
688  mSource = QgsComposerAttributeTableV2::ContentSource( itemElem.attribute( "source", "0" ).toInt() );
689  mRelationId = itemElem.attribute( "relationId", "" );
690 
692  {
693  mCurrentAtlasLayer = mComposition->atlasComposition().coverageLayer();
694  }
695 
696  mShowUniqueRowsOnly = itemElem.attribute( "showUniqueRowsOnly", "0" ).toInt();
697  mShowOnlyVisibleFeatures = itemElem.attribute( "showOnlyVisibleFeatures", "1" ).toInt();
698  mFilterToAtlasIntersection = itemElem.attribute( "filterToAtlasIntersection", "0" ).toInt();
699  mFilterFeatures = itemElem.attribute( "filterFeatures", "false" ) == "true" ? true : false;
700  mFeatureFilter = itemElem.attribute( "featureFilter", "" );
701  mMaximumNumberOfFeatures = itemElem.attribute( "maxFeatures", "5" ).toInt();
702  mWrapString = itemElem.attribute( "wrapString" );
703 
704  //composer map
705  int composerMapId = itemElem.attribute( "composerMap", "-1" ).toInt();
706  if ( composerMapId == -1 )
707  {
708  mComposerMap = nullptr;
709  }
710 
711  if ( composition() )
712  {
713  mComposerMap = composition()->getComposerMapById( composerMapId );
714  }
715  else
716  {
717  mComposerMap = nullptr;
718  }
719 
720  if ( mComposerMap )
721  {
722  //if we have found a valid map item, listen out to extent changes on it and refresh the table
723  connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
724  }
725 
726  //vector layer
727  QString layerId = itemElem.attribute( "vectorLayer", "not_existing" );
728  if ( layerId == "not_existing" )
729  {
730  mVectorLayer = nullptr;
731  }
732  else
733  {
735  if ( ml )
736  {
737  mVectorLayer = dynamic_cast<QgsVectorLayer*>( ml );
738  }
739  }
740 
741  //connect to new layer
742  connect( sourceLayer(), SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
743 
745 
746  emit changed();
747  return true;
748 }
749 
751 {
752  mFrameItems.push_back( frame );
753  connect( frame, SIGNAL( sizeChanged() ), this, SLOT( recalculateFrameSizes() ) );
754  if ( mComposition )
755  {
756  mComposition->addComposerTableFrame( this, frame );
757  }
758 
759  if ( recalcFrameSizes )
760  {
762  }
763 }
764 
766 {
767  if ( source == mSource )
768  {
769  return;
770  }
771 
772  QgsVectorLayer* prevLayer = sourceLayer();
773  mSource = source;
774  QgsVectorLayer* newLayer = sourceLayer();
775 
776  if ( newLayer != prevLayer )
777  {
778  //disconnect from previous layer
779  if ( prevLayer )
780  {
781  disconnect( prevLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
782  }
783 
784  //connect to new layer
785  connect( newLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
787  {
788  mCurrentAtlasLayer = newLayer;
789  }
790 
791  //layer has changed as a result of the source change, so reset column list
792  resetColumns();
793  }
794 
796  emit changed();
797 }
void setFilterToAtlasFeature(const bool filterToAtlas)
Sets attribute table to only show features which intersect the current atlas feature.
Class for parsing and evaluation of expressions (formerly called "search strings").
void clear()
Wrapper for iterator of features from vector data provider or vector layer.
void setAttribute(const QString &attribute)
Sets the attribute name or expression used for the column&#39;s values.
Single variable definition for use within a QgsExpressionContextScope.
QgsVectorLayer * sourceLayer()
Returns the source layer for the table, considering the table source mode.
virtual QgsExpressionContext * createExpressionContext() const override
Creates an expression context relating to the objects&#39; current state.
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
const QgsComposerMap * getComposerMapById(const int id) const
Returns the composer map with specified id.
bool intersects(const QgsRectangle &r) const
Test for intersection with a rectangle (uses GEOS)
bool contains(const Key &key) const
Q_DECL_DEPRECATED QVariant evaluate(const QgsFeature *f)
Evaluate the feature and return the result.
Helper class for sorting tables, takes into account sorting column and ascending / descending...
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
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:375
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
void setWrapString(const QString &wrapString)
Sets a string to wrap the contents of the table cells by.
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.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const override
Stores state information about multiframe in DOM element.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
int id() const
Get identification number.
Container of fields for a vector layer.
Definition: qgsfield.h:187
virtual bool writeXML(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const override
Writes properties specific to attribute tables.
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
Definition: qgsfeature.cpp:82
void setComposerMap(const QgsComposerMap *map)
Sets the composer map to use to limit the extent of features shown in the attribute table...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
QgsRelationManager * relationManager() const
void recalculateTableSize()
Recalculates and updates the size of the table and all table frames.
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:335
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
int count() const
Return number of items.
Definition: qgsfield.cpp:365
QString tr(const char *sourceText, const char *disambiguation, int n)
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false) override
Reads the properties specific to an attribute table from xml.
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:267
int size() const
QgsMapLayer * mapLayer(const QString &theLayerId)
Retrieve a pointer to a loaded layer by id.
void reset(T *other)
QgsFields fields() const
Returns the list of fields of this layer.
const char * name() const
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Set feature ID that should be fetched.
QString number(int n, int base)
void append(const T &value)
bool contentsContainsRow(const QgsComposerTableContents &contents, const QgsComposerTableRow &row) const
Checks whether a table contents contains a given row.
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...
void setFilterFeatures(const bool filter)
Sets whether the feature filter is active for the attribute table.
bool isEmpty() const
test if rectangle is empty.
void setAttribute(const QString &name, const QString &value)
void setSortColumn(int col)
Sets column number to sort by.
int toInt(bool *ok, int base) const
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool isEmpty() const
QList< QgsComposerFrame * > mFrameItems
const_iterator constEnd() const
void setFeatureFilter(const QString &expression)
Sets the expression used for filtering features in the table.
void addComposerTableFrame(QgsComposerAttributeTableV2 *table, QgsComposerFrame *frame)
Adds composer tablev2 frame and advises composer to create a widget for it (through signal) ...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
A class to display a table in the print composer, and allow the table to span over multiple frames...
ContentSource source() const
Returns the source for attributes shown in the table body.
const T & value() const
void recalculateFrameSizes() override
const_iterator constEnd() const
QgsFeatureRequest & setFlags(const QgsFeatureRequest::Flags &flags)
Set flags that affect how features will be fetched.
bool operator()(const QgsComposerTableRow &m1, const QgsComposerTableRow &m2)
void setRelationId(const QString &relationId)
Sets the relation id from which to display child features.
QgsFeatureRequest getRelatedFeaturesRequest(const QgsFeature &feature) const
Creates a request to return all the features on the referencing (child) layer which have a foreign ke...
Stores properties of a column in a QgsComposerTable.
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false) override
Reads multiframe state information from a DOM element.
Graphics scene for map printing.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
Object representing map window.
Frame item for a composer multiframe item.
T * data() const
iterator end()
QgsFeatureId id() const
Get the feature ID for this feature.
Definition: qgsfeature.cpp:65
bool contains(QChar ch, Qt::CaseSensitivity cs) const
void setDisplayAttributes(const QSet< int > &attr, bool refresh=true)
Sets the attributes to display in the table.
void setSource(const ContentSource source)
Sets the source for attributes to show in table body.
bool getTableContents(QgsComposerTableContents &contents) override
Queries the attribute table&#39;s vector layer for attributes to show in the table.
const_iterator constBegin() const
bool isNull() const
QList< QPair< int, bool > > sortAttributes() const
Returns the attributes used to sort the table&#39;s features.
QgsComposition * mComposition
bool isNull() const
QString & replace(int position, int n, QChar after)
QgsComposerTableColumns mColumns
Columns to show in table.
void setVectorLayer(QgsVectorLayer *layer)
Sets the vector layer from which to display feature attributes.
const T & at(int i) const
bool empty() const
QgsVectorLayer * referencingLayer() const
Access the referencing (child) layer This is the layer which has the field(s) which point to another ...
const_iterator constBegin() const
virtual void addFrame(QgsComposerFrame *frame, bool recalcFrameSizes=true) override
Adds a frame to the multiframe.
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
void resetColumns()
Resets the attribute table&#39;s columns to match the vector layer&#39;s fields.
ContentSource
Specifies the content source for the attribute table.
void setMaximumNumberOfFeatures(const int features)
Sets the maximum number of features shown by the table.
QgsComposition * composition()
Returns the parent composition for the multiframe.
virtual void refreshAttributes()
Refreshes the contents shown in the table by querying for new data.
static bool columnsBySortRank(QPair< int, QgsComposerTableColumn * > a, QPair< int, QgsComposerTableColumn * > b)
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
static QgsProject * instance()
access to canonical QgsProject instance
Definition: qgsproject.cpp:381
void setUniqueRowsOnly(const bool uniqueOnly)
Sets attribute table to only show unique rows.
const QMap< QString, QgsMapLayer * > & mapLayers()
Retrieve the mapLayers collection (mainly intended for use by projection)
Class for doing transforms between two map coordinate systems.
QString relationId() const
Returns the relation id which the table displays child features from.
bool toBool() const
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
QgsAtlasComposition & atlasComposition()
QgsFeature feature() const
Returns the current atlas feature.
QString wrapString() const
Returns the string used to wrap the contents of the table cells by.
Custom exception class for Coordinate Reference System related exceptions.
void setAscending(bool asc)
Sets sort order for column sorting.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
const_iterator constEnd() const
QDomElement createElement(const QString &tagName)
bool nextFeature(QgsFeature &f)
const_iterator constBegin() const
QgsRelation relation(const QString &id) const
Get access to a relation by its 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.
QgsComposerTableContents * contents()
Returns the current contents of the table.
QgsComposerFrame * frame(int i) const
Returns a child frame from the multiframe.
QString toString() const
iterator end()
QString attributeDisplayName(int attributeIndex) const
Convenience function that returns the attribute alias if defined or the field name else...
const QgsRectangle * currentMapExtent() const
Returns a pointer to the current map extent, which is either the original user specified extent or th...
iterator begin()
virtual QString displayName() const override
Get multiframe display name.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
void setDisplayOnlyVisibleFeatures(const bool visibleOnly)
Sets attribute table to only show features which are visible in a composer map item.
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.
bool enabled() const
Returns whether the atlas generation is enabled.
virtual QgsExpressionContext * createExpressionContext() const
Creates an expression context relating to the objects&#39; current state.
QgsComposerAttributeTableV2(QgsComposition *composition, bool createUndoCommands)
void changed()
Emitted when the properties of a multi frame have changed, and the GUI item widget must be updated...
const T value(const Key &key) const