Don't allow name-less parameters

This commit is contained in:
Nyall Dawson 2019-07-01 10:56:20 +10:00
parent 8e3287a7ee
commit 074c584c54
5 changed files with 22 additions and 3 deletions

View File

@ -142,6 +142,10 @@ Returns a new instance of a parameter definition, using the current settings def
The ``name`` parameter specifies the name for the newly created parameter.
%End
public slots:
virtual void accept();
};

View File

@ -28,6 +28,7 @@
#include <QCheckBox>
#include <QDialog>
#include <QDialogButtonBox>
#include <QMessageBox>
QgsProcessingAbstractParameterDefinitionWidget::QgsProcessingAbstractParameterDefinitionWidget( QgsProcessingContext &,
const QgsProcessingParameterWidgetContext &,
@ -147,3 +148,14 @@ QgsProcessingParameterDefinition *QgsProcessingParameterDefinitionDialog::create
{
return mWidget->createParameter( name );
}
void QgsProcessingParameterDefinitionDialog::accept()
{
if ( mWidget->mDescriptionLineEdit->text().isEmpty() )
{
QMessageBox::warning( this, tr( "Unable to define parameter" ),
tr( "Invalid parameter name" ) );
return;
}
QDialog::accept();
}

View File

@ -122,6 +122,8 @@ class GUI_EXPORT QgsProcessingParameterDefinitionWidget: public QWidget
QCheckBox *mRequiredCheckBox = nullptr;
QCheckBox *mAdvancedCheckBox = nullptr;
friend class QgsProcessingParameterDefinitionDialog;
};
/**
@ -165,6 +167,9 @@ class GUI_EXPORT QgsProcessingParameterDefinitionDialog: public QDialog
*/
QgsProcessingParameterDefinition *createParameter( const QString &name = QString() ) const SIP_FACTORY;
public slots:
void accept() override;
private:
QgsProcessingParameterDefinitionWidget *mWidget = nullptr;

View File

@ -1888,8 +1888,6 @@ QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingEnumWidgetWrapper::cre
return new QgsProcessingEnumWidgetWrapper( parameter, type );
}
//
// QgsProcessingLayoutWidgetWrapper
//

View File

@ -3206,7 +3206,7 @@ void TestProcessingGui::testColorWrapper()
QCOMPARE( def->description(), QStringLiteral( "test desc" ) );
QVERIFY( def->flags() & QgsProcessingParameterDefinition::FlagOptional );
QVERIFY( def->flags() & QgsProcessingParameterDefinition::FlagAdvanced );
QCOMPARE( static_cast< QgsProcessingParameterColor * >( def.get() )->defaultValue().value< QColor >(), QColor( 255, 0, 0 ) );
QCOMPARE( static_cast< QgsProcessingParameterColor * >( def.get() )->defaultValue().value< QColor >(), QColor( 255, 0, 0 ) ); // (no opacity!)
QVERIFY( !static_cast< QgsProcessingParameterColor * >( def.get() )->opacityEnabled() );
}