QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
22
23QgsReportSectionLayout::QgsReportSectionLayout( QgsAbstractReportSection *parent )
24 : QgsAbstractReportSection( parent )
25{}
26
27QIcon QgsReportSectionLayout::icon() const
28{
29 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconLayout.svg" ) );
30}
31
32QgsReportSectionLayout *QgsReportSectionLayout::clone() const
33{
34 auto copy = std::make_unique< QgsReportSectionLayout >( nullptr );
35 copyCommonProperties( copy.get() );
36
37 if ( mBody )
38 {
39 copy->mBody.reset( mBody->clone() );
40 }
41 else
42 copy->mBody.reset();
43
44 copy->mBodyEnabled = mBodyEnabled;
45
46 return copy.release();
47}
48
49bool QgsReportSectionLayout::beginRender()
50{
51 mExportedBody = false;
52 return QgsAbstractReportSection::beginRender();
53}
54
55QgsLayout *QgsReportSectionLayout::nextBody( bool &ok )
56{
57 if ( !mExportedBody && mBody && mBodyEnabled )
58 {
59 mExportedBody = true;
60 ok = true;
61 return mBody.get();
62 }
63 else
64 {
65 ok = false;
66 return nullptr;
67 }
68}
69
70void QgsReportSectionLayout::reloadSettings()
71{
72 QgsAbstractReportSection::reloadSettings();
73 if ( mBody )
74 mBody->reloadSettings();
75}
76
77bool QgsReportSectionLayout::writePropertiesToElement( QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context ) const
78{
79 if ( mBody )
80 {
81 QDomElement bodyElement = doc.createElement( QStringLiteral( "body" ) );
82 bodyElement.appendChild( mBody->writeXml( doc, context ) );
83 element.appendChild( bodyElement );
84 }
85 element.setAttribute( QStringLiteral( "bodyEnabled" ), mBodyEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
86 return true;
87}
88
89bool QgsReportSectionLayout::readPropertiesFromElement( const QDomElement &element, const QDomDocument &doc, const QgsReadWriteContext &context )
90{
91 const QDomElement bodyElement = element.firstChildElement( QStringLiteral( "body" ) );
92 if ( !bodyElement.isNull() )
93 {
94 const QDomElement bodyLayoutElem = bodyElement.firstChild().toElement();
95 auto body = std::make_unique< QgsLayout >( project() );
96 body->readXml( bodyLayoutElem, doc, context );
97 mBody = std::move( body );
98 }
99 mBodyEnabled = element.attribute( QStringLiteral( "bodyEnabled" ) ).toInt();
100 return true;
101}
102
104
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.