浏览代码

Adapted add(child) function of ctkXnatObject

Since upload is now possible, a child might be added without a foregone
fetch. If a fetch is then called afterwards the child will be added
twice, since the add(child) funciton did just compare the pointers.
Now the ID is compared and if the ID is empty the name is compared.
If the child exists it is simply replaced.
Andreas Fetzer 10 年之前
父节点
当前提交
71a6a8ff32
共有 1 个文件被更改,包括 12 次插入4 次删除
  1. 12 4
      Libs/XNAT/Core/ctkXnatObject.cpp

+ 12 - 4
Libs/XNAT/Core/ctkXnatObject.cpp

@@ -228,13 +228,21 @@ void ctkXnatObject::add(ctkXnatObject* child)
   {
     child->d_func()->parent = this;
   }
-  if (!d->children.contains(child))
+
+  bool childExists (false);
+  foreach (ctkXnatObject* existingChild, d->children)
   {
-    d->children.push_back(child);
+    if ((existingChild->id().length() != 0 && existingChild->id() == child->id()) ||
+        (existingChild->id().length() == 0 && existingChild->name() == child->name()))
+    {
+      d->children.replace(d->children.indexOf(existingChild), child);
+      childExists = true;
+      qWarning() << "ctkXnatObject::add(): Child already exists -> Replaced child!";
+    }
   }
-  else
+  if (!childExists)
   {
-    qWarning() << "ctkXnatObject::add(): Child already exists";
+    d->children.push_back(child);
   }
 }