21 #include <QStringListModel> 22 #include <QStandardItemModel> 35 connect( mBtnAdd, &QAbstractButton::clicked,
this, &QgsLayerTreeEmbeddedConfigWidget::onAddClicked );
36 connect( mBtnRemove, &QAbstractButton::clicked,
this, &QgsLayerTreeEmbeddedConfigWidget::onRemoveClicked );
38 QStandardItemModel *modelAvailable =
new QStandardItemModel(
this );
39 QStandardItemModel *modelUsed =
new QStandardItemModel(
this );
43 for (
const QString &providerId : constProviders )
48 QStandardItem *item =
new QStandardItem( provider->
name() );
49 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
50 item->setData( provider->
id(), Qt::UserRole + 1 );
51 modelAvailable->appendRow( item );
54 mListAvailable->setModel( modelAvailable );
57 int widgetsCount = layer->
customProperty( QStringLiteral(
"embeddedWidgets/count" ), 0 ).toInt();
58 for (
int i = 0; i < widgetsCount; ++i )
60 QString providerId = layer->
customProperty( QStringLiteral(
"embeddedWidgets/%1/id" ).arg( i ) ).toString();
63 QStandardItem *item =
new QStandardItem( provider->name() );
64 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
65 item->setData( provider->id(), Qt::UserRole + 1 );
66 modelUsed->appendRow( item );
69 mListUsed->setModel( modelUsed );
72 void QgsLayerTreeEmbeddedConfigWidget::onAddClicked()
74 if ( !mListAvailable->currentIndex().isValid() )
77 QString providerId = mListAvailable->model()->data( mListAvailable->currentIndex(), Qt::UserRole + 1 ).toString();
82 if ( QStandardItemModel *model = qobject_cast<QStandardItemModel *>( mListUsed->model() ) )
84 QStandardItem *item =
new QStandardItem( provider->
name() );
85 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
86 item->setData( provider->
id(), Qt::UserRole + 1 );
87 model->appendRow( item );
91 void QgsLayerTreeEmbeddedConfigWidget::onRemoveClicked()
93 if ( !mListUsed->currentIndex().isValid() )
96 int row = mListUsed->currentIndex().row();
97 mListUsed->model()->removeRow( row );
106 int widgetsCount = mLayer->
customProperty( QStringLiteral(
"embeddedWidgets/count" ), 0 ).toInt();
107 for (
int i = 0; i < widgetsCount; ++i )
113 int newCount = mListUsed->model()->rowCount();
114 mLayer->
setCustomProperty( QStringLiteral(
"embeddedWidgets/count" ), newCount );
115 for (
int i = 0; i < newCount; ++i )
117 QString providerId = mListUsed->model()->data( mListUsed->model()->index( i, 0 ), Qt::UserRole + 1 ).toString();
118 mLayer->
setCustomProperty( QStringLiteral(
"embeddedWidgets/%1/id" ).arg( i ), providerId );
Base class for all map layer types.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
static QgsLayerTreeEmbeddedWidgetRegistry * layerTreeEmbeddedWidgetRegistry()
Returns the global layer tree embedded widget registry, used for registering widgets that may be embe...
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.