21#include "moc_qgslayoutcombobox.cpp"
28 connect(
this,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutComboBox::indexChanged );
34 mModel->deleteLater();
36 mProxyModel->deleteLater();
40 mProxyModel->setSourceModel( mModel );
42 connect( mProxyModel, &QAbstractItemModel::rowsInserted,
this, &QgsLayoutComboBox::rowsChanged );
43 connect( mProxyModel, &QAbstractItemModel::rowsRemoved,
this, &QgsLayoutComboBox::rowsChanged );
44 setModel( mProxyModel );
45 mProxyModel->sort( 0, Qt::AscendingOrder );
50 return mProxyModel->filters();
55 mProxyModel->setFilters(
filters );
60 mModel->setAllowEmptyLayout( allowEmpty );
65 return mModel->allowEmptyLayout();
73 const QModelIndex idx = mModel->indexFromLayout(
layout );
76 const QModelIndex proxyIdx = mProxyModel->mapFromSource( idx );
77 if ( proxyIdx.isValid() )
79 setCurrentIndex( proxyIdx.row() );
88 return layout( currentIndex() );
91void QgsLayoutComboBox::indexChanged(
int i )
97void QgsLayoutComboBox::rowsChanged()
104 else if ( count() == 0 )
112 const QModelIndex proxyIndex = mProxyModel->index( index, 0 );
113 if ( !proxyIndex.isValid() )
118 const QModelIndex sourceIndex = mProxyModel->mapToSource( proxyIndex );
119 if ( !sourceIndex.isValid() )
124 return mModel->layoutFromIndex( sourceIndex );
bool allowEmptyLayout() const
Returns true if the combobox includes the empty layout ("not set") choice.
void setLayoutManager(QgsLayoutManager *manager)
Sets the layout manager containing the layouts to list in the combo box.
void layoutChanged(QgsMasterLayoutInterface *layout)
Emitted whenever the currently selected layout changes.
QgsMasterLayoutInterface * currentLayout() const
Returns the layout currently selected in the combo box.
QgsLayoutComboBox(QWidget *parent=nullptr, QgsLayoutManager *manager=nullptr)
QgsLayoutComboBox creates a combo box to display a list of items in a layout manager.
void setCurrentLayout(QgsMasterLayoutInterface *layout)
Sets the currently selected layout in the combo box.
void setAllowEmptyLayout(bool allowEmpty)
Sets whether an optional empty layout ("not set") option is present in the combobox.
QgsLayoutManagerProxyModel::Filters filters() const
Returns the current filters used for filtering available layouts.
void setFilters(QgsLayoutManagerProxyModel::Filters filters)
Sets the current filters used for filtering available layouts.
QgsMasterLayoutInterface * layout(int index) const
Returns the layout at the specified index.
List model representing the print layouts and reports available in a layout manager.
QSortFilterProxyModel subclass for QgsLayoutManagerModel.
Manages storage of a set of layouts.
Interface for master layout type objects, such as print layouts and reports.