QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
qgslayoutmanagermodel.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutmanagermodel.cpp
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
17
18#include "qgslayoutmanager.h"
19#include "qgsproject.h"
20
21#include <QMessageBox>
22
23#include "moc_qgslayoutmanagermodel.cpp"
24
25//
26// QgsLayoutManagerModel
27//
28
30 : QgsProjectStoredObjectManagerModel( manager, parent )
31{
32 connect( manager, &QgsLayoutManager::layoutRenamed, this, &QgsLayoutManagerModel::objectRenamedInternal );
33}
34
36{
37 return objectFromIndex( index );
38}
39
41{
42 return indexFromObject( layout );
43}
44
46{
47 setAllowEmptyObject( allowEmpty );
48}
49
50
51//
52// QgsLayoutManagerProxyModel
53//
54
59
60bool QgsLayoutManagerProxyModel::filterAcceptsRowInternal( int sourceRow, const QModelIndex &sourceParent ) const
61{
63 return false;
64
65 QgsLayoutManagerModel *model = qobject_cast< QgsLayoutManagerModel * >( sourceModel() );
66 if ( !model )
67 return false;
68
69 QgsMasterLayoutInterface *layout = model->layoutFromIndex( model->index( sourceRow, 0, sourceParent ) );
70 if ( !layout )
71 return model->allowEmptyLayout();
72
73 // clang-tidy false positive
74 // NOLINTBEGIN(bugprone-branch-clone)
75 switch ( layout->layoutType() )
76 {
78 return mFilters & FilterPrintLayouts;
80 return mFilters & FilterReports;
81 }
82 // NOLINTEND(bugprone-branch-clone)
83 return false;
84}
85
90
92{
93 mFilters = filters;
94 invalidateFilter();
95}
List model representing the print layouts and reports available in a layout manager.
QModelIndex indexFromLayout(QgsMasterLayoutInterface *layout) const
Returns the model index corresponding to a layout.
QgsMasterLayoutInterface * layoutFromIndex(const QModelIndex &index) const
Returns the layout at the corresponding index.
void setAllowEmptyLayout(bool allowEmpty)
Sets whether an optional empty layout ("not set") option is present in the model.
bool allowEmptyLayout() const
Returns true if the model allows the empty layout ("not set") choice.
QgsLayoutManagerModel(QgsLayoutManager *manager, QObject *parent=nullptr)
Constructor for QgsLayoutManagerModel, showing the layouts from the specified manager.
void setFilters(QgsLayoutManagerProxyModel::Filters filters)
Sets the current filters used for filtering available layouts.
QgsLayoutManagerProxyModel::Filters filters() const
Returns the current filters used for filtering available layouts.
@ FilterPrintLayouts
Includes print layouts.
QgsLayoutManagerProxyModel(QObject *parent=nullptr)
Constructor for QgsLayoutManagerProxyModel.
bool filterAcceptsRowInternal(int sourceRow, const QModelIndex &sourceParent) const override
Returns true if the proxy accepts the matching source row.
Manages storage of a set of layouts.
void layoutRenamed(QgsMasterLayoutInterface *layout, const QString &newName)
Emitted when a layout is renamed.
Interface for master layout type objects, such as print layouts and reports.
virtual QgsMasterLayoutInterface::Type layoutType() const =0
Returns the master layout type.
@ PrintLayout
Individual print layout (QgsPrintLayout).
QgsMasterLayoutInterface * objectFromIndex(const QModelIndex &index) const
QgsProjectStoredObjectManagerModel(QgsAbstractProjectStoredObjectManager< QgsMasterLayoutInterface > *manager, QObject *parent=nullptr)
bool filterAcceptsRowInternal(int sourceRow, const QModelIndex &sourceParent) const override
Returns true if the proxy accepts the matching source row.