2026-05-30 10:16:07 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2026 Equinor ASA
|
|
|
|
|
//
|
|
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
//
|
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "RimWorkflowStringBinding.h"
|
|
|
|
|
|
2026-10-26 14:19:29 +01:00
|
|
|
#include "RimWorkflowSchemaTools.h"
|
|
|
|
|
|
2026-05-30 10:16:07 +02:00
|
|
|
#include <QJsonObject>
|
|
|
|
|
|
|
|
|
|
CAF_PDM_SOURCE_INIT( RimWorkflowStringBinding, "WorkflowStringBinding" );
|
|
|
|
|
|
2026-10-05 16:12:01 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2026-05-30 10:16:07 +02:00
|
|
|
RimWorkflowStringBinding::RimWorkflowStringBinding()
|
|
|
|
|
{
|
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_value, "Value", "Value" );
|
2026-10-26 14:19:29 +01:00
|
|
|
|
|
|
|
|
// Untyped (Any) fields read the text as a literal, see RimWorkflowSchemaTools::literalFromText
|
|
|
|
|
CAF_PDM_InitField( &m_isLiteral, "IsLiteral", false, "Is Literal" );
|
|
|
|
|
m_isLiteral.uiCapability()->setUiHidden( true );
|
2026-05-30 10:16:07 +02:00
|
|
|
}
|
|
|
|
|
|
2026-10-05 16:12:01 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2026-05-30 10:16:07 +02:00
|
|
|
void RimWorkflowStringBinding::applySchema( const QJsonObject& fieldSchema )
|
|
|
|
|
{
|
2026-10-26 14:19:29 +01:00
|
|
|
// A binding without a field name is new, and its default is a typed value
|
|
|
|
|
const bool isNew = m_fieldName().isEmpty();
|
2026-05-30 10:16:07 +02:00
|
|
|
RimWorkflowFieldBinding::applySchema( fieldSchema );
|
2026-10-26 14:19:29 +01:00
|
|
|
|
|
|
|
|
const bool wasLiteral = m_isLiteral();
|
|
|
|
|
m_isLiteral = fieldSchema.value( "type" ).toString() == "any";
|
|
|
|
|
if ( m_isLiteral() )
|
|
|
|
|
{
|
|
|
|
|
QString toolTip = fieldSchema.value( "description" ).toString();
|
|
|
|
|
if ( !toolTip.isEmpty() ) toolTip += "\n\n";
|
|
|
|
|
toolTip += "Any value: true, false, a number, null (None) or JSON. Other text is a string; quote it to keep \"true\" as text.";
|
|
|
|
|
m_value.uiCapability()->setUiToolTip( toolTip );
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-30 10:16:07 +02:00
|
|
|
if ( fieldSchema.contains( "default" ) )
|
|
|
|
|
{
|
2026-10-26 14:19:29 +01:00
|
|
|
const QJsonValue value = fieldSchema.value( "default" );
|
|
|
|
|
if ( !m_isLiteral() )
|
|
|
|
|
m_value = value.toString();
|
|
|
|
|
else if ( value.isNull() )
|
|
|
|
|
{
|
|
|
|
|
// Only an entered None is a value; a model default of None leaves the field unset
|
|
|
|
|
const bool entered = fieldSchema.value( RimWorkflowSchemaTools::explicitNullKey() ).toBool();
|
|
|
|
|
m_value = entered ? RimWorkflowSchemaTools::textFromLiteral( value ) : QString();
|
|
|
|
|
setHasValue( entered );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// The text of an existing binding that did not read literals is kept, and now read as a
|
|
|
|
|
// literal. Typed values (input.yaml, model defaults, detached values) keep their type.
|
|
|
|
|
const bool legacyText = !isNew && !wasLiteral && value.isString();
|
|
|
|
|
m_value = legacyText ? value.toString() : RimWorkflowSchemaTools::textFromLiteral( value );
|
|
|
|
|
}
|
2026-05-30 10:16:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-05 16:12:01 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2026-10-02 13:13:27 +02:00
|
|
|
QJsonValue RimWorkflowStringBinding::toJsonValue() const
|
2026-05-30 10:16:07 +02:00
|
|
|
{
|
2026-10-26 14:19:29 +01:00
|
|
|
if ( !hasValue() ) return QJsonValue( QJsonValue::Null );
|
|
|
|
|
return m_isLiteral() ? RimWorkflowSchemaTools::literalFromText( m_value() ) : QJsonValue( m_value() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
bool RimWorkflowStringBinding::isExplicitNull() const
|
|
|
|
|
{
|
|
|
|
|
return hasValue() && m_isLiteral() && !m_value().trimmed().isEmpty() && toJsonValue().isNull();
|
2026-05-30 10:16:07 +02:00
|
|
|
}
|