QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgslayoutmanager.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutmanager.h
3 ------------------
4 Date : January 2017
5 Copyright : (C) 2017 Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSLAYOUTMANAGER_H
17#define QGSLAYOUTMANAGER_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
22#include <QObject>
23#include <QAbstractListModel>
24#include <QSortFilterProxyModel>
25
26class QgsProject;
27class QgsPrintLayout;
29
43class CORE_EXPORT QgsLayoutManager : public QObject
44{
45 Q_OBJECT
46
47 public:
48
53 explicit QgsLayoutManager( QgsProject *project SIP_TRANSFERTHIS = nullptr );
54
55 ~QgsLayoutManager() override;
56
64 bool addLayout( QgsMasterLayoutInterface *layout SIP_TRANSFER );
65
75 bool removeLayout( QgsMasterLayoutInterface *layout );
76
81 void clear();
82
86 QList< QgsMasterLayoutInterface * > layouts() const;
87
91 QList< QgsPrintLayout * > printLayouts() const;
92
97 QgsMasterLayoutInterface *layoutByName( const QString &name ) const;
98
104 bool readXml( const QDomElement &element, const QDomDocument &doc );
105
110 QDomElement writeXml( QDomDocument &doc ) const;
111
117 QgsMasterLayoutInterface *duplicateLayout( const QgsMasterLayoutInterface *layout, const QString &newName );
118
123 QString generateUniqueTitle( QgsMasterLayoutInterface::Type type = QgsMasterLayoutInterface::PrintLayout ) const;
124
134 bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
135
136 signals:
137
139 void layoutAboutToBeAdded( const QString &name );
140
142 void layoutAdded( const QString &name );
143
145 void layoutRemoved( const QString &name );
146
148 void layoutAboutToBeRemoved( const QString &name );
149
151 void layoutRenamed( QgsMasterLayoutInterface *layout, const QString &newName );
152
153 private:
154
155 QgsProject *mProject = nullptr;
156
157 QList< QgsMasterLayoutInterface * > mLayouts;
158
159};
160
161
171class CORE_EXPORT QgsLayoutManagerModel : public QAbstractListModel
172{
173 Q_OBJECT
174
175 public:
176
177 // *INDENT-OFF*
178
186 {
187 Layout SIP_MONKEYPATCH_COMPAT_NAME(LayoutRole) = Qt::UserRole + 1,
188 };
189 Q_ENUM( CustomRole )
190 // *INDENT-ON*
191
192
195 explicit QgsLayoutManagerModel( QgsLayoutManager *manager, QObject *parent SIP_TRANSFERTHIS = nullptr );
196
197 int rowCount( const QModelIndex &parent ) const override;
198 QVariant data( const QModelIndex &index, int role ) const override;
199 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
200 Qt::ItemFlags flags( const QModelIndex &index ) const override;
201
206 QgsMasterLayoutInterface *layoutFromIndex( const QModelIndex &index ) const;
207
212 QModelIndex indexFromLayout( QgsMasterLayoutInterface *layout ) const;
213
218 void setAllowEmptyLayout( bool allowEmpty );
219
224 bool allowEmptyLayout() const { return mAllowEmpty; }
225
226 private slots:
227 void layoutAboutToBeAdded( const QString &name );
228 void layoutAboutToBeRemoved( const QString &name );
229 void layoutAdded( const QString &name );
230 void layoutRemoved( const QString &name );
231 void layoutRenamed( QgsMasterLayoutInterface *layout, const QString &newName );
232 private:
233 QgsLayoutManager *mLayoutManager = nullptr;
234 bool mAllowEmpty = false;
235};
236
237
246class CORE_EXPORT QgsLayoutManagerProxyModel : public QSortFilterProxyModel
247{
248 Q_OBJECT
249
250 public:
251
253 enum Filter SIP_ENUM_BASETYPE( IntFlag )
254 {
255 FilterPrintLayouts = 1 << 1,
256 FilterReports = 1 << 2,
257 };
258 Q_DECLARE_FLAGS( Filters, Filter )
259 Q_FLAG( Filters )
260
261
264 explicit QgsLayoutManagerProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
265 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
266 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
267
274
280 void setFilters( QgsLayoutManagerProxyModel::Filters filters );
281
288 QString filterString() const { return mFilterString; }
289
290 public slots:
291
299 void setFilterString( const QString &filter );
300
301 private:
302
303 Filters mFilters = Filters( FilterPrintLayouts | FilterReports );
304
305 QString mFilterString;
306};
307
309
310#endif // QGSLAYOUTMANAGER_H
List model representing the print layouts and reports available in a layout manager.
CustomRole
Custom model roles.
bool allowEmptyLayout() const
Returns true if the model allows the empty layout ("not set") choice.
QSortFilterProxyModel subclass for QgsLayoutManagerModel.
QString filterString() const
Returns the current filter string, if set.
Filter
Available filter flags for filtering the model.
Manages storage of a set of layouts.
void layoutAboutToBeRemoved(const QString &name)
Emitted when a layout is about to be removed from the manager.
void layoutAboutToBeAdded(const QString &name)
Emitted when a layout is about to be added to the manager.
void layoutRenamed(QgsMasterLayoutInterface *layout, const QString &newName)
Emitted when a layout is renamed.
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.
Interface for master layout type objects, such as print layouts and reports.
@ PrintLayout
Individual print layout (QgsPrintLayout)
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
An interface for classes which can visit style entity (e.g.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:271
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:273
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)