diff --git a/Modules/SegmentationUI/Qmitk/QmitkEditableContourToolGUIBase.cpp b/Modules/SegmentationUI/Qmitk/QmitkEditableContourToolGUIBase.cpp index 727cc2b6af..09cbd12f7c 100644 --- a/Modules/SegmentationUI/Qmitk/QmitkEditableContourToolGUIBase.cpp +++ b/Modules/SegmentationUI/Qmitk/QmitkEditableContourToolGUIBase.cpp @@ -1,101 +1,110 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include #include +#include + #include QmitkEditableContourToolGUIBase::QmitkEditableContourToolGUIBase() : QmitkToolGUI(), - m_Controls(new Ui::QmitkEditableContourToolGUIControls) + m_Controls(new Ui::QmitkEditableContourToolGUIControls), + m_ModeButtonGroup(new QButtonGroup(this)) { m_Controls->setupUi(this); - m_Controls->m_Information->hide(); - m_Controls->m_AutoCheck->setChecked(true); m_Controls->m_ConfirmButton->hide(); - m_Controls->m_AddMode->setChecked(true); - m_Controls->m_SubtractMode->hide(); m_Controls->m_AddMode->hide(); + m_Controls->m_SubtractMode->hide(); m_Controls->m_ClearButton->hide(); + m_Controls->m_Information->hide(); + + m_ModeButtonGroup->addButton(m_Controls->m_AddMode, static_cast(Mode::Add)); + m_ModeButtonGroup->addButton(m_Controls->m_SubtractMode, static_cast(Mode::Subtract)); + connect(this, &Self::NewToolAssociated, this, &Self::OnNewToolAssociated); + + connect(m_Controls->m_AutoCheck, &QCheckBox::toggled, this, &Self::OnAutoConfirm); + connect(m_ModeButtonGroup, &QButtonGroup::idClicked, [this](int id) { this->OnModeToggled(static_cast(id)); }); connect(m_Controls->m_ConfirmButton, &QPushButton::clicked, this, &Self::OnConfirmSegmentation); connect(m_Controls->m_ClearButton, &QPushButton::clicked, this, &Self::OnClearContour); - connect(this, &Self::NewToolAssociated, this, &Self::OnNewToolAssociated); connect(m_Controls->m_InformationCheckBox, &QCheckBox::toggled, this, &Self::OnShowInformation); - connect(m_Controls->m_AutoCheck, &QCheckBox::toggled, this, &Self::OnAutoConfirm); - connect(m_Controls->m_AddMode, &QRadioButton::toggled, this, &Self::OnAddModeToogled); } QmitkEditableContourToolGUIBase::~QmitkEditableContourToolGUIBase() { } void QmitkEditableContourToolGUIBase::OnNewToolAssociated(mitk::Tool* tool) { m_NewTool = dynamic_cast(tool); if (m_NewTool.IsNull()) mitkThrow() << "Tool is in an invalid state. QmitkEditableContourToolGUIBase needs tools based on EditableContourTool."; const auto autoConfirm = m_NewTool->GetAutoConfirm(); m_Controls->m_AutoCheck->setChecked(autoConfirm); - const auto addMode = m_NewTool->GetAddMode(); - m_Controls->m_AddMode->setChecked(addMode); + const auto mode = m_NewTool->GetAddMode() + ? Mode::Add + : Mode::Subtract; - this->OnAutoConfirm(autoConfirm); -} - -void QmitkEditableContourToolGUIBase::OnConfirmSegmentation() -{ - if (m_NewTool.IsNotNull()) - m_NewTool->ConfirmSegmentation(); -} - -void QmitkEditableContourToolGUIBase::OnClearContour() -{ - if (m_NewTool.IsNotNull()) - m_NewTool->ClearContour(); -} + m_ModeButtonGroup->button(static_cast(mode))->setChecked(true); -void QmitkEditableContourToolGUIBase::OnShowInformation(bool on) -{ - m_Controls->m_Information->setVisible(on); + this->OnAutoConfirm(autoConfirm); + this->OnModeToggled(mode); } void QmitkEditableContourToolGUIBase::OnAutoConfirm(bool on) { m_Controls->m_ConfirmButton->setVisible(!on); m_Controls->m_ClearButton->setVisible(!on); m_Controls->m_AddMode->setVisible(!on); + m_Controls->m_SubtractMode->setVisible(!on); if (on) m_Controls->m_AddMode->setChecked(true); - m_Controls->m_SubtractMode->setVisible(!on); - if (m_NewTool.IsNotNull()) { if (on && m_NewTool->IsEditingContour()) this->OnConfirmSegmentation(); m_NewTool->SetAutoConfirm(on); + m_NewTool->SetAddMode(m_Controls->m_AddMode->isChecked()); } } -void QmitkEditableContourToolGUIBase::OnAddModeToogled(bool on) +void QmitkEditableContourToolGUIBase::OnModeToggled(Mode mode) +{ + if (m_NewTool.IsNotNull()) + m_NewTool->SetAddMode(Mode::Add == mode); +} + +void QmitkEditableContourToolGUIBase::OnConfirmSegmentation() +{ + if (m_NewTool.IsNotNull()) + m_NewTool->ConfirmSegmentation(); +} + +void QmitkEditableContourToolGUIBase::OnClearContour() { if (m_NewTool.IsNotNull()) - m_NewTool->SetAddMode(on); + m_NewTool->ClearContour(); +} + +void QmitkEditableContourToolGUIBase::OnShowInformation(bool on) +{ + m_Controls->m_Information->setVisible(on); } diff --git a/Modules/SegmentationUI/Qmitk/QmitkEditableContourToolGUIBase.h b/Modules/SegmentationUI/Qmitk/QmitkEditableContourToolGUIBase.h index e8858114a4..f394558ae0 100644 --- a/Modules/SegmentationUI/Qmitk/QmitkEditableContourToolGUIBase.h +++ b/Modules/SegmentationUI/Qmitk/QmitkEditableContourToolGUIBase.h @@ -1,59 +1,68 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #ifndef QmitkEditableContourToolGUIBase_h #define QmitkEditableContourToolGUIBase_h #include #include +class QButtonGroup; + namespace mitk { class EditableContourTool; } namespace Ui { class QmitkEditableContourToolGUIControls; } /** \ingroup org_mitk_gui_qt_interactivesegmentation_internal \brief GUI for mitk::EditableContourTool based classes. \sa mitk::LassoTool */ class MITKSEGMENTATIONUI_EXPORT QmitkEditableContourToolGUIBase : public QmitkToolGUI { Q_OBJECT public: + enum class MITKSEGMENTATIONUI_EXPORT Mode + { + Add, + Subtract + }; + mitkClassMacro(QmitkEditableContourToolGUIBase, QmitkToolGUI); itkFactorylessNewMacro(Self); protected slots: void OnNewToolAssociated(mitk::Tool*); void OnConfirmSegmentation(); void OnClearContour(); void OnAutoConfirm(bool on); - void OnAddModeToogled(bool on); + void OnModeToggled(Mode mode); void OnShowInformation(bool on); protected: QmitkEditableContourToolGUIBase(); ~QmitkEditableContourToolGUIBase() override; Ui::QmitkEditableContourToolGUIControls* m_Controls; + QButtonGroup* m_ModeButtonGroup; itk::SmartPointer m_NewTool; }; #endif