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();
233 hl->setContentsMargins( 0, 0, 0, 0 );
235 mLineEdit =
new QLineEdit();
236 mLineEdit->setEnabled(
false );
237 hl->addWidget( mLineEdit, 1 );
239 mToolButton =
new QToolButton();
240 mToolButton->setText( QString( QChar( 0x2026 ) ) );
241 hl->addWidget( mToolButton );
247 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingVectorTileWriterLayersWidget::showDialog );
250 void QgsProcessingVectorTileWriterLayersWidget::setValue(
const QVariant &value )
252 if ( value.isValid() )
253 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
261 void QgsProcessingVectorTileWriterLayersWidget::setProject(
QgsProject *project )
266 void QgsProcessingVectorTileWriterLayersWidget::showDialog()
271 QgsProcessingVectorTileWriterLayersPanelWidget *widget =
new QgsProcessingVectorTileWriterLayersPanelWidget( mValue, mProject );
272 widget->setPanelTitle( tr(
"Input layers" ) );
273 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
275 setValue( widget->selectedOptions() );
283 dlg.setWindowTitle( tr(
"Input layers" ) );
284 QVBoxLayout *vLayout =
new QVBoxLayout();
285 QgsProcessingVectorTileWriterLayersPanelWidget *widget =
new QgsProcessingVectorTileWriterLayersPanelWidget( mValue, mProject );
286 vLayout->addWidget( widget );
287 widget->buttonBox()->addButton( QDialogButtonBox::Cancel );
288 connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
289 connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
290 dlg.setLayout( vLayout );
293 setValue( widget->selectedOptions() );
298 void QgsProcessingVectorTileWriterLayersWidget::updateSummaryText()
300 mLineEdit->setText( tr(
"%1 vector layers selected" ).arg( mValue.count() ) );
312 QString QgsProcessingVectorTileWriterLayersWidgetWrapper::parameterType()
const
319 return new QgsProcessingVectorTileWriterLayersWidgetWrapper( parameter, type );
322 QWidget *QgsProcessingVectorTileWriterLayersWidgetWrapper::createWidget()
324 mPanel =
new QgsProcessingVectorTileWriterLayersWidget(
nullptr );
325 mPanel->setProject( widgetContext().project() );
326 connect( mPanel, &QgsProcessingVectorTileWriterLayersWidget::changed,
this, [ = ]
328 emit widgetValueHasChanged(
this );
338 mPanel->setProject( context.
project() );
342 void QgsProcessingVectorTileWriterLayersWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
347 mPanel->setValue( value );
351 QVariant QgsProcessingVectorTileWriterLayersWidgetWrapper::widgetValue()
const
353 return mPanel ? mPanel->value() : QVariant();
356 QStringList QgsProcessingVectorTileWriterLayersWidgetWrapper::compatibleParameterTypes()
const
358 return QStringList();
361 QStringList QgsProcessingVectorTileWriterLayersWidgetWrapper::compatibleOutputTypes()
const
363 return QStringList();