QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgsabstractreportsection.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsabstractreportsection.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 QGSABSTRACTREPORTSECTION_H
17 #define QGSABSTRACTREPORTSECTION_H
18 
19 #include "qgis_core.h"
21 #include "qgslayoutreportcontext.h"
22 #include "qgsvectorlayerref.h"
23 
24 
26 
27 // This is not considered stable API - it is exposed to python bindings only for unit testing!
28 
37 class CORE_EXPORT QgsReportSectionContext
38 {
39  public:
40 
42  QgsFeature feature;
43 
45  QgsVectorLayer *currentLayer = nullptr;
46 
48  QVariantMap fieldFilters;
49 };
50 
59 class CORE_EXPORT QgsAbstractReportSection : public QgsAbstractLayoutIterator
60 {
61 
62 #ifdef SIP_RUN
64  if ( dynamic_cast< QgsReportSectionFieldGroup * >( sipCpp ) )
65  sipType = sipType_QgsReportSectionFieldGroup;
66  else if ( dynamic_cast< QgsReportSectionLayout * >( sipCpp ) )
67  sipType = sipType_QgsReportSectionLayout;
68  else
69  sipType = NULL;
70  SIP_END
71 #endif
72 
73  public:
74 
79  QgsAbstractReportSection( QgsAbstractReportSection *parentSection = nullptr );
80 
81  ~QgsAbstractReportSection() override;
82 
84  QgsAbstractReportSection( const QgsAbstractReportSection &other ) = delete;
85 
87  QgsAbstractReportSection &operator=( const QgsAbstractReportSection &other ) = delete;
88 
92  virtual QString type() const = 0;
93 
97  virtual QString description() const = 0;
98 
102  virtual QIcon icon() const = 0;
103 
111  virtual QgsAbstractReportSection *clone() const = 0 SIP_FACTORY;
112 
116  QgsAbstractReportSection *parentSection() { return mParent; }
117 
121  QgsProject *project();
122 
123  // TODO - how to handle this?
124  int count() const override { return -1; }
125 
126  QString filePath( const QString &baseFilePath, const QString &extension ) override;
127  QgsLayout *layout() override;
128  bool beginRender() override;
129  bool next() override;
130  bool endRender() override;
131 
135  virtual void reset();
136 
143  virtual bool prepareHeader();
144 
151  virtual bool prepareFooter();
152 
159  virtual QgsLayout *nextBody( bool &ok SIP_OUT ) { ok = false; return nullptr; }
160 
167  bool headerEnabled() const { return mHeaderEnabled; }
168 
175  void setHeaderEnabled( bool enabled ) { mHeaderEnabled = enabled; }
176 
184  QgsLayout *header() { return mHeader.get(); }
185 
194  void setHeader( QgsLayout *header SIP_TRANSFER );
195 
202  bool footerEnabled() const { return mFooterEnabled; }
203 
210  void setFooterEnabled( bool enabled ) { mFooterEnabled = enabled; }
211 
219  QgsLayout *footer() { return mFooter.get(); }
220 
229  void setFooter( QgsLayout *footer SIP_TRANSFER );
230 
236  int childCount() const { return mChildren.count(); }
237 
241  int row() const;
242 
252  QList< QgsAbstractReportSection * > childSections() const { return mChildren; }
253 
258  QgsAbstractReportSection *childSection( int index );
259 
265  void appendChild( QgsAbstractReportSection *section SIP_TRANSFER );
266 
272  void insertChild( int index, QgsAbstractReportSection *section SIP_TRANSFER );
273 
278  void removeChild( QgsAbstractReportSection *section );
279 
284  void removeChildAt( int index );
285 
290  void setContext( const QgsReportSectionContext &context );
291 
296  const QgsReportSectionContext &context() const { return mContext; }
297 
302  bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
303 
308  bool readXml( const QDomElement &sectionElement, const QDomDocument &document, const QgsReadWriteContext &context );
309 
313  virtual void reloadSettings();
314 
324  bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
325 
326  protected:
327 
329  enum SubSection
330  {
331  Header,
332  Body,
333  Children,
334  Footer,
335  End,
336  };
337 
342  void copyCommonProperties( QgsAbstractReportSection *destination ) const;
343 
347  virtual void setParentSection( QgsAbstractReportSection *parent ) { mParent = parent; }
348 
354  virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
355 
361  virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context );
362 
363  private:
364 
365  QgsAbstractReportSection *mParent = nullptr;
366 
367  int mSectionNumber = 0;
368  SubSection mNextSection = Header;
369  int mNextChild = 0;
370  QgsLayout *mCurrentLayout = nullptr;
371 
372  bool mHeaderEnabled = false;
373  bool mFooterEnabled = false;
374  std::unique_ptr< QgsLayout > mHeader;
375  std::unique_ptr< QgsLayout > mFooter;
376 
377  QList< QgsAbstractReportSection * > mChildren;
378 
379  QgsReportSectionContext mContext;
380 
381 #ifdef SIP_RUN
382  QgsAbstractReportSection( const QgsAbstractReportSection &other );
383 #endif
384 };
385 
387 
388 #endif //QGSABSTRACTREPORTSECTION_H
An abstract base class for QgsLayout based classes which can be exported by QgsLayoutExporter.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:51
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:99
The class is used as a container of context for various read/write operations on other objects.
An interface for classes which can visit style entity (e.g.
Represents a vector layer which manages a vector based data sets.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:177
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_END
Definition: qgis_sip.h:194