QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
26 class QgsProject;
27 class QgsPrintLayout;
29 
44 class CORE_EXPORT QgsLayoutManager : public QObject
45 {
46  Q_OBJECT
47 
48  public:
49 
54  explicit QgsLayoutManager( QgsProject *project SIP_TRANSFERTHIS = nullptr );
55 
56  ~QgsLayoutManager() override;
57 
65  bool addLayout( QgsMasterLayoutInterface *layout SIP_TRANSFER );
66 
76  bool removeLayout( QgsMasterLayoutInterface *layout );
77 
82  void clear();
83 
87  QList< QgsMasterLayoutInterface * > layouts() const;
88 
92  QList< QgsPrintLayout * > printLayouts() const;
93 
98  QgsMasterLayoutInterface *layoutByName( const QString &name ) const;
99 
105  bool readXml( const QDomElement &element, const QDomDocument &doc );
106 
111  QDomElement writeXml( QDomDocument &doc ) const;
112 
118  QgsMasterLayoutInterface *duplicateLayout( const QgsMasterLayoutInterface *layout, const QString &newName );
119 
124  QString generateUniqueTitle( QgsMasterLayoutInterface::Type type = QgsMasterLayoutInterface::PrintLayout ) const;
125 
135  bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
136 
137  signals:
138 
140  void layoutAboutToBeAdded( const QString &name );
141 
143  void layoutAdded( const QString &name );
144 
146  void layoutRemoved( const QString &name );
147 
149  void layoutAboutToBeRemoved( const QString &name );
150 
152  void layoutRenamed( QgsMasterLayoutInterface *layout, const QString &newName );
153 
154  private:
155 
156  QgsProject *mProject = nullptr;
157 
158  QList< QgsMasterLayoutInterface * > mLayouts;
159 
160 };
161 
162 
172 class CORE_EXPORT QgsLayoutManagerModel : public QAbstractListModel
173 {
174  Q_OBJECT
175 
176  public:
177 
179  enum Role
180  {
181  LayoutRole = Qt::UserRole + 1,
182  };
183 
187  explicit QgsLayoutManagerModel( QgsLayoutManager *manager, QObject *parent SIP_TRANSFERTHIS = nullptr );
188 
189  int rowCount( const QModelIndex &parent ) const override;
190  QVariant data( const QModelIndex &index, int role ) const override;
191  bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
192  Qt::ItemFlags flags( const QModelIndex &index ) const override;
193 
198  QgsMasterLayoutInterface *layoutFromIndex( const QModelIndex &index ) const;
199 
204  QModelIndex indexFromLayout( QgsMasterLayoutInterface *layout ) const;
205 
210  void setAllowEmptyLayout( bool allowEmpty );
211 
216  bool allowEmptyLayout() const { return mAllowEmpty; }
217 
218  private slots:
219  void layoutAboutToBeAdded( const QString &name );
220  void layoutAboutToBeRemoved( const QString &name );
221  void layoutAdded( const QString &name );
222  void layoutRemoved( const QString &name );
223  void layoutRenamed( QgsMasterLayoutInterface *layout, const QString &newName );
224  private:
225  QgsLayoutManager *mLayoutManager = nullptr;
226  bool mAllowEmpty = false;
227 };
228 
229 
238 class CORE_EXPORT QgsLayoutManagerProxyModel : public QSortFilterProxyModel
239 {
240  Q_OBJECT
241 
242  public:
243 
245  enum Filter
246  {
247  FilterPrintLayouts = 1 << 1,
248  FilterReports = 1 << 2,
249  };
250  Q_DECLARE_FLAGS( Filters, Filter )
251  Q_FLAG( Filters )
252 
253 
256  explicit QgsLayoutManagerProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
257  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
258  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
259 
265  QgsLayoutManagerProxyModel::Filters filters() const;
266 
272  void setFilters( QgsLayoutManagerProxyModel::Filters filters );
273 
274  private:
275 
276  Filters mFilters = Filters( FilterPrintLayouts | FilterReports );
277 };
278 
279 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLayoutManagerProxyModel::Filters )
280 
281 #endif // QGSLAYOUTMANAGER_H
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
bool allowEmptyLayout() const
Returns true if the model allows the empty layout ("not set") choice.
Filter
Available filter flags for filtering the model.
An interface for classes which can visit style entity (e.g.
QSortFilterProxyModel subclass for QgsLayoutManagerModel.
List model representing the print layouts and reports available in a layout manager.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Role
Custom model roles.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
Definition: qgsproject.h:89
Manages storage of a set of layouts.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Interface for master layout type objects, such as print layouts and reports.
Individual print layout (QgsPrintLayout)