20 #include <QMessageBox>
21 #include <QPushButton>
22 #include <QStandardItemModel>
23 #include <QToolButton>
38 QgsProcessingVectorTileWriteLayerDetailsWidget::QgsProcessingVectorTileWriteLayerDetailsWidget(
const QVariant &value,
QgsProject *project )
46 mLayer = layer.
layer();
51 mSpinMinZoom->setClearValue( -1, tr(
"Not set" ) );
52 mSpinMaxZoom->setClearValue( -1, tr(
"Not set" ) );
53 mEditFilterExpression->setMultiLine(
true );
54 mEditFilterExpression->setLayer( mLayer );
56 mSpinMinZoom->setValue( layer.
minZoom() );
57 mSpinMaxZoom->setValue( layer.
maxZoom() );
58 mEditLayerName->setText( layer.
layerName() );
59 mEditLayerName->setPlaceholderText( mLayer->name() );
68 QVariant QgsProcessingVectorTileWriteLayerDetailsWidget::value()
const
83 QgsProcessingVectorTileWriterLayersPanelWidget::QgsProcessingVectorTileWriterLayersPanelWidget(
84 const QVariant &value,
87 : QgsProcessingMultipleSelectionPanelWidget( QVariantList(), QVariantList(), parent )
91 connect( listView(), &QListView::doubleClicked,
this, &QgsProcessingVectorTileWriterLayersPanelWidget::configureLayer );
93 QPushButton *configureLayerButton =
new QPushButton( tr(
"Configure Layer…" ) );
94 connect( configureLayerButton, &QPushButton::clicked,
this, &QgsProcessingVectorTileWriterLayersPanelWidget::configureLayer );
95 buttonBox()->addButton( configureLayerButton, QDialogButtonBox::ActionRole );
97 QPushButton *copyLayerButton =
new QPushButton( tr(
"Copy Layer" ) );
98 connect( copyLayerButton, &QPushButton::clicked,
this, &QgsProcessingVectorTileWriterLayersPanelWidget::copyLayer );
99 buttonBox()->addButton( copyLayerButton, QDialogButtonBox::ActionRole );
106 QSet<const QgsVectorLayer *> seenVectorLayers;
107 const QVariantList valueList = value.toList();
108 for (
const QVariant &v : valueList )
111 if ( !layer.
layer() )
114 addOption( v, titleForLayer( layer ),
true );
116 seenVectorLayers.insert( layer.
layer() );
122 if ( seenVectorLayers.contains( layer ) )
126 vm[
"layer"] = layer->id();
128 QString title = layer->name();
130 addOption( vm, title,
false );
135 void QgsProcessingVectorTileWriterLayersPanelWidget::configureLayer()
137 const QModelIndexList selection = listView()->selectionModel()->selectedIndexes();
138 if ( selection.size() != 1 )
140 QMessageBox::warning(
this, tr(
"Configure Layer" ), tr(
"Please select a single layer." ) );
144 QStandardItem *item = mModel->itemFromIndex( selection[0] );
145 QVariant value = item->data( Qt::UserRole );
150 QgsProcessingVectorTileWriteLayerDetailsWidget *widget =
new QgsProcessingVectorTileWriteLayerDetailsWidget( value, mProject );
151 widget->setPanelTitle( tr(
"Configure Layer" ) );
152 widget->buttonBox()->hide();
154 connect( widget, &QgsProcessingVectorTileWriteLayerDetailsWidget::widgetChanged,
this, [ = ]()
156 setItemValue( item, widget->value() );
163 dlg.setWindowTitle( tr(
"Configure Layer" ) );
164 QVBoxLayout *vLayout =
new QVBoxLayout();
165 QgsProcessingVectorTileWriteLayerDetailsWidget *widget =
new QgsProcessingVectorTileWriteLayerDetailsWidget( value, mProject );
166 vLayout->addWidget( widget );
167 connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
168 connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
169 dlg.setLayout( vLayout );
172 setItemValue( item, widget->value() );
178 void QgsProcessingVectorTileWriterLayersPanelWidget::copyLayer()
180 const QModelIndexList selection = listView()->selectionModel()->selectedIndexes();
181 if ( selection.size() != 1 )
183 QMessageBox::warning(
this, tr(
"Copy Layer" ), tr(
"Please select a single layer." ) );
187 QStandardItem *item = mModel->itemFromIndex( selection[0] );
188 QVariant value = item->data( Qt::UserRole );
189 mModel->insertRow( selection[0].row() + 1, item->clone() );
192 void QgsProcessingVectorTileWriterLayersPanelWidget::setItemValue( QStandardItem *item,
const QVariant &value )
199 item->setText( titleForLayer( layer ) );
200 item->setData( value, Qt::UserRole );
209 title += tr(
" [zoom %1...%2]" ).arg( layer.
minZoom() ).arg( layer.
maxZoom() );
210 else if ( layer.
minZoom() >= 0 )
211 title += tr(
" [zoom >= %1]" ).arg( layer.
minZoom() );
212 else if ( layer.
maxZoom() >= 0 )
213 title += tr(
" [zoom <= %1]" ).arg( layer.
maxZoom() );
216 title += tr(
" [name: %1]" ).arg( layer.
layerName() );
218 title += tr(
" [with filter]" );
229 QgsProcessingVectorTileWriterLayersWidget::QgsProcessingVectorTileWriterLayersWidget( QWidget *parent )
232 QHBoxLayout *hl =
new QHBoxLayout();
234 hl->setContentsMargins( 0, 0, 0, 0 );
236 mLineEdit =
new QLineEdit();
237 mLineEdit->setEnabled(
false );
238 hl->addWidget( mLineEdit, 1 );
240 mToolButton =
new QToolButton();
241 mToolButton->setText( QString( QChar( 0x2026 ) ) );
242 hl->addWidget( mToolButton );
248 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingVectorTileWriterLayersWidget::showDialog );
251 void QgsProcessingVectorTileWriterLayersWidget::setValue(
const QVariant &value )
253 if ( value.isValid() )
254 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
262 void QgsProcessingVectorTileWriterLayersWidget::setProject(
QgsProject *project )
267 void QgsProcessingVectorTileWriterLayersWidget::showDialog()
272 QgsProcessingVectorTileWriterLayersPanelWidget *widget =
new QgsProcessingVectorTileWriterLayersPanelWidget( mValue, mProject );
273 widget->setPanelTitle( tr(
"Input layers" ) );
274 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
276 setValue( widget->selectedOptions() );
284 dlg.setWindowTitle( tr(
"Input layers" ) );
285 QVBoxLayout *vLayout =
new QVBoxLayout();
286 QgsProcessingVectorTileWriterLayersPanelWidget *widget =
new QgsProcessingVectorTileWriterLayersPanelWidget( mValue, mProject );
287 vLayout->addWidget( widget );
288 widget->buttonBox()->addButton( QDialogButtonBox::Cancel );
289 connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
290 connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
291 dlg.setLayout( vLayout );
294 setValue( widget->selectedOptions() );
299 void QgsProcessingVectorTileWriterLayersWidget::updateSummaryText()
301 mLineEdit->setText( tr(
"%1 vector layers selected" ).arg( mValue.count() ) );
313 QString QgsProcessingVectorTileWriterLayersWidgetWrapper::parameterType()
const
320 return new QgsProcessingVectorTileWriterLayersWidgetWrapper( parameter, type );
323 QWidget *QgsProcessingVectorTileWriterLayersWidgetWrapper::createWidget()
325 mPanel =
new QgsProcessingVectorTileWriterLayersWidget(
nullptr );
326 mPanel->setProject( widgetContext().project() );
327 connect( mPanel, &QgsProcessingVectorTileWriterLayersWidget::changed,
this, [ = ]
329 emit widgetValueHasChanged(
this );
339 mPanel->setProject( context.
project() );
343 void QgsProcessingVectorTileWriterLayersWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
348 mPanel->setValue( value );
352 QVariant QgsProcessingVectorTileWriterLayersWidgetWrapper::widgetValue()
const
354 return mPanel ? mPanel->value() : QVariant();
357 QStringList QgsProcessingVectorTileWriterLayersWidgetWrapper::compatibleParameterTypes()
const
359 return QStringList();
362 QStringList QgsProcessingVectorTileWriterLayersWidgetWrapper::compatibleOutputTypes()
const
364 return QStringList();