QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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
QgsLayoutManager
Manages storage of a set of layouts.
Definition: qgslayoutmanager.h:44
QgsLayoutManagerModel::Role
Role
Custom model roles.
Definition: qgslayoutmanager.h:179
QgsLayoutManagerProxyModel::filterString
QString filterString() const
Returns the current filter string, if set.
Definition: qgslayoutmanager.h:280
QgsLayoutManagerProxyModel::Filter
Filter
Available filter flags for filtering the model.
Definition: qgslayoutmanager.h:245
QgsStyleEntityVisitorInterface
Definition: qgsstyleentityvisitor.h:33
QgsLayoutManagerModel::allowEmptyLayout
bool allowEmptyLayout() const
Returns true if the model allows the empty layout ("not set") choice.
Definition: qgslayoutmanager.h:216
QgsMasterLayoutInterface::PrintLayout
@ PrintLayout
Individual print layout (QgsPrintLayout)
Definition: qgsmasterlayoutinterface.h:68
QgsProject
Definition: qgsproject.h:92
QgsPrintLayout
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Definition: qgsprintlayout.h:30
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsMasterLayoutInterface::Type
Type
Master layout type.
Definition: qgsmasterlayoutinterface.h:66
QgsLayoutManagerModel
Definition: qgslayoutmanager.h:172
qgsmasterlayoutinterface.h
QgsLayoutManagerProxyModel
Definition: qgslayoutmanager.h:238
QgsMasterLayoutInterface
Interface for master layout type objects, such as print layouts and reports.
Definition: qgsmasterlayoutinterface.h:42
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53