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 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 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 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();
183 hl->setContentsMargins( 0, 0, 0, 0 );
185 mLineEdit =
new QLineEdit();
186 mLineEdit->setEnabled(
false );
187 hl->addWidget( mLineEdit, 1 );
189 mToolButton =
new QToolButton();
190 mToolButton->setText( QString( QChar( 0x2026 ) ) );
191 hl->addWidget( mToolButton );
197 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingDxfLayersWidget::showDialog );
200 void QgsProcessingDxfLayersWidget::setValue(
const QVariant &value )
202 if ( value.isValid() )
203 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
211 void QgsProcessingDxfLayersWidget::setProject(
QgsProject *project )
216 void QgsProcessingDxfLayersWidget::showDialog()
221 QgsProcessingDxfLayersPanelWidget *widget =
new QgsProcessingDxfLayersPanelWidget( mValue, mProject );
222 widget->setPanelTitle( tr(
"Input layers" ) );
223 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
225 setValue( widget->selectedOptions() );
233 dlg.setWindowTitle( tr(
"Input layers" ) );
234 QVBoxLayout *vLayout =
new QVBoxLayout();
235 QgsProcessingDxfLayersPanelWidget *widget =
new QgsProcessingDxfLayersPanelWidget( mValue, mProject );
236 vLayout->addWidget( widget );
237 widget->buttonBox()->addButton( QDialogButtonBox::Cancel );
238 connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
239 connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
240 dlg.setLayout( vLayout );
243 setValue( widget->selectedOptions() );
248 void QgsProcessingDxfLayersWidget::updateSummaryText()
250 mLineEdit->setText( tr(
"%1 vector layers selected" ).arg( mValue.count() ) );
263 QString QgsProcessingDxfLayersWidgetWrapper::parameterType()
const
270 return new QgsProcessingDxfLayersWidgetWrapper( parameter, type );
273 QWidget *QgsProcessingDxfLayersWidgetWrapper::createWidget()
275 mPanel =
new QgsProcessingDxfLayersWidget(
nullptr );
276 mPanel->setProject( widgetContext().project() );
277 connect( mPanel, &QgsProcessingDxfLayersWidget::changed,
this, [ = ]
279 emit widgetValueHasChanged(
this );
289 mPanel->setProject( context.
project() );
293 void QgsProcessingDxfLayersWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
298 mPanel->setValue( value );
302 QVariant QgsProcessingDxfLayersWidgetWrapper::widgetValue()
const
304 return mPanel ? mPanel->value() : QVariant();
307 QStringList QgsProcessingDxfLayersWidgetWrapper::compatibleParameterTypes()
const
318 QStringList QgsProcessingDxfLayersWidgetWrapper::compatibleOutputTypes()
const
void fieldChanged(const QString &fieldName)
Emitted when the currently selected field changes.
Contains information about the context in which a processing algorithm is executed.
WidgetType
Types of dialogs which Processing widgets can be created for.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
Base class for the definition of processing parameters.
static QVariantMap layerAsVariantMap(const QgsDxfExport::DxfLayer &layer)
Converts a single input layer to QVariant representation (a QVariantMap)
static QgsDxfExport::DxfLayer variantMapAsLayer(const QVariantMap &layerVariantMap, QgsProcessingContext &context)
Converts a QVariant value (a QVariantMap) to a single input layer.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
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.
Layers and optional attribute index to split into multiple layers using attribute value as layer name...
QgsVectorLayer * layer() const
Returns the layer.
QString splitLayerAttribute() const
If the split layer attribute is set, the vector layer will be split into several dxf layers,...
int layerOutputAttributeIndex() const
Returns the attribute index used to split into multiple layers.