QGIS API Documentation  3.6.0-Noosa (5873452)
qgsreportsectionfieldgroup.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsreportsectionfieldgroup.h
3  ---------------------------
4  begin : December 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 #ifndef QGSREPORTSECTIONFIELDGROUP_H
17 #define QGSREPORTSECTIONFIELDGROUP_H
18 
19 #include "qgis_core.h"
21 #include "qgsfeatureiterator.h"
22 
23 
25 
26 // This is not considered stable API - it is exposed to python bindings only for unit testing!
27 
38 class CORE_EXPORT QgsReportSectionFieldGroup : public QgsAbstractReportSection
39 {
40  public:
41 
45  enum SectionVisibility
46  {
47  IncludeWhenFeaturesFound,
48  AlwaysInclude
49  };
50 
55  QgsReportSectionFieldGroup( QgsAbstractReportSection *parentSection = nullptr );
56 
57  QString type() const override { return QStringLiteral( "SectionFieldGroup" ); }
58  QString description() const override;
59  QIcon icon() const override;
60 
67  QgsLayout *body() { return mBody.get(); }
68 
76  void setBody( QgsLayout *body SIP_TRANSFER ) { mBody.reset( body ); }
77 
84  bool bodyEnabled() const { return mBodyEnabled; }
85 
92  void setBodyEnabled( bool enabled ) { mBodyEnabled = enabled; }
93 
94 
99  QgsVectorLayer *layer() { return mCoverageLayer.get(); }
100 
105  void setLayer( QgsVectorLayer *layer ) { mCoverageLayer = layer; }
106 
111  QString field() const { return mField; }
112 
117  void setField( const QString &field ) { mField = field; }
118 
124  bool sortAscending() const;
125 
131  void setSortAscending( bool sortAscending );
132 
137  SectionVisibility headerVisibility() const { return mHeaderVisibility; }
138 
143  void setHeaderVisibility( SectionVisibility visibility ) { mHeaderVisibility = visibility; }
144 
149  SectionVisibility footerVisibility() const { return mFooterVisibility; }
150 
155  void setFooterVisibility( SectionVisibility visibility ) { mFooterVisibility = visibility; }
156 
157  QgsReportSectionFieldGroup *clone() const override SIP_FACTORY;
158  bool beginRender() override;
159  bool prepareHeader() override;
160  bool prepareFooter() override;
161  QgsLayout *nextBody( bool &ok ) override;
162  void reset() override;
163  void setParentSection( QgsAbstractReportSection *parentSection ) override;
164  void reloadSettings() override;
165 
166  protected:
167 
168  bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
169  bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
170 
171  private:
172 
173  QgsVectorLayerRef mCoverageLayer;
174  QString mField;
175  bool mSortAscending = true;
176  int mFieldIndex = -1;
177  QgsFeatureIterator mFeatures;
178  bool mSkipNextRequest = false;
179  bool mNoFeatures = false;
180  SectionVisibility mHeaderVisibility = IncludeWhenFeaturesFound;
181  SectionVisibility mFooterVisibility = IncludeWhenFeaturesFound;
182  QgsFeature mHeaderFeature;
183  QgsFeature mLastFeature;
184  QSet< QVariant > mEncounteredValues;
185 
186  bool mBodyEnabled = false;
187  std::unique_ptr< QgsLayout > mBody;
188 
189  QgsFeatureRequest buildFeatureRequest() const;
190 
191  QgsFeature getNextFeature();
192  void updateChildContexts( const QgsFeature &feature );
193 
194 };
195 
196 
198 
199 #endif //QGSREPORTSECTIONFIELDGROUP_H
The class is used as a container of context for various read/write operations on other objects...
Wrapper for iterator of features from vector data provider or vector layer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
#define SIP_TRANSFER
Definition: qgis_sip.h:36
This class wraps a request for features to a vector layer (or directly its vector data provider)...
#define SIP_FACTORY
Definition: qgis_sip.h:69
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
Represents a vector layer which manages a vector based data sets.