mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-05 21:53:27 -06:00
#7829 AppEnum : Make sure text used in XML serialization is trimmed
If the AppEnum text used to serialize the AppEnum contains whitespace at start or end, the serialization will fail and the AppEnum value will end up with a default value. This commit will make sure that this field is always trimmed ( text coming from the application, from xml parsing, text from scripting).
This commit is contained in:
parent
4e45f397e8
commit
3af8d32928
@ -191,7 +191,10 @@ private:
|
||||
public:
|
||||
void addItem( T enumVal, const QString& text, QString uiText )
|
||||
{
|
||||
instance()->m_mapping.push_back( Triplet( enumVal, text, uiText ) );
|
||||
// Make sure the text is trimmed, as this text is streamed to XML and will be trimmed when read back from
|
||||
// XML text
|
||||
// https://github.com/OPM/ResInsight/issues/7829
|
||||
instance()->m_mapping.push_back( Triplet( enumVal, text.trimmed(), uiText ) );
|
||||
}
|
||||
|
||||
static EnumMapper* instance()
|
||||
@ -244,7 +247,9 @@ private:
|
||||
size_t idx;
|
||||
for ( idx = 0; idx < m_mapping.size(); ++idx )
|
||||
{
|
||||
if ( text == m_mapping[idx].m_text )
|
||||
// Make sure the text parsed from a text stream is trimmed
|
||||
// https://github.com/OPM/ResInsight/issues/7829
|
||||
if ( text.trimmed() == m_mapping[idx].m_text )
|
||||
{
|
||||
value = m_mapping[idx].m_enumVal;
|
||||
return true;
|
||||
@ -349,7 +354,10 @@ QTextStream& operator>>( QTextStream& str, caf::AppEnum<T>& appEnum )
|
||||
{
|
||||
QString text;
|
||||
str >> text;
|
||||
appEnum.setFromText( text );
|
||||
|
||||
// Make sure the text parsed from a text stream is trimmed
|
||||
// https://github.com/OPM/ResInsight/issues/7829
|
||||
appEnum.setFromText( text.trimmed() );
|
||||
|
||||
return str;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user