Added TypeInfo::GetChildPropertyIndices 60/173760/3
authorDavid Steele <david.steele@samsung.com>
Fri, 23 Mar 2018 18:26:23 +0000 (18:26 +0000)
committerDavid Steele <david.steele@samsung.com>
Thu, 5 Apr 2018 17:36:48 +0000 (18:36 +0100)
Change-Id: I909a6ac928739a5563d3ad231686a2f43d5331c8

automated-tests/src/dali/utc-Dali-TypeRegistry.cpp
dali/internal/event/common/type-info-impl.cpp
dali/internal/event/common/type-info-impl.h
dali/public-api/object/type-info.cpp
dali/public-api/object/type-info.h

index 7da76eb..fb2bb5b 100644 (file)
@@ -2878,3 +2878,39 @@ int UtcDaliTypeInfoRegisterChildProperties02(void)
 
   END_TEST;
 }
+
+
+int UtcDaliTypeInfoRegisterChildProperties03(void)
+{
+  TestApplication application;
+  TypeRegistry typeRegistry = TypeRegistry::Get();
+
+  tet_infoline( "Check registered child properties can be retrieved" );
+
+  auto customActorTypeInfo = typeRegistry.GetTypeInfo( typeid(CustomActor) );
+  auto myCustomTypeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
+  DALI_TEST_CHECK( customActorTypeInfo );
+  DALI_TEST_CHECK( myCustomTypeInfo );
+
+  const Property::Index WIDTH_SPECIFICATION( CHILD_PROPERTY_REGISTRATION_START_INDEX );
+  const Property::Index HEIGHT_SPECIFICATION( CHILD_PROPERTY_REGISTRATION_START_INDEX + 1);
+  const Property::Index MARGIN_SPECIFICATION( CHILD_PROPERTY_REGISTRATION_START_INDEX + 100);
+
+  ChildPropertyRegistration( customActorTypeInfo.GetName(), "widthSpecification", WIDTH_SPECIFICATION, Property::INTEGER );
+  ChildPropertyRegistration( customActorTypeInfo.GetName(), "heightSpecification", HEIGHT_SPECIFICATION, Property::INTEGER );
+  ChildPropertyRegistration( myCustomTypeInfo.GetName(), "marginSpecification", MARGIN_SPECIFICATION, Property::EXTENTS );
+
+  Property::IndexContainer indices;
+  myCustomTypeInfo.GetChildPropertyIndices( indices );
+
+  auto result = std::find( indices.Begin(), indices.End(), WIDTH_SPECIFICATION );
+  DALI_TEST_EQUALS( result != indices.End(), true, TEST_LOCATION );
+
+  result = std::find( indices.Begin(), indices.End(), HEIGHT_SPECIFICATION );
+  DALI_TEST_EQUALS( result != indices.End(), true, TEST_LOCATION );
+
+  result = std::find( indices.Begin(), indices.End(), MARGIN_SPECIFICATION );
+  DALI_TEST_EQUALS( result != indices.End(), true, TEST_LOCATION );
+
+  END_TEST;
+}
index e3f8d79..2b41f54 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -317,14 +317,34 @@ void TypeInfo::GetPropertyIndices( Property::IndexContainer& indices ) const
     baseImpl.GetPropertyIndices( indices );
   }
 
-  if ( ! mRegisteredProperties.empty() )
+  AppendProperties( indices, mRegisteredProperties );
+}
+
+void TypeInfo::GetChildPropertyIndices( Property::IndexContainer& indices ) const
+{
+  Dali::TypeInfo base = TypeRegistry::Get()->GetTypeInfo( mBaseTypeName );
+  if ( base )
+  {
+    const TypeInfo& baseImpl( GetImplementation( base ) );
+    baseImpl.GetChildPropertyIndices( indices );
+  }
+
+  AppendProperties( indices, mRegisteredChildProperties );
+}
+
+/**
+ * Append the indices in RegisteredProperties to the given index container.
+ */
+void TypeInfo::AppendProperties( Dali::Property::IndexContainer& indices,
+                                 const TypeInfo::RegisteredPropertyContainer& registeredProperties ) const
+{
+  if ( ! registeredProperties.empty() )
   {
-    indices.Reserve( indices.Size() + mRegisteredProperties.size() );
+    indices.Reserve( indices.Size() + registeredProperties.size() );
 
-    const RegisteredPropertyContainer::const_iterator endIter = mRegisteredProperties.end();
-    for ( RegisteredPropertyContainer::const_iterator iter = mRegisteredProperties.begin(); iter != endIter; ++iter )
+    for( auto&& elem : registeredProperties )
     {
-      indices.PushBack( iter->first );
+      indices.PushBack( elem.first );
     }
   }
 }
index 325f4f6..3587ede 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTERNAL_TYPE_INFO_H__
 
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -268,6 +268,12 @@ public:
   Property::Type GetChildPropertyType( Property::Index index ) const;
 
   /**
+   * Retrive the child indices into the given container.
+   * @param[in,out] indices The container to put the child indices into
+   */
+  void GetChildPropertyIndices( Property::IndexContainer& indices ) const;
+
+  /**
    * Retrieve the default value of the property at the given index.
    * @param[in] index The property index.
    * @return The default property value at that index.
@@ -378,6 +384,17 @@ private:
   typedef std::vector< RegisteredPropertyPair > RegisteredPropertyContainer;
   typedef std::vector< PropertyDefaultValuePair > PropertyDefaultValueContainer;
 
+
+  /**
+   * Append properties from registeredProperties onto indices.
+   * @param[in,out] indices The vector to append indices onto
+   * @param[in] registeredProperties The container to retrive indices from
+   */
+  void AppendProperties( Dali::Property::IndexContainer& indices,
+                         const TypeInfo::RegisteredPropertyContainer& registeredProperties ) const;
+
+private:
+
   std::string mTypeName;
   std::string mBaseTypeName;
   bool        mCSharpType:1;    ///< Whether this type info is for a CSharp control (instead of C++)
index eb4c8b2..92f1b67 100644 (file)
@@ -116,6 +116,12 @@ Property::Type TypeInfo::GetChildPropertyType( Property::Index index ) const
   return GetImplementation(*this).GetChildPropertyType( index );
 }
 
+void TypeInfo::GetChildPropertyIndices( Property::IndexContainer& indices ) const
+{
+  indices.Clear(); // We do not want to clear the container if called internally, so only clear here
+  GetImplementation(*this).GetChildPropertyIndices( indices );
+}
+
 TypeInfo::TypeInfo(Internal::TypeInfo* internal)
 : BaseHandle(internal)
 {
index 87a1958..290c2b9 100644 (file)
@@ -205,6 +205,15 @@ public:
   void GetPropertyIndices( Property::IndexContainer& indices ) const;
 
   /**
+   * @brief Retrieves all the child property indices for this type.
+   *
+   * @SINCE_1_3.20
+   * @param[out] indices Container of property indices
+   * @note The container will be cleared
+   */
+  void GetChildPropertyIndices( Property::IndexContainer& indices ) const;
+
+  /**
    * @brief Given a property index, retrieve the property name associated with it.
    *
    * @SINCE_1_0.0