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 );
47 QStandardItem *item =
new QStandardItem( provider->
name() );
48 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
49 item->setData( provider->
id(), Qt::UserRole + 1 );
50 modelAvailable->appendRow( item );
53 mListAvailable->setModel( modelAvailable );
56 int widgetsCount = layer->
customProperty( QStringLiteral(
"embeddedWidgets/count" ), 0 ).toInt();
57 for (
int i = 0; i < widgetsCount; ++i )
59 QString providerId = layer->
customProperty( QStringLiteral(
"embeddedWidgets/%1/id" ).arg( i ) ).toString();
62 QStandardItem *item =
new QStandardItem( provider->name() );
63 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
64 item->setData( provider->id(), Qt::UserRole + 1 );
65 modelUsed->appendRow( item );
68 mListUsed->setModel( modelUsed );
71 void QgsLayerTreeEmbeddedConfigWidget::onAddClicked()
73 if ( !mListAvailable->currentIndex().isValid() )
76 QString providerId = mListAvailable->model()->data( mListAvailable->currentIndex(), Qt::UserRole + 1 ).toString();
81 if ( QStandardItemModel *model = qobject_cast<QStandardItemModel *>( mListUsed->model() ) )
83 QStandardItem *item =
new QStandardItem( provider->
name() );
84 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
85 item->setData( provider->
id(), Qt::UserRole + 1 );
86 model->appendRow( item );
90 void QgsLayerTreeEmbeddedConfigWidget::onRemoveClicked()
92 if ( !mListUsed->currentIndex().isValid() )
95 int row = mListUsed->currentIndex().row();
96 mListUsed->model()->removeRow( row );
105 int widgetsCount = mLayer->
customProperty( QStringLiteral(
"embeddedWidgets/count" ), 0 ).toInt();
106 for (
int i = 0; i < widgetsCount; ++i )
112 int newCount = mListUsed->model()->rowCount();
113 mLayer->
setCustomProperty( QStringLiteral(
"embeddedWidgets/count" ), newCount );
114 for (
int i = 0; i < newCount; ++i )
116 QString providerId = mListUsed->model()->data( mListUsed->model()->index( i, 0 ), Qt::UserRole + 1 ).toString();
117 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.