From ed0e8511872db1306821d2ea018b75ab53bc9493 Mon Sep 17 00:00:00 2001 From: san Date: Fri, 11 May 2012 19:50:06 +0000 Subject: [PATCH] value() and setValue() now treat Data Dictionary type correctly instead of ignoring it --- src/QDS/QDS_Datum.cxx | 58 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/src/QDS/QDS_Datum.cxx b/src/QDS/QDS_Datum.cxx index ec0b53b48..c84d2cf45 100644 --- a/src/QDS/QDS_Datum.cxx +++ b/src/QDS/QDS_Datum.cxx @@ -551,8 +551,29 @@ int QDS_Datum::optionInteger( const QString& name ) const QVariant QDS_Datum::value() const { QVariant val; - if ( !isEmpty() ) - val = stringValue(); + // trying to return QVariant containing value of correct data type + if ( dicItem().IsNull() ) + { + if ( !isEmpty() ) + val = stringValue(); + } + else + { + switch( type() ) + { + case DDS_DicItem::Float: + val = doubleValue(); + break; + case DDS_DicItem::Integer: + case DDS_DicItem::List: + val = integerValue(); + break; + case DDS_DicItem::String: + case DDS_DicItem::Unknown: + val = stringValue(); + break; + } + } return val; } @@ -698,6 +719,39 @@ void QDS_Datum::clear() */ void QDS_Datum::setValue( const QVariant& val ) { + // trying to extract data of correct type from QVariant + if ( !dicItem().IsNull() ) + { + bool isOk = false; + switch( type() ) + { + case DDS_DicItem::Float: + { + double aDblVal = val.toDouble( &isOk ); + if ( isOk ) + { + setDoubleValue( aDblVal ); + return; + } + break; + } + case DDS_DicItem::Integer: + case DDS_DicItem::List: + { + int anIntVal = val.toInt( &isOk ); + if ( isOk ) + { + setIntegerValue( anIntVal ); + return; + } + break; + } + case DDS_DicItem::String: + case DDS_DicItem::Unknown: + break; + } + } + if ( val.isValid() && val.canConvert( QVariant::String ) ) setStringValue( val.toString() ); else -- 2.39.2