QGIS API Documentation 3.43.0-Master (e01d6d7c4c0)
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#include "moc_qgsprocessingrasteroptionswidgetwrapper.cpp"
23
24#include <QComboBox>
25#include <QLineEdit>
26
28
29QgsProcessingRasterOptionsWidgetWrapper::QgsProcessingRasterOptionsWidgetWrapper( const QgsProcessingParameterDefinition *parameter, Qgis::ProcessingMode type, QWidget *parent )
30 : QgsAbstractProcessingParameterWidgetWrapper( parameter, type, parent )
31{
32}
33
34QString QgsProcessingRasterOptionsWidgetWrapper::parameterType() const
35{
36 return QStringLiteral( "rasteroptions" );
37}
38
39QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingRasterOptionsWidgetWrapper::createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, Qgis::ProcessingMode type )
40{
41 return new QgsProcessingRasterOptionsWidgetWrapper( parameter, type );
42}
43
44QWidget *QgsProcessingRasterOptionsWidgetWrapper::createWidget()
45{
46 switch ( type() )
47 {
49 {
50 mOptionsWidget = new QgsRasterFormatSaveOptionsWidget();
51 mOptionsWidget->setToolTip( parameterDefinition()->toolTip() );
52 connect( mOptionsWidget, &QgsRasterFormatSaveOptionsWidget::optionsChanged, this, [=] {
53 emit widgetValueHasChanged( this );
54 } );
55 return mOptionsWidget;
56 }
59 {
60 mLineEdit = new QLineEdit();
61 mLineEdit->setToolTip( parameterDefinition()->toolTip() );
62 connect( mLineEdit, &QLineEdit::textChanged, this, [=] {
63 emit widgetValueHasChanged( this );
64 } );
65 return mLineEdit;
66 }
67 }
68
69 return nullptr;
70}
71
72void QgsProcessingRasterOptionsWidgetWrapper::setWidgetValue( const QVariant &value, QgsProcessingContext &context )
73{
74 QString val = QgsProcessingParameters::parameterAsString( parameterDefinition(), value, context );
75
76 if ( mOptionsWidget )
77 {
78 if ( value.isValid() )
79 mOptionsWidget->setOptions( val.replace( '|', ' ' ) );
80 else
81 mOptionsWidget->setOptions( QString() );
82 }
83 else if ( mLineEdit )
84 {
85 if ( value.isValid() )
86 mLineEdit->setText( val );
87 else
88 mLineEdit->clear();
89 }
90}
91
92QVariant QgsProcessingRasterOptionsWidgetWrapper::widgetValue() const
93{
94 if ( mOptionsWidget )
95 {
96 return mOptionsWidget->options().join( '|' );
97 }
98 else if ( mLineEdit )
99 {
100 return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
101 }
102 else
103 return QVariant();
104}
105
ProcessingMode
Types of modes which Processing widgets can be created for.
Definition qgis.h:3537
@ Batch
Batch processing mode.
@ Modeler
Modeler mode.
@ Standard
Standard (single-run) algorithm mode.
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.