Ability to retrieve all the property values of a handle 02/209402/2
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 5 Jul 2019 10:48:07 +0000 (11:48 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 5 Jul 2019 14:36:48 +0000 (15:36 +0100)
Change-Id: I74987e9a0b4619fcbcce52e2888083bd2caafdb4

automated-tests/src/dali/utc-Dali-Handle.cpp
dali/devel-api/object/handle-devel.cpp
dali/devel-api/object/handle-devel.h
dali/internal/event/common/object-impl.cpp
dali/internal/event/common/object-impl.h

index ec92ffa..57a9b78 100644 (file)
@@ -1715,3 +1715,64 @@ int UtcDaliHandleTemplateNew(void)
 
   END_TEST;
 }
+
+int UtcDaliHandleGetProperties(void)
+{
+  TestApplication application;
+
+  Handle handle = Actor::New();
+  DevelHandle::SetProperties(
+    handle,
+    Property::Map
+    {
+      { Actor::Property::SIZE, Vector3( 400.0f, 200.0f, 100.0f ) },
+      { Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER },
+      { Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER },
+      { Actor::Property::NAME, "Actor" },
+      { Actor::Property::LEAVE_REQUIRED, true },
+      { "color", Color::RED },
+    }
+  );
+
+  Property::Map map;
+  DevelHandle::GetProperties( handle, map );
+
+  // Get all the properties and ensure they match
+
+  DALI_TEST_EQUALS( handle.GetPropertyCount(), map.Count(), TEST_LOCATION );
+
+  for( auto position = 0u; position < map.Count(); ++position )
+  {
+    auto keyValuePair = map.GetKeyValue( position );
+    const auto& index = keyValuePair.first.indexKey;
+    const auto& value = keyValuePair.second;
+    auto handleValue = handle.GetProperty( index );
+
+    switch( value.GetType() )
+    {
+      case Property::NONE:       break;
+      case Property::BOOLEAN:    DALI_TEST_EQUALS( value.Get< bool >(), handleValue.Get< bool >(), TEST_LOCATION ); break;
+      case Property::FLOAT:      DALI_TEST_EQUALS( value.Get< float >(), handleValue.Get< float >(), TEST_LOCATION ); break;
+      case Property::INTEGER:    DALI_TEST_EQUALS( value.Get< int >(), handleValue.Get< int >(), TEST_LOCATION ); break;
+      case Property::VECTOR2:    DALI_TEST_EQUALS( value.Get< Vector2 >(), handleValue.Get< Vector2 >(), TEST_LOCATION ); break;
+      case Property::VECTOR3:    DALI_TEST_EQUALS( value.Get< Vector3 >(), handleValue.Get< Vector3 >(), TEST_LOCATION ); break;
+      case Property::VECTOR4:    DALI_TEST_EQUALS( value.Get< Vector4 >(), handleValue.Get< Vector4 >(), TEST_LOCATION ); break;
+      case Property::MATRIX3:    DALI_TEST_EQUALS( value.Get< Matrix3 >(), handleValue.Get< Matrix3 >(), TEST_LOCATION ); break;
+      case Property::MATRIX:     DALI_TEST_EQUALS( value.Get< Matrix >(), handleValue.Get< Matrix >(), TEST_LOCATION ); break;
+      case Property::RECTANGLE:  DALI_TEST_EQUALS( value.Get< Rect< int > >(), handleValue.Get< Rect< int > >(), TEST_LOCATION ); break;
+      case Property::ROTATION:   DALI_TEST_EQUALS( value.Get< Quaternion >(), handleValue.Get< Quaternion >(), TEST_LOCATION ); break;
+      case Property::STRING:     DALI_TEST_EQUALS( value.Get< std::string >(), handleValue.Get< std::string >(), TEST_LOCATION ); break;
+      case Property::ARRAY:      DALI_TEST_EQUALS( value.GetArray()->Count(), handleValue.GetArray()->Count(), TEST_LOCATION ); break;
+      case Property::MAP:        DALI_TEST_EQUALS( value.GetMap()->Count(), handleValue.GetMap()->Count(), TEST_LOCATION ); break;
+      case Property::EXTENTS:    DALI_TEST_EQUALS( value.Get< Extents >(), handleValue.Get< Extents >(), TEST_LOCATION ); break;
+    }
+  }
+
+  // Add a custom property and ensure the count goes up by one.
+  const auto countBefore = map.Count();
+  handle.RegisterProperty( "tempProperty", Color::GREEN );
+  DevelHandle::GetProperties( handle, map );
+  DALI_TEST_EQUALS( countBefore + 1, map.Count(), TEST_LOCATION );
+
+  END_TEST;
+}
index 68ddb92..6a01e45 100644 (file)
@@ -49,6 +49,11 @@ void SetProperties( Handle handle, const Property::Map& properties )
   GetImplementation( handle ).SetProperties( properties );
 }
 
+void GetProperties( Handle handle, Property::Map& properties )
+{
+  GetImplementation( handle ).GetProperties( properties );
+}
+
 void SetTypeInfo( Handle& handle, const TypeInfo& typeInfo )
 {
   GetImplementation( handle ).SetTypeInfo( &GetImplementation( typeInfo ) );
index d5c2862..df6a4d6 100644 (file)
@@ -107,6 +107,16 @@ DALI_CORE_API Property::Index RegisterProperty( Handle handle, Property::Index k
 DALI_CORE_API void SetProperties( Handle handle, const Property::Map& properties );
 
 /**
+ * @brief Retrieves all the properties and the values for a handle.
+ *
+ * @param[in] handle The handle to retrieve properties from
+ * @param[out] properties A map which is populated with the index-value pairs
+ *
+ * @note The properties map will be cleared by this method first.
+ */
+DALI_CORE_API void GetProperties( Handle handle, Property::Map& properties );
+
+/**
  * @brief Set the type-info that the object is created by.
  *
  * @note This is particularly useful to link C# custom control with its correct type-info in the native side
index 5dd66f8..bf521bb 100644 (file)
@@ -600,6 +600,19 @@ void Object::SetProperties( const Property::Map& properties )
   }
 }
 
+void Object::GetProperties( Property::Map& properties )
+{
+  properties.Clear();
+
+  Property::IndexContainer indexContainer;
+  GetPropertyIndices( indexContainer );
+
+  for( auto index : indexContainer )
+  {
+    properties[ index ] = GetProperty( index );
+  }
+}
+
 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode )
 {
   return RegisterProperty( name, Property::INVALID_KEY, propertyValue, accessMode );
index d66eb9e..e2c5d9f 100644 (file)
@@ -220,6 +220,11 @@ public:
   void SetProperties( const Property::Map& properties );
 
   /**
+   * @copydoc Dali::DevelHandle::GetProperties()
+   */
+  void GetProperties( Property::Map& properties );
+
+  /**
    * @copydoc Dali::Handle::RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode)
    */
   Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode );