17#include "moc_qgsprocessingdxflayerswidgetwrapper.cpp"
23#include <QStandardItemModel>
37QgsProcessingDxfLayerDetailsWidget::QgsProcessingDxfLayerDetailsWidget(
const QVariant &value,
QgsProject *project )
41 mFieldsComboBox->setAllowEmptyFieldName(
true );
43 mContext.setProject( project );
46 mLayer = layer.
layer();
51 mFieldsComboBox->setLayer( mLayer );
61 mGroupBoxBlocks->setVisible(
true );
67 mGroupBoxBlocks->setVisible(
false );
76QVariant QgsProcessingDxfLayerDetailsWidget::value()
const
78 const int index = mLayer->fields().lookupField( mFieldsComboBox->currentField() );
79 const QgsDxfExport::DxfLayer layer( mLayer, index, mGroupBoxBlocks->isChecked(), mSpinBoxBlocks->value(), mOverriddenName->text().trimmed() );
88QgsProcessingDxfLayersPanelWidget::QgsProcessingDxfLayersPanelWidget(
89 const QVariant &value,
93 : QgsProcessingMultipleSelectionPanelWidget( QVariantList(), QVariantList(), parent )
96 connect( listView(), &QListView::doubleClicked,
this, &QgsProcessingDxfLayersPanelWidget::configureLayer );
98 QPushButton *configureLayerButton =
new QPushButton( tr(
"Configure Layer…" ) );
99 connect( configureLayerButton, &QPushButton::clicked,
this, &QgsProcessingDxfLayersPanelWidget::configureLayer );
100 buttonBox()->addButton( configureLayerButton, QDialogButtonBox::ActionRole );
103 mContext.setProject( project );
105 QSet<const QgsVectorLayer *> seenVectorLayers;
106 const QVariantList valueList = value.toList();
107 for (
const QVariant &v : valueList )
110 if ( !layer.
layer() )
113 addOption( v, titleForLayer( layer ),
true );
114 seenVectorLayers.insert( layer.
layer() );
120 if ( seenVectorLayers.contains( layer ) )
124 vm[
"layer"] = layer->id();
125 vm[
"attributeIndex"] = -1;
126 vm[
"overriddenLayerName"] = QString();
127 vm[
"buildDataDefinedBlocks"] = DEFAULT_DXF_DATA_DEFINED_BLOCKS;
128 vm[
"dataDefinedBlocksMaximumNumberOfClasses"] = -1;
130 const QString title = layer->name();
131 addOption( vm, title,
false );
135void QgsProcessingDxfLayersPanelWidget::configureLayer()
137 const QModelIndexList selection = listView()->selectionModel()->selectedIndexes();
138 if ( selection.size() != 1 )
140 QMessageBox::warning(
this, tr(
"Configure Layer" ), tr(
"Please select a single layer." ) );
144 QStandardItem *item = mModel->itemFromIndex( selection[0] );
145 const QVariant value = item->data( Qt::UserRole );
150 QgsProcessingDxfLayerDetailsWidget *widget =
new QgsProcessingDxfLayerDetailsWidget( value, mProject );
151 widget->setPanelTitle( tr(
"Configure Layer" ) );
152 widget->buttonBox()->hide();
154 connect( widget, &QgsProcessingDxfLayerDetailsWidget::widgetChanged,
this, [=]() {
155 setItemValue( item, widget->value() );
162 dlg.setWindowTitle( tr(
"Configure Layer" ) );
163 QVBoxLayout *vLayout =
new QVBoxLayout();
164 QgsProcessingDxfLayerDetailsWidget *widget =
new QgsProcessingDxfLayerDetailsWidget( value, mProject );
165 vLayout->addWidget( widget );
166 connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
167 connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
168 dlg.setLayout( vLayout );
171 setItemValue( item, widget->value() );
176void QgsProcessingDxfLayersPanelWidget::setItemValue( QStandardItem *item,
const QVariant &value )
178 mContext.setProject( mProject );
182 item->setText( titleForLayer( layer ) );
183 item->setData( value, Qt::UserRole );
200 title += tr(
" [overridden name: %1]" ).arg( layer.
overriddenName() );
212QgsProcessingDxfLayersWidget::QgsProcessingDxfLayersWidget( QWidget *parent )
215 QHBoxLayout *hl =
new QHBoxLayout();
216 hl->setContentsMargins( 0, 0, 0, 0 );
218 mLineEdit =
new QLineEdit();
219 mLineEdit->setEnabled(
false );
220 hl->addWidget( mLineEdit, 1 );
222 mToolButton =
new QToolButton();
223 mToolButton->setText( QString( QChar( 0x2026 ) ) );
224 hl->addWidget( mToolButton );
230 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingDxfLayersWidget::showDialog );
233void QgsProcessingDxfLayersWidget::setValue(
const QVariant &value )
235 if ( value.isValid() )
236 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
244void QgsProcessingDxfLayersWidget::setProject(
QgsProject *project )
249void QgsProcessingDxfLayersWidget::showDialog()
254 QgsProcessingDxfLayersPanelWidget *widget =
new QgsProcessingDxfLayersPanelWidget( mValue, mProject );
255 widget->setPanelTitle( tr(
"Input layers" ) );
256 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [=]() {
257 setValue( widget->selectedOptions() );
265 dlg.setWindowTitle( tr(
"Input layers" ) );
266 QVBoxLayout *vLayout =
new QVBoxLayout();
267 QgsProcessingDxfLayersPanelWidget *widget =
new QgsProcessingDxfLayersPanelWidget( mValue, mProject );
268 vLayout->addWidget( widget );
269 widget->buttonBox()->addButton( QDialogButtonBox::Cancel );
270 connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
271 connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
272 dlg.setLayout( vLayout );
275 setValue( widget->selectedOptions() );
280void QgsProcessingDxfLayersWidget::updateSummaryText()
282 mLineEdit->setText( tr(
"%n vector layer(s) selected",
nullptr, mValue.count() ) );
295QString QgsProcessingDxfLayersWidgetWrapper::parameterType()
const
302 return new QgsProcessingDxfLayersWidgetWrapper( parameter, type );
305QWidget *QgsProcessingDxfLayersWidgetWrapper::createWidget()
307 mPanel =
new QgsProcessingDxfLayersWidget(
nullptr );
308 mPanel->setProject( widgetContext().project() );
309 connect( mPanel, &QgsProcessingDxfLayersWidget::changed,
this, [=] {
310 emit widgetValueHasChanged(
this );
320 mPanel->setProject( context.
project() );
324void QgsProcessingDxfLayersWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
329 mPanel->setValue( value );
333QVariant QgsProcessingDxfLayersWidgetWrapper::widgetValue()
const
335 return mPanel ? mPanel->value() : QVariant();
338QStringList QgsProcessingDxfLayersWidgetWrapper::compatibleParameterTypes()
const
349QStringList QgsProcessingDxfLayersWidgetWrapper::compatibleOutputTypes()
const
@ VectorAnyGeometry
Any vector layer with geometry.
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...
QString overriddenName() const
Returns the overridden layer name to be used in the exported DXF.
bool buildDataDefinedBlocks() const
Flag if data defined point block symbols should be created.
QgsVectorLayer * layer() const
Returns the layer.
int dataDefinedBlocksMaximumNumberOfClasses() const
Returns the maximum number of data defined symbol classes for which blocks are created.
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.