QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 
280  QString filterString() const { return mFilterString; }
281 
282  public slots:
283 
291  void setFilterString( const QString &filter );
292 
293  private:
294 
295  Filters mFilters = Filters( FilterPrintLayouts | FilterReports );
296 
297  QString mFilterString;
298 };
299 
300 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLayoutManagerProxyModel::Filters )
301 
302 #endif // QGSLAYOUTMANAGER_H
List model representing the print layouts and reports available in a layout manager.
Role
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:99
An interface for classes which can visit style entity (e.g.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.