Merge "Remove deprecated SetSelected call" into devel/master
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 19 Jan 2017 16:35:08 +0000 (08:35 -0800)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Thu, 19 Jan 2017 16:35:08 +0000 (08:35 -0800)
automated-tests/src/dali-toolkit/utc-Dali-Button.cpp
dali-toolkit/internal/controls/buttons/button-impl.cpp
dali-toolkit/internal/image-loader/atlas-packer.cpp
dali-toolkit/internal/visuals/text/text-visual.cpp
dali-toolkit/internal/visuals/text/text-visual.h

index 9452649..244f667 100644 (file)
@@ -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;
index ed9b2c8..a8ab543 100644 (file)
@@ -39,6 +39,7 @@
 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali-toolkit/internal/visuals/text/text-visual.h>
 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
 
@@ -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 );
           }
         }
index e02eba6..26ad3e0 100644 (file)
@@ -258,12 +258,11 @@ void AtlasPacker::GrowPack( SizeType blockWidth, SizeType blockHeight,
     firstFit = InsertNode( mRoot->child[1], blockWidth, blockHeight );
   }
 
-  if( firstFit != NULL )
-  {
-    firstFit->occupied = true;
-    packPositionX = firstFit->rectArea.x;
-    packPositionY = firstFit->rectArea.y;
-  }
+  DALI_ASSERT_ALWAYS( firstFit != NULL && "It should never happen!")
+
+  firstFit->occupied = true;
+  packPositionX = firstFit->rectArea.x;
+  packPositionY = firstFit->rectArea.y;
 }
 
 void AtlasPacker::GrowNode( SizeType blockWidth, SizeType blockHeight )
index 6977eb5..f3b895b 100644 (file)
@@ -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.
index ebeb867..9edf08c 100644 (file)
@@ -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
 
   /**