QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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:
39 QgsFeature feature;
40
42 QgsVectorLayer *currentLayer = nullptr;
43
45 QVariantMap fieldFilters;
46};
47
55class CORE_EXPORT QgsAbstractReportSection : public QgsAbstractLayoutIterator
56{
57#ifdef SIP_RUN
59 if ( dynamic_cast< QgsReportSectionFieldGroup * >( sipCpp ) )
60 sipType = sipType_QgsReportSectionFieldGroup;
61 else if ( dynamic_cast< QgsReportSectionLayout * >( sipCpp ) )
62 sipType = sipType_QgsReportSectionLayout;
63 else
64 sipType = NULL;
66#endif
67
68 public:
69
74 QgsAbstractReportSection( QgsAbstractReportSection *parentSection = nullptr );
75
76 ~QgsAbstractReportSection() override;
77 QgsAbstractReportSection( const QgsAbstractReportSection &other ) = delete;
78 QgsAbstractReportSection &operator=( const QgsAbstractReportSection &other ) = delete;
79
83 virtual QString type() const = 0;
84
88 virtual QString description() const = 0;
89
93 virtual QIcon icon() const = 0;
94
102 virtual QgsAbstractReportSection *clone() const = 0 SIP_FACTORY;
103
107 QgsAbstractReportSection *parentSection() { return mParent; }
108
112 QgsProject *project();
113
114 // TODO - how to handle this?
115 int count() const override { return -1; }
116
117 QString filePath( const QString &baseFilePath, const QString &extension ) override;
118 QgsLayout *layout() override;
119 bool beginRender() override;
120 bool next() override;
121 bool endRender() override;
122
126 virtual void reset();
127
134 virtual bool prepareHeader();
135
142 virtual bool prepareFooter();
143
150 virtual QgsLayout *nextBody( bool &ok SIP_OUT )
151 {
152 ok = false;
153 return nullptr;
154 }
155
162 bool headerEnabled() const { return mHeaderEnabled; }
163
170 void setHeaderEnabled( bool enabled ) { mHeaderEnabled = enabled; }
171
179 QgsLayout *header() { return mHeader.get(); }
180
189 void setHeader( QgsLayout *header SIP_TRANSFER );
190
197 bool footerEnabled() const { return mFooterEnabled; }
198
205 void setFooterEnabled( bool enabled ) { mFooterEnabled = enabled; }
206
214 QgsLayout *footer() { return mFooter.get(); }
215
224 void setFooter( QgsLayout *footer SIP_TRANSFER );
225
231 int childCount() const { return mChildren.count(); }
232
236 int row() const;
237
247 QList< QgsAbstractReportSection * > childSections() const { return mChildren; }
248
253 QgsAbstractReportSection *childSection( int index );
254
260 void appendChild( QgsAbstractReportSection *section SIP_TRANSFER );
261
267 void insertChild( int index, QgsAbstractReportSection *section SIP_TRANSFER );
268
273 void removeChild( QgsAbstractReportSection *section );
274
279 void removeChildAt( int index );
280
285 void setContext( const QgsReportSectionContext &context );
286
291 const QgsReportSectionContext &context() const { return mContext; }
292
297 bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
298
303 bool readXml( const QDomElement &sectionElement, const QDomDocument &document, const QgsReadWriteContext &context );
304
308 virtual void reloadSettings();
309
319 bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
320
321 protected:
323 enum SubSection
324 {
325 Header,
326 Body,
327 Children,
328 Footer,
329 End,
330 };
331
336 void copyCommonProperties( QgsAbstractReportSection *destination ) const;
337
341 virtual void setParentSection( QgsAbstractReportSection *parent ) { mParent = parent; }
342
348 virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
349
355 virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context );
356
357 private:
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:198
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_OUT
Definition qgis_sip.h:57
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_END
Definition qgis_sip.h:215