Browse Source

fix not all elements where updated correctly when the uiml of a uiml view was changed

Kolja Strohm 8 months ago
parent
commit
ec69a5cdaf
1 changed files with 29 additions and 20 deletions
  1. 29 20
      UIMLView.cpp

+ 29 - 20
UIMLView.cpp

@@ -790,7 +790,6 @@ DLLEXPORT bool Framework::UIMLTable::updateElement(
                     || !generalFactory.updateElement(
                         element, *z, generalFactory))
                 {
-                    if (z) generalFactory.removeZeichnung(*z);
                     z = generalFactory.parseElement(*i.val(), generalFactory);
                     if (z) t->setZeichnungZ(Text(c - 1), id, z);
                 }
@@ -805,22 +804,12 @@ DLLEXPORT bool Framework::UIMLTable::updateElement(
                  .whereAttributeEquals("id", *t->zZeilenName(i))
                  .exists())
         {
-            for (int j = 0; j < t->getSpaltenAnzahl(); j++)
-            {
-                Zeichnung* z = t->zZeichnung(j, i);
-                if (z) generalFactory.removeZeichnung(*z);
-            }
             t->removeZeile(i);
             i--;
         }
     }
     for (int i = numCols; i < t->getSpaltenAnzahl(); i++)
     { // remove all columns that are not in the xml
-        for (int j = 0; j < t->getZeilenAnzahl(); j++)
-        {
-            Zeichnung* z = t->zZeichnung(i, j);
-            if (z) generalFactory.removeZeichnung(*z);
-        }
         t->removeSpalte(i);
         i--;
     }
@@ -892,12 +881,8 @@ bool Framework::UIMLFrame::updateElement(
     if (!f) return false;
     for (auto member = f->getMembers().begin(); member; )
     { // remove all members that are not in the xml
-        if (!element
-                 .selectChildsByAttribute(
-                     "id", generalFactory.getZeichnungId(*member.val()))
-                 .exists())
-        {
-            generalFactory.removeZeichnung(*member.val());
+        Framework::Text id = generalFactory.getZeichnungId(*member.val());
+        if (id.getLength() == 0){
             member.remove();
             f->setRender();
         }
@@ -1179,6 +1164,17 @@ void UIMLView::setUIML(XML::Element* uiml)
 {
     if (dom)
     { // update dom and members
+        auto newChilds = uiml->selectChildren().selectAllElements();
+        // remove old members
+        for (XML::Element *i : dom->selectChildren().selectAllElements().whereAttributeExists("id"))
+        {
+            Framework::Text id = i->getAttributeValue("id");
+            if (!newChilds.whereAttributeEquals("id", id).exists())
+            {
+				Zeichnung* z = members->z(id, id.getLength());
+                if (z) removeZeichnung(*z);
+			}
+		}
         dom = uiml;
         update();
     }
@@ -1222,7 +1218,6 @@ void Framework::UIMLView::update()
         Zeichnung* z = zZeichnungById(id);
         if (!id.getLength() || !z || !updateElement(*i.val(), *z, *this))
         {
-            if (z) removeZeichnung(*z);
             z = parseElement(*i.val(), *this);
             if (z) z->release();
         }
@@ -1524,14 +1519,28 @@ Zeichnung* UIMLView::parseElement(
 bool Framework::UIMLView::updateElement(
     XML::Element& element, Zeichnung& z, UIMLContainer& generalFactory)
 {
+    bool result = 0;
     for (UIMLElement* e : knownElements)
     {
         if (e->isApplicableFor(element))
         {
-            return e->updateElement(element, z, *this);
+            result = e->updateElement(element, z, *this);
+            break;
+        }
+    }
+    if (!result)
+    {
+        for (XML::Element* element :
+            element.selectChildren().selectAllElements().whereAttributeExists(
+                "id"))
+        { // element could not be updated so all children will be removed
+            Framework::Text id = element->getAttributeValue("id");
+            Zeichnung* z = zZeichnungById(id);
+            if (z) removeZeichnung(*z);
         }
+        removeZeichnung(z);
     }
-    return false;
+    return result;
 }
 
 void UIMLView::layout(XML::Element& element,