Procházet zdrojové kódy

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 před 10 roky
rodič
revize
71a6a8ff32
1 změnil soubory, kde provedl 12 přidání a 4 odebrání
  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);
   }
 }