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 );
45 QStandardItem *item =
new QStandardItem( provider->
name() );
46 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
47 item->setData( provider->
id(), Qt::UserRole + 1 );
48 modelAvailable->appendRow( item );
50 mListAvailable->setModel( modelAvailable );
53 int widgetsCount = layer->
customProperty( QStringLiteral(
"embeddedWidgets/count" ), 0 ).toInt();
54 for (
int i = 0; i < widgetsCount; ++i )
56 QString providerId = layer->
customProperty( QStringLiteral(
"embeddedWidgets/%1/id" ).arg( i ) ).toString();
59 QStandardItem *item =
new QStandardItem( provider->name() );
60 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
61 item->setData( provider->id(), Qt::UserRole + 1 );
62 modelUsed->appendRow( item );
65 mListUsed->setModel( modelUsed );
68 void QgsLayerTreeEmbeddedConfigWidget::onAddClicked()
70 if ( !mListAvailable->currentIndex().isValid() )
73 QString providerId = mListAvailable->model()->data( mListAvailable->currentIndex(), Qt::UserRole + 1 ).toString();
78 if ( QStandardItemModel *model = qobject_cast<QStandardItemModel *>( mListUsed->model() ) )
80 QStandardItem *item =
new QStandardItem( provider->
name() );
81 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
82 item->setData( provider->
id(), Qt::UserRole + 1 );
83 model->appendRow( item );
87 void QgsLayerTreeEmbeddedConfigWidget::onRemoveClicked()
89 if ( !mListUsed->currentIndex().isValid() )
92 int row = mListUsed->currentIndex().row();
93 mListUsed->model()->removeRow( row );
102 int widgetsCount = mLayer->
customProperty( QStringLiteral(
"embeddedWidgets/count" ), 0 ).toInt();
103 for (
int i = 0; i < widgetsCount; ++i )
109 int newCount = mListUsed->model()->rowCount();
110 mLayer->
setCustomProperty( QStringLiteral(
"embeddedWidgets/count" ), newCount );
111 for (
int i = 0; i < newCount; ++i )
113 QString providerId = mListUsed->model()->data( mListUsed->model()->index( i, 0 ), Qt::UserRole + 1 ).toString();
114 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.