20 #include <QMessageBox>
21 #include <QPushButton>
22 #include <QStandardItemModel>
23 #include <QToolButton>
36 QgsProcessingDxfLayerDetailsWidget::QgsProcessingDxfLayerDetailsWidget(
const QVariant &value,
QgsProject *project )
40 mFieldsComboBox->setAllowEmptyFieldName(
true );
42 mContext.setProject( project );
45 mLayer = layer.
layer();
50 mFieldsComboBox->setLayer( mLayer );
56 QVariant QgsProcessingDxfLayerDetailsWidget::value()
const
58 const int index = mLayer->fields().lookupField( mFieldsComboBox->currentField() );
68 QgsProcessingDxfLayersPanelWidget::QgsProcessingDxfLayersPanelWidget(
69 const QVariant &value,
72 : QgsProcessingMultipleSelectionPanelWidget( QVariantList(), QVariantList(), parent )
75 connect( listView(), &QListView::doubleClicked,
this, &QgsProcessingDxfLayersPanelWidget::configureLayer );
77 QPushButton *configureLayerButton =
new QPushButton( tr(
"Configure Layer…" ) );
78 connect( configureLayerButton, &QPushButton::clicked,
this, &QgsProcessingDxfLayersPanelWidget::configureLayer );
79 buttonBox()->addButton( configureLayerButton, QDialogButtonBox::ActionRole );
82 mContext.setProject( project );
84 QSet<const QgsVectorLayer *> seenVectorLayers;
85 const QVariantList valueList = value.toList();
86 for (
const QVariant &v : valueList )
92 addOption( v, titleForLayer( layer ),
true );
93 seenVectorLayers.insert( layer.
layer() );
99 if ( seenVectorLayers.contains( layer ) )
103 vm[
"layer"] = layer->id();
104 vm[
"attributeIndex"] = -1;
106 const QString title = layer->name();
107 addOption( vm, title,
false );
111 void QgsProcessingDxfLayersPanelWidget::configureLayer()
113 const QModelIndexList selection = listView()->selectionModel()->selectedIndexes();
114 if ( selection.size() != 1 )
116 QMessageBox::warning(
this, tr(
"Configure Layer" ), tr(
"Please select a single layer." ) );
120 QStandardItem *item = mModel->itemFromIndex( selection[0] );
121 const QVariant value = item->data( Qt::UserRole );
126 QgsProcessingDxfLayerDetailsWidget *widget =
new QgsProcessingDxfLayerDetailsWidget( value, mProject );
127 widget->setPanelTitle( tr(
"Configure Layer" ) );
128 widget->buttonBox()->hide();
130 connect( widget, &QgsProcessingDxfLayerDetailsWidget::widgetChanged,
this, [ = ]()
132 setItemValue( item, widget->value() );
139 dlg.setWindowTitle( tr(
"Configure Layer" ) );
140 QVBoxLayout *vLayout =
new QVBoxLayout();
141 QgsProcessingDxfLayerDetailsWidget *widget =
new QgsProcessingDxfLayerDetailsWidget( value, mProject );
142 vLayout->addWidget( widget );
143 connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
144 connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
145 dlg.setLayout( vLayout );
148 setItemValue( item, widget->value() );
153 void QgsProcessingDxfLayersPanelWidget::setItemValue( QStandardItem *item,
const QVariant &value )
155 mContext.setProject( mProject );
159 item->setText( titleForLayer( layer ) );
160 item->setData( value, Qt::UserRole );
178 QgsProcessingDxfLayersWidget::QgsProcessingDxfLayersWidget( QWidget *parent )
181 QHBoxLayout *hl =
new QHBoxLayout();
182 hl->setContentsMargins( 0, 0, 0, 0 );
184 mLineEdit =
new QLineEdit();
185 mLineEdit->setEnabled(
false );
186 hl->addWidget( mLineEdit, 1 );
188 mToolButton =
new QToolButton();
189 mToolButton->setText( QString( QChar( 0x2026 ) ) );
190 hl->addWidget( mToolButton );
196 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingDxfLayersWidget::showDialog );
199 void QgsProcessingDxfLayersWidget::setValue(
const QVariant &value )
201 if ( value.isValid() )
202 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
210 void QgsProcessingDxfLayersWidget::setProject(
QgsProject *project )
215 void QgsProcessingDxfLayersWidget::showDialog()
220 QgsProcessingDxfLayersPanelWidget *widget =
new QgsProcessingDxfLayersPanelWidget( mValue, mProject );
221 widget->setPanelTitle( tr(
"Input layers" ) );
222 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
224 setValue( widget->selectedOptions() );
232 dlg.setWindowTitle( tr(
"Input layers" ) );
233 QVBoxLayout *vLayout =
new QVBoxLayout();
234 QgsProcessingDxfLayersPanelWidget *widget =
new QgsProcessingDxfLayersPanelWidget( mValue, mProject );
235 vLayout->addWidget( widget );
236 widget->buttonBox()->addButton( QDialogButtonBox::Cancel );
237 connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
238 connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
239 dlg.setLayout( vLayout );
242 setValue( widget->selectedOptions() );
247 void QgsProcessingDxfLayersWidget::updateSummaryText()
249 mLineEdit->setText( tr(
"%n vector layer(s) selected",
nullptr, mValue.count() ) );
262 QString QgsProcessingDxfLayersWidgetWrapper::parameterType()
const
269 return new QgsProcessingDxfLayersWidgetWrapper( parameter, type );
272 QWidget *QgsProcessingDxfLayersWidgetWrapper::createWidget()
274 mPanel =
new QgsProcessingDxfLayersWidget(
nullptr );
275 mPanel->setProject( widgetContext().project() );
276 connect( mPanel, &QgsProcessingDxfLayersWidget::changed,
this, [ = ]
278 emit widgetValueHasChanged(
this );
288 mPanel->setProject( context.
project() );
292 void QgsProcessingDxfLayersWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
297 mPanel->setValue( value );
301 QVariant QgsProcessingDxfLayersWidgetWrapper::widgetValue()
const
303 return mPanel ? mPanel->value() : QVariant();
306 QStringList QgsProcessingDxfLayersWidgetWrapper::compatibleParameterTypes()
const
317 QStringList QgsProcessingDxfLayersWidgetWrapper::compatibleOutputTypes()
const