27 BaseWidget(parent,
"DataSelectWidget",
"DataSelectWidget"),
29 mViewService(viewService),
30 mPatientModelService(patientModelService)
33 QHBoxLayout* layout =
new QHBoxLayout(
this);
35 layout->setSpacing(0);
40 QIcon(
":/icons/open_icon_library/eye.png.png"),
41 "Toggle show data in view",
"",
42 SLOT(toggleShowData()),
44 mToggleShowAction->setCheckable(
true);
46 toggleShowButton->setDefaultAction(mToggleShowAction);
53 gridLayout->setMargin(0);
54 gridLayout->setSpacing(0);
55 QHBoxLayout* lay =
new QHBoxLayout;
56 lay->addWidget(toggleShowButton);
57 lay->addWidget(mRemoveButton);
58 gridLayout->addLayout(lay, row, 2);
61 layout->addWidget(widget);
62 layout->addWidget(toggleShowButton);
63 layout->addWidget(mRemoveButton);
66 connect(mViewService.get(), SIGNAL(activeViewChanged()),
this, SLOT(viewGroupChangedSlot()));
67 connect(mData.get(), SIGNAL(changed()),
this, SLOT(updateDataVisibility()));
69 this->viewGroupChangedSlot();
74 disconnect(mViewService.get(), SIGNAL(activeViewChanged()),
this, SLOT(viewGroupChangedSlot()));
79 int groupIdx = mViewService->getActiveGroupId();
82 return mViewService->getGroup(groupIdx);
85 void DataSelectWidget::viewGroupChangedSlot()
88 if (mCurrentViewGroupData==group)
91 if (mCurrentViewGroupData)
94 this, &DataSelectWidget::updateDataVisibility);
97 mCurrentViewGroupData = group;
99 if (mCurrentViewGroupData)
102 this, &DataSelectWidget::updateDataVisibility);
105 this->updateDataVisibility();
108 void DataSelectWidget::updateDataVisibility()
110 mToggleShowAction->setEnabled(mData->getData() && (mCurrentViewGroupData!=0));
111 mRemoveButton->setEnabled(mData->getData() ?
true :
false);
113 bool visible =
false;
114 if (mData->getData())
116 std::vector<DataPtr> visibleData;
117 if (mCurrentViewGroupData)
119 visibleData = mCurrentViewGroupData->getData();
121 visible = std::count(visibleData.begin(), visibleData.end(), mData->getData());
123 mToggleShowAction->blockSignals(
true);
124 mToggleShowAction->setChecked(visible);
125 mToggleShowAction->blockSignals(
false);
126 mRemoveButton->
reset();
130 void DataSelectWidget::eraseData()
132 if (!mData->getData())
135 mPatientModelService->removeData(mData->getData()->getUid());
138 void DataSelectWidget::setShowIcon()
140 if (mToggleShowAction->isChecked())
142 mToggleShowAction->setIcon(QIcon(
":/icons/open_icon_library/eye.png.png"));
146 mToggleShowAction->setIcon(QIcon(
":/icons/eye.png"));
150 void DataSelectWidget::toggleShowData()
152 if (!mData->getData())
155 if (mToggleShowAction->isChecked())
157 mCurrentViewGroupData->addData(mData->getData()->getUid());
161 mCurrentViewGroupData->removeData(mData->getData()->getUid());
172 QString tip(
"<html><h4>Permanently delete data.</h4><p>Press button twice to delete.<br>"
173 "Right-click after the first click to cancel.<p></html>");
175 mRemoveAction =
new QAction(
this);
176 mRemoveAction->setToolTip(tip);
177 connect(mRemoveAction, &QAction::triggered,
this, &EraseDataToolButton::requestEraseData);
178 mRemoveAction->setCheckable(
true);
179 this->setDefaultAction(mRemoveAction);
181 this->setRemoveIcon();
186 this->cancelRemovalSlot();
189 void EraseDataToolButton::mousePressEvent(QMouseEvent *e)
191 CXSmallToolButton::mousePressEvent(e);
192 if (e->button() == Qt::RightButton)
193 this->cancelRemovalSlot();
199 void EraseDataToolButton::cancelRemovalSlot()
201 mRemoveAction->blockSignals(
true);
202 mRemoveAction->setChecked(
false);
203 this->setRemoveIcon();
204 mRemoveAction->blockSignals(
false);
207 void EraseDataToolButton::setRemoveIcon()
209 if (mRemoveAction->isChecked())
211 mRemoveAction->setIcon(QIcon(
":/icons/preset_remove.png"));
215 mRemoveAction->setIcon(QIcon(
":/icons/open_icon_library/edit-delete-2.png"));
223 void EraseDataToolButton::requestEraseData()
225 this->setRemoveIcon();
227 if (mRemoveAction->isChecked())