QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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;
28 
43 class 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 
125  signals:
126 
128  void layoutAboutToBeAdded( const QString &name );
129 
131  void layoutAdded( const QString &name );
132 
134  void layoutRemoved( const QString &name );
135 
137  void layoutAboutToBeRemoved( const QString &name );
138 
140  void layoutRenamed( QgsMasterLayoutInterface *layout, const QString &newName );
141 
142  private:
143 
144  QgsProject *mProject = nullptr;
145 
146  QList< QgsMasterLayoutInterface * > mLayouts;
147 
148 };
149 
150 
160 class CORE_EXPORT QgsLayoutManagerModel : public QAbstractListModel
161 {
162  Q_OBJECT
163 
164  public:
165 
167  enum Role
168  {
169  LayoutRole = Qt::UserRole + 1,
170  };
171 
175  explicit QgsLayoutManagerModel( QgsLayoutManager *manager, QObject *parent SIP_TRANSFERTHIS = nullptr );
176 
177  int rowCount( const QModelIndex &parent ) const override;
178  QVariant data( const QModelIndex &index, int role ) const override;
179  bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
180  Qt::ItemFlags flags( const QModelIndex &index ) const override;
181 
186  QgsMasterLayoutInterface *layoutFromIndex( const QModelIndex &index ) const;
187 
192  QModelIndex indexFromLayout( QgsMasterLayoutInterface *layout ) const;
193 
198  void setAllowEmptyLayout( bool allowEmpty );
199 
204  bool allowEmptyLayout() const { return mAllowEmpty; }
205 
206  private slots:
207  void layoutAboutToBeAdded( const QString &name );
208  void layoutAboutToBeRemoved( const QString &name );
209  void layoutAdded( const QString &name );
210  void layoutRemoved( const QString &name );
211  void layoutRenamed( QgsMasterLayoutInterface *layout, const QString &newName );
212  private:
213  QgsLayoutManager *mLayoutManager = nullptr;
214  bool mAllowEmpty = false;
215 };
216 
217 
226 class CORE_EXPORT QgsLayoutManagerProxyModel : public QSortFilterProxyModel
227 {
228  Q_OBJECT
229 
230  public:
231 
233  enum Filter
234  {
235  FilterPrintLayouts = 1 << 1,
236  FilterReports = 1 << 2,
237  };
238  Q_DECLARE_FLAGS( Filters, Filter )
239  Q_FLAG( Filters )
240 
241 
244  explicit QgsLayoutManagerProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
245  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
246  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
247 
253  QgsLayoutManagerProxyModel::Filters filters() const;
254 
260  void setFilters( QgsLayoutManagerProxyModel::Filters filters );
261 
262  private:
263 
264  Filters mFilters = Filters( FilterPrintLayouts | FilterReports );
265 };
266 
267 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLayoutManagerProxyModel::Filters )
268 
269 #endif // QGSLAYOUTMANAGER_H
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
bool allowEmptyLayout() const
Returns true if the model allows the empty layout ("not set") choice.
Filter
Available filter flags for filtering the model.
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.
Reads and writes project states.
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)