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