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

Method QmitkMultiLabelInspector

Modules/SegmentationUI/src/QmitkMultiLabelInspector.cpp:43–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41#include <ui_QmitkMultiLabelInspectorControls.h>
42
43QmitkMultiLabelInspector::QmitkMultiLabelInspector(QWidget* parent/* = nullptr*/)
44 : QWidget(parent), m_Controls(std::make_unique<Ui::QmitkMultiLabelInspector>()), m_SegmentationNodeDataMTime(0), m_Completer(nullptr)
45{
46 m_Controls->setupUi(this);
47
48 m_Model = new QmitkMultiLabelTreeModel(this);
49
50 m_Controls->view->setModel(m_Model);
51
52 m_ColorItemDelegate = new QmitkLabelColorItemDelegate(this);
53
54 auto visibleIcon = QmitkStyleManager::ThemeIcon(QLatin1String(":/Qmitk/visible.svg"));
55 auto invisibleIcon = QmitkStyleManager::ThemeIcon(QLatin1String(":/Qmitk/invisible.svg"));
56 m_VisibilityItemDelegate = new QmitkLabelToggleItemDelegate(visibleIcon, invisibleIcon, this);
57
58 auto lockIcon = QmitkStyleManager::ThemeIcon(QLatin1String(":/Qmitk/lock.svg"));
59 auto unlockIcon = QmitkStyleManager::ThemeIcon(QLatin1String(":/Qmitk/unlock.svg"));
60 m_LockItemDelegate = new QmitkLabelToggleItemDelegate(lockIcon, unlockIcon, this);
61
62 auto* view = this->m_Controls->view;
63 view->setItemDelegateForColumn(1, m_LockItemDelegate);
64 view->setItemDelegateForColumn(2, m_ColorItemDelegate);
65 view->setItemDelegateForColumn(3, m_VisibilityItemDelegate);
66
67 auto* header = view->header();
68 header->setSectionResizeMode(0,QHeaderView::Stretch);
69 header->setSectionResizeMode(1, QHeaderView::ResizeToContents);
70 header->setSectionResizeMode(2, QHeaderView::ResizeToContents);
71 header->setSectionResizeMode(3, QHeaderView::ResizeToContents);
72 view->setContextMenuPolicy(Qt::CustomContextMenu);
73
74 m_Completer = new QCompleter(this);
75 this->RefreshCompleter();
76
77 auto labelSearchBox = m_Controls->labelSearchBox;
78 labelSearchBox->setCompleter(m_Completer);
79
80 connect(m_Model, &QAbstractItemModel::modelReset, this, &QmitkMultiLabelInspector::OnModelReset);
81 connect(m_Model, &QAbstractItemModel::dataChanged, this, &QmitkMultiLabelInspector::OnDataChanged);
82 connect(m_Model, &QmitkMultiLabelTreeModel::modelChanged, this, &QmitkMultiLabelInspector::OnModelChanged);
83 connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), SLOT(OnChangeModelSelection(const QItemSelection&, const QItemSelection&)));
84 connect(view, &QAbstractItemView::customContextMenuRequested, this, &QmitkMultiLabelInspector::OnContextMenuRequested);
85 connect(view, &QAbstractItemView::doubleClicked, this, &QmitkMultiLabelInspector::OnItemDoubleClicked);
86 connect(view, &QAbstractItemView::entered, this, &QmitkMultiLabelInspector::OnEntered);
87 connect(view, &QmitkMultiLabelTreeView::MouseLeave, this, &QmitkMultiLabelInspector::OnMouseLeave);
88
89 connect(labelSearchBox, &QLineEdit::returnPressed, this, &QmitkMultiLabelInspector::OnSearchLabel);
90
91 // Pressing return on the completer also triggers the line edit signal, resulting in a redundant
92 // call of OnLabelSearch(). At this time (same for a click on a completer entry), the text of the
93 // line edit is not yet set. Hence, it cannot be cleared by OnSearchLabel().
94 //
95 // The trick is to use a zero-delay single-shot timer to immediately clear the text after it
96 // was set by the completer. Since we cannot prevent the redundant call when pressing enter,
97 // We can early-out in OnSearchLabel() when the currently selected label already is the label
98 // that is requested to be selected.
99
100 connect(m_Completer, qOverload<const QString&>(&QCompleter::activated), labelSearchBox,

Callers

nothing calls this directly

Calls 5

RefreshCompleterMethod · 0.95
OnSearchLabelMethod · 0.95
setModelMethod · 0.80
clearMethod · 0.45
setTextMethod · 0.45

Tested by

no test coverage detected