40 if ( !layout || mLayouts.contains( layout ) )
46 if ( l->name() == layout->
name() )
54 if (
QgsPrintLayout *l = dynamic_cast< QgsPrintLayout * >( layout ) )
61 else if ( QgsReport *r = dynamic_cast< QgsReport * >( layout ) )
63 connect( r, &QgsReport::nameChanged,
this, [
this, r](
const QString & newName )
81 if ( !mLayouts.contains( layout ) )
84 QString name = layout->
name();
86 mLayouts.removeAll( layout );
95 const QList< QgsMasterLayoutInterface * >
layouts = mLayouts;
109 QList<QgsPrintLayout *> result;
110 const QList<QgsMasterLayoutInterface *> _layouts( mLayouts );
111 for (
const auto &layout : _layouts )
113 QgsPrintLayout *_item( dynamic_cast<QgsPrintLayout *>( layout ) );
115 result.push_back( _item );
124 if ( l->name() == name )
134 QDomElement layoutsElem = element;
135 if ( element.tagName() != QStringLiteral(
"Layouts" ) )
137 layoutsElem = element.firstChildElement( QStringLiteral(
"Layouts" ) );
139 if ( layoutsElem.isNull() )
142 layoutsElem = doc.documentElement();
147 QDomNodeList composerNodes = element.elementsByTagName( QStringLiteral(
"Composer" ) );
148 for (
int i = 0; i < composerNodes.size(); ++i )
151 QString legacyTitle = composerNodes.at( i ).toElement().attribute( QStringLiteral(
"title" ) );
153 QDomNodeList compositionNodes = composerNodes.at( i ).toElement().elementsByTagName( QStringLiteral(
"Composition" ) );
154 for (
int j = 0; j < compositionNodes.size(); ++j )
159 if ( l->name().isEmpty() )
160 l->setName( legacyTitle );
165 bool isDuplicateName =
false;
166 QString originalName = l->name();
169 isDuplicateName =
false;
172 if ( l->name() == layout->name() )
174 isDuplicateName =
true;
178 if ( isDuplicateName )
180 l->setName( QStringLiteral(
"%1 %2" ).arg( originalName ).arg(
id ) );
184 while ( isDuplicateName );
187 result = added && result;
196 const QDomNodeList layoutNodes = layoutsElem.childNodes();
197 for (
int i = 0; i < layoutNodes.size(); ++i )
199 if ( layoutNodes.at( i ).nodeName() != QStringLiteral(
"Layout" ) )
202 std::unique_ptr< QgsPrintLayout > l = qgis::make_unique< QgsPrintLayout >( mProject );
203 l->undoStack()->blockCommands(
true );
204 if ( !l->readLayoutXml( layoutNodes.at( i ).toElement(), doc, context ) )
209 l->undoStack()->blockCommands(
false );
220 const QDomNodeList reportNodes = element.elementsByTagName( QStringLiteral(
"Report" ) );
221 for (
int i = 0; i < reportNodes.size(); ++i )
223 std::unique_ptr< QgsReport > r = qgis::make_unique< QgsReport >( mProject );
224 if ( !r->readLayoutXml( reportNodes.at( i ).toElement(), doc, context ) )
243 QDomElement layoutsElem = doc.createElement( QStringLiteral(
"Layouts" ) );
249 QDomElement layoutElem = l->writeLayoutXml( doc, context );
250 layoutsElem.appendChild( layoutElem );
260 std::unique_ptr< QgsMasterLayoutInterface > newLayout( layout->
clone() );
287 while ( name.isEmpty() || names.contains( name ) )
292 name = tr(
"Layout %1" ).arg(
id );
295 name = tr(
"Report %1" ).arg(
id );
void setDirty(bool b=true)
Flag the project as dirty (modified).
The class is used as a container of context for various read/write operations on other objects...
void layoutAboutToBeRemoved(const QString &name)
Emitted when a layout is about to be removed from the manager.
void setPathResolver(const QgsPathResolver &resolver)
Sets up path resolver for conversion between relative and absolute paths.
QgsMasterLayoutInterface * layoutByName(const QString &name) const
Returns the layout with a matching name, or nullptr if no matching layouts were found.
virtual QgsMasterLayoutInterface * clone() const =0
Creates a clone of the layout.
static std::unique_ptr< QgsPrintLayout > createLayoutFromCompositionXml(const QDomElement &composerElement, QgsProject *project)
createLayoutFromCompositionXml is a factory that creates layout instances from a QGIS 2...
virtual void setName(const QString &name)=0
Sets the layout's name.
bool readXml(const QDomElement &element, const QDomDocument &doc)
Reads the manager's state from a DOM element, restoring all layouts present in the XML document...
QList< QgsPrintLayout *> printLayouts() const
Returns a list of all print layouts contained in the manager.
void layoutAboutToBeAdded(const QString &name)
Emitted when a layout is about to be added to the manager.
QgsLayoutManager(QgsProject *project=nullptr)
Constructor for QgsLayoutManager.
QgsPathResolver pathResolver() const
Returns path resolver object with considering whether the project uses absolute or relative paths and...
QDomElement writeXml(QDomDocument &doc) const
Returns a DOM element representing the state of the manager.
Reads and writes project states.
void layoutRemoved(const QString &name)
Emitted when a layout was removed from the manager.
void layoutAdded(const QString &name)
Emitted when a layout has been added to the manager.
void layoutRenamed(QgsMasterLayoutInterface *layout, const QString &newName)
Emitted when a layout is renamed.
void clear()
Removes and deletes all layouts from the manager.
void nameChanged(const QString &name)
Emitted when the layout's name is changed.
virtual QString name() const =0
Returns the layout's name.
QString generateUniqueTitle(QgsMasterLayoutInterface::Type type=QgsMasterLayoutInterface::PrintLayout) const
Generates a unique title for a new layout of the specified type, which does not clash with any alread...
bool removeLayout(QgsMasterLayoutInterface *layout)
Removes a layout from the manager.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
QList< QgsMasterLayoutInterface *> layouts() const
Returns a list of all layouts contained in the manager.
Interface for master layout type objects, such as print layouts and reports.
QgsMasterLayoutInterface * duplicateLayout(const QgsMasterLayoutInterface *layout, const QString &newName)
Duplicates an existing layout from the manager.
~QgsLayoutManager() override
Individual print layout (QgsPrintLayout)
bool addLayout(QgsMasterLayoutInterface *layout)
Adds a layout to the manager.