QGIS API Documentation 3.99.0-Master (357b655ed83)
Loading...
Searching...
No Matches
qgsreportsectionlayout.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsreportsectionlayout.cpp
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
18
19#include "qgslayout.h"
20
21#include <QString>
22
23using namespace Qt::StringLiterals;
24
26
27QgsReportSectionLayout::QgsReportSectionLayout( QgsAbstractReportSection *parent )
28 : QgsAbstractReportSection( parent )
29{}
30
31QIcon QgsReportSectionLayout::icon() const
32{
33 return QgsApplication::getThemeIcon( u"/mIconLayout.svg"_s );
34}
35
36QgsReportSectionLayout *QgsReportSectionLayout::clone() const
37{
38 auto copy = std::make_unique< QgsReportSectionLayout >( nullptr );
39 copyCommonProperties( copy.get() );
40
41 if ( mBody )
42 {
43 copy->mBody.reset( mBody->clone() );
44 }
45 else
46 copy->mBody.reset();
47
48 copy->mBodyEnabled = mBodyEnabled;
49
50 return copy.release();
51}
52
53bool QgsReportSectionLayout::beginRender()
54{
55 mExportedBody = false;
56 return QgsAbstractReportSection::beginRender();
57}
58
59QgsLayout *QgsReportSectionLayout::nextBody( bool &ok )
60{
61 if ( !mExportedBody && mBody && mBodyEnabled )
62 {
63 mExportedBody = true;
64 ok = true;
65 return mBody.get();
66 }
67 else
68 {
69 ok = false;
70 return nullptr;
71 }
72}
73
74void QgsReportSectionLayout::reloadSettings()
75{
76 QgsAbstractReportSection::reloadSettings();
77 if ( mBody )
78 mBody->reloadSettings();
79}
80
81bool QgsReportSectionLayout::writePropertiesToElement( QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context ) const
82{
83 if ( mBody )
84 {
85 QDomElement bodyElement = doc.createElement( u"body"_s );
86 bodyElement.appendChild( mBody->writeXml( doc, context ) );
87 element.appendChild( bodyElement );
88 }
89 element.setAttribute( u"bodyEnabled"_s, mBodyEnabled ? u"1"_s : u"0"_s );
90 return true;
91}
92
93bool QgsReportSectionLayout::readPropertiesFromElement( const QDomElement &element, const QDomDocument &doc, const QgsReadWriteContext &context )
94{
95 const QDomElement bodyElement = element.firstChildElement( u"body"_s );
96 if ( !bodyElement.isNull() )
97 {
98 const QDomElement bodyLayoutElem = bodyElement.firstChild().toElement();
99 auto body = std::make_unique< QgsLayout >( project() );
100 body->readXml( bodyLayoutElem, doc, context );
101 mBody = std::move( body );
102 }
103 mBodyEnabled = element.attribute( u"bodyEnabled"_s ).toInt();
104 return true;
105}
106
108
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:50
A container for the context for various read/write operations on objects.