diff --git a/Modules/SegmentationUI/Qmitk/QmitkEditableContourToolGUIBase.cpp b/Modules/SegmentationUI/Qmitk/QmitkEditableContourToolGUIBase.cpp index 15cb4647b8..09cbd12f7c 100644 --- a/Modules/SegmentationUI/Qmitk/QmitkEditableContourToolGUIBase.cpp +++ b/Modules/SegmentationUI/Qmitk/QmitkEditableContourToolGUIBase.cpp @@ -1,100 +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 "QmitkEditableContourToolGUIBase.h" +#include <QmitkEditableContourToolGUIBase.h> +#include <ui_QmitkEditableContourToolGUIControls.h> -QmitkEditableContourToolGUIBase::QmitkEditableContourToolGUIBase() : QmitkToolGUI() +#include <QButtonGroup> + +#include <mitkEditableContourTool.h> + +QmitkEditableContourToolGUIBase::QmitkEditableContourToolGUIBase() + : QmitkToolGUI(), + 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_ClearButton->hide(); - - connect(m_Controls.m_ConfirmButton, SIGNAL(clicked()), this, SLOT(OnConfirmSegmentation())); - connect(m_Controls.m_ClearButton, SIGNAL(clicked()), this, SLOT(OnClearContour())); - connect(this, SIGNAL(NewToolAssociated(mitk::Tool *)), this, SLOT(OnNewToolAssociated(mitk::Tool *))); - connect(m_Controls.m_InformationCheckBox, SIGNAL(toggled(bool)), this, SLOT(OnShowInformation(bool))); - connect(m_Controls.m_AutoCheck, SIGNAL(toggled(bool)), this, SLOT(OnAutoConfirm(bool))); - connect(m_Controls.m_AddMode, SIGNAL(toggled(bool)), this, SLOT(OnAddModeToogled(bool))); + m_Controls->setupUi(this); + + m_Controls->m_ConfirmButton->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<int>(Mode::Add)); + m_ModeButtonGroup->addButton(m_Controls->m_SubtractMode, static_cast<int>(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<Mode>(id)); }); + connect(m_Controls->m_ConfirmButton, &QPushButton::clicked, this, &Self::OnConfirmSegmentation); + connect(m_Controls->m_ClearButton, &QPushButton::clicked, this, &Self::OnClearContour); + connect(m_Controls->m_InformationCheckBox, &QCheckBox::toggled, this, &Self::OnShowInformation); } QmitkEditableContourToolGUIBase::~QmitkEditableContourToolGUIBase() { } -void QmitkEditableContourToolGUIBase::OnNewToolAssociated(mitk::Tool *tool) +void QmitkEditableContourToolGUIBase::OnNewToolAssociated(mitk::Tool* tool) { - m_NewTool = dynamic_cast<mitk::EditableContourTool *>(tool); + m_NewTool = dynamic_cast<mitk::EditableContourTool*>(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); + m_Controls->m_AutoCheck->setChecked(autoConfirm); + + const auto mode = m_NewTool->GetAddMode() + ? Mode::Add + : Mode::Subtract; + + m_ModeButtonGroup->button(static_cast<int>(mode))->setChecked(true); + this->OnAutoConfirm(autoConfirm); + this->OnModeToggled(mode); } -void QmitkEditableContourToolGUIBase::OnConfirmSegmentation() +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); + if (m_NewTool.IsNotNull()) { - m_NewTool->ConfirmSegmentation(); + if (on && m_NewTool->IsEditingContour()) + this->OnConfirmSegmentation(); + + m_NewTool->SetAutoConfirm(on); + m_NewTool->SetAddMode(m_Controls->m_AddMode->isChecked()); } } -void QmitkEditableContourToolGUIBase::OnClearContour() +void QmitkEditableContourToolGUIBase::OnModeToggled(Mode mode) { if (m_NewTool.IsNotNull()) - m_NewTool->ClearContour(); + m_NewTool->SetAddMode(Mode::Add == mode); } -void QmitkEditableContourToolGUIBase::OnShowInformation(bool on) +void QmitkEditableContourToolGUIBase::OnConfirmSegmentation() { - m_Controls.m_Information->setVisible(on); + if (m_NewTool.IsNotNull()) + m_NewTool->ConfirmSegmentation(); } -void QmitkEditableContourToolGUIBase::OnAutoConfirm(bool on) +void QmitkEditableContourToolGUIBase::OnClearContour() { - m_Controls.m_ConfirmButton->setVisible(!on); - m_Controls.m_ClearButton->setVisible(!on); - m_Controls.m_AddMode->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->ClearContour(); } -void QmitkEditableContourToolGUIBase::OnAddModeToogled(bool on) +void QmitkEditableContourToolGUIBase::OnShowInformation(bool on) { - if (m_NewTool.IsNotNull()) - { - m_NewTool->SetAddMode(on); - } + m_Controls->m_Information->setVisible(on); } diff --git a/Modules/SegmentationUI/Qmitk/QmitkEditableContourToolGUIBase.h b/Modules/SegmentationUI/Qmitk/QmitkEditableContourToolGUIBase.h index 28e89d4fb9..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 "QmitkToolGUI.h" -#include "mitkEditableContourTool.h" -#include "ui_QmitkEditableContourToolGUIControls.h" +#include <QmitkToolGUI.h> #include <MitkSegmentationUIExports.h> -class QmitkEditableContourToolGUIBaseControls; +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); - itkCloneMacro(Self); -protected slots : - - void OnNewToolAssociated(mitk::Tool *); +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; - - mitk::EditableContourTool::Pointer m_NewTool; + Ui::QmitkEditableContourToolGUIControls* m_Controls; + QButtonGroup* m_ModeButtonGroup; + itk::SmartPointer<mitk::EditableContourTool> m_NewTool; }; #endif