17#include "moc_qgsprocessingvectortilewriterlayerswidgetwrapper.cpp"
23#include <QStandardItemModel>
38QgsProcessingVectorTileWriteLayerDetailsWidget::QgsProcessingVectorTileWriteLayerDetailsWidget(
const QVariant &value,
QgsProject *project )
42 mContext.setProject( project );
45 mLayer = layer.
layer();
50 mSpinMinZoom->setClearValue( -1, tr(
"Not set" ) );
51 mSpinMaxZoom->setClearValue( -1, tr(
"Not set" ) );
52 mEditFilterExpression->setMultiLine(
true );
53 mEditFilterExpression->setLayer( mLayer );
55 mSpinMinZoom->setValue( layer.
minZoom() );
56 mSpinMaxZoom->setValue( layer.
maxZoom() );
57 mEditLayerName->setText( layer.
layerName() );
58 mEditLayerName->setPlaceholderText( mLayer->name() );
67QVariant QgsProcessingVectorTileWriteLayerDetailsWidget::value()
const
82QgsProcessingVectorTileWriterLayersPanelWidget::QgsProcessingVectorTileWriterLayersPanelWidget(
83 const QVariant &value,
87 : QgsProcessingMultipleSelectionPanelWidget( QVariantList(), QVariantList(), parent )
90 connect( listView(), &QListView::doubleClicked,
this, &QgsProcessingVectorTileWriterLayersPanelWidget::configureLayer );
92 QPushButton *configureLayerButton =
new QPushButton( tr(
"Configure Layer…" ) );
93 connect( configureLayerButton, &QPushButton::clicked,
this, &QgsProcessingVectorTileWriterLayersPanelWidget::configureLayer );
94 buttonBox()->addButton( configureLayerButton, QDialogButtonBox::ActionRole );
96 QPushButton *copyLayerButton =
new QPushButton( tr(
"Copy Layer" ) );
97 connect( copyLayerButton, &QPushButton::clicked,
this, &QgsProcessingVectorTileWriterLayersPanelWidget::copyLayer );
98 buttonBox()->addButton( copyLayerButton, QDialogButtonBox::ActionRole );
101 mContext.setProject( project );
103 QSet<const QgsVectorLayer *> seenVectorLayers;
104 const QVariantList valueList = value.toList();
105 for (
const QVariant &v : valueList )
108 if ( !layer.
layer() )
111 addOption( v, titleForLayer( layer ),
true );
113 seenVectorLayers.insert( layer.
layer() );
119 if ( seenVectorLayers.contains( layer ) )
123 vm[
"layer"] = layer->id();
125 const QString title = layer->name();
127 addOption( vm, title,
false );
131void QgsProcessingVectorTileWriterLayersPanelWidget::configureLayer()
133 const QModelIndexList selection = listView()->selectionModel()->selectedIndexes();
134 if ( selection.size() != 1 )
136 QMessageBox::warning(
this, tr(
"Configure Layer" ), tr(
"Please select a single layer." ) );
140 QStandardItem *item = mModel->itemFromIndex( selection[0] );
141 const QVariant value = item->data( Qt::UserRole );
146 QgsProcessingVectorTileWriteLayerDetailsWidget *widget =
new QgsProcessingVectorTileWriteLayerDetailsWidget( value, mProject );
147 widget->setPanelTitle( tr(
"Configure Layer" ) );
148 widget->buttonBox()->hide();
150 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() );
172void 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() );
185void 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]" );
221QgsProcessingVectorTileWriterLayersWidget::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 );
242void QgsProcessingVectorTileWriterLayersWidget::setValue(
const QVariant &value )
244 if ( value.isValid() )
245 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
253void QgsProcessingVectorTileWriterLayersWidget::setProject(
QgsProject *project )
258void QgsProcessingVectorTileWriterLayersWidget::showDialog()
263 QgsProcessingVectorTileWriterLayersPanelWidget *widget =
new QgsProcessingVectorTileWriterLayersPanelWidget( mValue, mProject );
264 widget->setPanelTitle( tr(
"Input layers" ) );
265 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [=]() {
266 setValue( widget->selectedOptions() );
274 dlg.setWindowTitle( tr(
"Input layers" ) );
275 QVBoxLayout *vLayout =
new QVBoxLayout();
276 QgsProcessingVectorTileWriterLayersPanelWidget *widget =
new QgsProcessingVectorTileWriterLayersPanelWidget( mValue, mProject );
277 vLayout->addWidget( widget );
278 widget->buttonBox()->addButton( QDialogButtonBox::Cancel );
279 connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
280 connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
281 dlg.setLayout( vLayout );
284 setValue( widget->selectedOptions() );
289void QgsProcessingVectorTileWriterLayersWidget::updateSummaryText()
291 mLineEdit->setText( tr(
"%n vector layer(s) selected",
nullptr, mValue.count() ) );
303QString QgsProcessingVectorTileWriterLayersWidgetWrapper::parameterType()
const
310 return new QgsProcessingVectorTileWriterLayersWidgetWrapper( parameter, type );
313QWidget *QgsProcessingVectorTileWriterLayersWidgetWrapper::createWidget()
315 mPanel =
new QgsProcessingVectorTileWriterLayersWidget(
nullptr );
316 mPanel->setProject( widgetContext().project() );
317 connect( mPanel, &QgsProcessingVectorTileWriterLayersWidget::changed,
this, [=] {
318 emit widgetValueHasChanged(
this );
328 mPanel->setProject( context.
project() );
332void QgsProcessingVectorTileWriterLayersWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
337 mPanel->setValue( value );
341QVariant QgsProcessingVectorTileWriterLayersWidgetWrapper::widgetValue()
const
343 return mPanel ? mPanel->value() : QVariant();
346QStringList QgsProcessingVectorTileWriterLayersWidgetWrapper::compatibleParameterTypes()
const
348 return QStringList();
351QStringList QgsProcessingVectorTileWriterLayersWidgetWrapper::compatibleOutputTypes()
const
353 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.
void setLayerName(const QString &name)
Sets layer name in the output. If not set, layer()->name() will be used.
QgsVectorLayer * layer() const
Returns vector layer of this entry.
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....