20 #include <QMessageBox>
21 #include <QPushButton>
22 #include <QStandardItemModel>
23 #include <QToolButton>
37 QgsProcessingVectorTileWriteLayerDetailsWidget::QgsProcessingVectorTileWriteLayerDetailsWidget(
const QVariant &value,
QgsProject *project )
41 mContext.setProject( project );
44 mLayer = layer.
layer();
49 mSpinMinZoom->setClearValue( -1, tr(
"Not set" ) );
50 mSpinMaxZoom->setClearValue( -1, tr(
"Not set" ) );
51 mEditFilterExpression->setMultiLine(
true );
52 mEditFilterExpression->setLayer( mLayer );
54 mSpinMinZoom->setValue( layer.
minZoom() );
55 mSpinMaxZoom->setValue( layer.
maxZoom() );
56 mEditLayerName->setText( layer.
layerName() );
57 mEditLayerName->setPlaceholderText( mLayer->name() );
66 QVariant QgsProcessingVectorTileWriteLayerDetailsWidget::value()
const
81 QgsProcessingVectorTileWriterLayersPanelWidget::QgsProcessingVectorTileWriterLayersPanelWidget(
82 const QVariant &value,
85 : QgsProcessingMultipleSelectionPanelWidget( QVariantList(), QVariantList(), parent )
89 connect( listView(), &QListView::doubleClicked,
this, &QgsProcessingVectorTileWriterLayersPanelWidget::configureLayer );
91 QPushButton *configureLayerButton =
new QPushButton( tr(
"Configure Layer…" ) );
92 connect( configureLayerButton, &QPushButton::clicked,
this, &QgsProcessingVectorTileWriterLayersPanelWidget::configureLayer );
93 buttonBox()->addButton( configureLayerButton, QDialogButtonBox::ActionRole );
95 QPushButton *copyLayerButton =
new QPushButton( tr(
"Copy Layer" ) );
96 connect( copyLayerButton, &QPushButton::clicked,
this, &QgsProcessingVectorTileWriterLayersPanelWidget::copyLayer );
97 buttonBox()->addButton( copyLayerButton, QDialogButtonBox::ActionRole );
100 mContext.setProject( project );
102 QSet<const QgsVectorLayer *> seenVectorLayers;
103 const QVariantList valueList = value.toList();
104 for (
const QVariant &v : valueList )
107 if ( !layer.
layer() )
110 addOption( v, titleForLayer( layer ),
true );
112 seenVectorLayers.insert( layer.
layer() );
118 if ( seenVectorLayers.contains( layer ) )
122 vm[
"layer"] = layer->id();
124 const QString title = layer->name();
126 addOption( vm, title,
false );
130 void QgsProcessingVectorTileWriterLayersPanelWidget::configureLayer()
132 const QModelIndexList selection = listView()->selectionModel()->selectedIndexes();
133 if ( selection.size() != 1 )
135 QMessageBox::warning(
this, tr(
"Configure Layer" ), tr(
"Please select a single layer." ) );
139 QStandardItem *item = mModel->itemFromIndex( selection[0] );
140 const QVariant value = item->data( Qt::UserRole );
145 QgsProcessingVectorTileWriteLayerDetailsWidget *widget =
new QgsProcessingVectorTileWriteLayerDetailsWidget( value, mProject );
146 widget->setPanelTitle( tr(
"Configure Layer" ) );
147 widget->buttonBox()->hide();
149 connect( widget, &QgsProcessingVectorTileWriteLayerDetailsWidget::widgetChanged,
this, [ = ]()
151 setItemValue( item, widget->value() );
158 dlg.setWindowTitle( tr(
"Configure Layer" ) );
159 QVBoxLayout *vLayout =
new QVBoxLayout();
160 QgsProcessingVectorTileWriteLayerDetailsWidget *widget =
new QgsProcessingVectorTileWriteLayerDetailsWidget( value, mProject );
161 vLayout->addWidget( widget );
162 connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
163 connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
164 dlg.setLayout( vLayout );
167 setItemValue( item, widget->value() );
172 void QgsProcessingVectorTileWriterLayersPanelWidget::copyLayer()
174 const QModelIndexList selection = listView()->selectionModel()->selectedIndexes();
175 if ( selection.size() != 1 )
177 QMessageBox::warning(
this, tr(
"Copy Layer" ), tr(
"Please select a single layer." ) );
181 QStandardItem *item = mModel->itemFromIndex( selection[0] );
182 mModel->insertRow( selection[0].row() + 1, item->clone() );
185 void QgsProcessingVectorTileWriterLayersPanelWidget::setItemValue( QStandardItem *item,
const QVariant &value )
187 mContext.setProject( mProject );
191 item->setText( titleForLayer( layer ) );
192 item->setData( value, Qt::UserRole );
201 title += tr(
" [zoom %1...%2]" ).arg( layer.
minZoom() ).arg( layer.
maxZoom() );
202 else if ( layer.
minZoom() >= 0 )
203 title += tr(
" [zoom >= %1]" ).arg( layer.
minZoom() );
204 else if ( layer.
maxZoom() >= 0 )
205 title += tr(
" [zoom <= %1]" ).arg( layer.
maxZoom() );
208 title += tr(
" [name: %1]" ).arg( layer.
layerName() );
210 title += tr(
" [with filter]" );
221 QgsProcessingVectorTileWriterLayersWidget::QgsProcessingVectorTileWriterLayersWidget( QWidget *parent )
224 QHBoxLayout *hl =
new QHBoxLayout();
225 hl->setContentsMargins( 0, 0, 0, 0 );
227 mLineEdit =
new QLineEdit();
228 mLineEdit->setEnabled(
false );
229 hl->addWidget( mLineEdit, 1 );
231 mToolButton =
new QToolButton();
232 mToolButton->setText( QString( QChar( 0x2026 ) ) );
233 hl->addWidget( mToolButton );
239 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingVectorTileWriterLayersWidget::showDialog );
242 void QgsProcessingVectorTileWriterLayersWidget::setValue(
const QVariant &value )
244 if ( value.isValid() )
245 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
253 void QgsProcessingVectorTileWriterLayersWidget::setProject(
QgsProject *project )
258 void QgsProcessingVectorTileWriterLayersWidget::showDialog()
263 QgsProcessingVectorTileWriterLayersPanelWidget *widget =
new QgsProcessingVectorTileWriterLayersPanelWidget( mValue, mProject );
264 widget->setPanelTitle( tr(
"Input layers" ) );
265 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
267 setValue( widget->selectedOptions() );
275 dlg.setWindowTitle( tr(
"Input layers" ) );
276 QVBoxLayout *vLayout =
new QVBoxLayout();
277 QgsProcessingVectorTileWriterLayersPanelWidget *widget =
new QgsProcessingVectorTileWriterLayersPanelWidget( mValue, mProject );
278 vLayout->addWidget( widget );
279 widget->buttonBox()->addButton( QDialogButtonBox::Cancel );
280 connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
281 connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
282 dlg.setLayout( vLayout );
285 setValue( widget->selectedOptions() );
290 void QgsProcessingVectorTileWriterLayersWidget::updateSummaryText()
292 mLineEdit->setText( tr(
"%n vector layer(s) selected",
nullptr, mValue.count() ) );
304 QString QgsProcessingVectorTileWriterLayersWidgetWrapper::parameterType()
const
311 return new QgsProcessingVectorTileWriterLayersWidgetWrapper( parameter, type );
314 QWidget *QgsProcessingVectorTileWriterLayersWidgetWrapper::createWidget()
316 mPanel =
new QgsProcessingVectorTileWriterLayersWidget(
nullptr );
317 mPanel->setProject( widgetContext().project() );
318 connect( mPanel, &QgsProcessingVectorTileWriterLayersWidget::changed,
this, [ = ]
320 emit widgetValueHasChanged(
this );
330 mPanel->setProject( context.
project() );
334 void QgsProcessingVectorTileWriterLayersWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
339 mPanel->setValue( value );
343 QVariant QgsProcessingVectorTileWriterLayersWidgetWrapper::widgetValue()
const
345 return mPanel ? mPanel->value() : QVariant();
348 QStringList QgsProcessingVectorTileWriterLayersWidgetWrapper::compatibleParameterTypes()
const
350 return QStringList();
353 QStringList QgsProcessingVectorTileWriterLayersWidgetWrapper::compatibleOutputTypes()
const
355 return QStringList();