25 connect(
this,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutItemComboBox::indexChanged );
30 mProxyModel = qgis::make_unique< QgsLayoutProxyModel >( layout, this );
31 connect( mProxyModel.get(), &QAbstractItemModel::rowsInserted,
this, &QgsLayoutItemComboBox::rowsChanged );
32 connect( mProxyModel.get(), &QAbstractItemModel::rowsRemoved,
this, &QgsLayoutItemComboBox::rowsChanged );
33 setModel( mProxyModel.get() );
35 mProxyModel->sort( 0, Qt::AscendingOrder );
40 if ( !mProxyModel->sourceLayerModel() )
43 QModelIndex idx = mProxyModel->sourceLayerModel()->indexForItem( const_cast< QgsLayoutItem * >( item ) );
46 QModelIndex proxyIdx = mProxyModel->mapFromSource( idx );
47 if ( proxyIdx.isValid() )
49 setCurrentIndex( proxyIdx.row() );
53 setCurrentIndex( -1 );
58 return item( currentIndex() );
61 void QgsLayoutItemComboBox::indexChanged(
int i )
67 void QgsLayoutItemComboBox::rowsChanged()
74 else if ( count() == 0 )
82 mProxyModel->setFilterType( itemType );
87 return mProxyModel->filterType();
92 mProxyModel->setExceptedItemList( exceptList );
97 return mProxyModel->exceptedItemList();
102 const QModelIndex proxyIndex = mProxyModel->index( index, 0 );
103 if ( !proxyIndex.isValid() )
108 QModelIndex sourceIndex = mProxyModel->mapToSource( proxyIndex );
109 if ( !sourceIndex.isValid() )
114 return mProxyModel->itemFromSourceIndex( sourceIndex );
QgsLayoutItemComboBox(QWidget *parent=nullptr, QgsLayout *layout=nullptr)
QgsLayoutItemComboBox creates a combo box to display a list of items in a layout. ...
Base class for graphical items within a QgsLayout.
void setItemType(QgsLayoutItemRegistry::ItemType itemType)
Sets a filter for the item type to show in the combo box.
QgsLayoutItem * currentItem() const
Returns the item currently selected in the combo box.
QgsLayoutItemRegistry::ItemType itemType() const
Returns the filter for the item types to show in the combo box.
void setItem(const QgsLayoutItem *item)
Sets the currently selected item in the combo box.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
QgsLayoutItem * item(int index) const
Returns the item currently shown at the specified index within the combo box.
void itemChanged(QgsLayoutItem *item)
Emitted whenever the currently selected item changes.
void setExceptedItemList(const QList< QgsLayoutItem * > &exceptList)
Sets a list of specific items to exclude from the combo box.
QList< QgsLayoutItem * > exceptedItemList() const
Returns the list of specific items excluded from the combo box.
void setCurrentLayout(QgsLayout *layout)
Sets the layout containing the items to list in the combo box.