| 1626 | } |
| 1627 | |
| 1628 | void QmitkMxNMultiWidget::SetSynchronizationGroup(QmitkSynchronizedNodeSelectionWidget* synchronizedWidget, const GroupSyncIndexType index) |
| 1629 | { |
| 1630 | if (nullptr == synchronizedWidget) |
| 1631 | { |
| 1632 | mitkThrow() << "SetSynchronizationGroup: synchronizedWidget must not be null."; |
| 1633 | } |
| 1634 | |
| 1635 | // Auto-create on first reference. Add() validates index >= 1 and storage presence. |
| 1636 | if (m_SynchronizedWidgetConnectors.find(index) == m_SynchronizedWidgetConnectors.end()) |
| 1637 | { |
| 1638 | this->AddSynchronizationGroup(index); |
| 1639 | } |
| 1640 | |
| 1641 | const auto old_index = synchronizedWidget->GetSyncGroup(); |
| 1642 | |
| 1643 | if (old_index == index) |
| 1644 | { |
| 1645 | // Already on this group. Connector edge stays (no double-Connect that would |
| 1646 | // double-bump the connection counter); just refresh state from the connector |
| 1647 | // so the freshly attached widget sees the cached selection / select-all mode. |
| 1648 | m_SynchronizedWidgetConnectors[index]->SynchronizeWidget(synchronizedWidget); |
| 1649 | return; |
| 1650 | } |
| 1651 | |
| 1652 | // For the initial setting of the synchronization, nothing old is there to disconnect. |
| 1653 | if (old_index != -1) |
| 1654 | { |
| 1655 | const auto oldIt = m_SynchronizedWidgetConnectors.find(old_index); |
| 1656 | if (oldIt != m_SynchronizedWidgetConnectors.end()) |
| 1657 | { |
| 1658 | oldIt->second->DisconnectWidget(synchronizedWidget); |
| 1659 | } |
| 1660 | } |
| 1661 | |
| 1662 | synchronizedWidget->SetSyncGroup(index); |
| 1663 | m_SynchronizedWidgetConnectors[index]->ConnectWidget(synchronizedWidget); |
| 1664 | m_SynchronizedWidgetConnectors[index]->SynchronizeWidget(synchronizedWidget); |
| 1665 | } |
| 1666 | |
| 1667 | QmitkSynchronizedWidgetConnector* QmitkMxNMultiWidget::GetSyncGroupConnector(const GroupSyncIndexType index) const |
| 1668 | { |