diff --git a/Modules/QtWidgets/include/QmitkInteractionSchemeToolBar.h b/Modules/QtWidgets/include/QmitkInteractionSchemeToolBar.h index 49f1c58eec..d230c84a77 100644 --- a/Modules/QtWidgets/include/QmitkInteractionSchemeToolBar.h +++ b/Modules/QtWidgets/include/QmitkInteractionSchemeToolBar.h @@ -1,56 +1,56 @@ /*============================================================================ 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 QMITKINTERACTIONSCHEMETOOLBAR_H #define QMITKINTERACTIONSCHEMETOOLBAR_H #include "MitkQtWidgetsExports.h" // mitk core #include "mitkInteractionSchemeSwitcher.h" #include #include /** * @brief * * */ class MITKQTWIDGETS_EXPORT QmitkInteractionSchemeToolBar : public QToolBar { Q_OBJECT public: using InteractionScheme = mitk::InteractionSchemeSwitcher::InteractionScheme; QmitkInteractionSchemeToolBar(QWidget* parent = nullptr); ~QmitkInteractionSchemeToolBar() override; void SetInteractionEventHandler(mitk::InteractionEventHandler::Pointer interactionEventHandler); -protected slots: +protected Q_SLOTS: - void OnInteractionSchemeChanged(); void AddButton(InteractionScheme id, const QString& toolName, const QIcon& icon, bool on = false); + void OnInteractionSchemeChanged(); private: QActionGroup* m_ActionGroup; mitk::InteractionSchemeSwitcher::Pointer m_InteractionSchemeSwitcher; mitk::InteractionEventHandler::Pointer m_InteractionEventHandler; }; #endif // QMITKINTERACTIONSCHEMETOOLBAR_H diff --git a/Modules/QtWidgets/src/QmitkInteractionSchemeToolBar.cpp b/Modules/QtWidgets/src/QmitkInteractionSchemeToolBar.cpp index 4b001600ad..383e3cdfcc 100644 --- a/Modules/QtWidgets/src/QmitkInteractionSchemeToolBar.cpp +++ b/Modules/QtWidgets/src/QmitkInteractionSchemeToolBar.cpp @@ -1,100 +1,106 @@ /*============================================================================ 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 "QmitkInteractionSchemeToolBar.h" #include QmitkInteractionSchemeToolBar::QmitkInteractionSchemeToolBar(QWidget* parent/* = nullptr*/) : QToolBar(parent) , m_ActionGroup(new QActionGroup(this)) , m_InteractionSchemeSwitcher(nullptr) , m_InteractionEventHandler(nullptr) { QToolBar::setOrientation(Qt::Vertical); QToolBar::setIconSize(QSize(17, 17)); QToolBar::setFixedWidth(33); m_ActionGroup->setExclusive(false); // allow having no action selected AddButton(InteractionScheme::PACSStandard, tr("Pointer"), QIcon(":/Qmitk/mm_pointer.png"), true); AddButton(InteractionScheme::PACSLevelWindow, tr("Level/Window"), QIcon(":/Qmitk/mm_contrast.png")); AddButton(InteractionScheme::PACSPan, tr("Pan"), QIcon(":/Qmitk/mm_pan.png")); AddButton(InteractionScheme::PACSScroll, tr("Scroll"), QIcon(":/Qmitk/mm_scroll.png")); AddButton(InteractionScheme::PACSZoom, tr("Zoom"), QIcon(":/Qmitk/mm_zoom.png")); m_InteractionSchemeSwitcher = mitk::InteractionSchemeSwitcher::New(); } +QmitkInteractionSchemeToolBar::~QmitkInteractionSchemeToolBar() +{ + // nothing here +} + void QmitkInteractionSchemeToolBar::SetInteractionEventHandler(mitk::InteractionEventHandler::Pointer interactionEventHandler) { if (interactionEventHandler == m_InteractionEventHandler) { return; } m_InteractionEventHandler = interactionEventHandler; - try - { - m_InteractionSchemeSwitcher->SetInteractionScheme(m_InteractionEventHandler, InteractionScheme::PACSStandard); - } - catch (const mitk::Exception&) + if (nullptr != m_InteractionSchemeSwitcher) { - return; + try + { + m_InteractionSchemeSwitcher->SetInteractionScheme(m_InteractionEventHandler, InteractionScheme::PACSStandard); + } + catch (const mitk::Exception&) + { + return; + } } } void QmitkInteractionSchemeToolBar::AddButton(InteractionScheme interactionScheme, const QString& toolName, const QIcon& icon, bool on) { QAction* action = new QAction(icon, toolName, this); action->setCheckable(true); action->setActionGroup(m_ActionGroup); action->setChecked(on); action->setData(interactionScheme); - connect(action, SIGNAL(triggered()), this, SLOT(OnInteractionSchemeChanged())); + connect(action, &QAction::triggered, this, &QmitkInteractionSchemeToolBar::OnInteractionSchemeChanged); QToolBar::addAction(action); } -QmitkInteractionSchemeToolBar::~QmitkInteractionSchemeToolBar() -{ - // nothing here -} - void QmitkInteractionSchemeToolBar::OnInteractionSchemeChanged() { QAction* action = dynamic_cast(sender()); - if (action) + if (nullptr != action) { for (auto actionIter : m_ActionGroup->actions()) { if (actionIter != action) { actionIter->setChecked(false); } } InteractionScheme interactionScheme = static_cast(action->data().toInt()); // If the selected option is unchecked, use the base interaction with no primary tool if (!action->isChecked()) { interactionScheme = InteractionScheme::PACSBase; } - try - { - m_InteractionSchemeSwitcher->SetInteractionScheme(m_InteractionEventHandler, interactionScheme); - } - catch (const mitk::Exception&) + if (nullptr != m_InteractionSchemeSwitcher) { - return; + try + { + m_InteractionSchemeSwitcher->SetInteractionScheme(m_InteractionEventHandler, interactionScheme); + } + catch (const mitk::Exception&) + { + return; + } } } }