|
25 | 25 | #include "qgspanelwidget.h"
|
26 | 26 |
|
27 | 27 | #include "qgsprocessingcontext.h"
|
28 |
| -#include "qgsvectortilewriter.h" |
| 28 | +#include "qgsprocessingmodelalgorithm.h" |
29 | 29 |
|
30 | 30 | #include "qgsprocessingparameterfieldmap.h"
|
31 | 31 |
|
@@ -178,6 +178,69 @@ void QgsProcessingFieldMapPanelWidget::loadLayerFields()
|
178 | 178 | }
|
179 | 179 | }
|
180 | 180 |
|
| 181 | +// |
| 182 | +// QgsProcessingFieldMapParameterDefinitionWidget |
| 183 | +// |
| 184 | + |
| 185 | +QgsProcessingFieldMapParameterDefinitionWidget::QgsProcessingFieldMapParameterDefinitionWidget( QgsProcessingContext &context, const QgsProcessingParameterWidgetContext &widgetContext, const QgsProcessingParameterDefinition *definition, const QgsProcessingAlgorithm *algorithm, QWidget *parent ) |
| 186 | + : QgsProcessingAbstractParameterDefinitionWidget( context, widgetContext, definition, algorithm, parent ) |
| 187 | +{ |
| 188 | + QVBoxLayout *vlayout = new QVBoxLayout(); |
| 189 | + vlayout->setMargin( 0 ); |
| 190 | + vlayout->setContentsMargins( 0, 0, 0, 0 ); |
| 191 | + |
| 192 | + vlayout->addWidget( new QLabel( tr( "Parent layer" ) ) ); |
| 193 | + |
| 194 | + mParentLayerComboBox = new QComboBox(); |
| 195 | + mParentLayerComboBox->addItem( tr( "None" ), QVariant() ); |
| 196 | + |
| 197 | + QString initialParent; |
| 198 | + if ( const QgsProcessingParameterFieldMapping *mapParam = dynamic_cast<const QgsProcessingParameterFieldMapping *>( definition ) ) |
| 199 | + initialParent = mapParam->parentLayerParameterName(); |
| 200 | + |
| 201 | + if ( widgetContext.model() ) |
| 202 | + { |
| 203 | + // populate combo box with other model input choices |
| 204 | + const QMap<QString, QgsProcessingModelParameter> components = widgetContext.model()->parameterComponents(); |
| 205 | + for ( auto it = components.constBegin(); it != components.constEnd(); ++it ) |
| 206 | + { |
| 207 | + if ( const QgsProcessingParameterFeatureSource *definition = dynamic_cast< const QgsProcessingParameterFeatureSource * >( widgetContext.model()->parameterDefinition( it.value().parameterName() ) ) ) |
| 208 | + { |
| 209 | + mParentLayerComboBox-> addItem( definition->description(), definition->name() ); |
| 210 | + if ( !initialParent.isEmpty() && initialParent == definition->name() ) |
| 211 | + { |
| 212 | + mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 ); |
| 213 | + } |
| 214 | + } |
| 215 | + else if ( const QgsProcessingParameterVectorLayer *definition = dynamic_cast< const QgsProcessingParameterVectorLayer * >( widgetContext.model()->parameterDefinition( it.value().parameterName() ) ) ) |
| 216 | + { |
| 217 | + mParentLayerComboBox-> addItem( definition->description(), definition->name() ); |
| 218 | + if ( !initialParent.isEmpty() && initialParent == definition->name() ) |
| 219 | + { |
| 220 | + mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 ); |
| 221 | + } |
| 222 | + } |
| 223 | + } |
| 224 | + } |
| 225 | + |
| 226 | + if ( mParentLayerComboBox->count() == 1 && !initialParent.isEmpty() ) |
| 227 | + { |
| 228 | + // if no parent candidates found, we just add the existing one as a placeholder |
| 229 | + mParentLayerComboBox->addItem( initialParent, initialParent ); |
| 230 | + mParentLayerComboBox->setCurrentIndex( mParentLayerComboBox->count() - 1 ); |
| 231 | + } |
| 232 | + |
| 233 | + vlayout->addWidget( mParentLayerComboBox ); |
| 234 | + setLayout( vlayout ); |
| 235 | +} |
| 236 | + |
| 237 | +QgsProcessingParameterDefinition *QgsProcessingFieldMapParameterDefinitionWidget::createParameter( const QString &name, const QString &description, QgsProcessingParameterDefinition::Flags flags ) const |
| 238 | +{ |
| 239 | + auto param = qgis::make_unique< QgsProcessingParameterFieldMapping >( name, description, mParentLayerComboBox->currentData().toString() ); |
| 240 | + param->setFlags( flags ); |
| 241 | + return param.release(); |
| 242 | +} |
| 243 | + |
181 | 244 | //
|
182 | 245 | // QgsProcessingFieldMapWidgetWrapper
|
183 | 246 | //
|
@@ -210,6 +273,11 @@ QWidget *QgsProcessingFieldMapWidgetWrapper::createWidget()
|
210 | 273 | return mPanel;
|
211 | 274 | }
|
212 | 275 |
|
| 276 | +QgsProcessingAbstractParameterDefinitionWidget *QgsProcessingFieldMapWidgetWrapper::createParameterDefinitionWidget( QgsProcessingContext &context, const QgsProcessingParameterWidgetContext &widgetContext, const QgsProcessingParameterDefinition *definition, const QgsProcessingAlgorithm *algorithm ) |
| 277 | +{ |
| 278 | + return new QgsProcessingFieldMapParameterDefinitionWidget( context, widgetContext, definition, algorithm ); |
| 279 | +} |
| 280 | + |
213 | 281 | void QgsProcessingFieldMapWidgetWrapper::postInitialize( const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
|
214 | 282 | {
|
215 | 283 | QgsAbstractProcessingParameterWidgetWrapper::postInitialize( wrappers );
|
@@ -318,3 +386,5 @@ const QgsVectorLayer *QgsProcessingFieldMapWidgetWrapper::linkedVectorLayer() co
|
318 | 386 | }
|
319 | 387 |
|
320 | 388 | /// @endcond
|
| 389 | + |
| 390 | + |
0 commit comments