From 84ef0dd3c2bff8bf1351b1748c5d0c11834f9368 Mon Sep 17 00:00:00 2001 From: David Steele Date: Wed, 14 Mar 2018 16:48:37 +0000 Subject: [PATCH] Added mechanism for registering child properties on arbitrary actor Want to register child properties for a container view from a second class, e.g. a layout. This adds mechanism to register properties on a registered type by type name. Added a signal which triggers when a property is set on an object (Note, OnPropertySet is available for derived types, but not for arbitrary objects) Change-Id: Icf5c9856c66e1beadf80e55bc31ca9c1130f4a60 Signed-off-by: David Steele --- automated-tests/src/dali/utc-Dali-Handle.cpp | 230 ++++++++++++++++++++- automated-tests/src/dali/utc-Dali-TypeRegistry.cpp | 102 ++++++++- dali/devel-api/object/handle-devel.cpp | 12 +- dali/devel-api/object/handle-devel.h | 26 ++- dali/internal/event/common/object-impl.cpp | 18 +- dali/internal/event/common/object-impl.h | 23 ++- dali/internal/event/common/type-registry-impl.cpp | 11 +- dali/internal/event/common/type-registry-impl.h | 12 +- dali/public-api/object/handle.h | 3 +- dali/public-api/object/type-info.cpp | 18 +- dali/public-api/object/type-info.h | 32 ++- dali/public-api/object/type-registry.cpp | 10 +- dali/public-api/object/type-registry.h | 15 +- 13 files changed, 493 insertions(+), 19 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-Handle.cpp b/automated-tests/src/dali/utc-Dali-Handle.cpp index 19e04f6..71b431f 100644 --- a/automated-tests/src/dali/utc-Dali-Handle.cpp +++ b/automated-tests/src/dali/utc-Dali-Handle.cpp @@ -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. @@ -22,6 +22,8 @@ #include #include #include "dali-test-suite-utils/dali-test-suite-utils.h" +#include "dali-test-suite-utils/test-custom-actor.h" + #include using namespace Dali; @@ -1036,3 +1038,229 @@ int UtcDaliHandleGetCurrentProperty(void) END_TEST; } + +int UtcDaliHandleDoesCustomPropertyExistP1(void) +{ + TestApplication application; // Needs type registry + + tet_infoline( "Test if a registered custom property exists on object" ); + + Actor actor = Actor::New(); + auto propertyIndex = actor.RegisterProperty("customProperty1", 1.0f); + + DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( actor, propertyIndex ), true, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliHandleDoesCustomPropertyExistN1(void) +{ + TestApplication application; // Needs type registry + + tet_infoline( "Test if a registered custom property does not exist on object" ); + + Actor actor = Actor::New(); + auto propertyIndex = actor.RegisterProperty("customProperty1", 1.0f); + + DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( actor, propertyIndex+1 ), false, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliHandleDoesCustomPropertyExistN2(void) +{ + TestApplication application; // Needs type registry + + tet_infoline( "Test that a default property does not show as a custom property on object" ); + + Actor actor = Actor::New(); + DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( actor, Actor::Property::POSITION ), false, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliHandleDoesCustomPropertyExistN3(void) +{ + TestApplication application; // Needs type registry + + tet_infoline( "Test that a child property does not exist on actor after parenting to container" ); + TypeRegistry typeRegistry = TypeRegistry::Get(); + + auto customActorTypeInfo = typeRegistry.GetTypeInfo( typeid(Test::TestCustomActor) ); + + const Property::Index CHILD_PROPERTY( CHILD_PROPERTY_REGISTRATION_START_INDEX ); + const char* CHILD_PROPERTY_NAME( "childProperty" ); + + ChildPropertyRegistration( customActorTypeInfo.GetName(), CHILD_PROPERTY_NAME, CHILD_PROPERTY, Property::INTEGER ); + + auto container = Test::TestCustomActor::New(); + Stage::GetCurrent().Add( container ); + auto child = Actor::New(); + container.Add( child ); // Resolve child properties (if any) + + DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), false, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliHandleDoesCustomPropertyExistP2(void) +{ + TestApplication application; // Needs type registry + + tet_infoline( "Test that a child property exists after being set" ); + TypeRegistry typeRegistry = TypeRegistry::Get(); + + auto customActorTypeInfo = typeRegistry.GetTypeInfo( typeid(Test::TestCustomActor) ); + + const Property::Index CHILD_PROPERTY( CHILD_PROPERTY_REGISTRATION_START_INDEX ); + const char* CHILD_PROPERTY_NAME( "childProperty" ); + + ChildPropertyRegistration( customActorTypeInfo.GetName(), CHILD_PROPERTY_NAME, CHILD_PROPERTY, Property::INTEGER ); + + auto container = Test::TestCustomActor::New(); + Stage::GetCurrent().Add( container ); + auto child = Actor::New(); + container.Add( child ); // Resolve child properties (if any) + child.SetProperty( CHILD_PROPERTY, 2 ); + + DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( child.GetProperty( CHILD_PROPERTY ), 2, TEST_LOCATION ); + END_TEST; +} + +int UtcDaliHandleDoesCustomPropertyExistP3(void) +{ + TestApplication application; // Needs type registry + + tet_infoline( "Test that a child property is re-indexed after registration, and that it exists" ); + TypeRegistry typeRegistry = TypeRegistry::Get(); + + auto customActorTypeInfo = typeRegistry.GetTypeInfo( typeid(Test::TestCustomActor) ); + + const Property::Index CHILD_PROPERTY( CHILD_PROPERTY_REGISTRATION_START_INDEX ); + const char* CHILD_PROPERTY_NAME( "childProperty" ); + + ChildPropertyRegistration( customActorTypeInfo.GetName(), CHILD_PROPERTY_NAME, CHILD_PROPERTY, Property::INTEGER ); + + auto container = Test::TestCustomActor::New(); + Stage::GetCurrent().Add( container ); + auto child = Actor::New(); + child.RegisterProperty( CHILD_PROPERTY_NAME, Property::Value(3) ); + container.Add( child ); // Resolve child properties (if any) + + DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( child.GetProperty( CHILD_PROPERTY ), 3, TEST_LOCATION ); + END_TEST; +} + +namespace +{ + +struct PropertySetSignalCheck +{ + PropertySetSignalCheck(bool& signalReceived, Property::Value& value) + : mSignalReceived(signalReceived), + mValue(value) + { + } + + void operator()(Handle& handle, Property::Index index, Property::Value value) + { + mSignalReceived = true; + mValue = value; + } + + void Reset() + { + mSignalReceived = false; + } + + void CheckSignalReceived() + { + if (!mSignalReceived) + { + tet_printf("Expected Property Set signal was not received\n"); + tet_result(TET_FAIL); + } + else + { + tet_result(TET_PASS); + } + } + + bool& mSignalReceived; // owned by individual tests + Property::Value& mValue; +}; + +} // anon namespace + +int UtcDaliHandlePropertySetSignal01(void) +{ + TestApplication app; + + bool signalReceived(false); + Property::Value value; + PropertySetSignalCheck propertySetCheck(signalReceived, value); + + tet_infoline( "Test that setting a default property triggers a signal" ); + + auto actor = Actor::New(); + DevelHandle::PropertySetSignal(actor).Connect(&app, propertySetCheck); + + actor.SetProperty( Actor::Property::POSITION, Vector3::XAXIS ); + propertySetCheck.CheckSignalReceived(); + + END_TEST; +} + + +int UtcDaliHandlePropertySetSignal02(void) +{ + TestApplication app; + + bool signalReceived(false); + Property::Value value; + PropertySetSignalCheck propertySetCheck(signalReceived, value); + + tet_infoline( "Test that setting a custom property triggers a signal" ); + + auto actor = Actor::New(); + DevelHandle::PropertySetSignal(actor).Connect(&app, propertySetCheck); + + auto propertyIndex = actor.RegisterProperty("propName", 3.0f); + actor.SetProperty( propertyIndex, 5.0f ); + propertySetCheck.CheckSignalReceived(); + DALI_TEST_EQUALS( propertySetCheck.mValue, Property::Value( 5.0f ), 0.001f, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliHandlePropertySetSignal03(void) +{ + TestApplication app; + TypeRegistry typeRegistry = TypeRegistry::Get(); + + bool signalReceived(false); + Property::Value value; + PropertySetSignalCheck propertySetCheck(signalReceived, value); + + tet_infoline( "Test that setting a child property triggers a signal" ); + + auto customActorTypeInfo = typeRegistry.GetTypeInfo( typeid(Test::TestCustomActor) ); + + const Property::Index CHILD_PROPERTY( CHILD_PROPERTY_REGISTRATION_START_INDEX ); + const char* CHILD_PROPERTY_NAME( "childProperty" ); + + ChildPropertyRegistration( customActorTypeInfo.GetName(), CHILD_PROPERTY_NAME, CHILD_PROPERTY, Property::INTEGER ); + + auto container = Test::TestCustomActor::New(); + Stage::GetCurrent().Add( container ); + auto child = Actor::New(); + child.RegisterProperty( CHILD_PROPERTY_NAME, Property::Value(3) ); + DevelHandle::PropertySetSignal(child).Connect(&app, propertySetCheck); + container.Add( child ); // Resolve child properties (if any) + + DALI_TEST_EQUALS( DevelHandle::DoesCustomPropertyExist( child, CHILD_PROPERTY ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( child.GetProperty( CHILD_PROPERTY ), 3, TEST_LOCATION ); + + child.SetProperty( CHILD_PROPERTY, 29 ); + propertySetCheck.CheckSignalReceived(); + DALI_TEST_EQUALS( propertySetCheck.mValue, Property::Value( 29 ), TEST_LOCATION ); + END_TEST; +} diff --git a/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp b/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp index feabd0e..7da76eb 100644 --- a/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp +++ b/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp @@ -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. @@ -2778,3 +2778,103 @@ int UtcDaliPropertyRegistrationPropertyAnimatableSynchronousSetGetWithComponents END_TEST; } + + +int UtcDaliTypeInfoRegisterChildProperties01(void) +{ + TestApplication application; + TypeRegistry typeRegistry = TypeRegistry::Get(); + + tet_infoline( "Register child properties on a type via name" ); + + 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 ); + + auto customActor = MyTestCustomActor::New(); + Stage::GetCurrent().Add( customActor ); + auto child = Actor::New(); + customActor.Add( child ); + + child.SetProperty( WIDTH_SPECIFICATION, 33 ); + + auto value = child.GetProperty( WIDTH_SPECIFICATION ); + DALI_TEST_EQUALS( value, Property::Value(33), TEST_LOCATION ); + + child.SetProperty( HEIGHT_SPECIFICATION, 44 ); + value = child.GetProperty( HEIGHT_SPECIFICATION ); + DALI_TEST_EQUALS( value, Property::Value(44), TEST_LOCATION ); + + child.SetProperty( MARGIN_SPECIFICATION, Extents(10, 10, 10, 10) ); + value = child.GetProperty( MARGIN_SPECIFICATION ); + DALI_TEST_EQUALS( value, Property::Value(Extents(10,10,10,10)), TEST_LOCATION ); + + END_TEST; +} + + +int UtcDaliTypeInfoRegisterChildProperties02(void) +{ + TestApplication application; + TypeRegistry typeRegistry = TypeRegistry::Get(); + + tet_infoline( "Register child properties on a type via name" ); + + 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 ); + + + auto index = customActorTypeInfo.GetChildPropertyIndex( "widthSpecification" ); + DALI_TEST_EQUALS( index, WIDTH_SPECIFICATION, TEST_LOCATION ); + + index = customActorTypeInfo.GetChildPropertyIndex( "heightSpecification" ); + DALI_TEST_EQUALS( index, HEIGHT_SPECIFICATION, TEST_LOCATION ); + + index = customActorTypeInfo.GetChildPropertyIndex( "marginSpecification" ); + DALI_TEST_EQUALS( index, Property::INVALID_INDEX, TEST_LOCATION ); + + index = myCustomTypeInfo.GetChildPropertyIndex( "marginSpecification" ); + DALI_TEST_EQUALS( index, MARGIN_SPECIFICATION, TEST_LOCATION ); + + + auto name = customActorTypeInfo.GetChildPropertyName( WIDTH_SPECIFICATION ); + DALI_TEST_EQUALS( name, "widthSpecification", TEST_LOCATION ); + + name = customActorTypeInfo.GetChildPropertyName( HEIGHT_SPECIFICATION ); + DALI_TEST_EQUALS( name, "heightSpecification", TEST_LOCATION ); + + name = myCustomTypeInfo.GetChildPropertyName( MARGIN_SPECIFICATION ); + DALI_TEST_EQUALS( name, "marginSpecification", TEST_LOCATION ); + + + auto type = customActorTypeInfo.GetChildPropertyType( WIDTH_SPECIFICATION ); + DALI_TEST_EQUALS( type, Property::INTEGER, TEST_LOCATION ); + + type = customActorTypeInfo.GetChildPropertyType( HEIGHT_SPECIFICATION ); + DALI_TEST_EQUALS( type, Property::INTEGER, TEST_LOCATION ); + + type = myCustomTypeInfo.GetChildPropertyType( MARGIN_SPECIFICATION ); + DALI_TEST_EQUALS( type, Property::EXTENTS, TEST_LOCATION ); + + + END_TEST; +} diff --git a/dali/devel-api/object/handle-devel.cpp b/dali/devel-api/object/handle-devel.cpp index 3097836..f5e8951 100644 --- a/dali/devel-api/object/handle-devel.cpp +++ b/dali/devel-api/object/handle-devel.cpp @@ -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. @@ -49,6 +49,16 @@ void SetTypeInfo( Handle& handle, const TypeInfo& typeInfo ) GetImplementation( handle ).SetTypeInfo( &GetImplementation( typeInfo ) ); } +bool DoesCustomPropertyExist( Handle& handle, Property::Index index ) +{ + return GetImplementation( handle ).DoesCustomPropertyExist( index ); +} + +PropertySetSignalType& PropertySetSignal( Handle handle ) +{ + return GetImplementation( handle ).PropertySetSignal(); +} + } // namespace DevelHandle } // namespace Dali diff --git a/dali/devel-api/object/handle-devel.h b/dali/devel-api/object/handle-devel.h index cd06a82..caae1b8 100644 --- a/dali/devel-api/object/handle-devel.h +++ b/dali/devel-api/object/handle-devel.h @@ -2,7 +2,7 @@ #define DALI_HANDLE_DEVEL_H /* - * 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. @@ -108,6 +108,30 @@ DALI_IMPORT_API Property::Index RegisterProperty( Handle handle, Property::Index */ DALI_IMPORT_API void SetTypeInfo( Handle& handle, const TypeInfo& typeInfo ); + +/** + * @brief Determine if the custom property index exists on this object without throwing a Dali::Exception. + * + * @note This does not check default properties. + * @param[in] handle The handle to check + * @param[in] index The index of the property to test for + */ +DALI_IMPORT_API bool DoesCustomPropertyExist( Handle& handle, Property::Index index ); + +/** + * @brief PropertySetSignal function prototype for signal handler. Called when a property is set on this object. + */ +using PropertySetSignalType = Signal< void( Handle& handle, Property::Index index, Property::Value value ) >; + +/** + * @brief Get a signal when a property is set on this object through the API (i.e. not when animating) + * + * @param[in] handle The handle of the object to listen to. + * @return The signal to attach a connection to. + */ +DALI_IMPORT_API PropertySetSignalType& PropertySetSignal( Handle handle ); + + } // namespace DevelHandle } // namespace Dali diff --git a/dali/internal/event/common/object-impl.cpp b/dali/internal/event/common/object-impl.cpp index 2396fd1..1663e61 100644 --- a/dali/internal/event/common/object-impl.cpp +++ b/dali/internal/event/common/object-impl.cpp @@ -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. @@ -23,6 +23,7 @@ // INTERNAL INCLUDES #include +#include #include #include #include @@ -423,6 +424,11 @@ Property::Type Object::GetPropertyType( Property::Index index ) const return Property::NONE; } +DevelHandle::PropertySetSignalType& Object::PropertySetSignal() +{ + return mPropertySetSignal; +} + void Object::SetProperty( Property::Index index, const Property::Value& propertyValue ) { DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" ); @@ -523,7 +529,9 @@ void Object::SetProperty( Property::Index index, const Property::Value& property // TODO: We should not call this for read-only properties, SetDefaultProperty() && TypeInfo::SetProperty() should return a bool, which would be true if the property is set if ( propertySet ) { - OnPropertySet(index, propertyValue); + OnPropertySet( index, propertyValue ); + Dali::Handle handle( this ); + mPropertySetSignal.Emit( handle, index, propertyValue ); } } @@ -671,6 +679,12 @@ void Object::GetPropertyIndices( Property::IndexContainer& indices ) const } } +bool Object::DoesCustomPropertyExist( Property::Index index ) +{ + auto metadata = FindCustomProperty( index ); + return metadata != nullptr; +} + Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Property::Index key, Property::Index index, const Property::Value& propertyValue) const { // Create a new property diff --git a/dali/internal/event/common/object-impl.h b/dali/internal/event/common/object-impl.h index 89fc73f..7658482 100644 --- a/dali/internal/event/common/object-impl.h +++ b/dali/internal/event/common/object-impl.h @@ -2,7 +2,7 @@ #define __DALI_INTERNAL_OBJECT_H__ /* - * 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. @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -44,7 +45,6 @@ namespace Internal { class ConstraintBase; class EventThreadServices; -class Handle; class PropertyCondition; class PropertyInputImpl; class Stage; @@ -224,6 +224,19 @@ public: virtual Property::Index RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue, Property::AccessMode accessMode ); /** + * @brief returns true if the custom property exists on this object. + * + * @note The property may be defined for a type within the type registry, but it isn't explicity + * defined in every consequent instantiation. It can be automatically added, e.g. parenting an actor + * automatically registers it's parent container's child properties. + * + * @param[in] handle The handle of the object to test + * @param[in] index The property index to look for. + * @return true if the property exists on the object, false otherwise. + */ + bool DoesCustomPropertyExist( Property::Index index ); + + /** * @copydoc Dali::Handle::AddPropertyNotification() */ virtual Dali::PropertyNotification AddPropertyNotification( Property::Index index, @@ -331,6 +344,11 @@ public: */ virtual int GetPropertyComponentIndex( Property::Index index ) const; + /** + * @copydoc Dali::Handle::PropertySetSignal() + */ + DevelHandle::PropertySetSignalType& PropertySetSignal(); + protected: /** @@ -597,6 +615,7 @@ private: typedef PropertyNotificationContainer::iterator PropertyNotificationContainerIter; typedef PropertyNotificationContainer::const_iterator PropertyNotificationContainerConstIter; PropertyNotificationContainer* mPropertyNotifications; ///< Container of owned property notifications. + DevelHandle::PropertySetSignalType mPropertySetSignal; }; } // namespace Internal diff --git a/dali/internal/event/common/type-registry-impl.cpp b/dali/internal/event/common/type-registry-impl.cpp index 977cb87..66b9fcb 100644 --- a/dali/internal/event/common/type-registry-impl.cpp +++ b/dali/internal/event/common/type-registry-impl.cpp @@ -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. @@ -276,12 +276,12 @@ bool TypeRegistry::RegisterAnimatablePropertyComponent( TypeRegistration& typeRe return false; } -bool TypeRegistry::RegisterChildProperty( TypeRegistration& typeRegistration, const std::string& name, Property::Index index, Property::Type type ) +bool TypeRegistry::RegisterChildProperty( const std::string& registeredType, const std::string& name, Property::Index index, Property::Type type ) { for( auto&& iter : mRegistryLut ) { auto&& impl = GetImplementation( iter ); - if( impl.GetName() == typeRegistration.RegisteredName() ) + if( impl.GetName() == registeredType ) { impl.AddChildProperty( name, index, type ); return true; @@ -291,6 +291,11 @@ bool TypeRegistry::RegisterChildProperty( TypeRegistration& typeRegistration, co return false; } +bool TypeRegistry::RegisterChildProperty( TypeRegistration& typeRegistration, const std::string& name, Property::Index index, Property::Type type ) +{ + return RegisterChildProperty( typeRegistration.RegisteredName(), name, index, type ); +} + bool TypeRegistry::DoActionTo( BaseObject * const object, const std::string& actionName, const Property::Map& properties ) { bool done = false; diff --git a/dali/internal/event/common/type-registry-impl.h b/dali/internal/event/common/type-registry-impl.h index 47364f3..e097c76 100644 --- a/dali/internal/event/common/type-registry-impl.h +++ b/dali/internal/event/common/type-registry-impl.h @@ -2,7 +2,7 @@ #define __DALI_INTERNAL_TYPE_REGISTRY_H__ /* - * 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. @@ -172,6 +172,16 @@ public: /** * Register a event-thread only property with a type and a default value + * @param [in] registeredType Name of a registered type on which to register the child property. + * @param [in] name Property name + * @param [in] index Property index + * @param [in] type Property type + * @return true if registered + */ + bool RegisterChildProperty( const std::string& registeredType, const std::string& name, Property::Index index, Property::Type type ); + + /** + * Register a event-thread only property with a type and a default value * @param [in] registered TypeRegistration object used to register the type * @param [in] name Property name * @param [in] index Property index diff --git a/dali/public-api/object/handle.h b/dali/public-api/object/handle.h index 063f0cc..f139f97 100644 --- a/dali/public-api/object/handle.h +++ b/dali/public-api/object/handle.h @@ -2,7 +2,7 @@ #define __DALI_HANDLE_H__ /* - * Copyright (c) 2015 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. @@ -391,7 +391,6 @@ public: * @pre The Object has been initialized. */ void RemoveConstraints( unsigned int tag ); - }; /** diff --git a/dali/public-api/object/type-info.cpp b/dali/public-api/object/type-info.cpp index 03d96dc..eb4c8b2 100644 --- a/dali/public-api/object/type-info.cpp +++ b/dali/public-api/object/type-info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 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. @@ -101,10 +101,24 @@ const std::string& TypeInfo::GetPropertyName( Property::Index index ) const return GetImplementation(*this).GetPropertyName( index ); } +Property::Index TypeInfo::GetChildPropertyIndex( const std::string& name ) const +{ + return GetImplementation(*this).GetChildPropertyIndex( name ); +} + +const std::string& TypeInfo::GetChildPropertyName( Property::Index index ) const +{ + return GetImplementation(*this).GetChildPropertyName( index ); +} + +Property::Type TypeInfo::GetChildPropertyType( Property::Index index ) const +{ + return GetImplementation(*this).GetChildPropertyType( index ); +} + TypeInfo::TypeInfo(Internal::TypeInfo* internal) : BaseHandle(internal) { } } // namespace Dali - diff --git a/dali/public-api/object/type-info.h b/dali/public-api/object/type-info.h index 77de7f0..87a1958 100644 --- a/dali/public-api/object/type-info.h +++ b/dali/public-api/object/type-info.h @@ -2,7 +2,7 @@ #define __DALI_TYPE_INFO_H__ /* - * Copyright (c) 2015 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. @@ -215,6 +215,36 @@ public: */ const std::string& GetPropertyName( Property::Index index ) const; + + /** + * @brief Given a child property name, retrieve the property index associated with it, + * + * @SINCE_1_3.20 + * @param[in] name The name of the property at the given index, + * @return The property index or Property::INVALID_INDEX + */ + Property::Index GetChildPropertyIndex( const std::string& name ) const; + + /** + * @brief Given a child property index, retrieve the property name associated with it. + * + * @SINCE_1_3.20 + * @param[in] index The property index + * @return The name of the property at the given index, or empty string if it does not exist + */ + const std::string& GetChildPropertyName( Property::Index index ) const; + + /** + * @brief Given a child property index, retrieve the property name associated with it. + * + * @SINCE_1_3.20 + * @param[in] index The property index + * @return The name of the property at the given index, or empty string if it does not exist + */ + Property::Type GetChildPropertyType( Property::Index index ) const; + + + public: // Not intended for application developers /// @cond internal diff --git a/dali/public-api/object/type-registry.cpp b/dali/public-api/object/type-registry.cpp index f28bb39..ed1bb70 100644 --- a/dali/public-api/object/type-registry.cpp +++ b/dali/public-api/object/type-registry.cpp @@ -1,5 +1,5 @@ /* - * 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. @@ -163,4 +163,12 @@ ChildPropertyRegistration::ChildPropertyRegistration( TypeRegistration& register Internal::TypeRegistry::Get()->RegisterChildProperty( registered, name, index, type ); } +ChildPropertyRegistration::ChildPropertyRegistration( const std::string& registered, const std::string& name, Property::Index index, Property::Type type ) +{ + DALI_ASSERT_ALWAYS( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) ); + + Internal::TypeRegistry::Get()->RegisterChildProperty( registered, name, index, type ); +} + + } // namespace Dali diff --git a/dali/public-api/object/type-registry.h b/dali/public-api/object/type-registry.h index a34b89d..3c7574b 100644 --- a/dali/public-api/object/type-registry.h +++ b/dali/public-api/object/type-registry.h @@ -2,7 +2,7 @@ #define __DALI_TYPE_REGISTRY_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. @@ -401,6 +401,19 @@ public: * @pre "registered" must be registered with the TypeRegistry. */ ChildPropertyRegistration( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type ); + + /** + * @brief This constructor registers an event-thread only child property (i.e. a property + * that the parent supports in its children) with the registered type. + * + * @SINCE_1_3.20 + * @param[in] registered The name of the registered type + * @param[in] name The name of the property + * @param[in] index The property index. Must be a value between CHILD_PROPERTY_REGISTRATION_START_INDEX and CHILD_PROPERTY_REGISTRATION_MAX_INDEX inclusive + * @param[in] type The property value type + * @pre "registered" must be registered with the TypeRegistry. + */ + ChildPropertyRegistration( const std::string& registered, const std::string& name, Property::Index index, Property::Type type ); }; -- 2.7.4