Tidy up some is_candidate() methods.
authordooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Thu, 6 Mar 2008 20:37:48 +0000 (20:37 +0000)
committerdooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Thu, 6 Mar 2008 20:37:48 +0000 (20:37 +0000)
git-svn-id: http://svn.voria.com/code@1864 1f10aa63-cdf2-0310-b900-c93c546f37ac

16 files changed:
synfig-studio/trunk/src/synfigapp/actions/activepointadd.cpp
synfig-studio/trunk/src/synfigapp/actions/activepointremove.cpp
synfig-studio/trunk/src/synfigapp/actions/activepointset.cpp
synfig-studio/trunk/src/synfigapp/actions/activepointsetoff.cpp
synfig-studio/trunk/src/synfigapp/actions/activepointseton.cpp
synfig-studio/trunk/src/synfigapp/actions/activepointsetsmart.cpp
synfig-studio/trunk/src/synfigapp/actions/valuedescdisconnect.cpp
synfig-studio/trunk/src/synfigapp/actions/valuenodedynamiclistinsert.cpp
synfig-studio/trunk/src/synfigapp/actions/valuenodedynamiclistinsertsmart.cpp
synfig-studio/trunk/src/synfigapp/actions/valuenodedynamiclistloop.cpp
synfig-studio/trunk/src/synfigapp/actions/valuenodedynamiclistremove.cpp
synfig-studio/trunk/src/synfigapp/actions/valuenodedynamiclistremovesmart.cpp
synfig-studio/trunk/src/synfigapp/actions/valuenodedynamiclistrotateorder.cpp
synfig-studio/trunk/src/synfigapp/actions/valuenodedynamiclistunloop.cpp
synfig-studio/trunk/src/synfigapp/actions/waypointadd.cpp
synfig-studio/trunk/src/synfigapp/actions/waypointsetsmart.cpp

index 2840796..b6f04a5 100644 (file)
@@ -93,17 +93,16 @@ Action::ActivepointAdd::get_param_vocab()
 bool
 Action::ActivepointAdd::is_candidate(const ParamList &x)
 {
-       if(candidate_check(get_param_vocab(),x))
-       {
-               ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
-               if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
-                       return false;
+       if (!candidate_check(get_param_vocab(),x))
+               return false;
 
-               // We need either a activepoint or a time.
-               if(x.count("activepoint") || x.count("time"))
-                       return true;
-       }
-       return false;
+       ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
+
+       return (value_desc.parent_is_value_node() &&
+                       // We need a dynamic list.
+                       ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()) &&
+                       // We need either an activepoint or a time.
+                       (x.count("activepoint") || x.count("time")));
 }
 
 bool
index 7626eb0..d43a64a 100644 (file)
@@ -85,15 +85,14 @@ Action::ActivepointRemove::get_param_vocab()
 bool
 Action::ActivepointRemove::is_candidate(const ParamList &x)
 {
-       if(candidate_check(get_param_vocab(),x))
-       {
-               ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
-               if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
-                       return false;
+       if (!candidate_check(get_param_vocab(),x))
+               return false;
 
-               return true;
-       }
-       return false;
+       ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
+
+       return (value_desc.parent_is_value_node() &&
+                       // We need a dynamic list.
+                       ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()));
 }
 
 bool
index 904b556..f3a5323 100644 (file)
@@ -85,15 +85,14 @@ Action::ActivepointSet::get_param_vocab()
 bool
 Action::ActivepointSet::is_candidate(const ParamList &x)
 {
-       if(candidate_check(get_param_vocab(),x))
-       {
-               ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
-               if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
-                       return false;
+       if (!candidate_check(get_param_vocab(),x))
+               return false;
 
-               return true;
-       }
-       return false;
+       ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
+
+       return (value_desc.parent_is_value_node() &&
+                       // We need a dynamic list.
+                       ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()));
 }
 
 bool
index b1c7156..15bfe14 100644 (file)
@@ -99,22 +99,22 @@ Action::ActivepointSetOff::get_param_vocab()
 bool
 Action::ActivepointSetOff::is_candidate(const ParamList &x)
 {
-       if(candidate_check(get_param_vocab(),x))
-       {
-               ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
-               if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
-                       return false;
+       if (!candidate_check(get_param_vocab(),x))
+               return false;
 
-               // We are only a candidate if this canvas is animated.
-               Canvas::Handle canvas(x.find("canvas")->second.get_canvas());
-               if(canvas->rend_desc().get_time_start()==canvas->rend_desc().get_time_end())
-                       return false;
+       ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
 
-               // We need either a activepoint or a time.
-               if(x.count("activepoint") || x.count("time"))
-                       return true;
-       }
-       return false;
+       if (!(value_desc.parent_is_value_node() &&
+                 // We need a dynamic list.
+                 ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node())))
+               return false;
+
+       Canvas::Handle canvas(x.find("canvas")->second.get_canvas());
+
+       // We are only a candidate if this canvas is animated.
+       return (canvas->rend_desc().get_time_start() != canvas->rend_desc().get_time_end() &&
+                       // We need either an activepoint or a time.
+                       (x.count("activepoint") || x.count("time")));
 }
 
 bool
index 3f48f05..217eb8a 100644 (file)
@@ -99,22 +99,22 @@ Action::ActivepointSetOn::get_param_vocab()
 bool
 Action::ActivepointSetOn::is_candidate(const ParamList &x)
 {
-       if(candidate_check(get_param_vocab(),x))
-       {
-               ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
-               if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
-                       return false;
+       if (!candidate_check(get_param_vocab(),x))
+               return false;
 
-               // We are only a candidate if this canvas is animated.
-               Canvas::Handle canvas(x.find("canvas")->second.get_canvas());
-               if(canvas->rend_desc().get_time_start()==canvas->rend_desc().get_time_end())
-                       return false;
+       ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
 
-               // We need either a activepoint or a time.
-               if(x.count("activepoint") || x.count("time"))
-                       return true;
-       }
-       return false;
+       if (!(value_desc.parent_is_value_node() &&
+                 // We need a dynamic list.
+                 ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node())))
+               return false;
+
+       Canvas::Handle canvas(x.find("canvas")->second.get_canvas());
+
+       // We are only a candidate if this canvas is animated.
+       return (canvas->rend_desc().get_time_start() != canvas->rend_desc().get_time_end() &&
+                       // We need either an activepoint or a time.
+                       (x.count("activepoint") || x.count("time")));
 }
 
 bool
index 8358f33..3713e04 100644 (file)
@@ -100,17 +100,16 @@ Action::ActivepointSetSmart::get_param_vocab()
 bool
 Action::ActivepointSetSmart::is_candidate(const ParamList &x)
 {
-       if(candidate_check(get_param_vocab(),x))
-       {
-               ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
-               if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
-                       return false;
+       if (!candidate_check(get_param_vocab(),x))
+               return false;
 
-               // We need either a activepoint or a time.
-               if(x.count("activepoint") || x.count("time"))
-                       return true;
-       }
-       return false;
+       ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
+
+       return (value_desc.parent_is_value_node() &&
+                       // We need a dynamic list.
+                       ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()) &&
+                       // We need either an activepoint or a time.
+                       (x.count("activepoint") || x.count("time")));
 }
 
 bool
index 0501f8f..91c58ca 100644 (file)
@@ -101,28 +101,27 @@ Action::ValueDescDisconnect::get_param_vocab()
 bool
 Action::ValueDescDisconnect::is_candidate(const ParamList &x)
 {
-       if(candidate_check(get_param_vocab(),x))
-       {
-               ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
-
-               // don't allow the Index parameter of the Duplicate layer to be disconnected
-               if(value_desc.parent_is_layer_param() && value_desc.get_layer()->get_name() == "duplicate" && value_desc.get_param_name() == "index")
-                       return false;
-               if(!value_desc.parent_is_canvas() && value_desc.is_value_node() && value_desc.get_value_node()->rcount()>1)
-                       return true;
-               if(value_desc.is_const())
-                       return false;
-               if(value_desc.is_value_node() && ValueNode_Const::Handle::cast_dynamic(value_desc.get_value_node()))
-                       return false;
-               // don't allow Duplicate ValueNodes in the Children dialog to be disconnected
-               if(value_desc.is_value_node() &&
-                  ValueNode_Duplicate::Handle::cast_dynamic(value_desc.get_value_node()) &&
-                  !value_desc.parent_is_layer_param() &&
-                  !value_desc.parent_is_value_node())
-                       return false;
+       if (!candidate_check(get_param_vocab(),x))
+               return false;
+
+       ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
+
+       // don't allow the Index parameter of the Duplicate layer to be disconnected
+       if(value_desc.parent_is_layer_param() && value_desc.get_layer()->get_name() == "duplicate" && value_desc.get_param_name() == "index")
+               return false;
+       if(!value_desc.parent_is_canvas() && value_desc.is_value_node() && value_desc.get_value_node()->rcount()>1)
                return true;
-       }
-       return false;
+       if(value_desc.is_const())
+               return false;
+       if(value_desc.is_value_node() && ValueNode_Const::Handle::cast_dynamic(value_desc.get_value_node()))
+               return false;
+       // don't allow Duplicate ValueNodes in the Children dialog to be disconnected
+       if(value_desc.is_value_node() &&
+          ValueNode_Duplicate::Handle::cast_dynamic(value_desc.get_value_node()) &&
+          !value_desc.parent_is_layer_param() &&
+          !value_desc.parent_is_value_node())
+               return false;
+       return true;
 }
 
 bool
index 46078ab..d962dbe 100644 (file)
@@ -94,15 +94,14 @@ Action::ValueNodeDynamicListInsert::get_param_vocab()
 bool
 Action::ValueNodeDynamicListInsert::is_candidate(const ParamList &x)
 {
-       if(candidate_check(get_param_vocab(),x))
-       {
-               ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
-               if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
-                       return false;
+       if (!candidate_check(get_param_vocab(),x))
+               return false;
 
-               return true;
-       }
-       return false;
+       ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
+
+       return (value_desc.parent_is_value_node() &&
+                       // We need a dynamic list.
+                       ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()));
 }
 
 bool
index 0e0dbe4..889aa87 100644 (file)
@@ -92,15 +92,14 @@ Action::ValueNodeDynamicListInsertSmart::get_param_vocab()
 bool
 Action::ValueNodeDynamicListInsertSmart::is_candidate(const ParamList &x)
 {
-       if(candidate_check(get_param_vocab(),x))
-       {
-               ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
-               if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
-                       return false;
+       if (!candidate_check(get_param_vocab(),x))
+               return false;
 
-               return true;
-       }
-       return false;
+       ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
+
+       return (value_desc.parent_is_value_node() &&
+                       // We need a dynamic list.
+                       ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()));
 }
 
 bool
index 8b618d1..c3cecbe 100644 (file)
@@ -78,21 +78,21 @@ Action::ValueNodeDynamicListLoop::get_param_vocab()
 bool
 Action::ValueNodeDynamicListLoop::is_candidate(const ParamList &x)
 {
-       if(candidate_check(get_param_vocab(),x))
-       {
-               ValueNode::Handle value_node;
-               ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
-               if(value_desc.parent_is_value_node())
-                       value_node = value_desc.get_parent_value_node();
-               else
-                       value_node = x.find("value_node")->second.get_value_node();
-               if(!ValueNode_DynamicList::Handle::cast_dynamic(value_node))
-                       return false;
-               if(ValueNode_DynamicList::Handle::cast_dynamic(value_node)->get_loop()==true)
-                       return false;
-               return true;
-       }
-       return false;
+       if (!candidate_check(get_param_vocab(),x))
+               return false;
+
+       ValueNode::Handle value_node;
+       ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
+
+       if(value_desc.parent_is_value_node())
+               value_node = value_desc.get_parent_value_node();
+       else
+               value_node = x.find("value_node")->second.get_value_node();
+
+       // We need a dynamic list.
+       return (ValueNode_DynamicList::Handle::cast_dynamic(value_node) &&
+                       // We need the list not to be looped.
+                       !ValueNode_DynamicList::Handle::cast_dynamic(value_node)->get_loop());
 }
 
 bool
index 1c4f1b0..a4c4d5f 100644 (file)
@@ -80,15 +80,14 @@ Action::ValueNodeDynamicListRemove::get_param_vocab()
 bool
 Action::ValueNodeDynamicListRemove::is_candidate(const ParamList &x)
 {
-       if(candidate_check(get_param_vocab(),x))
-       {
-               ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
-               if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
-                       return false;
+       if (!candidate_check(get_param_vocab(),x))
+               return false;
 
-               return true;
-       }
-       return false;
+       ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
+
+       return (value_desc.parent_is_value_node() &&
+                       // We need a dynamic list.
+                       ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()));
 }
 
 bool
index e7b315c..f479de5 100644 (file)
@@ -91,15 +91,14 @@ Action::ValueNodeDynamicListRemoveSmart::get_param_vocab()
 bool
 Action::ValueNodeDynamicListRemoveSmart::is_candidate(const ParamList &x)
 {
-       if(candidate_check(get_param_vocab(),x))
-       {
-               ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
-               if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
-                       return false;
+       if (!candidate_check(get_param_vocab(),x))
+               return false;
 
-               return true;
-       }
-       return false;
+       ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
+
+       return (value_desc.parent_is_value_node() &&
+                       // We need a dynamic list.
+                       ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()));
 }
 
 bool
index a9d1ff6..4e1c40a 100644 (file)
@@ -80,15 +80,14 @@ Action::ValueNodeDynamicListRotateOrder::get_param_vocab()
 bool
 Action::ValueNodeDynamicListRotateOrder::is_candidate(const ParamList &x)
 {
-       if(candidate_check(get_param_vocab(),x))
-       {
-               ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
-               if(!value_desc.parent_is_value_node() || !ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()))
-                       return false;
+       if (!candidate_check(get_param_vocab(),x))
+               return false;
 
-               return true;
-       }
-       return false;
+       ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
+
+       return (value_desc.parent_is_value_node() &&
+                       // We need a dynamic list.
+                       ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()));
 }
 
 bool
index ff3056f..3269e12 100644 (file)
@@ -78,21 +78,21 @@ Action::ValueNodeDynamicListUnLoop::get_param_vocab()
 bool
 Action::ValueNodeDynamicListUnLoop::is_candidate(const ParamList &x)
 {
-       if(candidate_check(get_param_vocab(),x))
-       {
-               ValueNode::Handle value_node;
-               ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
-               if(value_desc.parent_is_value_node())
-                       value_node = value_desc.get_parent_value_node();
-               else
-                       value_node = x.find("value_node")->second.get_value_node();
-               if(!ValueNode_DynamicList::Handle::cast_dynamic(value_node))
-                       return false;
-               if(ValueNode_DynamicList::Handle::cast_dynamic(value_node)->get_loop()==false)
-                       return false;
-               return true;
-       }
-       return false;
+       if (!candidate_check(get_param_vocab(),x))
+               return false;
+
+       ValueNode::Handle value_node;
+       ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
+
+       if(value_desc.parent_is_value_node())
+               value_node = value_desc.get_parent_value_node();
+       else
+               value_node = x.find("value_node")->second.get_value_node();
+
+       // We need a dynamic list.
+       return (ValueNode_DynamicList::Handle::cast_dynamic(value_node) &&
+                       // We need the list to be looped.
+                       ValueNode_DynamicList::Handle::cast_dynamic(value_node)->get_loop());
 }
 
 bool
index 8912b3a..f080910 100644 (file)
@@ -94,16 +94,11 @@ Action::WaypointAdd::get_param_vocab()
 bool
 Action::WaypointAdd::is_candidate(const ParamList &x)
 {
-       if(candidate_check(get_param_vocab(),x))
-       {
-               if(!ValueNode_Animated::Handle::cast_dynamic(x.find("value_node")->second.get_value_node()))
-                       return false;
-
-               // We need either a waypoint or a time.
-               if(x.count("waypoint") || x.count("time"))
-                       return true;
-       }
-       return false;
+       return (candidate_check(get_param_vocab(),x) &&
+                       // We need an animated valuenode.
+                       ValueNode_Animated::Handle::cast_dynamic(x.find("value_node")->second.get_value_node()) &&
+                       // We need either a waypoint or a time.
+                       (x.count("waypoint") || x.count("time")));
 }
 
 bool
index 26c86cb..23a0ea2 100644 (file)
@@ -108,16 +108,11 @@ Action::WaypointSetSmart::get_param_vocab()
 bool
 Action::WaypointSetSmart::is_candidate(const ParamList &x)
 {
-       if(candidate_check(get_param_vocab(),x))
-       {
-               if(!ValueNode_Animated::Handle::cast_dynamic(x.find("value_node")->second.get_value_node()))
-                       return false;
-               // We need either a waypoint or a time.
-               if(x.count("waypoint") || x.count("time"))
-                       return true;
-               return false;
-       }
-       return false;
+       return (candidate_check(get_param_vocab(),x) &&
+                       // We need an animated valuenode.
+                       ValueNode_Animated::Handle::cast_dynamic(x.find("value_node")->second.get_value_node()) &&
+                       // We need either a waypoint or a time.
+                       (x.count("waypoint") || x.count("time")));
 }
 
 bool