QGIS API Documentation  2.14.0-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  QVariant v1 = m1[mCurrentSortColumn];
41  QVariant v2 = m2[mCurrentSortColumn];
42 
43  bool less = false;
44 
45  //sort null values first
46  if ( v1.isNull() && v2.isNull() )
47  {
48  less = false;
49  }
50  else if ( v1.isNull() )
51  {
52  less = true;
53  }
54  else if ( v2.isNull() )
55  {
56  less = false;
57  }
58  else
59  {
60  //otherwise sort by converting to corresponding type and comparing
61  switch ( v1.type() )
62  {
63  case QVariant::Int:
64  case QVariant::UInt:
65  case QVariant::LongLong:
66  case QVariant::ULongLong:
67  less = v1.toLongLong() < v2.toLongLong();
68  break;
69 
70  case QVariant::Double:
71  less = v1.toDouble() < v2.toDouble();
72  break;
73 
74  case QVariant::Date:
75  less = v1.toDate() < v2.toDate();
76  break;
77 
78  case QVariant::DateTime:
79  less = v1.toDateTime() < v2.toDateTime();
80  break;
81 
82  case QVariant::Time:
83  less = v1.toTime() < v2.toTime();
84  break;
85 
86  default:
87  //use locale aware compare for strings
88  less = v1.toString().localeAwareCompare( v2.toString() ) < 0;
89  break;
90  }
91  }
92 
93  return ( mAscending ? less : !less );
94 }
95 
96 //
97 // QgsComposerAttributeTableV2
98 //
99 
101  : QgsComposerTableV2( composition, createUndoCommands )
102  , mSource( LayerAttributes )
103  , mVectorLayer( nullptr )
104  , mCurrentAtlasLayer( nullptr )
105  , mComposerMap( nullptr )
106  , mMaximumNumberOfFeatures( 30 )
107  , mShowUniqueRowsOnly( false )
108  , mShowOnlyVisibleFeatures( false )
109  , mFilterToAtlasIntersection( false )
110  , mFilterFeatures( false )
111  , mFeatureFilter( "" )
112 {
113  //set first vector layer from layer registry as default one
116  for ( ; mapIt != layerMap.constEnd(); ++mapIt )
117  {
118  QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( mapIt.value() );
119  if ( vl )
120  {
121  mVectorLayer = vl;
122  break;
123  }
124  }
125  if ( mVectorLayer )
126  {
127  resetColumns();
128  //listen for modifications to layer and refresh table when they occur
129  connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
130  }
131  connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( removeLayer( const QString& ) ) );
132 
133  if ( mComposition )
134  {
135  //refresh table attributes when composition is refreshed
136  connect( mComposition, SIGNAL( refreshItemsTriggered() ), this, SLOT( refreshAttributes() ) );
137 
138  //connect to atlas feature changes to update table rows
139  connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshAttributes() ) );
140 
141  //atlas coverage layer change = regenerate columns
142  connect( &mComposition->atlasComposition(), SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( atlasLayerChanged( QgsVectorLayer* ) ) );
143  }
145 }
146 
148 {
149 }
150 
152 {
153  return tr( "<attribute table>" );
154 }
155 
157 {
158  if ( layer == mVectorLayer )
159  {
160  //no change
161  return;
162  }
163 
164  QgsVectorLayer* prevLayer = sourceLayer();
165  mVectorLayer = layer;
166 
167  if ( mSource == QgsComposerAttributeTableV2::LayerAttributes && layer != prevLayer )
168  {
169  if ( prevLayer )
170  {
171  //disconnect from previous layer
172  disconnect( prevLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
173  }
174 
175  //rebuild column list to match all columns from layer
176  resetColumns();
177 
178  //listen for modifications to layer and refresh table when they occur
179  connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
180  }
181 
183  emit changed();
184 }
185 
187 {
188  if ( relationId == mRelationId )
189  {
190  //no change
191  return;
192  }
193 
194  QgsVectorLayer* prevLayer = sourceLayer();
195  mRelationId = relationId;
196  QgsRelation relation = QgsProject::instance()->relationManager()->relation( mRelationId );
197  QgsVectorLayer* newLayer = relation.referencingLayer();
198 
199  if ( mSource == QgsComposerAttributeTableV2::RelationChildren && newLayer != prevLayer )
200  {
201  if ( prevLayer )
202  {
203  //disconnect from previous layer
204  disconnect( prevLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
205  }
206 
207  //rebuild column list to match all columns from layer
208  resetColumns();
209 
210  //listen for modifications to layer and refresh table when they occur
211  connect( newLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
212  }
213 
215  emit changed();
216 }
217 
218 void QgsComposerAttributeTableV2::atlasLayerChanged( QgsVectorLayer *layer )
219 {
220  if ( mSource != QgsComposerAttributeTableV2::AtlasFeature || layer == mCurrentAtlasLayer )
221  {
222  //nothing to do
223  return;
224  }
225 
226  //atlas feature mode, atlas layer changed, so we need to reset columns
227  if ( mCurrentAtlasLayer )
228  {
229  //disconnect from previous layer
230  disconnect( mCurrentAtlasLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
231  }
232 
233  mCurrentAtlasLayer = layer;
234 
235  //rebuild column list to match all columns from layer
236  resetColumns();
238 
239  //listen for modifications to layer and refresh table when they occur
240  connect( layer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
241 }
242 
244 {
246  if ( !source )
247  {
248  return;
249  }
250 
251  //remove existing columns
252  qDeleteAll( mColumns );
253  mColumns.clear();
254 
255  //rebuild columns list from vector layer fields
256  const QgsFields& fields = source->fields();
257  for ( int idx = 0; idx < fields.count(); ++idx )
258  {
259  QString currentAlias = source->attributeDisplayName( idx );
261  col->setAttribute( fields[idx].name() );
262  col->setHeading( currentAlias );
263  mColumns.append( col );
264  }
265 }
266 
268 {
269  if ( map == mComposerMap )
270  {
271  //no change
272  return;
273  }
274 
275  if ( mComposerMap )
276  {
277  //disconnect from previous map
278  disconnect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
279  }
280  mComposerMap = map;
281  if ( mComposerMap )
282  {
283  //listen out for extent changes in linked map
284  connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
285  }
287  emit changed();
288 }
289 
291 {
292  if ( features == mMaximumNumberOfFeatures )
293  {
294  return;
295  }
296 
297  mMaximumNumberOfFeatures = features;
299  emit changed();
300 }
301 
303 {
304  if ( uniqueOnly == mShowUniqueRowsOnly )
305  {
306  return;
307  }
308 
309  mShowUniqueRowsOnly = uniqueOnly;
311  emit changed();
312 }
313 
315 {
316  if ( visibleOnly == mShowOnlyVisibleFeatures )
317  {
318  return;
319  }
320 
321  mShowOnlyVisibleFeatures = visibleOnly;
323  emit changed();
324 }
325 
327 {
328  if ( filterToAtlas == mFilterToAtlasIntersection )
329  {
330  return;
331  }
332 
333  mFilterToAtlasIntersection = filterToAtlas;
335  emit changed();
336 }
337 
339 {
340  if ( filter == mFilterFeatures )
341  {
342  return;
343  }
344 
345  mFilterFeatures = filter;
347  emit changed();
348 }
349 
351 {
352  if ( expression == mFeatureFilter )
353  {
354  return;
355  }
356 
357  mFeatureFilter = expression;
359  emit changed();
360 }
361 
363 {
365  if ( !source )
366  {
367  return;
368  }
369 
370  //rebuild columns list, taking only attributes with index in supplied QSet
371  qDeleteAll( mColumns );
372  mColumns.clear();
373 
374  const QgsFields& fields = source->fields();
375 
376  if ( !attr.empty() )
377  {
378  QSet<int>::const_iterator attIt = attr.constBegin();
379  for ( ; attIt != attr.constEnd(); ++attIt )
380  {
381  int attrIdx = ( *attIt );
382  if ( !fields.exists( attrIdx ) )
383  {
384  continue;
385  }
386  QString currentAlias = source->attributeDisplayName( attrIdx );
388  col->setAttribute( fields[attrIdx].name() );
389  col->setHeading( currentAlias );
390  mColumns.append( col );
391  }
392  }
393  else
394  {
395  //resetting, so add all attributes to columns
396  for ( int idx = 0; idx < fields.count(); ++idx )
397  {
398  QString currentAlias = source->attributeDisplayName( idx );
400  col->setAttribute( fields[idx].name() );
401  col->setHeading( currentAlias );
402  mColumns.append( col );
403  }
404  }
405 
406  if ( refresh )
407  {
409  }
410 }
411 
412 void QgsComposerAttributeTableV2::restoreFieldAliasMap( const QMap<int, QString>& map )
413 {
415  if ( !source )
416  {
417  return;
418  }
419 
421  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
422  {
423  int attrIdx = source->fieldNameIndex(( *columnIt )->attribute() );
424  if ( map.contains( attrIdx ) )
425  {
426  ( *columnIt )->setHeading( map.value( attrIdx ) );
427  }
428  else
429  {
430  ( *columnIt )->setHeading( source->attributeDisplayName( attrIdx ) );
431  }
432  }
433 }
434 
436 {
437  contents.clear();
438 
441  {
442  //source mode requires atlas, but atlas disabled
443  return false;
444  }
445 
446  QgsVectorLayer* layer = sourceLayer();
447 
448  if ( !layer )
449  {
450  //no source layer
451  return false;
452  }
453 
455  context->setFields( layer->fields() );
456 
457  //prepare filter expression
458  QScopedPointer<QgsExpression> filterExpression;
459  bool activeFilter = false;
460  if ( mFilterFeatures && !mFeatureFilter.isEmpty() )
461  {
462  filterExpression.reset( new QgsExpression( mFeatureFilter ) );
463  if ( !filterExpression->hasParserError() )
464  {
465  activeFilter = true;
466  }
467  }
468 
469  QgsRectangle selectionRect;
470  if ( mComposerMap && mShowOnlyVisibleFeatures )
471  {
472  selectionRect = *mComposerMap->currentMapExtent();
473  if ( layer && mComposition->mapSettings().hasCrsTransformEnabled() )
474  {
475  //transform back to layer CRS
476  QgsCoordinateTransform coordTransform( layer->crs(), mComposition->mapSettings().destinationCrs() );
477  try
478  {
479  selectionRect = coordTransform.transformBoundingBox( selectionRect, QgsCoordinateTransform::ReverseTransform );
480  }
481  catch ( QgsCsException &cse )
482  {
483  Q_UNUSED( cse );
484  return false;
485  }
486  }
487  }
488 
489  QgsFeatureRequest req;
490 
492  {
493  QgsRelation relation = QgsProject::instance()->relationManager()->relation( mRelationId );
494  QgsFeature atlasFeature = mComposition->atlasComposition().feature();
495  req = relation.getRelatedFeaturesRequest( atlasFeature );
496  }
497 
498  if ( !selectionRect.isEmpty() )
499  req.setFilterRect( selectionRect );
500 
501  req.setFlags( mShowOnlyVisibleFeatures ? QgsFeatureRequest::ExactIntersect : QgsFeatureRequest::NoFlags );
502 
505  {
506  //source mode is current atlas feature
507  QgsFeature atlasFeature = mComposition->atlasComposition().feature();
508  req.setFilterFid( atlasFeature.id() );
509  }
510 
511  QgsFeature f;
512  int counter = 0;
513  QgsFeatureIterator fit = layer->getFeatures( req );
514 
515  while ( fit.nextFeature( f ) && counter < mMaximumNumberOfFeatures )
516  {
517  context->setFeature( f );
518  //check feature against filter
519  if ( activeFilter && !filterExpression.isNull() )
520  {
521  QVariant result = filterExpression->evaluate( context.data() );
522  // skip this feature if the filter evaluation is false
523  if ( !result.toBool() )
524  {
525  continue;
526  }
527  }
528  //check against atlas feature intersection
529  if ( mFilterToAtlasIntersection )
530  {
531  if ( !f.constGeometry() || ! mComposition->atlasComposition().enabled() )
532  {
533  continue;
534  }
535  QgsFeature atlasFeature = mComposition->atlasComposition().feature();
536  if ( !atlasFeature.constGeometry() ||
537  !f.constGeometry()->intersects( atlasFeature.constGeometry() ) )
538  {
539  //feature falls outside current atlas feature
540  continue;
541  }
542  }
543 
544  QgsComposerTableRow currentRow;
545 
547  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
548  {
549  int idx = layer->fieldNameIndex(( *columnIt )->attribute() );
550  if ( idx != -1 )
551  {
552  currentRow << replaceWrapChar( f.attributes().at( idx ) );
553  }
554  else
555  {
556  // Lets assume it's an expression
557  QgsExpression* expression = new QgsExpression(( *columnIt )->attribute() );
558  context->lastScope()->setVariable( QString( "row_number" ), counter + 1 );
559  expression->prepare( context.data() );
560  QVariant value = expression->evaluate( context.data() );
561  currentRow << value;
562  }
563  }
564 
565  if ( !mShowUniqueRowsOnly || !contentsContainsRow( contents, currentRow ) )
566  {
567  contents << currentRow;
568  ++counter;
569  }
570  }
571 
572  //sort the list, starting with the last attribute
574  QList< QPair<int, bool> > sortColumns = sortAttributes();
575  for ( int i = sortColumns.size() - 1; i >= 0; --i )
576  {
577  c.setSortColumn( sortColumns.at( i ).first );
578  c.setAscending( sortColumns.at( i ).second );
579  qStableSort( contents.begin(), contents.end(), c );
580  }
581 
583  return true;
584 }
585 
587 {
589 
590  if ( mSource == LayerAttributes )
591  {
592  context->appendScope( QgsExpressionContextUtils::layerScope( mVectorLayer ) );
593  }
594 
595  return context;
596 }
597 
598 QVariant QgsComposerAttributeTableV2::replaceWrapChar( const QVariant &variant ) const
599 {
600  //avoid converting variants to string if not required (try to maintain original type for sorting)
601  if ( mWrapString.isEmpty() || !variant.toString().contains( mWrapString ) )
602  return variant;
603 
604  QString replaced = variant.toString();
605  replaced.replace( mWrapString, "\n" );
606  return replaced;
607 }
608 
610 {
611  switch ( mSource )
612  {
616  return mVectorLayer;
618  {
619  QgsRelation relation = QgsProject::instance()->relationManager()->relation( mRelationId );
620  return relation.referencingLayer();
621  }
622  }
623  return nullptr;
624 }
625 
626 void QgsComposerAttributeTableV2::removeLayer( const QString& layerId )
627 {
628  if ( mVectorLayer && mSource == QgsComposerAttributeTableV2::LayerAttributes )
629  {
630  if ( layerId == mVectorLayer->id() )
631  {
632  mVectorLayer = nullptr;
633  //remove existing columns
634  qDeleteAll( mColumns );
635  mColumns.clear();
636  }
637  }
638 }
639 
641 {
642  return a.second->sortByRank() < b.second->sortByRank();
643 }
644 
646 {
647  //generate list of all sorted columns
650  int idx = 0;
651  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
652  {
653  if (( *columnIt )->sortByRank() > 0 )
654  {
655  sortedColumns.append( qMakePair( idx, *columnIt ) );
656  }
657  idx++;
658  }
659 
660  //sort columns by rank
661  qSort( sortedColumns.begin(), sortedColumns.end(), columnsBySortRank );
662 
663  //generate list of column index, bool for sort direction (to match 2.0 api)
664  QList<QPair<int, bool> > attributesBySortRank;
665  QVector< QPair<int, QgsComposerTableColumn* > >::const_iterator sortedColumnIt = sortedColumns.constBegin();
666  for ( ; sortedColumnIt != sortedColumns.constEnd(); ++sortedColumnIt )
667  {
668 
669  attributesBySortRank.append( qMakePair(( *sortedColumnIt ).first,
670  ( *sortedColumnIt ).second->sortOrder() == Qt::AscendingOrder ) );
671  }
672  return attributesBySortRank;
673 }
674 
676 {
677  if ( wrapString == mWrapString )
678  {
679  return;
680  }
681 
682  mWrapString = wrapString;
684  emit changed();
685 }
686 
687 bool QgsComposerAttributeTableV2::writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames ) const
688 {
689  QDomElement composerTableElem = doc.createElement( "ComposerAttributeTableV2" );
690  composerTableElem.setAttribute( "source", QString::number( static_cast< int >( mSource ) ) );
691  composerTableElem.setAttribute( "relationId", mRelationId );
692  composerTableElem.setAttribute( "showUniqueRowsOnly", mShowUniqueRowsOnly );
693  composerTableElem.setAttribute( "showOnlyVisibleFeatures", mShowOnlyVisibleFeatures );
694  composerTableElem.setAttribute( "filterToAtlasIntersection", mFilterToAtlasIntersection );
695  composerTableElem.setAttribute( "maxFeatures", mMaximumNumberOfFeatures );
696  composerTableElem.setAttribute( "filterFeatures", mFilterFeatures ? "true" : "false" );
697  composerTableElem.setAttribute( "featureFilter", mFeatureFilter );
698  composerTableElem.setAttribute( "wrapString", mWrapString );
699 
700  if ( mComposerMap )
701  {
702  composerTableElem.setAttribute( "composerMap", mComposerMap->id() );
703  }
704  else
705  {
706  composerTableElem.setAttribute( "composerMap", -1 );
707  }
708  if ( mVectorLayer )
709  {
710  composerTableElem.setAttribute( "vectorLayer", mVectorLayer->id() );
711  }
712 
713  bool ok = QgsComposerTableV2::writeXML( composerTableElem, doc, ignoreFrames );
714 
715  elem.appendChild( composerTableElem );
716 
717  return ok;
718 }
719 
720 bool QgsComposerAttributeTableV2::readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames )
721 {
722  if ( itemElem.isNull() )
723  {
724  return false;
725  }
726 
727  //read general table properties
728  if ( !QgsComposerTableV2::readXML( itemElem, doc, ignoreFrames ) )
729  {
730  return false;
731  }
732 
733  QgsVectorLayer* prevLayer = sourceLayer();
734  if ( prevLayer )
735  {
736  //disconnect from previous layer
737  disconnect( prevLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
738  }
739 
740  mSource = QgsComposerAttributeTableV2::ContentSource( itemElem.attribute( "source", "0" ).toInt() );
741  mRelationId = itemElem.attribute( "relationId", "" );
742 
744  {
745  mCurrentAtlasLayer = mComposition->atlasComposition().coverageLayer();
746  }
747 
748  mShowUniqueRowsOnly = itemElem.attribute( "showUniqueRowsOnly", "0" ).toInt();
749  mShowOnlyVisibleFeatures = itemElem.attribute( "showOnlyVisibleFeatures", "1" ).toInt();
750  mFilterToAtlasIntersection = itemElem.attribute( "filterToAtlasIntersection", "0" ).toInt();
751  mFilterFeatures = itemElem.attribute( "filterFeatures", "false" ) == "true" ? true : false;
752  mFeatureFilter = itemElem.attribute( "featureFilter", "" );
753  mMaximumNumberOfFeatures = itemElem.attribute( "maxFeatures", "5" ).toInt();
754  mWrapString = itemElem.attribute( "wrapString" );
755 
756  //composer map
757  int composerMapId = itemElem.attribute( "composerMap", "-1" ).toInt();
758  if ( composerMapId == -1 )
759  {
760  mComposerMap = nullptr;
761  }
762 
763  if ( composition() )
764  {
765  mComposerMap = composition()->getComposerMapById( composerMapId );
766  }
767  else
768  {
769  mComposerMap = nullptr;
770  }
771 
772  if ( mComposerMap )
773  {
774  //if we have found a valid map item, listen out to extent changes on it and refresh the table
775  connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
776  }
777 
778  //vector layer
779  QString layerId = itemElem.attribute( "vectorLayer", "not_existing" );
780  if ( layerId == "not_existing" )
781  {
782  mVectorLayer = nullptr;
783  }
784  else
785  {
787  if ( ml )
788  {
789  mVectorLayer = dynamic_cast<QgsVectorLayer*>( ml );
790  }
791  }
792 
793  //connect to new layer
794  connect( sourceLayer(), SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
795 
797 
798  emit changed();
799  return true;
800 }
801 
803 {
804  mFrameItems.push_back( frame );
805  connect( frame, SIGNAL( sizeChanged() ), this, SLOT( recalculateFrameSizes() ) );
806  if ( mComposition )
807  {
808  mComposition->addComposerTableFrame( this, frame );
809  }
810 
811  if ( recalcFrameSizes )
812  {
814  }
815 }
816 
818 {
819  if ( source == mSource )
820  {
821  return;
822  }
823 
824  QgsVectorLayer* prevLayer = sourceLayer();
825  mSource = source;
826  QgsVectorLayer* newLayer = sourceLayer();
827 
828  if ( newLayer != prevLayer )
829  {
830  //disconnect from previous layer
831  if ( prevLayer )
832  {
833  disconnect( prevLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
834  }
835 
836  //connect to new layer
837  connect( newLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
839  {
840  mCurrentAtlasLayer = newLayer;
841  }
842 
843  //layer has changed as a result of the source change, so reset column list
844  resetColumns();
845  }
846 
848  emit changed();
849 }
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").
qlonglong toLongLong(bool *ok) const
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.
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.
bool contains(const Key &key) const
Q_DECL_DEPRECATED QVariant evaluate(const QgsFeature *f)
Evaluate the feature and return the result.
int localeAwareCompare(const QString &other) const
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.
QDateTime toDateTime() const
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
QTime toTime() 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:187
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 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.
int size() const
QgsMapLayer * mapLayer(const QString &theLayerId)
Retrieve a pointer to a loaded layer by id.
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:375
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.
bool isNull() const
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
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
int count() const
Return number of items.
Definition: qgsfield.cpp:365
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.
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...
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
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
QDate toDate() 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 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 QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
Definition: qgsfeature.cpp:82
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
const QgsCoordinateReferenceSystem & crs() const
Returns layer&#39;s spatial reference system.
QgsAtlasComposition & atlasComposition()
double toDouble(bool *ok) const
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
Type type() 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