Added tag ( id ) to Constraints so they can be identified ( and removed ) by its... dali-2014-wk16-release
authorFerran Sole <ferran.sole@samsung.com>
Tue, 15 Apr 2014 09:01:28 +0000 (10:01 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Wed, 16 Apr 2014 10:42:59 +0000 (11:42 +0100)
[Issue#] N/A

[Problem] ItemView is not flexible enough

[Cause] ItemView removes all constraints from actors it manages

[Solution] Added tag to constraints so ItemView can tag its constraints and remove only those when needed

Change-Id: Id2e016f7b9f906bd4fa62d6fe249bd1ad60a1d97

13 files changed:
automated-tests/src/dali/tct-dali-core.h
automated-tests/src/dali/utc-Dali-Actor.cpp
capi/dali/public-api/animation/constraint.h
capi/dali/public-api/object/constrainable.h
dali/internal/event/animation/active-constraint-base.cpp
dali/internal/event/animation/active-constraint-base.h
dali/internal/event/animation/active-constraint-impl.h
dali/internal/event/animation/constraint-impl.cpp
dali/internal/event/animation/constraint-impl.h
dali/internal/event/common/proxy-object.cpp
dali/internal/event/common/proxy-object.h
dali/public-api/animation/constraint.cpp
dali/public-api/object/constrainable.cpp

index 6c3544e..7a7d126 100644 (file)
@@ -205,6 +205,7 @@ extern int UtcDaliActorApplyConstraint(void);
 extern int UtcDaliActorApplyConstraintAppliedCallback(void);
 extern int UtcDaliActorRemoveConstraints(void);
 extern int UtcDaliActorRemoveConstraint(void);
+extern int UtcDaliActorRemoveConstraintTag(void);
 extern int UtcDaliActorTouchedSignal(void);
 extern int UtcDaliActorSetSizeSignal(void);
 extern int UtcDaliActorOnOffStageSignal(void);
@@ -1413,6 +1414,7 @@ testcase tc_array[] = {
     {"UtcDaliActorApplyConstraintAppliedCallback", UtcDaliActorApplyConstraintAppliedCallback, utc_dali_actor_startup, utc_dali_actor_cleanup},
     {"UtcDaliActorRemoveConstraints", UtcDaliActorRemoveConstraints, utc_dali_actor_startup, utc_dali_actor_cleanup},
     {"UtcDaliActorRemoveConstraint", UtcDaliActorRemoveConstraint, utc_dali_actor_startup, utc_dali_actor_cleanup},
+    {"UtcDaliActorRemoveConstraintTag", UtcDaliActorRemoveConstraintTag, utc_dali_actor_startup, utc_dali_actor_cleanup},
     {"UtcDaliActorTouchedSignal", UtcDaliActorTouchedSignal, utc_dali_actor_startup, utc_dali_actor_cleanup},
     {"UtcDaliActorSetSizeSignal", UtcDaliActorSetSizeSignal, utc_dali_actor_startup, utc_dali_actor_cleanup},
     {"UtcDaliActorOnOffStageSignal", UtcDaliActorOnOffStageSignal, utc_dali_actor_startup, utc_dali_actor_cleanup},
index dca5d0a..d703875 100644 (file)
@@ -2157,6 +2157,88 @@ int UtcDaliActorRemoveConstraint(void)
   END_TEST;
 }
 
+int UtcDaliActorRemoveConstraintTag(void)
+{
+  tet_infoline(" UtcDaliActorRemoveConstraintTag");
+  TestApplication application;
+
+  Actor actor = Actor::New();
+
+  // 1. Apply Constraint1 and Constraint2, and test...
+  unsigned int result1 = 0u;
+  unsigned int result2 = 0u;
+
+  unsigned constraint1Tag = 1u;
+  Constraint constraint1 = Constraint::New<Vector4>( Actor::COLOR, TestConstraintRef<Vector4>(result1, 1) );
+  constraint1.SetTag( constraint1Tag );
+  actor.ApplyConstraint( constraint1 );
+
+  unsigned constraint2Tag = 2u;
+  Constraint constraint2 = Constraint::New<Vector4>( Actor::COLOR, TestConstraintRef<Vector4>(result2, 2) );
+  constraint2.SetTag( constraint2Tag );
+  actor.ApplyConstraint( constraint2 );
+
+  Stage::GetCurrent().Add( actor );
+  // flush the queue and render once
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION );
+  DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION );
+
+  // 2. Remove Constraint1 and test...
+  result1 = 0;
+  result2 = 0;
+  actor.RemoveConstraints(constraint1Tag);
+  // make color property dirty, which will trigger constraints to be reapplied.
+  actor.SetColor( Color::WHITE );
+  // flush the queue and render once
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( result1, 0u, TEST_LOCATION );  ///< constraint 1 should not apply now.
+  DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION );
+
+  // 3. Re-Apply Constraint1 and test...
+  result1 = 0;
+  result2 = 0;
+  actor.ApplyConstraint( constraint1 );
+  // make color property dirty, which will trigger constraints to be reapplied.
+  actor.SetColor( Color::WHITE );
+  // flush the queue and render once
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION );
+  DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION );
+
+  // 2. Remove Constraint2 and test...
+  result1 = 0;
+  result2 = 0;
+  actor.RemoveConstraints(constraint2Tag);
+  // make color property dirty, which will trigger constraints to be reapplied.
+  actor.SetColor( Color::WHITE );
+  // flush the queue and render once
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION );
+  DALI_TEST_EQUALS( result2, 0u, TEST_LOCATION ); ///< constraint 2 should not apply now.
+
+  // 2. Remove Constraint1 as well and test...
+  result1 = 0;
+  result2 = 0;
+  actor.RemoveConstraints(constraint1Tag);
+  // make color property dirty, which will trigger constraints to be reapplied.
+  actor.SetColor( Color::WHITE );
+  // flush the queue and render once
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( result1, 0u, TEST_LOCATION ); ///< constraint 1 should not apply now.
+  DALI_TEST_EQUALS( result2, 0u, TEST_LOCATION ); ///< constraint 2 should not apply now.
+  END_TEST;
+}
 
 int UtcDaliActorTouchedSignal(void)
 {
index b00af1b..a07c517 100644 (file)
@@ -591,6 +591,20 @@ public:
    */
   RemoveAction GetRemoveAction() const;
 
+  /**
+   * @brief Set a tag for the constraint so it can be identified later
+   *
+   * @param[in] tag An integer to identify the constraint
+   */
+  void SetTag( const unsigned int tag );
+
+  /**
+   * @brief Get the tag
+   *
+   * @return The tag
+   */
+  unsigned int GetTag() const;
+
 public: // Not intended for use by Application developers
 
   /**
index b7e6706..7bc68d1 100644 (file)
@@ -118,6 +118,14 @@ public:
    */
   void RemoveConstraints();
 
+  /**
+     * @brief Remove all the constraint from the Object with a matching tag.
+     *
+     * @pre The Object has been intialized.
+     * @param[in] tag The tag of the constraints which will be removed
+     */
+  void RemoveConstraints( unsigned int tag );
+
 public:
 
 
index 5aa63b4..7f29377 100644 (file)
@@ -82,6 +82,7 @@ ActiveConstraintBase::ActiveConstraintBase( EventToUpdate& eventToUpdate, Proper
   mRemoveTime( 0.0f ),
   mAlphaFunction( Dali::Constraint::DEFAULT_ALPHA_FUNCTION ),
   mRemoveAction( Dali::Constraint::DEFAULT_REMOVE_ACTION ),
+  mTag(0),
   mApplyAnimation(),
   mRemoveAnimation()
 {
@@ -263,6 +264,17 @@ ActiveConstraintBase::RemoveAction ActiveConstraintBase::GetRemoveAction() const
   return mRemoveAction;
 }
 
+void ActiveConstraintBase::SetTag(const unsigned int tag)
+{
+  mTag = tag;
+}
+
+unsigned int ActiveConstraintBase::GetTag() const
+{
+  return mTag;
+}
+
+
 bool ActiveConstraintBase::IsSceneObjectRemovable() const
 {
   return true; // The constraint removed when target SceneGraph::PropertyOwner is destroyed
index 051ee19..2f0090e 100644 (file)
@@ -157,6 +157,18 @@ public:
   RemoveAction GetRemoveAction() const;
 
   /**
+   * @copydoc Dali::Constraint::SetTag()
+   */
+  void SetTag(const unsigned int tag);
+
+  /**
+   * @copydoc Dali::Constraint::GetTag()
+   */
+  unsigned int GetTag() const;
+
+
+
+  /**
    * Connects a callback function with the object's signals.
    * @param[in] object The object providing the signal.
    * @param[in] tracker Used to disconnect the signal.
@@ -293,6 +305,7 @@ protected:
   AlphaFunction mAlphaFunction;
 
   RemoveAction mRemoveAction;
+  unsigned int mTag;
 
 private:
 
@@ -300,6 +313,8 @@ private:
 
   Dali::Animation mApplyAnimation;  ///< Used to automatically animate weight from 0.0f -> 1.0f
   Dali::Animation mRemoveAnimation; ///< Used to automatically animate weight back to 0.0f
+
+
 };
 
 } // namespace Internal
index 44a6c8d..7d3c7a5 100644 (file)
@@ -106,6 +106,7 @@ public:
     clone->SetRemoveTime(mRemoveTime);
     clone->SetAlphaFunction(mAlphaFunction);
     clone->SetRemoveAction(mRemoveAction);
+    clone->SetTag( mTag );
 
     return clone;
   }
@@ -484,6 +485,7 @@ public:
     clone->SetRemoveTime(mRemoveTime);
     clone->SetAlphaFunction(mAlphaFunction);
     clone->SetRemoveAction(mRemoveAction);
+    clone->SetTag( mTag );
 
     return clone;
   }
index 4e1e3ce..6c618af 100644 (file)
@@ -269,6 +269,19 @@ Dali::Constraint::RemoveAction Constraint::GetRemoveAction() const
   return GetImplementation( mActiveConstraintTemplate ).GetRemoveAction();
 }
 
+
+void Constraint::SetTag(unsigned int tag)
+{
+  GetImplementation( mActiveConstraintTemplate ).SetTag(tag);
+}
+
+unsigned int Constraint::GetTag() const
+{
+  return GetImplementation( mActiveConstraintTemplate ).GetTag();
+}
+
+
+
 Constraint::~Constraint()
 {
 }
index 7c0b9fa..daa5d4d 100644 (file)
@@ -98,6 +98,19 @@ public:
   Dali::Constraint::RemoveAction GetRemoveAction() const;
 
   /**
+   * @copydoc Dali::Constraint::SetTag()
+   */
+  void SetTag( const unsigned int tag);
+
+  /**
+   * @copydoc Dali::Constraint::GetTag()
+   */
+  unsigned int GetTag() const;
+
+
+
+
+  /**
    * Create an active constraint.
    * An active constraint is created each time the constraint is applied to an object.
    * @return A newly allocated active-constraint.
index 47b4fb5..1f311bd 100644 (file)
@@ -894,43 +894,74 @@ TypeInfo* ProxyObject::GetTypeInfo() const
   return mTypeInfo;
 }
 
-void ProxyObject::RemoveConstraint( Dali::ActiveConstraint activeConstraint )
+void ProxyObject::RemoveConstraint( ActiveConstraint& constraint, bool isInScenegraph )
 {
-  if( mConstraints )
+  if( isInScenegraph )
   {
-    // If we have nothing in the scene-graph, just remove the activeConstraint from container
-    const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject();
-    if ( NULL == propertyOwner )
+    ActiveConstraintBase& baseConstraint = GetImplementation( constraint );
+    baseConstraint.BeginRemove();
+    if ( baseConstraint.IsRemoving() )
     {
-      ActiveConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), activeConstraint ) );
-      if( it != mConstraints->end() )
+      if( !mRemovedConstraints )
       {
-        mConstraints->erase( it );
+        mRemovedConstraints = new ActiveConstraintContainer;
       }
-      delete mRemovedConstraints;
-      mRemovedConstraints = NULL;
-      return;
+      // Wait for remove animation before destroying active-constraints
+      mRemovedConstraints->push_back( constraint );
     }
+  }
+  else if( mRemovedConstraints )
+  {
+    delete mRemovedConstraints;
+    mRemovedConstraints = NULL;
+  }
+}
 
-    // Discard constraints which are fully removed
-    DeleteRemovedConstraints();
 
-    ActiveConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), activeConstraint ) );
-    if( it != mConstraints->end() )
+void ProxyObject::RemoveConstraint( Dali::ActiveConstraint activeConstraint )
+{
+  if( mConstraints )
+  {
+    bool isInSceneGraph( NULL != GetSceneObject() );
+    if( isInSceneGraph )
     {
-      ActiveConstraintBase& constraint = GetImplementation( *it );
+      DeleteRemovedConstraints();
+    }
 
-      constraint.BeginRemove();
+    ActiveConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), activeConstraint ) );
+    if( it !=  mConstraints->end() )
+    {
+      RemoveConstraint( *it, isInSceneGraph );
       mConstraints->erase( it );
+    }
+  }
+
+}
+
 
-      if ( constraint.IsRemoving() )
+
+void ProxyObject::RemoveConstraints( unsigned int tag )
+{
+  if( mConstraints )
+  {
+    bool isInSceneGraph( NULL != GetSceneObject() );
+    if( isInSceneGraph )
+    {
+      DeleteRemovedConstraints();
+    }
+
+    ActiveConstraintIter iter( mConstraints->begin() );
+    while(iter != mConstraints->end() )
+    {
+      ActiveConstraintBase& constraint = GetImplementation( *iter );
+      if( constraint.GetTag() == tag )
       {
-        if( !mRemovedConstraints )
-        {
-          mRemovedConstraints = new ActiveConstraintContainer;
-        }
-        // Wait for remove animation before destroying active-constraints
-        mRemovedConstraints->push_back( *it );
+        RemoveConstraint( *iter, isInSceneGraph );
+        iter = mConstraints->erase( iter );
+      }
+      else
+      {
+        ++iter;
       }
     }
   }
@@ -944,31 +975,18 @@ void ProxyObject::RemoveConstraints()
     const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject();
     if ( NULL == propertyOwner )
     {
-      delete mConstraints;
-      mConstraints = NULL;
       delete mRemovedConstraints;
       mRemovedConstraints = NULL;
-      return;
     }
-
-    // Discard constraints which are fully removed
-    DeleteRemovedConstraints();
-
-    const ActiveConstraintConstIter endIter = mConstraints->end();
-    for ( ActiveConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter )
+    else
     {
-      ActiveConstraintBase& constraint = GetImplementation( *iter );
+      // Discard constraints which are fully removed
+      DeleteRemovedConstraints();
 
-      constraint.BeginRemove();
-
-      if ( constraint.IsRemoving() )
+      const ActiveConstraintConstIter endIter = mConstraints->end();
+      for ( ActiveConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter )
       {
-        if( !mRemovedConstraints )
-        {
-          mRemovedConstraints = new ActiveConstraintContainer;
-        }
-        // Wait for remove animation before destroying active-constraints
-        mRemovedConstraints->push_back( *iter );
+        RemoveConstraint( *iter, true );
       }
     }
 
@@ -977,6 +995,8 @@ void ProxyObject::RemoveConstraints()
   }
 }
 
+
+
 ProxyObject::~ProxyObject()
 {
   // Notification for observers
index 5a932e6..056720c 100644 (file)
@@ -276,6 +276,11 @@ public: // Constraints
    */
   void RemoveConstraints();
 
+  /**
+   * Remove all constraints from a ProxyObject with a matching tag
+   */
+  void RemoveConstraints( unsigned int tag );
+
 protected:
 
   /**
@@ -312,6 +317,12 @@ private:
    */
   void DeleteRemovedConstraints();
 
+  /**
+   * Helper to remove active constraints
+   */
+  void RemoveConstraint( ActiveConstraint& constraint, bool isInScenegraph );
+
+
 private: // Default property extensions for derived classes
 
   /**
index 7e1773a..7e1afd3 100644 (file)
@@ -81,6 +81,20 @@ Constraint::RemoveAction Constraint::GetRemoveAction() const
   return GetImplementation(*this).GetRemoveAction();
 }
 
+void Constraint::SetTag( const unsigned int tag )
+{
+  GetImplementation(*this).SetTag( tag );
+}
+
+unsigned int Constraint::GetTag() const
+{
+  return GetImplementation(*this).GetTag();
+}
+
+
+
+
+
 Constraint Constraint::New( Property::Index target,
                             Property::Type targetType,
                             AnyFunction func,
index 8ff96d7..edb0a45 100644 (file)
@@ -67,4 +67,11 @@ void Constrainable::RemoveConstraints()
   GetImplementation(*this).RemoveConstraints();
 }
 
+void Constrainable::RemoveConstraints( unsigned int tag )
+{
+  GetImplementation(*this).RemoveConstraints( tag );
+}
+
+
+
 } // Dali