MCPcopy Create free account
hub / github.com/MITK/MITK / SerializeSplitter

Method SerializeSplitter

Modules/QtWidgets/src/QmitkMxNMultiWidget.cpp:800–855  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

798}
799
800nlohmann::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
857QmitkMxNMultiWidget::WindowDescriptor

Callers 1

SerializeLayoutMethod · 0.95

Calls 6

MakeWindowDescriptorMethod · 0.95
countMethod · 0.80
GetUtilityWidgetMethod · 0.80
GetSyncGroupMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected