diff --git a/Modules/QtWidgets/include/QmitkDataStorageInspectorProviderBase.tpp b/Modules/QtWidgets/include/QmitkDataStorageInspectorProviderBase.tpp index d7e9360308..686f1c3d16 100644 --- a/Modules/QtWidgets/include/QmitkDataStorageInspectorProviderBase.tpp +++ b/Modules/QtWidgets/include/QmitkDataStorageInspectorProviderBase.tpp @@ -1,166 +1,166 @@ /*============================================================================ 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 #include #include #include template class QmitkDataStorageInspectorProviderBase::Impl { public: Impl(const std::string& id, const std::string& displayName, const std::string& desc, const QByteArray& svg) : m_Ranking(0), m_ID(id), m_DisplayName(displayName), m_Desc(desc), m_SVG(svg) { }; Impl(const Impl &other) = default; void SetRanking(int ranking) { m_Ranking = ranking; }; int GetRanking() const { return m_Ranking; }; us::ServiceRegistration m_Reg; int m_Ranking; std::string m_ID; std::string m_DisplayName; std::string m_Desc; QByteArray m_SVG; }; template QmitkDataStorageInspectorProviderBase::QmitkDataStorageInspectorProviderBase(const std::string& id) : QmitkDataStorageInspectorProviderBase(id, id) { } template QmitkDataStorageInspectorProviderBase::QmitkDataStorageInspectorProviderBase(const std::string& id, const std::string& displayName, const std::string& desc, const std::string& pathToIconSVG) { QByteArray svg; if (!pathToIconSVG.empty()) { QFile iconFile(QString::fromStdString(pathToIconSVG)); if (iconFile.open(QIODevice::ReadOnly)) svg = iconFile.readAll(); } d.reset(new Impl(id, displayName, desc, svg)); RegisterService(); } template QmitkDataStorageInspectorProviderBase::~QmitkDataStorageInspectorProviderBase() { UnregisterService(); } template QmitkDataStorageInspectorProviderBase::QmitkDataStorageInspectorProviderBase(const QmitkDataStorageInspectorProviderBase &other) : IDataStorageInspectorProvider(), d(new Impl(*other.d.get())) { } template QmitkAbstractDataStorageInspector* QmitkDataStorageInspectorProviderBase::CreateInspector() const { return new TInspector; -}; +} template typename QmitkDataStorageInspectorProviderBase::InspectorIDType QmitkDataStorageInspectorProviderBase::GetInspectorID() const { return d->m_ID; -}; +} template std::string QmitkDataStorageInspectorProviderBase::GetInspectorDisplayName() const { return d->m_DisplayName; -}; +} template std::string QmitkDataStorageInspectorProviderBase::GetInspectorDescription() const { return d->m_Desc; -}; +} template QIcon QmitkDataStorageInspectorProviderBase::GetInspectorIcon() const { return QmitkStyleManager::ThemeIcon(d->m_SVG); -}; +} template us::ServiceRegistration QmitkDataStorageInspectorProviderBase::RegisterService(us::ModuleContext *context) { if (d->m_Reg) return d->m_Reg; if (context == nullptr) { context = us::GetModuleContext(); } us::ServiceProperties props = this->GetServiceProperties(); d->m_Reg = context->RegisterService(this, props); return d->m_Reg; } template void QmitkDataStorageInspectorProviderBase::UnregisterService() { try { d->m_Reg.Unregister(); } catch (const std::exception &) { } } template us::ServiceProperties QmitkDataStorageInspectorProviderBase::GetServiceProperties() const { us::ServiceProperties result; result[IDataStorageInspectorProvider::PROP_INSPECTOR_ID()] = this->d->m_ID; result[us::ServiceConstants::SERVICE_RANKING()] = this->GetRanking(); return result; } template void QmitkDataStorageInspectorProviderBase::SetRanking(int ranking) { d->SetRanking(ranking); } template int QmitkDataStorageInspectorProviderBase::GetRanking() const { return d->GetRanking(); } diff --git a/Modules/QtWidgets/include/QmitkDataStorageListInspector.h b/Modules/QtWidgets/include/QmitkDataStorageListInspector.h index 8fb096e71e..082ef54ba4 100644 --- a/Modules/QtWidgets/include/QmitkDataStorageListInspector.h +++ b/Modules/QtWidgets/include/QmitkDataStorageListInspector.h @@ -1,50 +1,48 @@ /*============================================================================ 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 QMITKDATASTORAGELISTINSPECTOR_H #define QMITKDATASTORAGELISTINSPECTOR_H #include #include "QmitkAbstractDataStorageInspector.h" #include "QmitkSimpleTextOverlayWidget.h" -#include - #include "ui_QmitkDataStorageListInspector.h" /* * @brief This is an inspector that offers a simple list view on a data storage. */ class MITKQTWIDGETS_EXPORT QmitkDataStorageListInspector : public QmitkAbstractDataStorageInspector { Q_OBJECT public: QmitkDataStorageListInspector(QWidget* parent = nullptr); QAbstractItemView* GetView() override; const QAbstractItemView* GetView() const override; void SetSelectionMode(SelectionMode mode) override; SelectionMode GetSelectionMode() const override; protected: void Initialize() override; void OnModelReset(); QmitkAbstractDataStorageModel* m_StorageModel; Ui_QmitkDataStorageListInspector m_Controls; QmitkSimpleTextOverlayWidget* m_Overlay; }; #endif // QMITKDATASTORAGELISTINSPECTOR_H diff --git a/Modules/QtWidgets/include/QmitkDataStorageSelectionHistoryInspector.h b/Modules/QtWidgets/include/QmitkDataStorageSelectionHistoryInspector.h index a21dbf6e91..c03c22a3c4 100644 --- a/Modules/QtWidgets/include/QmitkDataStorageSelectionHistoryInspector.h +++ b/Modules/QtWidgets/include/QmitkDataStorageSelectionHistoryInspector.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 QMITKDATASTORAGESELECTIONHISTORYINSPECTOR_H #define QMITKDATASTORAGESELECTIONHISTORYINSPECTOR_H #include -#include +#include "QmitkAbstractDataStorageInspector.h" #include #include "QmitkSimpleTextOverlayWidget.h" #include "ui_QmitkDataStorageSelectionHistoryInspector.h" /* * @brief This is an inspector that offers a simple list view on the last selected nodes (in chronologic order) in a data storage. */ class MITKQTWIDGETS_EXPORT QmitkDataStorageSelectionHistoryInspector : public QmitkAbstractDataStorageInspector { Q_OBJECT public: QmitkDataStorageSelectionHistoryInspector(QWidget* parent = nullptr); QAbstractItemView* GetView() override; const QAbstractItemView* GetView() const override; void SetSelectionMode(SelectionMode mode) override; SelectionMode GetSelectionMode() const override; static void AddNodeToHistory(mitk::DataNode* node); static void ResetHistory(); constexpr static const char* INSPECTOR_ID() { return "org.mitk.QmitkDataStorageSelectionHistoryInspector"; }; protected: void Initialize() override; QmitkAbstractDataStorageModel* m_StorageModel; Ui_QmitkDataStorageSelectionHistoryInspector m_Controls; QmitkSimpleTextOverlayWidget* m_Overlay; }; #endif // QMITKDATASTORAGESELECTIONHISTORYINSPECTOR_H diff --git a/Modules/QtWidgets/include/mitkDataStorageInspectorGenerator.h b/Modules/QtWidgets/include/mitkDataStorageInspectorGenerator.h index 8567300ecb..226646e10a 100644 --- a/Modules/QtWidgets/include/mitkDataStorageInspectorGenerator.h +++ b/Modules/QtWidgets/include/mitkDataStorageInspectorGenerator.h @@ -1,41 +1,41 @@ /*============================================================================ 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 mitkDataStorageInspectorGenerator_H #define mitkDataStorageInspectorGenerator_H #include "mitkIDataStorageInspectorProvider.h" #include namespace mitk { - /** Convinvience class to get all or specific DataStorageInspectorProvider. */ + /** Convenvience class to get all or specific DataStorageInspectorProvider. */ class MITKQTWIDGETS_EXPORT DataStorageInspectorGenerator { public: using IDType = mitk::IDataStorageInspectorProvider::InspectorIDType; using ProviderMapType = std::map; static ProviderMapType GetProviders(); static mitk::IDataStorageInspectorProvider *GetProvider(const IDType &id); protected: DataStorageInspectorGenerator(); virtual ~DataStorageInspectorGenerator(); DataStorageInspectorGenerator(const DataStorageInspectorGenerator &source) = delete; DataStorageInspectorGenerator& operator=(const DataStorageInspectorGenerator &) = delete; }; } #endif diff --git a/Modules/QtWidgets/src/QmitkDataStorageTreeInspector.cpp b/Modules/QtWidgets/src/QmitkDataStorageTreeInspector.cpp index 55d121510b..f1d7d95eab 100644 --- a/Modules/QtWidgets/src/QmitkDataStorageTreeInspector.cpp +++ b/Modules/QtWidgets/src/QmitkDataStorageTreeInspector.cpp @@ -1,72 +1,72 @@ /*============================================================================ 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 QmitkDataStorageTreeInspector::QmitkDataStorageTreeInspector(QWidget* parent/* = nullptr*/) : QmitkAbstractDataStorageInspector(parent) { m_Controls.setupUi(this); m_Controls.view->setSelectionMode(QAbstractItemView::ExtendedSelection); m_Controls.view->setSelectionBehavior(QAbstractItemView::SelectRows); m_Controls.view->setAlternatingRowColors(true); m_Controls.view->setHeaderHidden(true); m_Controls.view->setTextElideMode(Qt::ElideMiddle); m_Overlay = new QmitkSimpleTextOverlayWidget(this); m_Overlay->setVisible(false); m_Overlay->SetOverlayText(QStringLiteral("

No suitable data available in data storage.

")); m_StorageModel = new QmitkDataStorageSimpleTreeModel(this); m_Controls.view->setModel(m_StorageModel); connect(m_StorageModel, &QAbstractItemModel::modelReset, this, &QmitkDataStorageTreeInspector::OnModelReset); } QAbstractItemView* QmitkDataStorageTreeInspector::GetView() { return m_Controls.view; } const QAbstractItemView* QmitkDataStorageTreeInspector::GetView() const { return m_Controls.view; } void QmitkDataStorageTreeInspector::Initialize() { m_StorageModel->SetDataStorage(m_DataStorage.Lock()); m_StorageModel->SetNodePredicate(m_NodePredicate); m_Connector->SetView(m_Controls.view); m_Controls.view->expandAll(); } void QmitkDataStorageTreeInspector::SetSelectionMode(SelectionMode mode) { m_Controls.view->setSelectionMode(mode); } QmitkDataStorageTreeInspector::SelectionMode QmitkDataStorageTreeInspector::GetSelectionMode() const { return m_Controls.view->selectionMode(); } void QmitkDataStorageTreeInspector::OnModelReset() { - m_Overlay->setVisible(m_StorageModel->rowCount(m_StorageModel->sibling(0, 0, QModelIndex())) == 0); + m_Overlay->setVisible(!m_StorageModel->hasChildren()); } diff --git a/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionDialog.cpp b/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionDialog.cpp index 5adcf94c8b..4094044f3f 100644 --- a/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionDialog.cpp +++ b/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionDialog.cpp @@ -1,254 +1,254 @@ /*============================================================================ 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 "QmitkNodeSelectionDialog.h" #include #include #include #include #include QmitkNodeSelectionDialog::QmitkNodeSelectionDialog(QWidget* parent, QString title, QString hint) : QDialog(parent), m_NodePredicate(nullptr), m_SelectOnlyVisibleNodes(false), m_SelectedNodes(NodeList()), m_SelectionMode(QAbstractItemView::SingleSelection) { m_Controls.setupUi(this); m_CheckFunction = [](const NodeList &) { return ""; }; auto providers = mitk::DataStorageInspectorGenerator::GetProviders(); auto visibleProviders = mitk::GetVisibleDataStorageInspectors(); - auto favoriteID = mitk::GetPreferredDataStorageInspector(); + auto preferredID = mitk::GetPreferredDataStorageInspector(); if (visibleProviders.empty()) { MITK_DEBUG << "No presets for visible node selection inspectors available. Use fallback (show all available inspectors)"; unsigned int order = 0; for (auto proIter : providers) { visibleProviders.insert(std::make_pair(order, proIter.first)); ++order; } } - int favIndex = 0; - bool favoriteFound = false; + int preferredIndex = 0; + bool preferredFound = false; for (auto proIter : visibleProviders) { auto finding = providers.find(proIter.second); if (finding != providers.end()) { if (finding->second->GetInspectorID() != QmitkDataStorageFavoriteNodesInspector::INSPECTOR_ID() && finding->second->GetInspectorID() != QmitkDataStorageSelectionHistoryInspector::INSPECTOR_ID()) { auto provider = finding->second; - this->AddPanel(provider, favoriteID, favoriteFound, favIndex); + this->AddPanel(provider, preferredID, preferredFound, preferredIndex); } } else { MITK_DEBUG << "No provider registered for inspector that is defined as visible in the preferences. Illegal inspector ID: " << proIter.second; } } if (mitk::GetShowFavoritesInspector()) { auto favoritesPorvider = mitk::DataStorageInspectorGenerator::GetProvider(QmitkDataStorageFavoriteNodesInspector::INSPECTOR_ID()); if (favoritesPorvider != nullptr) { - this->AddPanel(favoritesPorvider, favoriteID, favoriteFound, favIndex); + this->AddPanel(favoritesPorvider, preferredID, preferredFound, preferredIndex); } } if (mitk::GetShowHistoryInspector()) { auto historyPorvider = mitk::DataStorageInspectorGenerator::GetProvider(QmitkDataStorageSelectionHistoryInspector::INSPECTOR_ID()); if (historyPorvider != nullptr) { - this->AddPanel(historyPorvider, favoriteID, favoriteFound, favIndex); + this->AddPanel(historyPorvider, preferredID, preferredFound, preferredIndex); } } - m_Controls.tabWidget->setCurrentIndex(favIndex); + m_Controls.tabWidget->setCurrentIndex(preferredIndex); this->setWindowTitle(title); this->setToolTip(hint); m_Controls.hint->setText(hint); m_Controls.hint->setVisible(!hint.isEmpty()); m_Controls.btnAddToFav->setIcon(berry::QtStyleManager::ThemeIcon(QStringLiteral(":/Qmitk/favorite_add.svg"))); connect(m_Controls.btnAddToFav, &QPushButton::clicked, this, &QmitkNodeSelectionDialog::OnFavoriteNodesButtonClicked); - connect(m_Controls.buttonBox, SIGNAL(accepted()), this, SLOT(OnOK())); - connect(m_Controls.buttonBox, SIGNAL(rejected()), this, SLOT(OnCancel())); + connect(m_Controls.buttonBox, &QDialogButtonBox::accepted, this, &QmitkNodeSelectionDialog::OnOK); + connect(m_Controls.buttonBox, &QDialogButtonBox::rejected, this, &QmitkNodeSelectionDialog::OnCancel); } void QmitkNodeSelectionDialog::SetDataStorage(mitk::DataStorage* dataStorage) { if (m_DataStorage != dataStorage) { m_DataStorage = dataStorage; if (!m_DataStorage.IsExpired()) { for (auto panel : m_Panels) { panel->SetDataStorage(dataStorage); } } } } void QmitkNodeSelectionDialog::SetNodePredicate(const mitk::NodePredicateBase* nodePredicate) { if (m_NodePredicate != nodePredicate) { m_NodePredicate = nodePredicate; for (auto panel : m_Panels) { panel->SetNodePredicate(m_NodePredicate); } } } const mitk::NodePredicateBase* QmitkNodeSelectionDialog::GetNodePredicate() const { return m_NodePredicate; } QmitkNodeSelectionDialog::NodeList QmitkNodeSelectionDialog::GetSelectedNodes() const { return m_SelectedNodes; } void QmitkNodeSelectionDialog::SetSelectionCheckFunction(const SelectionCheckFunctionType &checkFunction) { m_CheckFunction = checkFunction; auto checkResponse = m_CheckFunction(m_SelectedNodes); m_Controls.hint->setText(QString::fromStdString(checkResponse)); m_Controls.hint->setVisible(!checkResponse.empty()); m_Controls.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(checkResponse.empty()); } bool QmitkNodeSelectionDialog::GetSelectOnlyVisibleNodes() const { return m_SelectOnlyVisibleNodes; } void QmitkNodeSelectionDialog::SetSelectionMode(SelectionMode mode) { m_SelectionMode = mode; for (auto panel : m_Panels) { panel->SetSelectionMode(mode); } } QmitkNodeSelectionDialog::SelectionMode QmitkNodeSelectionDialog::GetSelectionMode() const { return m_SelectionMode; } void QmitkNodeSelectionDialog::SetSelectOnlyVisibleNodes(bool selectOnlyVisibleNodes) { if (m_SelectOnlyVisibleNodes != selectOnlyVisibleNodes) { m_SelectOnlyVisibleNodes = selectOnlyVisibleNodes; for (auto panel : m_Panels) { panel->SetSelectOnlyVisibleNodes(m_SelectOnlyVisibleNodes); } } } void QmitkNodeSelectionDialog::SetCurrentSelection(NodeList selectedNodes) { m_SelectedNodes = selectedNodes; auto checkResponse = m_CheckFunction(m_SelectedNodes); m_Controls.hint->setText(QString::fromStdString(checkResponse)); m_Controls.hint->setVisible(!checkResponse.empty()); m_Controls.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(checkResponse.empty()); for (auto panel : m_Panels) { panel->SetCurrentSelection(selectedNodes); } } void QmitkNodeSelectionDialog::OnSelectionChanged(NodeList selectedNodes) { SetCurrentSelection(selectedNodes); emit CurrentSelectionChanged(selectedNodes); } void QmitkNodeSelectionDialog::OnFavoriteNodesButtonClicked() { for (auto node : m_SelectedNodes) { node->SetBoolProperty("org.mitk.selection.favorite", true); } } void QmitkNodeSelectionDialog::OnOK() { for (auto node : m_SelectedNodes) { QmitkDataStorageSelectionHistoryInspector::AddNodeToHistory(node); } this->accept(); } void QmitkNodeSelectionDialog::OnCancel() { this->reject(); } -void QmitkNodeSelectionDialog::AddPanel(const mitk::IDataStorageInspectorProvider * provider, const mitk::IDataStorageInspectorProvider::InspectorIDType&favoriteID, bool &favoriteFound, int &favIndex) +void QmitkNodeSelectionDialog::AddPanel(const mitk::IDataStorageInspectorProvider * provider, const mitk::IDataStorageInspectorProvider::InspectorIDType& preferredID, bool &preferredFound, int &preferredIndex) { auto inspector = provider->CreateInspector(); QString name = QString::fromStdString(provider->GetInspectorDisplayName()); QString desc = QString::fromStdString(provider->GetInspectorDescription()); inspector->setParent(this); inspector->SetSelectionMode(m_SelectionMode); auto tabPanel = new QWidget(); tabPanel->setObjectName(QString("tab_") + name); tabPanel->setToolTip(desc); auto verticalLayout = new QVBoxLayout(tabPanel); verticalLayout->setSpacing(0); verticalLayout->setContentsMargins(0, 0, 0, 0); verticalLayout->addWidget(inspector); auto panelPos = m_Controls.tabWidget->insertTab(m_Controls.tabWidget->count(), tabPanel, name); auto icon = provider->GetInspectorIcon(); if (!icon.isNull()) { m_Controls.tabWidget->setTabIcon(panelPos, icon); } m_Panels.push_back(inspector); connect(inspector, &QmitkAbstractDataStorageInspector::CurrentSelectionChanged, this, &QmitkNodeSelectionDialog::OnSelectionChanged); - favoriteFound = favoriteFound || provider->GetInspectorID() == favoriteID; - if (!favoriteFound) + preferredFound = preferredFound || provider->GetInspectorID() == preferredID; + if (!preferredFound) { - ++favIndex; + ++preferredIndex; } } diff --git a/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionDialog.h b/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionDialog.h index 8910068bdf..c529aae35b 100644 --- a/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionDialog.h +++ b/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionDialog.h @@ -1,141 +1,141 @@ /*============================================================================ 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 QMITK_NODE_SELECTION_DIALOG_H #define QMITK_NODE_SELECTION_DIALOG_H #include #include #include #include "mitkIDataStorageInspectorProvider.h" #include #include "org_mitk_gui_qt_common_Export.h" #include "ui_QmitkNodeSelectionDialog.h" #include #include /** * \class QmitkNodeSelectionDialog * \brief Widget that allows to show and edit the content of an mitk::IsoDoseLevel instance. */ class MITK_QT_COMMON QmitkNodeSelectionDialog : public QDialog { Q_OBJECT public: explicit QmitkNodeSelectionDialog(QWidget* parent = nullptr, QString caption = "", QString hint = ""); /** * @brief Sets the data storage that will be used /monitored by widget. * * @param dataStorage A pointer to the data storage to set. */ void SetDataStorage(mitk::DataStorage* dataStorage); /** * @brief Sets the node predicate and updates the widget, according to the node predicate. * * @param nodePredicate A pointer to node predicate. */ virtual void SetNodePredicate(const mitk::NodePredicateBase* nodePredicate); const mitk::NodePredicateBase* GetNodePredicate() const; using NodeList = QList; NodeList GetSelectedNodes() const; /** * @brief Helper function that is used to check the given selection for consistency. * Returning an empty string assumes that everything is alright and the selection is valid. * If the string is not empty, the content of the string will be used as error message. */ using SelectionCheckFunctionType = std::function; /** * @brief A selection check function can be set. If set the dialog uses this function to check the made/set selection. * If the selection is valid, everything is fine. * If the selection is indicated as invalid, the dialog will display the selection check function error message. */ void SetSelectionCheckFunction(const SelectionCheckFunctionType &checkFunction); bool GetSelectOnlyVisibleNodes() const; using SelectionMode = QAbstractItemView::SelectionMode; void SetSelectionMode(SelectionMode mode); SelectionMode GetSelectionMode() const; Q_SIGNALS: /* * @brief A signal that will be emitted if the selected node has changed. * * @param nodes A list of data nodes that are newly selected. */ void CurrentSelectionChanged(NodeList nodes); public Q_SLOTS: /* * @brief Change the selection modus of the item view's selection model. * * If true, an incoming selection will be filtered (reduced) to only those nodes that are visible by the current view. * An outgoing selection can then at most contain the filtered nodes. * If false, the incoming non-visible selection will be stored and later added to the outgoing selection, * to include the original selection that could not be modified. * The part of the original selection, that is non-visible are the nodes that are not * * @param selectOnlyVisibleNodes The bool value to define the selection modus. */ void SetSelectOnlyVisibleNodes(bool selectOnlyVisibleNodes); /* * @brief Transform a list of data nodes into a model selection and set this as a new selection of the * selection model of the private member item view. * * The function filters the given list of nodes according to the 'm_SelectOnlyVisibleNodes' member variable. If * necessary, the non-visible nodes are stored. This is done if 'm_SelectOnlyVisibleNodes' is false: In this case * the selection may be filtered and only a subset of the selected nodes may be visible and therefore (de-)selectable * in the data storage viewer. By storing the non-visible nodes it is possible to send the new, modified selection * but also include the selected nodes from the original selection that could not be modified (see 'SetSelectOnlyVisibleNodes'). * * @param nodes A list of data nodes that should be newly selected. */ void SetCurrentSelection(NodeList selectedNodes); protected Q_SLOTS: void OnSelectionChanged(NodeList selectedNodes); void OnFavoriteNodesButtonClicked(); void OnOK(); void OnCancel(); protected: - void AddPanel(const mitk::IDataStorageInspectorProvider * provider, const mitk::IDataStorageInspectorProvider::InspectorIDType &favoriteID, bool &favoriteFound, int &favIndex); + void AddPanel(const mitk::IDataStorageInspectorProvider* provider, const mitk::IDataStorageInspectorProvider::InspectorIDType &preferredID, bool &preferredFound, int &preferredIndex); mitk::WeakPointer m_DataStorage; mitk::NodePredicateBase::ConstPointer m_NodePredicate; bool m_SelectOnlyVisibleNodes; NodeList m_SelectedNodes; SelectionCheckFunctionType m_CheckFunction; SelectionMode m_SelectionMode; using PanelVectorType = std::vector; PanelVectorType m_Panels; QPushButton* m_FavoriteNodesButton; Ui_QmitkNodeSelectionDialog m_Controls; }; #endif // QMITK_NODE_SELECTION_DIALOG_H diff --git a/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionPreferenceHelper.h b/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionPreferenceHelper.h index 1963bff7b3..477493c03e 100644 --- a/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionPreferenceHelper.h +++ b/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionPreferenceHelper.h @@ -1,55 +1,55 @@ /*============================================================================ 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 __QMITK_NODE_SELECTION_PREFERENCE_HELPER_H #define __QMITK_NODE_SELECTION_PREFERENCE_HELPER_H #include #include namespace mitk { using DataStorageInspectorIDType = std::string; - /** map containing the IDs of all inspectors that should be visible. The map key is the order of appareance + /** map containing the IDs of all inspectors that should be visible. The map key is the order of appearance of the respective inspector.*/ using VisibleDataStorageInspectorMapType = std::map; /** Stores the given ID as favorite inspector.*/ void PutPreferredDataStorageInspector(const DataStorageInspectorIDType& id); /** Gets the ID of the current favorite data storage inspector. * If empty string is returned, no favorite is set.*/ DataStorageInspectorIDType GetPreferredDataStorageInspector(); /** Stores the given map of visible inspectors.*/ void PutVisibleDataStorageInspectors(const VisibleDataStorageInspectorMapType& inspectors); /** Gets the map of current visible inspectors.*/ VisibleDataStorageInspectorMapType GetVisibleDataStorageInspectors(); /** Stores the given show state of the favorite inspector.*/ void PutShowFavoritesInspector(bool show); /** Indicates if the favorites inspector should be shown. */ bool GetShowFavoritesInspector(); /** Stores the given show state of the history inspector.*/ void PutShowHistoryInspector(bool show); /** Indicates if the history inspector should be shown. */ bool GetShowHistoryInspector(); } #endif diff --git a/Plugins/org.mitk.gui.qt.common/src/internal/QmitkNodeSelectionConstants.cpp b/Plugins/org.mitk.gui.qt.common/src/internal/QmitkNodeSelectionConstants.cpp index b5419d7458..4ab85ab5e1 100644 --- a/Plugins/org.mitk.gui.qt.common/src/internal/QmitkNodeSelectionConstants.cpp +++ b/Plugins/org.mitk.gui.qt.common/src/internal/QmitkNodeSelectionConstants.cpp @@ -1,20 +1,20 @@ /*============================================================================ 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 "QmitkNodeSelectionConstants.h" const std::string mitk::NodeSelectionConstants::ROOT_PREFERENCE_NODE_ID = "/NODESELECTION/UI"; const std::string mitk::NodeSelectionConstants::VISIBLE_INSPECTORS_NODE_ID = "visibleInspectors"; const std::string mitk::NodeSelectionConstants::PREFERRED_INSPECTOR_ID = "inspectorID"; const std::string mitk::NodeSelectionConstants::VISIBLE_INSPECTOR_ID = "inspectorID"; const std::string mitk::NodeSelectionConstants::SHOW_FAVORITE_INSPECTOR = "showFavoriteInspector"; -const std::string mitk::NodeSelectionConstants::SHOW_HISTORY_INSPECTOR = "showHistoryInspector"; \ No newline at end of file +const std::string mitk::NodeSelectionConstants::SHOW_HISTORY_INSPECTOR = "showHistoryInspector"; diff --git a/Plugins/org.mitk.gui.qt.common/src/internal/QmitkNodeSelectionPreferencePage.cpp b/Plugins/org.mitk.gui.qt.common/src/internal/QmitkNodeSelectionPreferencePage.cpp index 204d0f6e16..96d79e1a30 100644 --- a/Plugins/org.mitk.gui.qt.common/src/internal/QmitkNodeSelectionPreferencePage.cpp +++ b/Plugins/org.mitk.gui.qt.common/src/internal/QmitkNodeSelectionPreferencePage.cpp @@ -1,215 +1,221 @@ /*============================================================================ 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 "QmitkNodeSelectionPreferencePage.h" #include "QmitkNodeSelectionPreferenceHelper.h" #include #include //----------------------------------------------------------------------------- QmitkNodeSelectionPreferencePage::QmitkNodeSelectionPreferencePage() : m_MainControl(nullptr), m_Controls(nullptr) { } //----------------------------------------------------------------------------- QmitkNodeSelectionPreferencePage::~QmitkNodeSelectionPreferencePage() { delete m_Controls; } //----------------------------------------------------------------------------- void QmitkNodeSelectionPreferencePage::Init(berry::IWorkbench::Pointer ) { } //----------------------------------------------------------------------------- void QmitkNodeSelectionPreferencePage::CreateQtControl(QWidget* parent) { m_MainControl = new QWidget(parent); m_Controls = new Ui::QmitkNodeSelectionPreferencePage; m_Controls->setupUi( m_MainControl ); connect(m_Controls->comboPreferred, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateWidgets())); connect(m_Controls->btnUp, SIGNAL(clicked(bool)), this, SLOT(MoveUp())); connect(m_Controls->btnDown, SIGNAL(clicked(bool)), this, SLOT(MoveDown())); - connect(m_Controls->listInspectors, SIGNAL(itemSelectionChanged()), this, SLOT(UpdateWidgets())); + connect(m_Controls->listInspectors, &QListWidget::itemSelectionChanged, this, &QmitkNodeSelectionPreferencePage::UpdateWidgets); this->Update(); } //----------------------------------------------------------------------------- QWidget* QmitkNodeSelectionPreferencePage::GetQtControl() const { return m_MainControl; } //----------------------------------------------------------------------------- bool QmitkNodeSelectionPreferencePage::PerformOk() { //store favorite auto id = m_Controls->comboPreferred->currentData().toString(); mitk::PutPreferredDataStorageInspector(id.toStdString()); //store visible mitk::VisibleDataStorageInspectorMapType visibles; unsigned int visiblePos = 0; for (int i = 0; i < m_Controls->listInspectors->count(); ++i) { auto item = m_Controls->listInspectors->item(i); if (item->checkState() == Qt::Checked) { visibles.insert(std::make_pair(visiblePos++, item->data(Qt::UserRole).toString().toStdString())); } } mitk::PutVisibleDataStorageInspectors(visibles); mitk::PutShowFavoritesInspector(m_Controls->checkShowFav->isChecked()); mitk::PutShowHistoryInspector(m_Controls->checkShowHistory->isChecked()); return true; } //----------------------------------------------------------------------------- void QmitkNodeSelectionPreferencePage::PerformCancel() { } //----------------------------------------------------------------------------- void QmitkNodeSelectionPreferencePage::Update() { m_Providers = mitk::DataStorageInspectorGenerator::GetProviders(); auto visibleProviders = mitk::GetVisibleDataStorageInspectors(); auto allProviders = mitk::DataStorageInspectorGenerator::GetProviders(); auto favorite = mitk::GetPreferredDataStorageInspector(); auto finding = m_Providers.find(favorite); if (finding == m_Providers.cend()) { favorite = m_Providers.begin()->first; } //fill favorite combo int index = 0; int currentIndex = 0; m_Controls->comboPreferred->clear(); for (auto iter : m_Providers) { m_Controls->comboPreferred->addItem(QString::fromStdString(iter.second->GetInspectorDisplayName()),QVariant::fromValue(QString::fromStdString(iter.first))); if (iter.first == favorite) { currentIndex = index; }; ++index; } m_Controls->comboPreferred->setCurrentIndex(currentIndex); //fill inspector list m_Controls->listInspectors->clear(); for (const auto iter : allProviders) { if (iter.first != QmitkDataStorageFavoriteNodesInspector::INSPECTOR_ID() && iter.first != QmitkDataStorageSelectionHistoryInspector::INSPECTOR_ID()) { auto currentID = iter.first; QListWidgetItem* item = new QListWidgetItem; item->setText(QString::fromStdString(iter.second->GetInspectorDisplayName())); item->setData(Qt::UserRole, QVariant::fromValue(QString::fromStdString(currentID))); item->setToolTip(QString::fromStdString(iter.second->GetInspectorDescription())); auto finding = std::find_if(visibleProviders.cbegin(), visibleProviders.cend(), [¤tID](auto v) {return v.second == currentID; }); if (finding == visibleProviders.cend()) { item->setCheckState(Qt::Unchecked); m_Controls->listInspectors->addItem(item); } else { item->setCheckState(Qt::Checked); m_Controls->listInspectors->insertItem(finding->first, item); } } } m_Controls->checkShowFav->setChecked(mitk::GetShowFavoritesInspector()); m_Controls->checkShowHistory->setChecked(mitk::GetShowHistoryInspector()); this->UpdateWidgets(); } void QmitkNodeSelectionPreferencePage::UpdateWidgets() { int currentIndex = m_Controls->listInspectors->currentRow(); m_Controls->btnUp->setEnabled(!m_Controls->listInspectors->selectedItems().empty() && currentIndex > 0); m_Controls->btnDown->setEnabled(!m_Controls->listInspectors->selectedItems().empty() && currentIndex + 1 < m_Controls->listInspectors->count()); for (int i = 0; i < m_Controls->listInspectors->count(); ++i) { auto item = m_Controls->listInspectors->item(i); if (item->data(Qt::UserRole).toString() == m_Controls->comboPreferred->currentData().toString()) { //preferred inspector is always visible. item->setCheckState(Qt::Checked); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled); } else { item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable); } } - if (QmitkDataStorageFavoriteNodesInspector::INSPECTOR_ID() == m_Controls->comboPreferred->currentData().toString()) + auto isFavSelected = + QmitkDataStorageFavoriteNodesInspector::INSPECTOR_ID() == m_Controls->comboPreferred->currentData().toString(); + if (isFavSelected) { m_Controls->checkShowFav->setChecked(true); } - if (QmitkDataStorageSelectionHistoryInspector::INSPECTOR_ID() == m_Controls->comboPreferred->currentData().toString()) + m_Controls->checkShowFav->setEnabled(!isFavSelected); + + auto isHistorySelected = + QmitkDataStorageSelectionHistoryInspector::INSPECTOR_ID() == m_Controls->comboPreferred->currentData().toString(); + if (isHistorySelected) { m_Controls->checkShowHistory->setChecked(true); } - + m_Controls->checkShowHistory->setEnabled(!isHistorySelected); }; void QmitkNodeSelectionPreferencePage::MoveDown() { int currentIndex = m_Controls->listInspectors->currentRow(); if (currentIndex+1 < m_Controls->listInspectors->count()) { QListWidgetItem *currentItem = m_Controls->listInspectors->takeItem(currentIndex); m_Controls->listInspectors->insertItem(currentIndex + 1, currentItem); m_Controls->listInspectors->setCurrentRow(currentIndex + 1); } this->UpdateWidgets(); }; void QmitkNodeSelectionPreferencePage::MoveUp() { int currentIndex = m_Controls->listInspectors->currentRow(); if (currentIndex > 0) { QListWidgetItem *currentItem = m_Controls->listInspectors->takeItem(currentIndex); m_Controls->listInspectors->insertItem(currentIndex - 1, currentItem); m_Controls->listInspectors->setCurrentRow(currentIndex - 1); } this->UpdateWidgets(); };