QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsprintlayout.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprintlayout.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 "qgsprintlayout.h"
18
20#include "qgslayoutatlas.h"
21#include "qgsreadwritecontext.h"
23
24#include "moc_qgsprintlayout.cpp"
25
31
33{
34 QDomDocument currentDoc;
35
36 const QgsReadWriteContext context;
37 const QDomElement elem = writeXml( currentDoc, context );
38 currentDoc.appendChild( elem );
39
40 auto newLayout = std::make_unique< QgsPrintLayout >( project() );
41 bool ok = false;
42 newLayout->loadFromTemplate( currentDoc, context, true, &ok );
43 if ( !ok )
44 {
45 return nullptr;
46 }
47
48 return newLayout.release();
49}
50
52{
53 return project();
54}
55
57{
58 return QgsApplication::getThemeIcon( QStringLiteral( "mIconLayout.svg" ) );
59}
60
62{
63 return mAtlas;
64}
65
66void QgsPrintLayout::setName( const QString &name )
67{
68 mName = name;
69 emit nameChanged( name );
70 layoutProject()->setDirty( true );
71}
72
73QDomElement QgsPrintLayout::writeXml( QDomDocument &document, const QgsReadWriteContext &context ) const
74{
75 QDomElement layoutElem = QgsLayout::writeXml( document, context );
76 layoutElem.setAttribute( QStringLiteral( "name" ), mName );
77 mAtlas->writeXml( layoutElem, document, context );
78 return layoutElem;
79}
80
81bool QgsPrintLayout::readXml( const QDomElement &layoutElement, const QDomDocument &document, const QgsReadWriteContext &context )
82{
83 if ( !QgsLayout::readXml( layoutElement, document, context ) )
84 return false;
85
86 const QDomElement atlasElem = layoutElement.firstChildElement( QStringLiteral( "Atlas" ) );
87 mAtlas->readXml( atlasElem, document, context );
88
89 setName( layoutElement.attribute( QStringLiteral( "name" ) ) );
90
91 return true;
92}
93
94QDomElement QgsPrintLayout::writeLayoutXml( QDomDocument &document, const QgsReadWriteContext &context ) const
95{
96 return writeXml( document, context );
97}
98
99bool QgsPrintLayout::readLayoutXml( const QDomElement &layoutElement, const QDomDocument &document, const QgsReadWriteContext &context )
100{
101 return readXml( layoutElement, document, context );
102}
103
105{
107
108 if ( mAtlas->enabled() )
109 {
111 }
112
113 return context;
114}
115
120
122{
123 // NOTE: if visitEnter returns false it means "don't visit the layout", not "abort all further visitations"
125 return true;
126
127 if ( !accept( visitor ) )
128 return false;
130 return false;
131 return true;
132}
133
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QgsExpressionContextScope * atlasScope(const QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Used to render QgsLayout as an atlas, by iterating over the features from an associated vector layer.
void reloadSettings()
Refreshes the layout when global layout related options change.
virtual bool readXml(const QDomElement &layoutElement, const QDomDocument &document, const QgsReadWriteContext &context)
Sets the collection's state from a DOM element.
QgsExpressionContext createExpressionContext() const override
Creates an expression context relating to the layout's current state.
virtual QDomElement writeXml(QDomDocument &document, const QgsReadWriteContext &context) const
Returns the layout's state encapsulated in a DOM element.
bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
QgsProject * project() const
The project associated with the layout.
QgsLayout(QgsProject *project)
Construct a new layout linked to the specified project.
Definition qgslayout.cpp:50
@ PrintLayout
Individual print layout (QgsPrintLayout).
QgsProject * layoutProject() const override
The project associated with the layout.
QgsLayoutAtlas * atlas()
Returns the print layout's atlas.
void updateSettings() override
Refreshes the layout when global layout related options change.
bool layoutAccept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
QgsPrintLayout(QgsProject *project)
Constructor for QgsPrintLayout.
QgsExpressionContext createExpressionContext() const override
Creates an expression context relating to the layout's current state.
QIcon icon() const override
Returns an icon for the layout.
QgsPrintLayout * clone() const override
Creates a clone of the layout.
void setName(const QString &name) override
Sets the layout's name.
QgsMasterLayoutInterface::Type layoutType() const override
Returns the master layout type.
QDomElement writeLayoutXml(QDomDocument &document, const QgsReadWriteContext &context) const override
Returns the layout's state encapsulated in a DOM element.
QDomElement writeXml(QDomDocument &document, const QgsReadWriteContext &context) const override
Returns the layout's state encapsulated in a DOM element.
void nameChanged(const QString &name)
Emitted when the layout's name is changed.
bool readLayoutXml(const QDomElement &layoutElement, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets the layout's state from a DOM element.
bool readXml(const QDomElement &layoutElement, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets the collection's state from a DOM element.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:109
void setDirty(bool b=true)
Flag the project as dirty (modified).
A container for the context for various read/write operations on objects.
An interface for classes which can visit style entity (e.g.
virtual bool visitExit(const QgsStyleEntityVisitorInterface::Node &node)
Called when the visitor stops visiting a node.
virtual bool visitEnter(const QgsStyleEntityVisitorInterface::Node &node)
Called when the visitor starts visiting a node.
Contains information relating to a node (i.e.