Skip to content
Permalink
Browse files

[processing] Port string widget wrapper to new c++ class

  • Loading branch information
nyalldawson committed Sep 5, 2018
1 parent e10d16e commit f79d86edabcc5e78eb711805848dcd8be77bb713
@@ -28,6 +28,7 @@ QgsProcessingGuiRegistry::QgsProcessingGuiRegistry()
addAlgorithmConfigurationWidgetFactory( new QgsFilterAlgorithmConfigurationWidgetFactory() );

addParameterWidgetFactory( new QgsProcessingBooleanWidgetWrapper() );
addParameterWidgetFactory( new QgsProcessingStringWidgetWrapper() );
}

QgsProcessingGuiRegistry::~QgsProcessingGuiRegistry()
@@ -22,6 +22,8 @@
#include <QHBoxLayout>
#include <QCheckBox>
#include <QComboBox>
#include <QLineEdit>
#include <QPlainTextEdit>

///@cond PRIVATE

@@ -120,18 +122,25 @@ QVariant QgsProcessingBooleanWidgetWrapper::widgetValue() const

QStringList QgsProcessingBooleanWidgetWrapper::compatibleParameterTypes() const
{
//pretty much everything is compatible here and can be converted to a bool!
return QStringList() << QgsProcessingParameterBoolean::typeName()
<< QgsProcessingParameterString::typeName()
<< QgsProcessingParameterNumber::typeName()
<< QgsProcessingParameterDistance::typeName()
<< QgsProcessingParameterFile::typeName()
<< QgsProcessingParameterField::typeName()
<< QgsProcessingParameterFeatureSource::typeName()
<< QgsProcessingParameterMapLayer::typeName()
<< QgsProcessingParameterRasterLayer::typeName()
<< QgsProcessingParameterVectorLayer::typeName();
<< QgsProcessingParameterVectorLayer::typeName()
<< QgsProcessingParameterExpression::typeName();
}

QStringList QgsProcessingBooleanWidgetWrapper::compatibleOutputTypes() const
{
return QStringList() << QgsProcessingOutputNumber::typeName()
<< QgsProcessingOutputMapLayer::typeName()
<< QgsProcessingOutputFile::typeName()
<< QgsProcessingOutputRasterLayer::typeName()
<< QgsProcessingOutputVectorLayer::typeName()
<< QgsProcessingOutputString::typeName();
@@ -144,7 +153,7 @@ QList<int> QgsProcessingBooleanWidgetWrapper::compatibleDataTypes() const

QString QgsProcessingBooleanWidgetWrapper::parameterType() const
{
return QStringLiteral( "boolean" );
return QgsProcessingParameterBoolean::typeName();
}

QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingBooleanWidgetWrapper::createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type )
@@ -153,4 +162,114 @@ QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingBooleanWidgetWrapper::
}



//
// QgsProcessingStringWidgetWrapper
//

QgsProcessingStringWidgetWrapper::QgsProcessingStringWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type, QWidget *parent )
: QgsAbstractProcessingParameterWidgetWrapper( parameter, type, parent )
{

}

QWidget *QgsProcessingStringWidgetWrapper::createWidget()
{
switch ( type() )
{
case QgsProcessingGui::Standard:
case QgsProcessingGui::Modeler:
{
if ( static_cast< const QgsProcessingParameterString * >( parameterDefinition() )->multiLine() )
{
mPlainTextEdit = new QPlainTextEdit();
mPlainTextEdit->setToolTip( parameterDefinition()->toolTip() );

connect( mPlainTextEdit, &QPlainTextEdit::textChanged, this, [ = ]
{
emit widgetValueHasChanged( this );
} );
return mPlainTextEdit;
}
else
{
mLineEdit = new QLineEdit();
mLineEdit->setToolTip( parameterDefinition()->toolTip() );

connect( mLineEdit, &QLineEdit::textChanged, this, [ = ]
{
emit widgetValueHasChanged( this );
} );
return mLineEdit;
}
};

case QgsProcessingGui::Batch:
{
mLineEdit = new QLineEdit();
mLineEdit->setToolTip( parameterDefinition()->toolTip() );

connect( mLineEdit, &QLineEdit::textChanged, this, [ = ]
{
emit widgetValueHasChanged( this );
} );
return mLineEdit;
}
}
return nullptr;
}

void QgsProcessingStringWidgetWrapper::setWidgetValue( const QVariant &value, const QgsProcessingContext &context )
{
const QString v = QgsProcessingParameters::parameterAsString( parameterDefinition(), value, context );
if ( mLineEdit )
mLineEdit->setText( v );
if ( mPlainTextEdit )
mPlainTextEdit->setPlainText( v );
}

QVariant QgsProcessingStringWidgetWrapper::widgetValue() const
{
if ( mLineEdit )
return mLineEdit->text();
else if ( mPlainTextEdit )
return mPlainTextEdit->toPlainText();
else
return QVariant();
}

QStringList QgsProcessingStringWidgetWrapper::compatibleParameterTypes() const
{
return QStringList()
<< QgsProcessingParameterString::typeName()
<< QgsProcessingParameterNumber::typeName()
<< QgsProcessingParameterDistance::typeName()
<< QgsProcessingParameterFile::typeName()
<< QgsProcessingParameterField::typeName()
<< QgsProcessingParameterExpression::typeName();
}

QStringList QgsProcessingStringWidgetWrapper::compatibleOutputTypes() const
{
return QStringList() << QgsProcessingOutputNumber::typeName()
<< QgsProcessingOutputFile::typeName()
<< QgsProcessingOutputString::typeName();
}

QList<int> QgsProcessingStringWidgetWrapper::compatibleDataTypes() const
{
return QList< int >();
}

QString QgsProcessingStringWidgetWrapper::parameterType() const
{
return QgsProcessingParameterString::typeName();
}

QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingStringWidgetWrapper::createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type )
{
return new QgsProcessingStringWidgetWrapper( parameter, type );
}


///@endcond PRIVATE
@@ -24,6 +24,9 @@

class QCheckBox;
class QComboBox;
class QLineEdit;
class QPlainTextEdit;


///@cond PRIVATE

@@ -63,6 +66,43 @@ class GUI_EXPORT QgsProcessingBooleanWidgetWrapper : public QgsAbstractProcessin
friend class TestProcessingGui;
};


class GUI_EXPORT QgsProcessingStringWidgetWrapper : public QgsAbstractProcessingParameterWidgetWrapper, public QgsProcessingParameterWidgetFactoryInterface
{
Q_OBJECT

public:

QgsProcessingStringWidgetWrapper( const QgsProcessingParameterDefinition *parameter = nullptr,
QgsProcessingGui::WidgetType type = QgsProcessingGui::Standard, QWidget *parent = nullptr );

// QgsProcessingParameterWidgetFactoryInterface
QString parameterType() const override;
QgsAbstractProcessingParameterWidgetWrapper *createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type ) override;

// QgsProcessingParameterWidgetWrapper interface
QWidget *createWidget() override SIP_FACTORY;

protected:

void setWidgetValue( const QVariant &value, const QgsProcessingContext &context ) override;
QVariant widgetValue() const override;

QStringList compatibleParameterTypes() const override;

QStringList compatibleOutputTypes() const override;

QList< int > compatibleDataTypes() const override;

private:

QLineEdit *mLineEdit = nullptr;
QPlainTextEdit *mPlainTextEdit = nullptr;

friend class TestProcessingGui;
};


///@endcond PRIVATE

#endif // QGSPROCESSINGWIDGETWRAPPERIMPL_H

0 comments on commit f79d86e

Please sign in to comment.
You can’t perform that action at this time.