17#include "moc_qgslayertreeembeddedconfigwidget.cpp"
22#include <QStringListModel>
23#include <QStandardItemModel>
36 connect( mBtnAdd, &QAbstractButton::clicked,
this, &QgsLayerTreeEmbeddedConfigWidget::onAddClicked );
37 connect( mBtnRemove, &QAbstractButton::clicked,
this, &QgsLayerTreeEmbeddedConfigWidget::onRemoveClicked );
39 QStandardItemModel *modelAvailable =
new QStandardItemModel(
this );
40 QStandardItemModel *modelUsed =
new QStandardItemModel(
this );
44 for (
const QString &providerId : constProviders )
49 QStandardItem *item =
new QStandardItem( provider->
name() );
50 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
51 item->setData( provider->
id(), Qt::UserRole + 1 );
52 modelAvailable->appendRow( item );
55 mListAvailable->setModel( modelAvailable );
58 const int widgetsCount = layer->
customProperty( QStringLiteral(
"embeddedWidgets/count" ), 0 ).toInt();
59 for (
int i = 0; i < widgetsCount; ++i )
61 const QString providerId = layer->
customProperty( QStringLiteral(
"embeddedWidgets/%1/id" ).arg( i ) ).toString();
64 QStandardItem *item =
new QStandardItem( provider->name() );
65 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
66 item->setData( provider->id(), Qt::UserRole + 1 );
67 modelUsed->appendRow( item );
70 mListUsed->setModel( modelUsed );
73void QgsLayerTreeEmbeddedConfigWidget::onAddClicked()
75 if ( !mListAvailable->currentIndex().isValid() )
78 const QString providerId = mListAvailable->model()->data( mListAvailable->currentIndex(), Qt::UserRole + 1 ).toString();
83 if ( QStandardItemModel *model = qobject_cast<QStandardItemModel *>( mListUsed->model() ) )
85 QStandardItem *item =
new QStandardItem( provider->
name() );
86 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
87 item->setData( provider->
id(), Qt::UserRole + 1 );
88 model->appendRow( item );
92void QgsLayerTreeEmbeddedConfigWidget::onRemoveClicked()
94 if ( !mListUsed->currentIndex().isValid() )
97 const int row = mListUsed->currentIndex().row();
98 mListUsed->model()->removeRow( row );
107 const int widgetsCount = mLayer->
customProperty( QStringLiteral(
"embeddedWidgets/count" ), 0 ).toInt();
108 for (
int i = 0; i < widgetsCount; ++i )
114 const int newCount = mListUsed->model()->rowCount();
115 mLayer->
setCustomProperty( QStringLiteral(
"embeddedWidgets/count" ), newCount );
116 for (
int i = 0; i < newCount; ++i )
118 const QString providerId = mListUsed->model()->data( mListUsed->model()->index( i, 0 ), Qt::UserRole + 1 ).toString();
119 mLayer->
setCustomProperty( QStringLiteral(
"embeddedWidgets/%1/id" ).arg( i ), providerId );
static QgsLayerTreeEmbeddedWidgetRegistry * layerTreeEmbeddedWidgetRegistry()
Returns the global layer tree embedded widget registry, used for registering widgets that may be embe...
Base class for all map layer types.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.