-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgslayoutmanager.h
205 lines (165 loc) · 7 KB
/
qgslayoutmanager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/***************************************************************************
qgslayoutmanager.h
------------------
Date : January 2017
Copyright : (C) 2017 Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSLAYOUTMANAGER_H
#define QGSLAYOUTMANAGER_H
#include "qgis_core.h"
#include "qgis.h"
#include "qgscomposition.h"
#include "qgsmasterlayoutinterface.h"
#include <QObject>
class QgsProject;
/**
* \ingroup core
* \class QgsLayoutManager
* \since QGIS 3.0
*
* \brief Manages storage of a set of layouts.
*
* QgsLayoutManager handles the storage, serializing and deserializing
* of QgsLayouts. Usually this class is not constructed directly, but
* rather accessed through a QgsProject via QgsProject::layoutManager().
*
* QgsLayoutManager retains ownership of all the layouts contained
* in the manager.
*/
class CORE_EXPORT QgsLayoutManager : public QObject
{
Q_OBJECT
public:
/**
* Constructor for QgsLayoutManager. The project will become the parent object for this
* manager.
*/
explicit QgsLayoutManager( QgsProject *project SIP_TRANSFERTHIS = nullptr );
~QgsLayoutManager() override;
/**
* Adds a composition to the manager. Ownership of the composition is transferred to the manager.
* Returns true if the addition was successful, or false if the composition could not be added (eg
* as a result of a duplicate composition name).
* \see removeComposition()
* \see compositionAdded()
*/
bool addComposition( QgsComposition *composition SIP_TRANSFER );
/**
* Adds a \a layout to the manager. Ownership of the layout is transferred to the manager.
* Returns true if the addition was successful, or false if the layout could not be added (eg
* as a result of a duplicate layout name).
* \see removeLayout()
* \see layoutAdded()
*/
bool addLayout( QgsMasterLayoutInterface *layout SIP_TRANSFER );
/**
* Removes a composition from the manager. The composition is deleted.
* Returns true if the removal was successful, or false if the removal failed (eg as a result
* of removing a composition which is not contained in the manager).
* \see addComposition()
* \see compositionRemoved()
* \see compositionAboutToBeRemoved()
* \see clear()
*/
bool removeComposition( QgsComposition *composition );
/**
* Removes a \a layout from the manager. The layout is deleted.
* Returns true if the removal was successful, or false if the removal failed (eg as a result
* of removing a layout which is not contained in the manager).
* \see addLayout()
* \see layoutRemoved()
* \see layoutAboutToBeRemoved()
* \see clear()
*/
bool removeLayout( QgsMasterLayoutInterface *layout );
/**
* Removes and deletes all layouts from the manager.
* \see removeLayout()
*/
void clear();
/**
* Returns a list of all compositions contained in the manager.
*/
QList< QgsComposition * > compositions() const;
/**
* Returns a list of all layouts contained in the manager.
*/
QList< QgsMasterLayoutInterface * > layouts() const;
/**
* Returns the composition with a matching name, or nullptr if no matching compositions
* were found.
*/
QgsComposition *compositionByName( const QString &name ) const;
/**
* Returns the layout with a matching name, or nullptr if no matching layouts
* were found.
*/
QgsMasterLayoutInterface *layoutByName( const QString &name ) const;
/**
* Reads the manager's state from a DOM element, restoring all layouts
* present in the XML document.
* \see writeXml()
*/
bool readXml( const QDomElement &element, const QDomDocument &doc );
/**
* Returns a DOM element representing the state of the manager.
* \see readXml()
*/
QDomElement writeXml( QDomDocument &doc ) const;
/**
* Saves the composition with matching \a name in template format.
* Returns true if save was successful.
*/
bool saveAsTemplate( const QString &name, QDomDocument &doc ) const;
/**
* Duplicates an existing \a layout from the manager. The new
* layout will automatically be stored in the manager.
* Returns new the layout if duplication was successful.
*/
QgsMasterLayoutInterface *duplicateLayout( const QgsMasterLayoutInterface *layout, const QString &newName );
/**
* Generates a unique title for a new composition, which does not
* clash with any already contained by the manager.
*/
QString generateUniqueComposerTitle() const;
/**
* Generates a unique title for a new layout of the specified \a type, which does not
* clash with any already contained by the manager.
*/
QString generateUniqueTitle( QgsMasterLayoutInterface::Type type = QgsMasterLayoutInterface::PrintLayout ) const;
signals:
//! Emitted when a composition is about to be added to the manager
void compositionAboutToBeAdded( const QString &name );
//! Emitted when a layout is about to be added to the manager
void layoutAboutToBeAdded( const QString &name );
//! Emitted when a composition has been added to the manager
void compositionAdded( const QString &name );
//! Emitted when a layout has been added to the manager
void layoutAdded( const QString &name );
//! Emitted when a composition was removed from the manager
void compositionRemoved( const QString &name );
//! Emitted when a layout was removed from the manager
void layoutRemoved( const QString &name );
//! Emitted when a composition is about to be removed from the manager
void compositionAboutToBeRemoved( const QString &name );
//! Emitted when a layout is about to be removed from the manager
void layoutAboutToBeRemoved( const QString &name );
//! Emitted when a composition is renamed
void compositionRenamed( QgsComposition *composition, const QString &newName );
//! Emitted when a layout is renamed
void layoutRenamed( QgsMasterLayoutInterface *layout, const QString &newName );
private:
QgsProject *mProject = nullptr;
QList< QgsComposition * > mCompositions;
QList< QgsMasterLayoutInterface * > mLayouts;
QgsComposition *createCompositionFromXml( const QDomElement &element, const QDomDocument &doc ) const;
};
#endif // QGSLAYOUTMANAGER_H