QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 )
34  , mAscending( true )
35 {
36 }
37 
38 
40 {
41  return ( mAscending ? qgsVariantLessThan( m1[mCurrentSortColumn], m2[mCurrentSortColumn] )
42  : qgsVariantGreaterThan( m1[mCurrentSortColumn], m2[mCurrentSortColumn] ) );
43 }
44 
45 //
46 // QgsComposerAttributeTableV2
47 //
48 
50  : QgsComposerTableV2( composition, createUndoCommands )
51  , mSource( LayerAttributes )
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.setLayer( 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.get(), 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.get() )
107  {
108  //no change
109  return;
110  }
111 
112  QgsVectorLayer* prevLayer = sourceLayer();
113  mVectorLayer.setLayer( 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.get(), 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  int idx = 0;
205  Q_FOREACH ( const QgsField& field, source->fields() )
206  {
207  QString currentAlias = source->attributeDisplayName( idx );
209  col->setAttribute( field.name() );
210  col->setHeading( currentAlias );
211  mColumns.append( col );
212  idx++;
213  }
214 }
215 
217 {
218  if ( map == mComposerMap )
219  {
220  //no change
221  return;
222  }
223 
224  if ( mComposerMap )
225  {
226  //disconnect from previous map
227  disconnect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
228  }
229  mComposerMap = map;
230  if ( mComposerMap )
231  {
232  //listen out for extent changes in linked map
233  connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
234  }
236  emit changed();
237 }
238 
240 {
241  if ( features == mMaximumNumberOfFeatures )
242  {
243  return;
244  }
245 
246  mMaximumNumberOfFeatures = features;
248  emit changed();
249 }
250 
252 {
253  if ( uniqueOnly == mShowUniqueRowsOnly )
254  {
255  return;
256  }
257 
258  mShowUniqueRowsOnly = uniqueOnly;
260  emit changed();
261 }
262 
264 {
265  if ( visibleOnly == mShowOnlyVisibleFeatures )
266  {
267  return;
268  }
269 
270  mShowOnlyVisibleFeatures = visibleOnly;
272  emit changed();
273 }
274 
276 {
277  if ( filterToAtlas == mFilterToAtlasIntersection )
278  {
279  return;
280  }
281 
282  mFilterToAtlasIntersection = filterToAtlas;
284  emit changed();
285 }
286 
288 {
289  if ( filter == mFilterFeatures )
290  {
291  return;
292  }
293 
294  mFilterFeatures = filter;
296  emit changed();
297 }
298 
300 {
301  if ( expression == mFeatureFilter )
302  {
303  return;
304  }
305 
306  mFeatureFilter = expression;
308  emit changed();
309 }
310 
312 {
314  if ( !source )
315  {
316  return;
317  }
318 
319  //rebuild columns list, taking only attributes with index in supplied QSet
320  qDeleteAll( mColumns );
321  mColumns.clear();
322 
323  const QgsFields& fields = source->fields();
324 
325  if ( !attr.empty() )
326  {
327  QSet<int>::const_iterator attIt = attr.constBegin();
328  for ( ; attIt != attr.constEnd(); ++attIt )
329  {
330  int attrIdx = ( *attIt );
331  if ( !fields.exists( attrIdx ) )
332  {
333  continue;
334  }
335  QString currentAlias = source->attributeDisplayName( attrIdx );
337  col->setAttribute( fields[attrIdx].name() );
338  col->setHeading( currentAlias );
339  mColumns.append( col );
340  }
341  }
342  else
343  {
344  //resetting, so add all attributes to columns
345  int idx = 0;
346  Q_FOREACH ( const QgsField& field, fields )
347  {
348  QString currentAlias = source->attributeDisplayName( idx );
350  col->setAttribute( field.name() );
351  col->setHeading( currentAlias );
352  mColumns.append( col );
353  idx++;
354  }
355  }
356 
357  if ( refresh )
358  {
360  }
361 }
362 
364 {
366  if ( !source )
367  {
368  return;
369  }
370 
371  //rebuild columns list, taking only fields contained in supplied list
372  qDeleteAll( mColumns );
373  mColumns.clear();
374 
375  QgsFields layerFields = source->fields();
376 
377  if ( !fields.isEmpty() )
378  {
379  Q_FOREACH ( const QString& field, fields )
380  {
381  int attrIdx = layerFields.fieldNameIndex( field );
382  if ( attrIdx < 0 )
383  continue;
384 
385  QString currentAlias = source->attributeDisplayName( attrIdx );
387  col->setAttribute( layerFields.at( attrIdx ).name() );
388  col->setHeading( currentAlias );
389  mColumns.append( col );
390  }
391  }
392  else
393  {
394  //resetting, so add all attributes to columns
395  int idx = 0;
396  Q_FOREACH ( const QgsField& field, layerFields )
397  {
398  QString currentAlias = source->attributeDisplayName( idx );
400  col->setAttribute( field.name() );
401  col->setHeading( currentAlias );
402  mColumns.append( col );
403  idx++;
404  }
405  }
406 
407  if ( refresh )
408  {
410  }
411 }
412 
413 void QgsComposerAttributeTableV2::restoreFieldAliasMap( const QMap<int, QString>& map )
414 {
416  if ( !source )
417  {
418  return;
419  }
420 
422  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
423  {
424  int attrIdx = source->fieldNameIndex(( *columnIt )->attribute() );
425  if ( map.contains( attrIdx ) )
426  {
427  ( *columnIt )->setHeading( map.value( attrIdx ) );
428  }
429  else
430  {
431  ( *columnIt )->setHeading( source->attributeDisplayName( attrIdx ) );
432  }
433  }
434 }
435 
437 {
438  contents.clear();
439 
442  {
443  //source mode requires atlas, but atlas disabled
444  return false;
445  }
446 
447  QgsVectorLayer* layer = sourceLayer();
448 
449  if ( !layer )
450  {
451  //no source layer
452  return false;
453  }
454 
456  context->setFields( layer->fields() );
457 
458  //prepare filter expression
459  QScopedPointer<QgsExpression> filterExpression;
460  bool activeFilter = false;
461  if ( mFilterFeatures && !mFeatureFilter.isEmpty() )
462  {
463  filterExpression.reset( new QgsExpression( mFeatureFilter ) );
464  if ( !filterExpression->hasParserError() )
465  {
466  activeFilter = true;
467  }
468  }
469 
470  QgsRectangle selectionRect;
471  if ( mComposerMap && mShowOnlyVisibleFeatures )
472  {
473  selectionRect = *mComposerMap->currentMapExtent();
474  if ( layer && mComposition->mapSettings().hasCrsTransformEnabled() )
475  {
476  //transform back to layer CRS
477  QgsCoordinateTransform coordTransform( layer->crs(), mComposition->mapSettings().destinationCrs() );
478  try
479  {
480  selectionRect = coordTransform.transformBoundingBox( selectionRect, QgsCoordinateTransform::ReverseTransform );
481  }
482  catch ( QgsCsException &cse )
483  {
484  Q_UNUSED( cse );
485  return false;
486  }
487  }
488  }
489 
490  QgsFeatureRequest req;
491 
493  {
494  QgsRelation relation = QgsProject::instance()->relationManager()->relation( mRelationId );
495  QgsFeature atlasFeature = mComposition->atlasComposition().feature();
496  req = relation.getRelatedFeaturesRequest( atlasFeature );
497  }
498 
499  if ( !selectionRect.isEmpty() )
500  req.setFilterRect( selectionRect );
501 
502  req.setFlags( mShowOnlyVisibleFeatures ? QgsFeatureRequest::ExactIntersect : QgsFeatureRequest::NoFlags );
503 
506  {
507  //source mode is current atlas feature
508  QgsFeature atlasFeature = mComposition->atlasComposition().feature();
509  req.setFilterFid( atlasFeature.id() );
510  }
511 
512  QgsFeature f;
513  int counter = 0;
514  QgsFeatureIterator fit = layer->getFeatures( req );
515 
516  while ( fit.nextFeature( f ) && counter < mMaximumNumberOfFeatures )
517  {
518  context->setFeature( f );
519  //check feature against filter
520  if ( activeFilter && !filterExpression.isNull() )
521  {
522  QVariant result = filterExpression->evaluate( context.data() );
523  // skip this feature if the filter evaluation is false
524  if ( !result.toBool() )
525  {
526  continue;
527  }
528  }
529  //check against atlas feature intersection
530  if ( mFilterToAtlasIntersection )
531  {
532  if ( !f.constGeometry() || ! mComposition->atlasComposition().enabled() )
533  {
534  continue;
535  }
536  QgsFeature atlasFeature = mComposition->atlasComposition().feature();
537  if ( !atlasFeature.constGeometry() ||
538  !f.constGeometry()->intersects( atlasFeature.constGeometry() ) )
539  {
540  //feature falls outside current atlas feature
541  continue;
542  }
543  }
544 
545  QgsComposerTableRow currentRow;
546 
548  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
549  {
550  int idx = layer->fieldNameIndex(( *columnIt )->attribute() );
551  if ( idx != -1 )
552  {
553  currentRow << replaceWrapChar( f.attributes().at( idx ) );
554  }
555  else
556  {
557  // Lets assume it's an expression
558  QgsExpression* expression = new QgsExpression(( *columnIt )->attribute() );
559  context->lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QString( "row_number" ), counter + 1, true ) );
560  expression->prepare( context.data() );
561  QVariant value = expression->evaluate( context.data() );
562  currentRow << value;
563  }
564  }
565 
566  if ( !mShowUniqueRowsOnly || !contentsContainsRow( contents, currentRow ) )
567  {
568  contents << currentRow;
569  ++counter;
570  }
571  }
572 
573  //sort the list, starting with the last attribute
575  QList< QPair<int, bool> > sortColumns = sortAttributes();
576  for ( int i = sortColumns.size() - 1; i >= 0; --i )
577  {
578  c.setSortColumn( sortColumns.at( i ).first );
579  c.setAscending( sortColumns.at( i ).second );
580  qStableSort( contents.begin(), contents.end(), c );
581  }
582 
584  return true;
585 }
586 
588 {
590 
591  if ( mSource == LayerAttributes )
592  {
593  context->appendScope( QgsExpressionContextUtils::layerScope( mVectorLayer.get() ) );
594  }
595 
596  return context;
597 }
598 
599 QVariant QgsComposerAttributeTableV2::replaceWrapChar( const QVariant &variant ) const
600 {
601  //avoid converting variants to string if not required (try to maintain original type for sorting)
602  if ( mWrapString.isEmpty() || !variant.toString().contains( mWrapString ) )
603  return variant;
604 
605  QString replaced = variant.toString();
606  replaced.replace( mWrapString, "\n" );
607  return replaced;
608 }
609 
611 {
612  switch ( mSource )
613  {
617  return mVectorLayer.get();
619  {
620  QgsRelation relation = QgsProject::instance()->relationManager()->relation( mRelationId );
621  return relation.referencingLayer();
622  }
623  }
624  return nullptr;
625 }
626 
627 void QgsComposerAttributeTableV2::removeLayer( const QString& layerId )
628 {
629  if ( mVectorLayer && mSource == QgsComposerAttributeTableV2::LayerAttributes )
630  {
631  if ( layerId == mVectorLayer->id() )
632  {
633  mVectorLayer.setLayer( nullptr );
634  //remove existing columns
635  qDeleteAll( mColumns );
636  mColumns.clear();
637  }
638  }
639 }
640 
642 {
643  return a.second->sortByRank() < b.second->sortByRank();
644 }
645 
647 {
648  //generate list of all sorted columns
651  int idx = 0;
652  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
653  {
654  if (( *columnIt )->sortByRank() > 0 )
655  {
656  sortedColumns.append( qMakePair( idx, *columnIt ) );
657  }
658  idx++;
659  }
660 
661  //sort columns by rank
662  qSort( sortedColumns.begin(), sortedColumns.end(), columnsBySortRank );
663 
664  //generate list of column index, bool for sort direction (to match 2.0 api)
665  QList<QPair<int, bool> > attributesBySortRank;
666  QVector< QPair<int, QgsComposerTableColumn* > >::const_iterator sortedColumnIt = sortedColumns.constBegin();
667  for ( ; sortedColumnIt != sortedColumns.constEnd(); ++sortedColumnIt )
668  {
669 
670  attributesBySortRank.append( qMakePair(( *sortedColumnIt ).first,
671  ( *sortedColumnIt ).second->sortOrder() == Qt::AscendingOrder ) );
672  }
673  return attributesBySortRank;
674 }
675 
677 {
678  if ( wrapString == mWrapString )
679  {
680  return;
681  }
682 
683  mWrapString = wrapString;
685  emit changed();
686 }
687 
688 bool QgsComposerAttributeTableV2::writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames ) const
689 {
690  QDomElement composerTableElem = doc.createElement( "ComposerAttributeTableV2" );
691  composerTableElem.setAttribute( "source", QString::number( static_cast< int >( mSource ) ) );
692  composerTableElem.setAttribute( "relationId", mRelationId );
693  composerTableElem.setAttribute( "showUniqueRowsOnly", mShowUniqueRowsOnly );
694  composerTableElem.setAttribute( "showOnlyVisibleFeatures", mShowOnlyVisibleFeatures );
695  composerTableElem.setAttribute( "filterToAtlasIntersection", mFilterToAtlasIntersection );
696  composerTableElem.setAttribute( "maxFeatures", mMaximumNumberOfFeatures );
697  composerTableElem.setAttribute( "filterFeatures", mFilterFeatures ? "true" : "false" );
698  composerTableElem.setAttribute( "featureFilter", mFeatureFilter );
699  composerTableElem.setAttribute( "wrapString", mWrapString );
700 
701  if ( mComposerMap )
702  {
703  composerTableElem.setAttribute( "composerMap", mComposerMap->id() );
704  }
705  else
706  {
707  composerTableElem.setAttribute( "composerMap", -1 );
708  }
709  if ( mVectorLayer )
710  {
711  composerTableElem.setAttribute( "vectorLayer", mVectorLayer.layerId );
712  composerTableElem.setAttribute( "vectorLayerName", mVectorLayer.name );
713  composerTableElem.setAttribute( "vectorLayerSource", mVectorLayer.source );
714  composerTableElem.setAttribute( "vectorLayerProvider", mVectorLayer.provider );
715  }
716 
717  bool ok = QgsComposerTableV2::writeXML( composerTableElem, doc, ignoreFrames );
718 
719  elem.appendChild( composerTableElem );
720 
721  return ok;
722 }
723 
724 bool QgsComposerAttributeTableV2::readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames )
725 {
726  if ( itemElem.isNull() )
727  {
728  return false;
729  }
730 
731  //read general table properties
732  if ( !QgsComposerTableV2::readXML( itemElem, doc, ignoreFrames ) )
733  {
734  return false;
735  }
736 
737  QgsVectorLayer* prevLayer = sourceLayer();
738  if ( prevLayer )
739  {
740  //disconnect from previous layer
741  disconnect( prevLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
742  }
743 
744  mSource = QgsComposerAttributeTableV2::ContentSource( itemElem.attribute( "source", "0" ).toInt() );
745  mRelationId = itemElem.attribute( "relationId", "" );
746 
748  {
749  mCurrentAtlasLayer = mComposition->atlasComposition().coverageLayer();
750  }
751 
752  mShowUniqueRowsOnly = itemElem.attribute( "showUniqueRowsOnly", "0" ).toInt();
753  mShowOnlyVisibleFeatures = itemElem.attribute( "showOnlyVisibleFeatures", "1" ).toInt();
754  mFilterToAtlasIntersection = itemElem.attribute( "filterToAtlasIntersection", "0" ).toInt();
755  mFilterFeatures = itemElem.attribute( "filterFeatures", "false" ) == "true" ? true : false;
756  mFeatureFilter = itemElem.attribute( "featureFilter", "" );
757  mMaximumNumberOfFeatures = itemElem.attribute( "maxFeatures", "5" ).toInt();
758  mWrapString = itemElem.attribute( "wrapString" );
759 
760  //composer map
761  int composerMapId = itemElem.attribute( "composerMap", "-1" ).toInt();
762  if ( composerMapId == -1 )
763  {
764  mComposerMap = nullptr;
765  }
766 
767  if ( composition() )
768  {
769  mComposerMap = composition()->getComposerMapById( composerMapId );
770  }
771  else
772  {
773  mComposerMap = nullptr;
774  }
775 
776  if ( mComposerMap )
777  {
778  //if we have found a valid map item, listen out to extent changes on it and refresh the table
779  connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
780  }
781 
782  //vector layer
783  QString layerId = itemElem.attribute( "vectorLayer" );
784  QString layerName = itemElem.attribute( "vectorLayerName" );
785  QString layerSource = itemElem.attribute( "vectorLayerSource" );
786  QString layerProvider = itemElem.attribute( "vectorLayerProvider" );
787  mVectorLayer = QgsVectorLayerRef( layerId, layerName, layerSource, layerProvider );
788  mVectorLayer.resolveWeakly();
789 
790  //connect to new layer
791  connect( sourceLayer(), SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
792 
794 
795  emit changed();
796  return true;
797 }
798 
800 {
801  mFrameItems.push_back( frame );
802  connect( frame, SIGNAL( sizeChanged() ), this, SLOT( recalculateFrameSizes() ) );
803  if ( mComposition )
804  {
805  mComposition->addComposerTableFrame( this, frame );
806  }
807 
808  if ( recalcFrameSizes )
809  {
811  }
812 }
813 
815 {
816  if ( source == mSource )
817  {
818  return;
819  }
820 
821  QgsVectorLayer* prevLayer = sourceLayer();
822  mSource = source;
823  QgsVectorLayer* newLayer = sourceLayer();
824 
825  if ( newLayer != prevLayer )
826  {
827  //disconnect from previous layer
828  if ( prevLayer )
829  {
830  disconnect( prevLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
831  }
832 
833  //connect to new layer
834  connect( newLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
836  {
837  mCurrentAtlasLayer = newLayer;
838  }
839 
840  //layer has changed as a result of the source change, so reset column list
841  resetColumns();
842  }
843 
845  emit changed();
846 }
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
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.
QString name
Definition: qgsfield.h:52
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:412
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:252
QMap< QString, QgsMapLayer * > mapLayers() const
Returns a map of all registered layers by layer ID.
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:337
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
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:269
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
Definition: qgsfield.cpp:422
int size() const
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)
QString provider
Weak reference to layer provider.
bool contentsContainsRow(const QgsComposerTableContents &contents, const QgsComposerTableRow &row) const
Checks whether a table contents contains a given row.
QString layerId
Original layer ID.
QString id() const
Get this layer&#39;s unique ID, this ID is used to access this layer from map layer registry.
TYPE * resolveWeakly()
Resolves the map layer by attempting to find a matching layer in the map layer registry using a weak ...
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
bool isEmpty() const
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool isEmpty() const
QList< QgsComposerFrame * > mFrameItems
QString name
Weak reference to layer name.
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)
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:44
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.
void setLayer(TYPE *l)
Sets the reference to point to a specified layer.
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false) override
Reads multiframe state information from a DOM element.
QString source
Weak reference to layer public source.
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
int fieldNameIndex(const QString &fieldName) const
Look up field&#39;s index from name also looks up case-insensitive if there is no match otherwise...
Definition: qgsfield.cpp:571
bool contains(QChar ch, Qt::CaseSensitivity cs) const
Q_DECL_DEPRECATED 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 setDisplayedFields(const QStringList &fields, bool refresh=true)
Sets the attributes to display in the 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()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:382
void setUniqueRowsOnly(const bool uniqueOnly)
Sets attribute table to only show unique rows.
_LayerRef< QgsVectorLayer > QgsVectorLayerRef
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.
TYPE * get() const
Returns a pointer to the layer, or nullptr if the reference has not yet been matched to a layer...
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