From: Agnelo Vaz Date: Wed, 18 Jan 2017 14:17:59 +0000 (+0000) Subject: Added TextVisual function to convert string keys to index keys in Property Map X-Git-Tag: dali_1.2.23~3^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=6c02c5852ca329f720e4ae72d9cef2524629574c;ds=sidebyside Added TextVisual function to convert string keys to index keys in Property Map Fixes issue in which a PropertyMap made up of string keys would not merged into a PropertyMap made of Index keys. Instead it will have entries for both. The Visual Factory will only use Indexes to create the TextVisual hence the Properties set with strings are ignored. Change-Id: I0bf2495d96ce86616a70d9de544dfe9768db40d7 --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp index 9452649..244f667 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp @@ -504,6 +504,47 @@ int UtcDaliButtonSetLabelStringWithPropertyMapP(void) END_TEST; } +int UtcDaliButtonSetLabelStringWithPropertyMapStringsP(void) +{ + ToolkitTestApplication application; + + Button button = PushButton::New(); + + tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Setting Button text using String then replacing with Enum then string"); + + Property::Map textVisualMapInitial; + textVisualMapInitial["visualType"] = "TEXT"; + textVisualMapInitial["pointSize"] = 15.0f; + textVisualMapInitial["text"] = "button label initial"; + + button.SetProperty( Button::Property::LABEL, textVisualMapInitial ); + + DALI_TEST_EQUALS( GetButtonText( button ), "button label initial", TEST_LOCATION ); + + tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Intermediate part of test"); + + Property::Map propertyMap; + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT ); + propertyMap.Insert( Toolkit::TextVisual::Property::TEXT, "error if this is the final text" ); + propertyMap.Insert( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f ); + + button.SetProperty( Button::Property::LABEL, propertyMap ); + + DALI_TEST_EQUALS( GetButtonText( button ), "error if this is the final text", TEST_LOCATION ); + + tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Final part of test"); + + Property::Map textVisualMap; + textVisualMap["visualType"] = "TEXT"; + textVisualMap["pointSize"] = 15.0f; + textVisualMap["text"] = "Button Label"; + + button.SetProperty( Toolkit::Button::Property::LABEL, textVisualMap ); + + DALI_TEST_EQUALS( GetButtonText( button ), "Button Label", TEST_LOCATION ); + END_TEST; +} + int UtcDaliButtonSetLabelWithStringP(void) { ToolkitTestApplication application; diff --git a/dali-toolkit/internal/controls/buttons/button-impl.cpp b/dali-toolkit/internal/controls/buttons/button-impl.cpp index ed9b2c8..a8ab543 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/button-impl.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -1228,7 +1229,7 @@ void Button::SetProperty( BaseObject* object, Property::Index index, const Prope DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetProperty Setting TextVisual with string[%s]\n", textString.c_str() ); Property::Map setPropertyMap; - setPropertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT) + setPropertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT ) .Add( Toolkit::TextVisual::Property::TEXT, textString ); GetImplementation( button ).MergeWithExistingLabelProperties( setPropertyMap, outTextVisualProperties ); @@ -1239,6 +1240,7 @@ void Button::SetProperty( BaseObject* object, Property::Index index, const Prope Property::Map* setPropertyMap = value.GetMap(); if( setPropertyMap ) { + TextVisual::ConvertStringKeysToIndexKeys( *setPropertyMap ); GetImplementation( button ).MergeWithExistingLabelProperties( *setPropertyMap, outTextVisualProperties ); } } diff --git a/dali-toolkit/internal/visuals/text/text-visual.cpp b/dali-toolkit/internal/visuals/text/text-visual.cpp index 6977eb5..f3b895b 100644 --- a/dali-toolkit/internal/visuals/text/text-visual.cpp +++ b/dali-toolkit/internal/visuals/text/text-visual.cpp @@ -137,6 +137,60 @@ const char* FRAGMENT_SHADER_ATLAS_CLAMP = DALI_COMPOSE_SHADER( }\n ); +/** + * Return Property index for the given string key + * param[in] stringKey the string index key + * return the key as an index + */ + +Dali::Property::Index StringKeyToIndexKey( const std::string& stringKey ) +{ + Dali::Property::Index result = Property::INVALID_KEY; + + if( stringKey == VISUAL_TYPE ) + { + result = Toolkit::Visual::Property::TYPE; + } + else if( stringKey == TEXT_PROPERTY ) + { + result = Toolkit::TextVisual::Property::TEXT; + } + else if( stringKey == FONT_FAMILY_PROPERTY ) + { + result = Toolkit::TextVisual::Property::FONT_FAMILY; + } + else if( stringKey == FONT_STYLE_PROPERTY ) + { + result = Toolkit::TextVisual::Property::FONT_STYLE; + } + else if( stringKey == POINT_SIZE_PROPERTY ) + { + result = Toolkit::TextVisual::Property::POINT_SIZE; + } + else if( stringKey == MULTI_LINE_PROPERTY ) + { + result = Toolkit::TextVisual::Property::MULTI_LINE; + } + else if( stringKey == HORIZONTAL_ALIGNMENT_PROPERTY ) + { + result = Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT; + } + else if( stringKey == VERTICAL_ALIGNMENT_PROPERTY ) + { + result = Toolkit::TextVisual::Property::VERTICAL_ALIGNMENT; + } + else if( stringKey == TEXT_COLOR_PROPERTY ) + { + result = Toolkit::TextVisual::Property::TEXT_COLOR; + } + else if( stringKey == ENABLE_MARKUP_PROPERTY ) + { + result = Toolkit::TextVisual::Property::ENABLE_MARKUP; + } + + return result; +} + } // unnamed namespace TextVisualPtr TextVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties ) @@ -146,6 +200,27 @@ TextVisualPtr TextVisual::New( VisualFactoryCache& factoryCache, const Property: return TextVisualPtr; } +void TextVisual::ConvertStringKeysToIndexKeys( Property::Map& propertyMap ) +{ + Property::Map outMap; + + for( Property::Map::SizeType index = 0u, count = propertyMap.Count(); index < count; ++index ) + { + const KeyValuePair& keyValue = propertyMap.GetKeyValue( index ); + + Property::Index indexKey = keyValue.first.indexKey; + + if ( keyValue.first.type == Property::Key::STRING ) + { + indexKey = StringKeyToIndexKey( keyValue.first.stringKey ); + } + + outMap.Insert( indexKey, keyValue.second ); + } + + propertyMap = outMap; +} + float TextVisual::GetHeightForWidth( float width ) { return mController->GetHeightForWidth( width ); @@ -202,54 +277,14 @@ void TextVisual::DoSetProperties( const Property::Map& propertyMap ) { const KeyValuePair& keyValue = propertyMap.GetKeyValue( index ); - switch( keyValue.first.type ) + Property::Index indexKey = keyValue.first.indexKey; + + if( keyValue.first.type == Property::Key::STRING ) { - case Property::Key::INDEX: - { - DoSetProperty( keyValue.first.indexKey, keyValue.second ); - break; - } - case Property::Key::STRING: - { - if( keyValue.first.stringKey == TEXT_PROPERTY ) - { - DoSetProperty( Toolkit::TextVisual::Property::TEXT, keyValue.second ); - } - else if( keyValue.first.stringKey == FONT_FAMILY_PROPERTY ) - { - DoSetProperty( Toolkit::TextVisual::Property::FONT_FAMILY, keyValue.second ); - } - else if( keyValue.first.stringKey == FONT_STYLE_PROPERTY ) - { - DoSetProperty( Toolkit::TextVisual::Property::FONT_STYLE, keyValue.second ); - } - else if( keyValue.first.stringKey == POINT_SIZE_PROPERTY ) - { - DoSetProperty( Toolkit::TextVisual::Property::POINT_SIZE, keyValue.second ); - } - else if( keyValue.first.stringKey == MULTI_LINE_PROPERTY ) - { - DoSetProperty( Toolkit::TextVisual::Property::MULTI_LINE, keyValue.second ); - } - else if( keyValue.first.stringKey == HORIZONTAL_ALIGNMENT_PROPERTY ) - { - DoSetProperty( Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT, keyValue.second ); - } - else if( keyValue.first.stringKey == VERTICAL_ALIGNMENT_PROPERTY ) - { - DoSetProperty( Toolkit::TextVisual::Property::VERTICAL_ALIGNMENT, keyValue.second ); - } - else if( keyValue.first.stringKey == TEXT_COLOR_PROPERTY ) - { - DoSetProperty( Toolkit::TextVisual::Property::TEXT_COLOR, keyValue.second ); - } - else if( keyValue.first.stringKey == ENABLE_MARKUP_PROPERTY ) - { - DoSetProperty( Toolkit::TextVisual::Property::ENABLE_MARKUP, keyValue.second ); - } - break; - } + indexKey = StringKeyToIndexKey( keyValue.first.stringKey ); } + + DoSetProperty( indexKey, keyValue.second ); } // Elide the text if it exceeds the boundaries. diff --git a/dali-toolkit/internal/visuals/text/text-visual.h b/dali-toolkit/internal/visuals/text/text-visual.h index ebeb867..9edf08c 100644 --- a/dali-toolkit/internal/visuals/text/text-visual.h +++ b/dali-toolkit/internal/visuals/text/text-visual.h @@ -76,6 +76,12 @@ public: */ static TextVisualPtr New( VisualFactoryCache& factoryCache, const Property::Map& properties ); + /** + * @brief Converts all strings keys in property map to index keys. Property Map can then be merged correctly. + * @param[in,out] propertyMap containing string keys or a mix of strings and indexes. Will be changed to index keys. + */ + static void ConvertStringKeysToIndexKeys( Property::Map& propertyMap ); + public: // from Visual::Base /**