29 connect(
this,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutItemComboBox::indexChanged );
34 const bool prevAllowEmpty = mProxyModel && mProxyModel->allowEmptyItem();
35 const int itemType = mProxyModel ? mProxyModel->filterType() : -1;
36 mProxyModel = std::make_unique< QgsLayoutProxyModel >( layout,
this );
37 connect( mProxyModel.get(), &QAbstractItemModel::rowsInserted,
this, &QgsLayoutItemComboBox::rowsChanged );
38 connect( mProxyModel.get(), &QAbstractItemModel::rowsRemoved,
this, &QgsLayoutItemComboBox::rowsChanged );
39 setModel( mProxyModel.get() );
42 mProxyModel->setAllowEmptyItem( prevAllowEmpty );
49 return mProxyModel->layout();
54 if ( !mProxyModel->sourceLayerModel() )
57 const QModelIndex idx = mProxyModel->sourceLayerModel()->indexForItem(
const_cast< QgsLayoutItem *
>(
item ) );
60 const QModelIndex proxyIdx = mProxyModel->mapFromSource( idx );
61 if ( proxyIdx.isValid() )
63 setCurrentIndex( proxyIdx.row() );
67 setCurrentIndex( mProxyModel->allowEmptyItem() ? 0 : -1 );
72 return item( currentIndex() );
75 void QgsLayoutItemComboBox::indexChanged(
int i )
81 void QgsLayoutItemComboBox::rowsChanged()
88 else if ( count() == 0 )
96 mProxyModel->setFilterType(
itemType );
101 return mProxyModel->filterType();
106 mProxyModel->setExceptedItemList( exceptList );
111 return mProxyModel->exceptedItemList();
116 mProxyModel->setAllowEmptyItem( allowEmpty );
121 return mProxyModel->allowEmptyItem();
126 mProxyModel->setItemFlags( flags );
131 return mProxyModel->itemFlags();
136 const QModelIndex proxyIndex = mProxyModel->index( index, 0 );
137 if ( !proxyIndex.isValid() )
142 const QModelIndex sourceIndex = mProxyModel->mapToSource( proxyIndex );
143 if ( !sourceIndex.isValid() )
148 return mProxyModel->itemFromSourceIndex( sourceIndex );