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,
92 : QgsProcessingMultipleSelectionPanelWidget( QVariantList(), QVariantList(), parent )
95 connect( listView(), &QListView::doubleClicked,
this, &QgsProcessingDxfLayersPanelWidget::configureLayer );
97 QPushButton *configureLayerButton =
new QPushButton( tr(
"Configure Layer…" ) );
98 connect( configureLayerButton, &QPushButton::clicked,
this, &QgsProcessingDxfLayersPanelWidget::configureLayer );
99 buttonBox()->addButton( configureLayerButton, QDialogButtonBox::ActionRole );
102 mContext.setProject( project );
104 QSet<const QgsVectorLayer *> seenVectorLayers;
105 const QVariantList valueList = value.toList();
106 for (
const QVariant &v : valueList )
109 if ( !layer.
layer() )
112 addOption( v, titleForLayer( layer ),
true );
113 seenVectorLayers.insert( layer.
layer() );
119 if ( seenVectorLayers.contains( layer ) )
123 vm[
"layer"] = layer->id();
124 vm[
"attributeIndex"] = -1;
125 vm[
"overriddenLayerName"] = QString();
126 vm[
"buildDataDefinedBlocks"] = DEFAULT_DXF_DATA_DEFINED_BLOCKS;
127 vm[
"dataDefinedBlocksMaximumNumberOfClasses"] = -1;
129 const QString title = layer->name();
130 addOption( vm, title,
false );
134void QgsProcessingDxfLayersPanelWidget::configureLayer()
136 const QModelIndexList selection = listView()->selectionModel()->selectedIndexes();
137 if ( selection.size() != 1 )
139 QMessageBox::warning(
this, tr(
"Configure Layer" ), tr(
"Please select a single layer." ) );
143 QStandardItem *item = mModel->itemFromIndex( selection[0] );
144 const QVariant value = item->data( Qt::UserRole );
149 QgsProcessingDxfLayerDetailsWidget *widget =
new QgsProcessingDxfLayerDetailsWidget( value, mProject );
150 widget->setPanelTitle( tr(
"Configure Layer" ) );
151 widget->buttonBox()->hide();
153 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, [ = ]()
258 setValue( widget->selectedOptions() );
266 dlg.setWindowTitle( tr(
"Input layers" ) );
267 QVBoxLayout *vLayout =
new QVBoxLayout();
268 QgsProcessingDxfLayersPanelWidget *widget =
new QgsProcessingDxfLayersPanelWidget( mValue, mProject );
269 vLayout->addWidget( widget );
270 widget->buttonBox()->addButton( QDialogButtonBox::Cancel );
271 connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
272 connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
273 dlg.setLayout( vLayout );
276 setValue( widget->selectedOptions() );
281void QgsProcessingDxfLayersWidget::updateSummaryText()
283 mLineEdit->setText( tr(
"%n vector layer(s) selected",
nullptr, mValue.count() ) );
296QString QgsProcessingDxfLayersWidgetWrapper::parameterType()
const
303 return new QgsProcessingDxfLayersWidgetWrapper( parameter, type );
306QWidget *QgsProcessingDxfLayersWidgetWrapper::createWidget()
308 mPanel =
new QgsProcessingDxfLayersWidget(
nullptr );
309 mPanel->setProject( widgetContext().project() );
310 connect( mPanel, &QgsProcessingDxfLayersWidget::changed,
this, [ = ]
312 emit widgetValueHasChanged(
this );
322 mPanel->setProject( context.
project() );
326void QgsProcessingDxfLayersWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
331 mPanel->setValue( value );
335QVariant QgsProcessingDxfLayersWidgetWrapper::widgetValue()
const
337 return mPanel ? mPanel->value() : QVariant();
340QStringList QgsProcessingDxfLayersWidgetWrapper::compatibleParameterTypes()
const
351QStringList 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.