From: san Date: Fri, 11 May 2012 19:50:06 +0000 (+0000) Subject: value() and setValue() now treat Data Dictionary type correctly instead of ignoring it X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ed0e8511872db1306821d2ea018b75ab53bc9493;p=modules%2Fgui.git value() and setValue() now treat Data Dictionary type correctly instead of ignoring it --- 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