| 798 | } |
| 799 | |
| 800 | nlohmann::json QmitkMxNMultiWidget::SerializeSplitter( |
| 801 | const QSplitter* splitter, |
| 802 | const std::map<GroupSyncIndexType, std::string>& groupNames) const |
| 803 | { |
| 804 | nlohmann::json node; |
| 805 | node["type"] = "split"; |
| 806 | node["orientation"] = (splitter->orientation() == Qt::Vertical) ? "vertical" : "horizontal"; |
| 807 | |
| 808 | const auto sizes = splitter->sizes(); |
| 809 | auto children = nlohmann::json::array(); |
| 810 | for (int i = 0; i < splitter->count(); ++i) |
| 811 | { |
| 812 | auto* child = splitter->widget(i); |
| 813 | nlohmann::json childJson; |
| 814 | if (auto* sub = dynamic_cast<QSplitter*>(child)) |
| 815 | { |
| 816 | childJson = this->SerializeSplitter(sub, groupNames); |
| 817 | } |
| 818 | else if (auto* cell = dynamic_cast<QmitkRenderWindowWidget*>(child)) |
| 819 | { |
| 820 | // Sanity: the pre-walk must have visited every cell and added its |
| 821 | // sync-group index to 'groupNames'. A miss here would be engine |
| 822 | // corruption (cell with an index not seen during the pre-walk). |
| 823 | const auto idx = cell->GetUtilityWidget()->GetSyncGroup(); |
| 824 | if (groupNames.find(idx) == groupNames.end()) |
| 825 | { |
| 826 | mitkThrow() << "SerializeLayout: cell sync group " << idx |
| 827 | << " was not seen during the pre-walk pass."; |
| 828 | } |
| 829 | const auto descriptor = this->MakeWindowDescriptor(cell); |
| 830 | childJson["type"] = "window"; |
| 831 | childJson["id"] = descriptor.id.toStdString(); |
| 832 | // Optional display label: omit the JSON key when the cell has no |
| 833 | // display name, so empty strings never appear on disk (see schema: |
| 834 | // `name` requires minLength 1 when present). |
| 835 | if (!descriptor.displayName.isEmpty()) |
| 836 | { |
| 837 | childJson["name"] = descriptor.displayName.toStdString(); |
| 838 | } |
| 839 | childJson["view_direction"] = descriptor.viewDirection.toStdString(); |
| 840 | childJson["links"] = nlohmann::json{ { "selection", descriptor.selectionGroup.toStdString() } }; |
| 841 | } |
| 842 | else |
| 843 | { |
| 844 | mitkThrow() << "SerializeLayout: unknown child widget type at splitter index " << i << "."; |
| 845 | } |
| 846 | childJson["size"] = sizes[i]; |
| 847 | children.push_back(childJson); |
| 848 | } |
| 849 | node["children"] = children; |
| 850 | |
| 851 | // Note: the root has no 'size' field structurally - the parent loop above |
| 852 | // attaches 'size' to each child before pushing into the children array, |
| 853 | // and the root, having no parent loop, never gets one. |
| 854 | return node; |
| 855 | } |
| 856 | |
| 857 | QmitkMxNMultiWidget::WindowDescriptor |
no test coverage detected