Repository: pyqtgraph/pyqtgraph

Issue:
Dock restoreState fails silently if a dock object is the only item in a V- or HContainer
### Short description
Calling restoreState() on a dockArea where a dock is the only object inside a container leads to the state being not correctly restored.
I don't know how it happened that a dock could appear as the only item in a container but one user managed to do that.
I couldn't find out how to trigger that.
Anyway, in that case way too many container are apoptose'd and the state is nor correctly restored

### Code to reproduce
```python
import json
import sys

import pyqtgraph as pg
from PySide6.QtWidgets import QMainWindow
from pyqtgraph.dockarea import Dock, DockArea


class DockApp(QMainWindow):
    def __init__(self, title):
        super().__init__()
        self.dock_area = DockArea()
        self.setCentralWidget(self.dock_area)
        self.dock_area.addDock(Dock(name="Plot 1", closable=False), 'left')
        self.dock_area.addDock(Dock(name="Plot 2", closable=False), 'left')
        self.dock_area.addDock(Dock(name="Plot 4", closable=False), 'left')
        self.dock_area.addDock(Dock(name="Table 1", closable=False), 'left')
        self.dock_area.addDock(Dock(name="Table 2", closable=False), 'left')
        self.dock_area.addDock(Dock(name="Table 3", closable=False), 'left')

        state = json.loads("""{
          "main": [
            "vertical",
            [
              [
                "horizontal",
                [
                  [
                    "vertical",
                    [
                      [
                        "vertical",
                        [
                          [
                            "dock",
                            "Plot 1",
                            {}
                          ]
                        ],
                        {
                          "sizes": [
                            314
                          ]
                        }
                      ],
                      [
                        "dock",
                        "Plot 2",
                        {}
                      ]
                    ],
                    {
                      "sizes": [
                        314,
                        313
                      ]
                    }
                  ],
                  [
                    "vertical",
                    [
                      [
                        "dock",
                        "Table 3",
                        {}
                      ],
                      [
                        "dock",
                        "Table 2",
                        {}
                      ],
                      [
                        "dock",
                        "Table 1",
                        {}
                      ]
                    ],
                    {
                      "sizes": [
                        208,
                        207,
                        208
                      ]
                    }
                  ]
                ],
                {
                  "sizes": [
                    784,
                    783
                  ]
                }
              ],
              [
                "dock",
                "Plot 4",
                {}
              ]
            ],
            {
              "sizes": [
                631,
                210
              ]
            }
          ],
          "float": []
        }""")
        self.dock_area.restoreState(state)


if __name__ == '__main__':
    app = pg.Qt.mkQApp("LiveTrace")
    window = DockApp(title='Test')
    window.show()
    sys.exit(app.exec())
```

### Expected behavior
All 6 docks should be restored like this:
![image](https://github.com/pyqtgraph/pyqtgraph/assets/627373/850761a7-ce75-418a-858c-0e80449481ee)


### Real behavior
Only 2 docks are visible. All other docks are missing.
![image](https://github.com/pyqtgraph/pyqtgraph/assets/627373/3501edf7-c73d-421c-9f8c-a553f76f19ce)


Note: No exception is thrown

### Tested environment(s)

 * PyQtGraph version: 0.13.3
 * Qt Python binding: PySide6 6.6.0 Qt 6.6.0
 * Python version: 3.10.11 AMD64
 * NumPy version: 1.26.2
 * Operating system: Windows 10 22H2
 * Installation method: pip

### Additional context



Discussion:
I investigated the issue myself already and could trace the origin via the following call stack:
In DockArea.restoreState [.buildFromState](https://github.com/pyqtgraph/pyqtgraph/blob/master/pyqtgraph/dockarea/DockArea.py#L239) is called.
[buildFromState ](https://github.com/pyqtgraph/pyqtgraph/blob/master/pyqtgraph/dockarea/DockArea.py#L286) builds the container layout recursively.
When it builds the vertical container containing Plot 1 it calls [`obj.apoptose(propagate=False)`](https://github.com/pyqtgraph/pyqtgraph/blob/master/pyqtgraph/dockarea/DockArea.py#L289).
Here the dock widget is inserted in the parent container and removed from its original container: https://github.com/pyqtgraph/pyqtgraph/blob/master/pyqtgraph/dockarea/Container.py#L71
Finally the container change is propagated via the call to `containerChanged(self)`: https://github.com/pyqtgraph/pyqtgraph/blob/master/pyqtgraph/dockarea/Container.py#L54
And here finally is the culprit: apoptose() is called on the original container without any arguments: https://github.com/pyqtgraph/pyqtgraph/blob/master/pyqtgraph/dockarea/Dock.py#L213
This means propagate is True, as can be seen here: https://github.com/pyqtgraph/pyqtgraph/blob/master/pyqtgraph/dockarea/Container.py#L60
So, since there is only one element in the container currently and all parent containers have only one element as well, because we're in the middle of constructing the container tree, the entire tree is compacted into only one container and the dock itself.
Now, the container in the further state restoration are missing and therefore not visible and even garbage collected.

Changing [Line 213 in Dock.py](https://github.com/pyqtgraph/pyqtgraph/blob/master/pyqtgraph/dockarea/Dock.py#L213) to `self._container.apoptose(propagate=False)` fixes the issue and all docks are correctly restored.
The problem is I don't know if this was merely forgotten there, because it is no usual case, that a container has only 1 element or is it necessary because something else would break, which I'm not aware of.
Anyone has any idea?




Resolving patch:
diff --git a/pyqtgraph/dockarea/Dock.py b/pyqtgraph/dockarea/Dock.py
--- a/pyqtgraph/dockarea/Dock.py
+++ b/pyqtgraph/dockarea/Dock.py
@@ -210,7 +210,7 @@ def container(self):
     def containerChanged(self, c):
         if self._container is not None:
             # ask old container to close itself if it is no longer needed
-            self._container.apoptose()
+            self._container.apoptose(propagate=False)
         self._container = c
         if c is None:
             self.area = None


Test patch: