QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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"
22#include "qgsvectorlayerref.h"
23
25
26// This is not considered stable API - it is exposed to python bindings only for unit testing!
27
35class CORE_EXPORT QgsReportSectionContext
36{
37 public:
38
40 QgsFeature feature;
41
43 QgsVectorLayer *currentLayer = nullptr;
44
46 QVariantMap fieldFilters;
47};
48
56class CORE_EXPORT QgsAbstractReportSection : public QgsAbstractLayoutIterator
57{
58
59#ifdef SIP_RUN
61 if ( dynamic_cast< QgsReportSectionFieldGroup * >( sipCpp ) )
62 sipType = sipType_QgsReportSectionFieldGroup;
63 else if ( dynamic_cast< QgsReportSectionLayout * >( sipCpp ) )
64 sipType = sipType_QgsReportSectionLayout;
65 else
66 sipType = NULL;
68#endif
69
70 public:
71
76 QgsAbstractReportSection( QgsAbstractReportSection *parentSection = nullptr );
77
78 ~QgsAbstractReportSection() override;
79 QgsAbstractReportSection( const QgsAbstractReportSection &other ) = delete;
80 QgsAbstractReportSection &operator=( const QgsAbstractReportSection &other ) = delete;
81
85 virtual QString type() const = 0;
86
90 virtual QString description() const = 0;
91
95 virtual QIcon icon() const = 0;
96
104 virtual QgsAbstractReportSection *clone() const = 0 SIP_FACTORY;
105
109 QgsAbstractReportSection *parentSection() { return mParent; }
110
114 QgsProject *project();
115
116 // TODO - how to handle this?
117 int count() const override { return -1; }
118
119 QString filePath( const QString &baseFilePath, const QString &extension ) override;
120 QgsLayout *layout() override;
121 bool beginRender() override;
122 bool next() override;
123 bool endRender() override;
124
128 virtual void reset();
129
136 virtual bool prepareHeader();
137
144 virtual bool prepareFooter();
145
152 virtual QgsLayout *nextBody( bool &ok SIP_OUT ) { ok = false; return nullptr; }
153
160 bool headerEnabled() const { return mHeaderEnabled; }
161
168 void setHeaderEnabled( bool enabled ) { mHeaderEnabled = enabled; }
169
177 QgsLayout *header() { return mHeader.get(); }
178
187 void setHeader( QgsLayout *header SIP_TRANSFER );
188
195 bool footerEnabled() const { return mFooterEnabled; }
196
203 void setFooterEnabled( bool enabled ) { mFooterEnabled = enabled; }
204
212 QgsLayout *footer() { return mFooter.get(); }
213
222 void setFooter( QgsLayout *footer SIP_TRANSFER );
223
229 int childCount() const { return mChildren.count(); }
230
234 int row() const;
235
245 QList< QgsAbstractReportSection * > childSections() const { return mChildren; }
246
251 QgsAbstractReportSection *childSection( int index );
252
258 void appendChild( QgsAbstractReportSection *section SIP_TRANSFER );
259
265 void insertChild( int index, QgsAbstractReportSection *section SIP_TRANSFER );
266
271 void removeChild( QgsAbstractReportSection *section );
272
277 void removeChildAt( int index );
278
283 void setContext( const QgsReportSectionContext &context );
284
289 const QgsReportSectionContext &context() const { return mContext; }
290
295 bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
296
301 bool readXml( const QDomElement &sectionElement, const QDomDocument &document, const QgsReadWriteContext &context );
302
306 virtual void reloadSettings();
307
317 bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
318
319 protected:
320
322 enum SubSection
323 {
324 Header,
325 Body,
326 Children,
327 Footer,
328 End,
329 };
330
335 void copyCommonProperties( QgsAbstractReportSection *destination ) const;
336
340 virtual void setParentSection( QgsAbstractReportSection *parent ) { mParent = parent; }
341
347 virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
348
354 virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context );
355
356 private:
357
358 QgsAbstractReportSection *mParent = nullptr;
359
360 int mSectionNumber = 0;
361 SubSection mNextSection = Header;
362 int mNextChild = 0;
363 QgsLayout *mCurrentLayout = nullptr;
364
365 bool mHeaderEnabled = false;
366 bool mFooterEnabled = false;
367 std::unique_ptr< QgsLayout > mHeader;
368 std::unique_ptr< QgsLayout > mFooter;
369
370 QList< QgsAbstractReportSection * > mChildren;
371
372 QgsReportSectionContext mContext;
373
374#ifdef SIP_RUN
375 QgsAbstractReportSection( const QgsAbstractReportSection &other );
376#endif
377};
378
380
381#endif //QGSABSTRACTREPORTSECTION_H
An abstract base class for QgsLayout based classes which can be exported by QgsLayoutExporter.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:199
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_FACTORY
Definition qgis_sip.h:84
#define SIP_END
Definition qgis_sip.h:216