QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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() 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 
315  protected:
316 
318  enum SubSection
319  {
320  Header,
321  Body,
322  Children,
323  Footer,
324  End,
325  };
326 
331  void copyCommonProperties( QgsAbstractReportSection *destination ) const;
332 
336  virtual void setParentSection( QgsAbstractReportSection *parent ) { mParent = parent; }
337 
343  virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
344 
350  virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context );
351 
352  private:
353 
354  QgsAbstractReportSection *mParent = nullptr;
355 
356  int mSectionNumber = 0;
357  SubSection mNextSection = Header;
358  int mNextChild = 0;
359  QgsLayout *mCurrentLayout = nullptr;
360 
361  bool mHeaderEnabled = false;
362  bool mFooterEnabled = false;
363  std::unique_ptr< QgsLayout > mHeader;
364  std::unique_ptr< QgsLayout > mFooter;
365 
366  QList< QgsAbstractReportSection * > mChildren;
367 
368  QgsReportSectionContext mContext;
369 
370 #ifdef SIP_RUN
371  QgsAbstractReportSection( const QgsAbstractReportSection &other );
372 #endif
373 };
374 
376 
377 #endif //QGSABSTRACTREPORTSECTION_H
The class is used as a container of context for various read/write operations on other objects...
virtual bool endRender()=0
Ends the render, performing any required cleanup tasks.
virtual bool next()=0
Iterates to next feature, returning false if no more features exist to iterate over.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
An abstract base class for QgsLayout based classes which can be exported by QgsLayoutExporter.
virtual int count()=0
Returns the number of features to iterate over.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_END
Definition: qgis_sip.h:182
virtual QgsLayout * layout()=0
Returns the layout associated with the iterator.
Reads and writes project states.
Definition: qgsproject.h:89
#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
#define SIP_OUT
Definition: qgis_sip.h:51
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:165
Represents a vector layer which manages a vector based data sets.
virtual bool beginRender()=0
Called when rendering begins, before iteration commences.
virtual QString filePath(const QString &baseFilePath, const QString &extension)=0
Returns the file path for the current feature, based on a specified base file path and extension...