| 289 | } |
| 290 | |
| 291 | void QmitkMultiLabelInspector::OnModelChanged() |
| 292 | { |
| 293 | if (!m_ModelManipulationOngoing) |
| 294 | { //the model was changed externally and not by this instance |
| 295 | //ensure that selection state is still valid |
| 296 | //If this instance is manipulating it, it will take care of direct selection directly |
| 297 | |
| 298 | QmitkMultiLabelInspector::LabelValueVectorType validLabels; |
| 299 | |
| 300 | if (m_CheckSelectionDueToExternalModelChange) |
| 301 | { //selection model tried an update while label model was still updating. |
| 302 | //check selection now for validity and use it if appropriated. |
| 303 | m_CheckSelectionDueToExternalModelChange = false; |
| 304 | validLabels = FilterValidLabels(GetSelectedLabelsFromSelectionModel(), this->GetMultiLabelSegmentation()); |
| 305 | } |
| 306 | |
| 307 | if (validLabels.empty()) |
| 308 | { |
| 309 | //empty selections are not allowed by UI interactions, there should always be at least one valid label selected. |
| 310 | //but selections are e.g. also cleared if the model is updated (e.g. due to addition of labels). |
| 311 | //In this case all valid elements of m_LastValidSelectedLabels should be used. |
| 312 | validLabels = FilterValidLabels(m_LastValidSelectedLabels, this->GetMultiLabelSegmentation()); |
| 313 | } |
| 314 | |
| 315 | if (validLabels.empty() && m_Model->GetNearestLabelValueToLastChange() != mitk::MultiLabelSegmentation::UNLABELED_VALUE) |
| 316 | { |
| 317 | //we use the nearest existing label as valid value, like we do it in DeletLabelInternal |
| 318 | validLabels = { m_Model->GetNearestLabelValueToLastChange() }; |
| 319 | } |
| 320 | |
| 321 | if (!validLabels.empty()) |
| 322 | { |
| 323 | UpdateSelectionModel(validLabels); |
| 324 | } |
| 325 | else |
| 326 | { |
| 327 | m_LastValidSelectedLabels = {}; |
| 328 | emit CurrentSelectionChanged(GetSelectedLabels()); |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | void QmitkMultiLabelInspector::OnDataChanged(const QModelIndex& topLeft, const QModelIndex& /*bottomRight*/, |
| 334 | const QList<int>& /*roles*/) |
nothing calls this directly
no test coverage detected