Skip to content
Permalink
Browse files
[processing] Re-work the duration parameter so it _always_ returns mi…
…lliseconds, make default unit type a GUI helper only
  • Loading branch information
nirvn authored and nyalldawson committed Sep 6, 2021
1 parent 54e7e33 commit 85c5ad6c2a103824e1e2e96f89c1ad35dc464f29
@@ -1324,7 +1324,6 @@ QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingDurationWidgetWrapper:
QWidget *QgsProcessingDurationWidgetWrapper::createWidget()
{
const QgsProcessingParameterDuration *durationDef = static_cast< const QgsProcessingParameterDuration * >( parameterDefinition() );
mBaseUnit = durationDef->defaultUnit();

QWidget *spin = QgsProcessingNumericWidgetWrapper::createWidget();
switch ( type() )
@@ -1348,7 +1347,7 @@ QWidget *QgsProcessingDurationWidgetWrapper::createWidget()
layout->setContentsMargins( 0, 0, 0, 0 );
w->setLayout( layout );

mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( mBaseUnit ) );
mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( durationDef->defaultUnit() ) );
mUnitsCombo->show();

return w;
@@ -1368,8 +1367,7 @@ QLabel *QgsProcessingDurationWidgetWrapper::createLabel()

if ( type() == QgsProcessingGui::Modeler )
{
const QgsProcessingParameterDuration *durationDef = static_cast< const QgsProcessingParameterDuration * >( parameterDefinition() );
label->setText( QStringLiteral( "%1 [%2]" ).arg( label->text(), QgsUnitTypes::toString( durationDef->defaultUnit() ) ) );
label->setText( QStringLiteral( "%1 [%2]" ).arg( label->text(), QgsUnitTypes::toString( mBaseUnit ) ) );
}

return label;
@@ -1389,6 +1387,20 @@ QVariant QgsProcessingDurationWidgetWrapper::widgetValue() const
}
}

void QgsProcessingDurationWidgetWrapper::setWidgetValue( const QVariant &value, QgsProcessingContext &context )
{
if ( mUnitsCombo )
{
QgsUnitTypes::TemporalUnit displayUnit = static_cast<QgsUnitTypes::TemporalUnit >( mUnitsCombo->currentData().toInt() );
const QVariant val = value.toDouble() * QgsUnitTypes::fromUnitToUnitFactor( mBaseUnit, displayUnit );
QgsProcessingNumericWidgetWrapper::setWidgetValue( val, context );
}
else
{
QgsProcessingNumericWidgetWrapper::setWidgetValue( value, context );
}
}

QgsProcessingAbstractParameterDefinitionWidget *QgsProcessingDurationWidgetWrapper::createParameterDefinitionWidget( QgsProcessingContext &context, const QgsProcessingParameterWidgetContext &widgetContext, const QgsProcessingParameterDefinition *definition, const QgsProcessingAlgorithm *algorithm )
{
return new QgsProcessingDurationParameterDefinitionWidget( context, widgetContext, definition, algorithm );
@@ -444,6 +444,7 @@ class GUI_EXPORT QgsProcessingDurationWidgetWrapper : public QgsProcessingNumeri
protected:

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

private:

0 comments on commit 85c5ad6

Please sign in to comment.