]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
value() and setValue() now treat Data Dictionary type correctly instead of ignoring it
authorsan <san@opencascade.com>
Fri, 11 May 2012 19:50:06 +0000 (19:50 +0000)
committersan <san@opencascade.com>
Fri, 11 May 2012 19:50:06 +0000 (19:50 +0000)
src/QDS/QDS_Datum.cxx

index ec0b53b48d09d1d5b12996614ce86b26b02e614c..c84d2cf454aa85ee4ed5928167459519fbc0e0fd 100644 (file)
@@ -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