QGIS API Documentation  2.18.3-Las Palmas (77b8c3d)
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  , mVectorLayer( nullptr )
53  , mCurrentAtlasLayer( nullptr )
54  , mComposerMap( nullptr )
55  , mMaximumNumberOfFeatures( 30 )
56  , mShowUniqueRowsOnly( false )
57  , mShowOnlyVisibleFeatures( false )
58  , mFilterToAtlasIntersection( false )
59  , mFilterFeatures( false )
60  , mFeatureFilter( "" )
61 {
62  //set first vector layer from layer registry as default one
65  for ( ; mapIt != layerMap.constEnd(); ++mapIt )
66  {
67  QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( mapIt.value() );
68  if ( vl )
69  {
70  mVectorLayer = vl;
71  break;
72  }
73  }
74  if ( mVectorLayer )
75  {
76  resetColumns();
77  //listen for modifications to layer and refresh table when they occur
78  connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
79  }
80  connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( removeLayer( const QString& ) ) );
81 
82  if ( mComposition )
83  {
84  //refresh table attributes when composition is refreshed
85  connect( mComposition, SIGNAL( refreshItemsTriggered() ), this, SLOT( refreshAttributes() ) );
86 
87  //connect to atlas feature changes to update table rows
88  connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshAttributes() ) );
89 
90  //atlas coverage layer change = regenerate columns
91  connect( &mComposition->atlasComposition(), SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( atlasLayerChanged( QgsVectorLayer* ) ) );
92  }
94 }
95 
97 {
98 }
99 
101 {
102  return tr( "<attribute table>" );
103 }
104 
106 {
107  if ( layer == mVectorLayer )
108  {
109  //no change
110  return;
111  }
112 
113  QgsVectorLayer* prevLayer = sourceLayer();
114  mVectorLayer = layer;
115 
116  if ( mSource == QgsComposerAttributeTableV2::LayerAttributes && layer != prevLayer )
117  {
118  if ( prevLayer )
119  {
120  //disconnect from previous layer
121  disconnect( prevLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
122  }
123 
124  //rebuild column list to match all columns from layer
125  resetColumns();
126 
127  //listen for modifications to layer and refresh table when they occur
128  connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
129  }
130 
132  emit changed();
133 }
134 
136 {
137  if ( relationId == mRelationId )
138  {
139  //no change
140  return;
141  }
142 
143  QgsVectorLayer* prevLayer = sourceLayer();
144  mRelationId = relationId;
145  QgsRelation relation = QgsProject::instance()->relationManager()->relation( mRelationId );
146  QgsVectorLayer* newLayer = relation.referencingLayer();
147 
148  if ( mSource == QgsComposerAttributeTableV2::RelationChildren && newLayer != prevLayer )
149  {
150  if ( prevLayer )
151  {
152  //disconnect from previous layer
153  disconnect( prevLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
154  }
155 
156  //rebuild column list to match all columns from layer
157  resetColumns();
158 
159  //listen for modifications to layer and refresh table when they occur
160  connect( newLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
161  }
162 
164  emit changed();
165 }
166 
167 void QgsComposerAttributeTableV2::atlasLayerChanged( QgsVectorLayer *layer )
168 {
169  if ( mSource != QgsComposerAttributeTableV2::AtlasFeature || layer == mCurrentAtlasLayer )
170  {
171  //nothing to do
172  return;
173  }
174 
175  //atlas feature mode, atlas layer changed, so we need to reset columns
176  if ( mCurrentAtlasLayer )
177  {
178  //disconnect from previous layer
179  disconnect( mCurrentAtlasLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
180  }
181 
182  mCurrentAtlasLayer = layer;
183 
184  //rebuild column list to match all columns from layer
185  resetColumns();
187 
188  //listen for modifications to layer and refresh table when they occur
189  connect( layer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
190 }
191 
193 {
195  if ( !source )
196  {
197  return;
198  }
199 
200  //remove existing columns
201  qDeleteAll( mColumns );
202  mColumns.clear();
203 
204  //rebuild columns list from vector layer fields
205  int idx = 0;
206  Q_FOREACH ( const QgsField& field, source->fields() )
207  {
208  QString currentAlias = source->attributeDisplayName( idx );
210  col->setAttribute( field.name() );
211  col->setHeading( currentAlias );
212  mColumns.append( col );
213  idx++;
214  }
215 }
216 
218 {
219  if ( map == mComposerMap )
220  {
221  //no change
222  return;
223  }
224 
225  if ( mComposerMap )
226  {
227  //disconnect from previous map
228  disconnect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
229  }
230  mComposerMap = map;
231  if ( mComposerMap )
232  {
233  //listen out for extent changes in linked map
234  connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
235  }
237  emit changed();
238 }
239 
241 {
242  if ( features == mMaximumNumberOfFeatures )
243  {
244  return;
245  }
246 
247  mMaximumNumberOfFeatures = features;
249  emit changed();
250 }
251 
253 {
254  if ( uniqueOnly == mShowUniqueRowsOnly )
255  {
256  return;
257  }
258 
259  mShowUniqueRowsOnly = uniqueOnly;
261  emit changed();
262 }
263 
265 {
266  if ( visibleOnly == mShowOnlyVisibleFeatures )
267  {
268  return;
269  }
270 
271  mShowOnlyVisibleFeatures = visibleOnly;
273  emit changed();
274 }
275 
277 {
278  if ( filterToAtlas == mFilterToAtlasIntersection )
279  {
280  return;
281  }
282 
283  mFilterToAtlasIntersection = filterToAtlas;
285  emit changed();
286 }
287 
289 {
290  if ( filter == mFilterFeatures )
291  {
292  return;
293  }
294 
295  mFilterFeatures = filter;
297  emit changed();
298 }
299 
301 {
302  if ( expression == mFeatureFilter )
303  {
304  return;
305  }
306 
307  mFeatureFilter = expression;
309  emit changed();
310 }
311 
313 {
315  if ( !source )
316  {
317  return;
318  }
319 
320  //rebuild columns list, taking only attributes with index in supplied QSet
321  qDeleteAll( mColumns );
322  mColumns.clear();
323 
324  const QgsFields& fields = source->fields();
325 
326  if ( !attr.empty() )
327  {
328  QSet<int>::const_iterator attIt = attr.constBegin();
329  for ( ; attIt != attr.constEnd(); ++attIt )
330  {
331  int attrIdx = ( *attIt );
332  if ( !fields.exists( attrIdx ) )
333  {
334  continue;
335  }
336  QString currentAlias = source->attributeDisplayName( attrIdx );
338  col->setAttribute( fields[attrIdx].name() );
339  col->setHeading( currentAlias );
340  mColumns.append( col );
341  }
342  }
343  else
344  {
345  //resetting, so add all attributes to columns
346  int idx = 0;
347  Q_FOREACH ( const QgsField& field, fields )
348  {
349  QString currentAlias = source->attributeDisplayName( idx );
351  col->setAttribute( field.name() );
352  col->setHeading( currentAlias );
353  mColumns.append( col );
354  idx++;
355  }
356  }
357 
358  if ( refresh )
359  {
361  }
362 }
363 
365 {
367  if ( !source )
368  {
369  return;
370  }
371 
372  //rebuild columns list, taking only fields contained in supplied list
373  qDeleteAll( mColumns );
374  mColumns.clear();
375 
376  QgsFields layerFields = source->fields();
377 
378  if ( !fields.isEmpty() )
379  {
380  Q_FOREACH ( const QString& field, fields )
381  {
382  int attrIdx = layerFields.fieldNameIndex( field );
383  if ( attrIdx < 0 )
384  continue;
385 
386  QString currentAlias = source->attributeDisplayName( attrIdx );
388  col->setAttribute( layerFields.at( attrIdx ).name() );
389  col->setHeading( currentAlias );
390  mColumns.append( col );
391  }
392  }
393  else
394  {
395  //resetting, so add all attributes to columns
396  int idx = 0;
397  Q_FOREACH ( const QgsField& field, layerFields )
398  {
399  QString currentAlias = source->attributeDisplayName( idx );
401  col->setAttribute( field.name() );
402  col->setHeading( currentAlias );
403  mColumns.append( col );
404  idx++;
405  }
406  }
407 
408  if ( refresh )
409  {
411  }
412 }
413 
414 void QgsComposerAttributeTableV2::restoreFieldAliasMap( const QMap<int, QString>& map )
415 {
417  if ( !source )
418  {
419  return;
420  }
421 
423  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
424  {
425  int attrIdx = source->fieldNameIndex(( *columnIt )->attribute() );
426  if ( map.contains( attrIdx ) )
427  {
428  ( *columnIt )->setHeading( map.value( attrIdx ) );
429  }
430  else
431  {
432  ( *columnIt )->setHeading( source->attributeDisplayName( attrIdx ) );
433  }
434  }
435 }
436 
438 {
439  contents.clear();
440 
443  {
444  //source mode requires atlas, but atlas disabled
445  return false;
446  }
447 
448  QgsVectorLayer* layer = sourceLayer();
449 
450  if ( !layer )
451  {
452  //no source layer
453  return false;
454  }
455 
457  context->setFields( layer->fields() );
458 
459  //prepare filter expression
460  QScopedPointer<QgsExpression> filterExpression;
461  bool activeFilter = false;
462  if ( mFilterFeatures && !mFeatureFilter.isEmpty() )
463  {
464  filterExpression.reset( new QgsExpression( mFeatureFilter ) );
465  if ( !filterExpression->hasParserError() )
466  {
467  activeFilter = true;
468  }
469  }
470 
471  QgsRectangle selectionRect;
472  if ( mComposerMap && mShowOnlyVisibleFeatures )
473  {
474  selectionRect = *mComposerMap->currentMapExtent();
475  if ( layer && mComposition->mapSettings().hasCrsTransformEnabled() )
476  {
477  //transform back to layer CRS
478  QgsCoordinateTransform coordTransform( layer->crs(), mComposition->mapSettings().destinationCrs() );
479  try
480  {
481  selectionRect = coordTransform.transformBoundingBox( selectionRect, QgsCoordinateTransform::ReverseTransform );
482  }
483  catch ( QgsCsException &cse )
484  {
485  Q_UNUSED( cse );
486  return false;
487  }
488  }
489  }
490 
491  QgsFeatureRequest req;
492 
494  {
495  QgsRelation relation = QgsProject::instance()->relationManager()->relation( mRelationId );
496  QgsFeature atlasFeature = mComposition->atlasComposition().feature();
497  req = relation.getRelatedFeaturesRequest( atlasFeature );
498  }
499 
500  if ( !selectionRect.isEmpty() )
501  req.setFilterRect( selectionRect );
502 
503  req.setFlags( mShowOnlyVisibleFeatures ? QgsFeatureRequest::ExactIntersect : QgsFeatureRequest::NoFlags );
504 
507  {
508  //source mode is current atlas feature
509  QgsFeature atlasFeature = mComposition->atlasComposition().feature();
510  req.setFilterFid( atlasFeature.id() );
511  }
512 
513  QgsFeature f;
514  int counter = 0;
515  QgsFeatureIterator fit = layer->getFeatures( req );
516 
517  while ( fit.nextFeature( f ) && counter < mMaximumNumberOfFeatures )
518  {
519  context->setFeature( f );
520  //check feature against filter
521  if ( activeFilter && !filterExpression.isNull() )
522  {
523  QVariant result = filterExpression->evaluate( context.data() );
524  // skip this feature if the filter evaluation is false
525  if ( !result.toBool() )
526  {
527  continue;
528  }
529  }
530  //check against atlas feature intersection
531  if ( mFilterToAtlasIntersection )
532  {
533  if ( !f.constGeometry() || ! mComposition->atlasComposition().enabled() )
534  {
535  continue;
536  }
537  QgsFeature atlasFeature = mComposition->atlasComposition().feature();
538  if ( !atlasFeature.constGeometry() ||
539  !f.constGeometry()->intersects( atlasFeature.constGeometry() ) )
540  {
541  //feature falls outside current atlas feature
542  continue;
543  }
544  }
545 
546  QgsComposerTableRow currentRow;
547 
549  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
550  {
551  int idx = layer->fieldNameIndex(( *columnIt )->attribute() );
552  if ( idx != -1 )
553  {
554  currentRow << replaceWrapChar( f.attributes().at( idx ) );
555  }
556  else
557  {
558  // Lets assume it's an expression
559  QgsExpression* expression = new QgsExpression(( *columnIt )->attribute() );
560  context->lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QString( "row_number" ), counter + 1, true ) );
561  expression->prepare( context.data() );
562  QVariant value = expression->evaluate( context.data() );
563  currentRow << value;
564  }
565  }
566 
567  if ( !mShowUniqueRowsOnly || !contentsContainsRow( contents, currentRow ) )
568  {
569  contents << currentRow;
570  ++counter;
571  }
572  }
573 
574  //sort the list, starting with the last attribute
576  QList< QPair<int, bool> > sortColumns = sortAttributes();
577  for ( int i = sortColumns.size() - 1; i >= 0; --i )
578  {
579  c.setSortColumn( sortColumns.at( i ).first );
580  c.setAscending( sortColumns.at( i ).second );
581  qStableSort( contents.begin(), contents.end(), c );
582  }
583 
585  return true;
586 }
587 
589 {
591 
592  if ( mSource == LayerAttributes )
593  {
594  context->appendScope( QgsExpressionContextUtils::layerScope( mVectorLayer ) );
595  }
596 
597  return context;
598 }
599 
600 QVariant QgsComposerAttributeTableV2::replaceWrapChar( const QVariant &variant ) const
601 {
602  //avoid converting variants to string if not required (try to maintain original type for sorting)
603  if ( mWrapString.isEmpty() || !variant.toString().contains( mWrapString ) )
604  return variant;
605 
606  QString replaced = variant.toString();
607  replaced.replace( mWrapString, "\n" );
608  return replaced;
609 }
610 
612 {
613  switch ( mSource )
614  {
618  return mVectorLayer;
620  {
621  QgsRelation relation = QgsProject::instance()->relationManager()->relation( mRelationId );
622  return relation.referencingLayer();
623  }
624  }
625  return nullptr;
626 }
627 
628 void QgsComposerAttributeTableV2::removeLayer( const QString& layerId )
629 {
630  if ( mVectorLayer && mSource == QgsComposerAttributeTableV2::LayerAttributes )
631  {
632  if ( layerId == mVectorLayer->id() )
633  {
634  mVectorLayer = nullptr;
635  //remove existing columns
636  qDeleteAll( mColumns );
637  mColumns.clear();
638  }
639  }
640 }
641 
643 {
644  return a.second->sortByRank() < b.second->sortByRank();
645 }
646 
648 {
649  //generate list of all sorted columns
652  int idx = 0;
653  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
654  {
655  if (( *columnIt )->sortByRank() > 0 )
656  {
657  sortedColumns.append( qMakePair( idx, *columnIt ) );
658  }
659  idx++;
660  }
661 
662  //sort columns by rank
663  qSort( sortedColumns.begin(), sortedColumns.end(), columnsBySortRank );
664 
665  //generate list of column index, bool for sort direction (to match 2.0 api)
666  QList<QPair<int, bool> > attributesBySortRank;
667  QVector< QPair<int, QgsComposerTableColumn* > >::const_iterator sortedColumnIt = sortedColumns.constBegin();
668  for ( ; sortedColumnIt != sortedColumns.constEnd(); ++sortedColumnIt )
669  {
670 
671  attributesBySortRank.append( qMakePair(( *sortedColumnIt ).first,
672  ( *sortedColumnIt ).second->sortOrder() == Qt::AscendingOrder ) );
673  }
674  return attributesBySortRank;
675 }
676 
678 {
679  if ( wrapString == mWrapString )
680  {
681  return;
682  }
683 
684  mWrapString = wrapString;
686  emit changed();
687 }
688 
689 bool QgsComposerAttributeTableV2::writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames ) const
690 {
691  QDomElement composerTableElem = doc.createElement( "ComposerAttributeTableV2" );
692  composerTableElem.setAttribute( "source", QString::number( static_cast< int >( mSource ) ) );
693  composerTableElem.setAttribute( "relationId", mRelationId );
694  composerTableElem.setAttribute( "showUniqueRowsOnly", mShowUniqueRowsOnly );
695  composerTableElem.setAttribute( "showOnlyVisibleFeatures", mShowOnlyVisibleFeatures );
696  composerTableElem.setAttribute( "filterToAtlasIntersection", mFilterToAtlasIntersection );
697  composerTableElem.setAttribute( "maxFeatures", mMaximumNumberOfFeatures );
698  composerTableElem.setAttribute( "filterFeatures", mFilterFeatures ? "true" : "false" );
699  composerTableElem.setAttribute( "featureFilter", mFeatureFilter );
700  composerTableElem.setAttribute( "wrapString", mWrapString );
701 
702  if ( mComposerMap )
703  {
704  composerTableElem.setAttribute( "composerMap", mComposerMap->id() );
705  }
706  else
707  {
708  composerTableElem.setAttribute( "composerMap", -1 );
709  }
710  if ( mVectorLayer )
711  {
712  composerTableElem.setAttribute( "vectorLayer", mVectorLayer->id() );
713  }
714 
715  bool ok = QgsComposerTableV2::writeXML( composerTableElem, doc, ignoreFrames );
716 
717  elem.appendChild( composerTableElem );
718 
719  return ok;
720 }
721 
722 bool QgsComposerAttributeTableV2::readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames )
723 {
724  if ( itemElem.isNull() )
725  {
726  return false;
727  }
728 
729  //read general table properties
730  if ( !QgsComposerTableV2::readXML( itemElem, doc, ignoreFrames ) )
731  {
732  return false;
733  }
734 
735  QgsVectorLayer* prevLayer = sourceLayer();
736  if ( prevLayer )
737  {
738  //disconnect from previous layer
739  disconnect( prevLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
740  }
741 
742  mSource = QgsComposerAttributeTableV2::ContentSource( itemElem.attribute( "source", "0" ).toInt() );
743  mRelationId = itemElem.attribute( "relationId", "" );
744 
746  {
747  mCurrentAtlasLayer = mComposition->atlasComposition().coverageLayer();
748  }
749 
750  mShowUniqueRowsOnly = itemElem.attribute( "showUniqueRowsOnly", "0" ).toInt();
751  mShowOnlyVisibleFeatures = itemElem.attribute( "showOnlyVisibleFeatures", "1" ).toInt();
752  mFilterToAtlasIntersection = itemElem.attribute( "filterToAtlasIntersection", "0" ).toInt();
753  mFilterFeatures = itemElem.attribute( "filterFeatures", "false" ) == "true" ? true : false;
754  mFeatureFilter = itemElem.attribute( "featureFilter", "" );
755  mMaximumNumberOfFeatures = itemElem.attribute( "maxFeatures", "5" ).toInt();
756  mWrapString = itemElem.attribute( "wrapString" );
757 
758  //composer map
759  int composerMapId = itemElem.attribute( "composerMap", "-1" ).toInt();
760  if ( composerMapId == -1 )
761  {
762  mComposerMap = nullptr;
763  }
764 
765  if ( composition() )
766  {
767  mComposerMap = composition()->getComposerMapById( composerMapId );
768  }
769  else
770  {
771  mComposerMap = nullptr;
772  }
773 
774  if ( mComposerMap )
775  {
776  //if we have found a valid map item, listen out to extent changes on it and refresh the table
777  connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
778  }
779 
780  //vector layer
781  QString layerId = itemElem.attribute( "vectorLayer", "not_existing" );
782  if ( layerId == "not_existing" )
783  {
784  mVectorLayer = nullptr;
785  }
786  else
787  {
789  if ( ml )
790  {
791  mVectorLayer = dynamic_cast<QgsVectorLayer*>( ml );
792  }
793  }
794 
795  //connect to new layer
796  connect( sourceLayer(), SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
797 
799 
800  emit changed();
801  return true;
802 }
803 
805 {
806  mFrameItems.push_back( frame );
807  connect( frame, SIGNAL( sizeChanged() ), this, SLOT( recalculateFrameSizes() ) );
808  if ( mComposition )
809  {
810  mComposition->addComposerTableFrame( this, frame );
811  }
812 
813  if ( recalcFrameSizes )
814  {
816  }
817 }
818 
820 {
821  if ( source == mSource )
822  {
823  return;
824  }
825 
826  QgsVectorLayer* prevLayer = sourceLayer();
827  mSource = source;
828  QgsVectorLayer* newLayer = sourceLayer();
829 
830  if ( newLayer != prevLayer )
831  {
832  //disconnect from previous layer
833  if ( prevLayer )
834  {
835  disconnect( prevLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
836  }
837 
838  //connect to new layer
839  connect( newLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
841  {
842  mCurrentAtlasLayer = newLayer;
843  }
844 
845  //layer has changed as a result of the source change, so reset column list
846  resetColumns();
847  }
848 
850  emit changed();
851 }
QgsFeatureId id() const
Get the feature ID for this feature.
Definition: qgsfeature.cpp:65
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
bool isEmpty() const
test if rectangle is empty.
QgsMapLayer * mapLayer(const QString &theLayerId) const
Retrieve a pointer to a registered layer by layer ID.
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.
QgsFields fields() const
Returns the list of fields of this layer.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
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
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
virtual bool writeXML(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const override
Stores state information about multiframe in DOM element.
bool enabled() const
Returns whether the atlas generation is enabled.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
Container of fields for a vector layer.
Definition: qgsfield.h:252
virtual bool writeXML(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const override
Writes properties specific to attribute tables.
QgsFeature feature() const
Returns the current atlas feature.
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
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
int size() const
void reset(T *other)
const char * name() const
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Set feature ID that should be fetched.
virtual QgsExpressionContext * createExpressionContext() const
Creates an expression context relating to the objects&#39; current state.
bool exists(int i) const
Return if a field index is valid.
Definition: qgsfield.cpp:412
QString number(int n, int base)
QList< QPair< int, bool > > sortAttributes() const
Returns the attributes used to sort the table&#39;s features.
void append(const T &value)
bool contentsContainsRow(const QgsComposerTableContents &contents, const QgsComposerTableRow &row) const
Checks whether a table contents contains a given row.
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.
QString attributeDisplayName(int attributeIndex) const
Convenience function that returns the attribute alias if defined or the field name else...
QgsRelation relation(const QString &id) const
Get access to a relation by its id.
QgsAttributes attributes() const
Returns the feature&#39;s attributes.
Definition: qgsfeature.cpp:110
void setAttribute(const QString &name, const QString &value)
void setSortColumn(int col)
Sets column number to sort by.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
int toInt(bool *ok, int base) const
bool isEmpty() const
QgsVectorLayer * referencingLayer() const
Access the referencing (child) layer This is the layer which has the field(s) which point to another ...
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...
QString id() const
Get this layer&#39;s unique ID, this ID is used to access this layer from map layer registry.
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.
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.
QgsFeatureRequest getRelatedFeaturesRequest(const QgsFeature &feature) const
Creates a request to return all the features on the referencing (child) layer which have a foreign ke...
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
Definition: qgsfield.cpp:422
QMap< QString, QgsMapLayer * > mapLayers() const
Returns a map of all registered layers by layer ID.
Graphics scene for map printing.
Object representing map window.
Frame item for a composer multiframe item.
T * data() const
iterator end()
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
int id() const
Get identification number.
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
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.
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
Definition: qgsfeature.cpp:82
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
const QgsCoordinateReferenceSystem & crs() const
Returns layer&#39;s spatial reference system.
QgsAtlasComposition & atlasComposition()
QgsComposerFrame * frame(int i) const
Returns a child frame from the multiframe.
Custom exception class for Coordinate Reference System related exceptions.
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
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
const QgsComposerMap * getComposerMapById(const int id) const
Returns the composer map with specified id.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
bool intersects(const QgsRectangle &r) const
Test for intersection with a rectangle (uses GEOS)
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.
QgsComposerTableContents * contents()
Returns the current contents of the table.
QgsRelationManager * relationManager() const
QString toString() const
QString wrapString() const
Returns the string used to wrap the contents of the table cells by.
iterator end()
ContentSource source() const
Returns the source for attributes shown in the table body.
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.
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.
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