Added set property action to JSON 05/17705/1
authorLee Morgan <lee.morgan@partner.samsung.com>
Tue, 4 Mar 2014 13:25:28 +0000 (13:25 +0000)
committerPaul Wisbey <p.wisbey@samsung.com>
Fri, 7 Mar 2014 14:11:33 +0000 (14:11 +0000)
[Issue#]   N/A
[Problem]  N/A
[Cause]    N/A
[Solution] N/A

Signed-off-by: Paul Wisbey <p.wisbey@samsung.com>
Change-Id: Icdefe5fd1342615c9bb50ad8d3766c555d49fe79

automated-tests/dali-test-suite/builder/utc-Dali-Builder.cpp
dali-toolkit/internal/builder/builder-signals.cpp

index 78a4669..926e85f 100644 (file)
@@ -97,6 +97,15 @@ namespace
       'name':'text',                                           \
       'type':'basic-text',                                     \
       'text':'Hello'                                           \
+    },                                                         \
+    {                                                          \
+      'name':'text2',                                          \
+      'type':'basic-text',                                     \
+      'text':'Hello',                                          \
+      'signals':                                               \
+      [                                                        \
+        { 'name': 'on-stage', 'action':'set', 'actor':'text2', 'property':'text', 'value':'Jaylo' } \
+      ]                                                        \
     }                                                          \
   ],                                                           \
   'other':                                                     \
@@ -183,6 +192,7 @@ static void UtcDaliBuilderTextActorApplyFromStyle();
 static void UtcDaliBuilderStyles();
 static void UtcDaliBuilderAddActorsOther();
 static void UtcDaliBuilderAddActors();
+static void UtcDaliBuilderSetProperty();
 
 enum {
   POSITIVE_TC_IDX = 0x01,
@@ -198,6 +208,7 @@ extern "C" {
     { UtcDaliBuilderStyles, POSITIVE_TC_IDX },
     { UtcDaliBuilderAddActorsOther, POSITIVE_TC_IDX },
     { UtcDaliBuilderAddActors, POSITIVE_TC_IDX },
+    { UtcDaliBuilderSetProperty, POSITIVE_TC_IDX },
     { NULL, 0 }
   };
 }
@@ -391,3 +402,25 @@ static void UtcDaliBuilderStyles()
   DALI_TEST_CHECK( 0.8f == v.Get<float>() );
 
 }
+
+static void UtcDaliBuilderSetProperty()
+{
+  ToolkitTestApplication application;
+
+  tet_infoline(" UtcDaliBuilderSetProperty");
+
+  Builder builder = Builder::New();
+
+  builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
+
+  builder.AddActors( Stage::GetCurrent().GetRootLayer() );
+
+  application.SendNotification();
+  application.Render();
+
+  TextActor actor = TextActor::DownCast( Stage::GetCurrent().GetRootLayer().FindChildByName("text2") );
+
+  DALI_TEST_CHECK( actor );
+  DALI_TEST_CHECK( actor.GetText() == "Jaylo" );
+
+}
index a7ed4c2..edf961f 100644 (file)
@@ -97,7 +97,18 @@ struct PropertySetAction
 
       if( idx != Property::INVALID_INDEX )
       {
-        actor.SetProperty( idx, value );
+        if( actor.GetPropertyType(idx) != value.GetType() )
+        {
+          DALI_SCRIPT_WARNING("Set property action has different type for property '%s'\n", propertyName.c_str());
+        }
+        else
+        {
+          actor.SetProperty( idx, value );
+        }
+      }
+      else
+      {
+        DALI_SCRIPT_WARNING("Set property action cannot find property '%s'\n", propertyName.c_str());
       }
     }
   };
@@ -225,7 +236,7 @@ boost::function<void (void)> GetAction(const TreeNode &root, const TreeNode &chi
   OptionalString childActorName(IsString( IsChild(&child, "child-actor")) );
   OptionalString actorName(IsString( IsChild(&child, "actor")) );
   OptionalString propertyName(IsString( IsChild(&child, "property")) );
-  OptionalString valueChild(IsString( IsChild(&child, "value")) );
+  OptionalChild  valueChild( IsChild(&child, "value") );
 
   OptionalString actionName = IsString( IsChild(&child, "action") );
   DALI_ASSERT_ALWAYS(actionName && "Signal must have an action");
@@ -243,11 +254,16 @@ boost::function<void (void)> GetAction(const TreeNode &root, const TreeNode &chi
   }
   else if(actorName)
   {
-    if(propertyName && valueChild)
+    if(propertyName && valueChild && ("set" == *actionName) )
     {
       PropertySetAction action;
       action.actorName       = *actorName;
       action.propertyName    = *propertyName;
+      // actor may not exist yet so we can't check the property type
+      if( !Dali::Toolkit::Internal::SetPropertyFromNode( *valueChild, action.value ) )
+      {
+        DALI_SCRIPT_WARNING("Cannot set property for set property action\n");
+      }
       callback = action;
     }
     else