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