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

Method OnSearchLabel

Modules/SegmentationUI/src/QmitkMultiLabelInspector.cpp:1763–1805  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1761}
1762
1763void QmitkMultiLabelInspector::OnSearchLabel()
1764{
1765 if (!m_Completer || !m_Model)
1766 return;
1767
1768 const QString text = m_Controls->labelSearchBox->text().trimmed();
1769 if (text.isEmpty())
1770 return;
1771
1772 auto flatProxy = qobject_cast<QmitkFlatLabelInstanceProxyModel*>(m_Completer->model());
1773 if (!flatProxy)
1774 return;
1775
1776 // Find matching entries (case-insensitive, substring)
1777 // we need to use here the flat model and not just completionModel, as we need to get the real index
1778 // to fetch the label instance value later on.
1779 QList<QModelIndex> matches =
1780 flatProxy->match(flatProxy->index(0, 0), Qt::DisplayRole, text, 1, Qt::MatchContains | Qt::MatchWrap);
1781
1782 if (matches.isEmpty())
1783 return; // nothing matched -> do nothing
1784
1785 QModelIndex proxyMatch = matches.first();
1786 QModelIndex srcMatch = flatProxy->mapToSource(proxyMatch);
1787 QVariant labelVariant = m_Model->data(srcMatch, QmitkMultiLabelTreeModel::ItemModelRole::LabelInstanceValueRole);
1788
1789 if (!labelVariant.isValid() ||
1790 !labelVariant.canConvert<mitk::MultiLabelSegmentation::LabelValueType>())
1791 return;
1792
1793 const mitk::MultiLabelSegmentation::LabelValueType labelID =
1794 labelVariant.value<mitk::MultiLabelSegmentation::LabelValueType>();
1795
1796 auto selectedLabels = this->GetSelectedLabels();
1797
1798 if (selectedLabels.empty() || selectedLabels.front() != labelID)
1799 {
1800 this->SetSelectedLabel(labelID);
1801 this->PrepareGoToLabel(labelID);
1802 }
1803
1804 m_Controls->labelSearchBox->clear();
1805}

Callers 1

Calls 11

GetSelectedLabelsMethod · 0.95
SetSelectedLabelMethod · 0.95
PrepareGoToLabelMethod · 0.95
textMethod · 0.80
matchMethod · 0.80
mapToSourceMethod · 0.80
frontMethod · 0.80
indexMethod · 0.45
dataMethod · 0.45
emptyMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected