ソースを参照

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);
   }
 }