QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsprocessingrasteroptionswidgetwrapper.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprocessingrasteroptionswidgetwrapper.cpp
3 ---------------------
4 begin : November 2020
5 copyright : (C) 2020 by Alexander Bruy
6 email : alexander dot bruy at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19
23
24#include <QComboBox>
25#include <QLineEdit>
26
27#include "moc_qgsprocessingrasteroptionswidgetwrapper.cpp"
28
30
31QgsProcessingRasterOptionsWidgetWrapper::QgsProcessingRasterOptionsWidgetWrapper( const QgsProcessingParameterDefinition *parameter, Qgis::ProcessingMode type, QWidget *parent )
32 : QgsAbstractProcessingParameterWidgetWrapper( parameter, type, parent )
33{
34}
35
36QString QgsProcessingRasterOptionsWidgetWrapper::parameterType() const
37{
38 return QStringLiteral( "rasteroptions" );
39}
40
41QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingRasterOptionsWidgetWrapper::createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, Qgis::ProcessingMode type )
42{
43 return new QgsProcessingRasterOptionsWidgetWrapper( parameter, type );
44}
45
46QWidget *QgsProcessingRasterOptionsWidgetWrapper::createWidget()
47{
48 switch ( type() )
49 {
51 {
52 mOptionsWidget = new QgsRasterFormatSaveOptionsWidget();
53 mOptionsWidget->setToolTip( parameterDefinition()->toolTip() );
54 connect( mOptionsWidget, &QgsRasterFormatSaveOptionsWidget::optionsChanged, this, [this] {
55 emit widgetValueHasChanged( this );
56 } );
57 return mOptionsWidget;
58 }
61 {
62 mLineEdit = new QLineEdit();
63 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
64 connect( mLineEdit, &QLineEdit::textChanged, this, [this] {
65 emit widgetValueHasChanged( this );
66 } );
67 return mLineEdit;
68 }
69 }
70
71 return nullptr;
72}
73
74void QgsProcessingRasterOptionsWidgetWrapper::setWidgetValue( const QVariant &value, QgsProcessingContext &context )
75{
76 QString val = QgsProcessingParameters::parameterAsString( parameterDefinition(), value, context );
77
78 if ( mOptionsWidget )
79 {
80 if ( value.isValid() )
81 mOptionsWidget->setOptions( val.replace( '|', ' ' ) );
82 else
83 mOptionsWidget->setOptions( QString() );
84 }
85 else if ( mLineEdit )
86 {
87 if ( value.isValid() )
88 mLineEdit->setText( val );
89 else
90 mLineEdit->clear();
91 }
92}
93
94QVariant QgsProcessingRasterOptionsWidgetWrapper::widgetValue() const
95{
96 if ( mOptionsWidget )
97 {
98 return mOptionsWidget->options().join( '|' );
99 }
100 else if ( mLineEdit )
101 {
102 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
103 }
104 else
105 return QVariant();
106}
107
ProcessingMode
Types of modes which Processing widgets can be created for.
Definition qgis.h:3671
@ Batch
Batch processing mode.
Definition qgis.h:3673
@ Modeler
Modeler mode.
Definition qgis.h:3674
@ Standard
Standard (single-run) algorithm mode.
Definition qgis.h:3672
A widget wrapper for Processing parameter value widgets.
Contains information about the context in which a processing algorithm is executed.
Base class for the definition of processing parameters.
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.
A widget to select format-specific raster saving options.
void optionsChanged()
Emitted when the options configured in the widget are changed.