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 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 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 QVariant value = item->data( Qt::UserRole );
183 mModel->insertRow( selection[0].row() + 1, item->clone() );
186 void QgsProcessingVectorTileWriterLayersPanelWidget::setItemValue( QStandardItem *item,
const QVariant &value )
188 mContext.setProject( mProject );
192 item->setText( titleForLayer( layer ) );
193 item->setData( value, Qt::UserRole );
202 title += tr(
" [zoom %1...%2]" ).arg( layer.
minZoom() ).arg( layer.
maxZoom() );
203 else if ( layer.
minZoom() >= 0 )
204 title += tr(
" [zoom >= %1]" ).arg( layer.
minZoom() );
205 else if ( layer.
maxZoom() >= 0 )
206 title += tr(
" [zoom <= %1]" ).arg( layer.
maxZoom() );
209 title += tr(
" [name: %1]" ).arg( layer.
layerName() );
211 title += tr(
" [with filter]" );
222 QgsProcessingVectorTileWriterLayersWidget::QgsProcessingVectorTileWriterLayersWidget( QWidget *parent )
225 QHBoxLayout *hl =
new QHBoxLayout();
226 hl->setContentsMargins( 0, 0, 0, 0 );
228 mLineEdit =
new QLineEdit();
229 mLineEdit->setEnabled(
false );
230 hl->addWidget( mLineEdit, 1 );
232 mToolButton =
new QToolButton();
233 mToolButton->setText( QString( QChar( 0x2026 ) ) );
234 hl->addWidget( mToolButton );
240 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingVectorTileWriterLayersWidget::showDialog );
243 void QgsProcessingVectorTileWriterLayersWidget::setValue(
const QVariant &value )
245 if ( value.isValid() )
246 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
254 void QgsProcessingVectorTileWriterLayersWidget::setProject(
QgsProject *project )
259 void QgsProcessingVectorTileWriterLayersWidget::showDialog()
264 QgsProcessingVectorTileWriterLayersPanelWidget *widget =
new QgsProcessingVectorTileWriterLayersPanelWidget( mValue, mProject );
265 widget->setPanelTitle( tr(
"Input layers" ) );
266 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
268 setValue( widget->selectedOptions() );
276 dlg.setWindowTitle( tr(
"Input layers" ) );
277 QVBoxLayout *vLayout =
new QVBoxLayout();
278 QgsProcessingVectorTileWriterLayersPanelWidget *widget =
new QgsProcessingVectorTileWriterLayersPanelWidget( mValue, mProject );
279 vLayout->addWidget( widget );
280 widget->buttonBox()->addButton( QDialogButtonBox::Cancel );
281 connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
282 connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
283 dlg.setLayout( vLayout );
286 setValue( widget->selectedOptions() );
291 void QgsProcessingVectorTileWriterLayersWidget::updateSummaryText()
293 mLineEdit->setText( tr(
"%1 vector layers selected" ).arg( mValue.count() ) );
305 QString QgsProcessingVectorTileWriterLayersWidgetWrapper::parameterType()
const
312 return new QgsProcessingVectorTileWriterLayersWidgetWrapper( parameter, type );
315 QWidget *QgsProcessingVectorTileWriterLayersWidgetWrapper::createWidget()
317 mPanel =
new QgsProcessingVectorTileWriterLayersWidget(
nullptr );
318 mPanel->setProject( widgetContext().project() );
319 connect( mPanel, &QgsProcessingVectorTileWriterLayersWidget::changed,
this, [ = ]
321 emit widgetValueHasChanged(
this );
331 mPanel->setProject( context.
project() );
335 void QgsProcessingVectorTileWriterLayersWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
340 mPanel->setValue( value );
344 QVariant QgsProcessingVectorTileWriterLayersWidgetWrapper::widgetValue()
const
346 return mPanel ? mPanel->value() : QVariant();
349 QStringList QgsProcessingVectorTileWriterLayersWidgetWrapper::compatibleParameterTypes()
const
351 return QStringList();
354 QStringList QgsProcessingVectorTileWriterLayersWidgetWrapper::compatibleOutputTypes()
const
356 return QStringList();
void expressionChanged(const QString &expression)
Emitted when the expression is changed.
Contains information about the context in which a processing algorithm is executed.
WidgetType
Types of dialogs which Processing widgets can be created for.
Base class for the definition of processing parameters.
static QgsVectorTileWriter::Layer variantMapAsLayer(const QVariantMap &layerVariantMap, QgsProcessingContext &context)
Converts a QVariant value (a QVariantMap) to a single input layer.
static QVariantMap layerAsVariantMap(const QgsVectorTileWriter::Layer &layer)
Converts a single input layer to QVariant representation (a QVariantMap)
static QString typeName()
Returns the type name for the parameter class.
Contains settings which reflect the context in which a Processing parameter widget is shown,...
QgsProject * project() const
Returns the project associated with the widget.
static QList< QgsVectorLayer * > compatibleVectorLayers(QgsProject *project, const QList< int > &sourceTypes=QList< int >(), bool sort=true)
Returns a list of vector layers from a project which are compatible with the processing framework.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Represents a vector layer which manages a vector based data sets.
Configuration of a single input vector layer to be included in the output.
QString layerName() const
Returns layer name in the output. If not set, layer()->name() will be used.
QgsVectorLayer * layer() const
Returns vector layer of this entry.
void setLayerName(const QString &name)
Sets layer name in the output. If not set, layer()->name() will be used.
void setMaxZoom(int maxzoom)
Sets maximum zoom level at which this layer will be used. Negative value means no max....
void setFilterExpression(const QString &expr)
Sets filter expression. If not empty, only features matching the expression will be used.
void setMinZoom(int minzoom)
Sets minimum zoom level at which this layer will be used. Negative value means no min....
QString filterExpression() const
Returns filter expression. If not empty, only features matching the expression will be used.
int maxZoom() const
Returns maximum zoom level at which this layer will be used. Negative value means no max....
int minZoom() const
Returns minimum zoom level at which this layer will be used. Negative value means no min....