소스 검색

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