Prechádzať 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 10 rokov pred
rodič
commit
71a6a8ff32
1 zmenil súbory, kde vykonal 12 pridanie a 4 odobranie
  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);
   }
 }