diff --git a/Modules/QtWidgets/include/QmitkDataStorageHistoryModel.h b/Modules/QtWidgets/include/QmitkDataStorageHistoryModel.h index 9bfeb93e35..8e77a6d8f5 100644 --- a/Modules/QtWidgets/include/QmitkDataStorageHistoryModel.h +++ b/Modules/QtWidgets/include/QmitkDataStorageHistoryModel.h @@ -1,48 +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 QMITKDATASTORAGEHISTORYMODEL_H #define QMITKDATASTORAGEHISTORYMODEL_H #include #include /** * @brief Internal DataStorage model to represent the history of node selections. * * The model will present all nodes in the history under the following conditions * - the nodes are sorted by selection time (lifo -> last is first) * - node must be in the storage * - node must be valid * - node will only be in the history once. * */ class MITKQTWIDGETS_EXPORT QmitkDataStorageHistoryModel : public QmitkDataStorageDefaultListModel { Q_OBJECT public: QmitkDataStorageHistoryModel(QObject *parent); - /** Adds the passed node to the history. If the node is alread in the history, old instances will be removed. + /** Adds the passed node to the history. If the node is already in the history, old instances will be removed. If the passed node is nullptr, it will be ignored.*/ static void AddNodeToHistory(mitk::DataNode* node); static void ResetHistory(); protected: void UpdateModelData() override; }; -#endif // QMITKDATASTORAGELISTINSPECTOR_H +#endif // QMITKDATASTORAGEHISTORYMODEL_H diff --git a/Modules/QtWidgets/src/QmitkDataStorageHistoryModel.cpp b/Modules/QtWidgets/src/QmitkDataStorageHistoryModel.cpp index 4eb0995825..6bfcd722e3 100644 --- a/Modules/QtWidgets/src/QmitkDataStorageHistoryModel.cpp +++ b/Modules/QtWidgets/src/QmitkDataStorageHistoryModel.cpp @@ -1,86 +1,86 @@ /*============================================================================ 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 "mitkWeakPointer.h" #include #include #include -/** Type of the internal history contrainer. +/** Type of the internal history container. Remark: It stores raw pointer instead of mitk::WeakPointer - because this lead to ocassional crashes when the applcation was closed (see T24770 for a simelar problem + because this lead to occasional crashes when the application was closed (see T24770 for a similar problem with the same reason*/ using NodeHistoryType = std::deque< const mitk::DataNode* >; /** History of node selection. It is sorted from new to old.*/ NodeHistoryType _nodeHistory; std::mutex _historyMutex; QmitkDataStorageHistoryModel::QmitkDataStorageHistoryModel(QObject *parent) : QmitkDataStorageDefaultListModel(parent) { } void QmitkDataStorageHistoryModel::UpdateModelData() { std::vector dataNodes; if (!m_DataStorage.IsExpired()) { auto dataStorage = m_DataStorage.Lock(); mitk::DataStorage::SetOfObjects::ConstPointer nodesCandidats; if (m_NodePredicate.IsNotNull()) { nodesCandidats = dataStorage->GetSubset(m_NodePredicate); } else { nodesCandidats = dataStorage->GetAll(); } const std::lock_guard lock(_historyMutex); for (auto historyNode : _nodeHistory) { auto finding = std::find(nodesCandidats->begin(), nodesCandidats->end(), historyNode); if (finding != nodesCandidats->end()) { dataNodes.push_back(*finding); } } } // update the model, so that it will be filled with the nodes of the new data storage beginResetModel(); m_DataNodes = dataNodes; endResetModel(); } void QmitkDataStorageHistoryModel::AddNodeToHistory(mitk::DataNode* node) { const std::lock_guard lock(_historyMutex); auto finding = std::find(std::begin(_nodeHistory), std::end(_nodeHistory), node); while (finding != std::end(_nodeHistory)) { _nodeHistory.erase(finding); finding = std::find(std::begin(_nodeHistory), std::end(_nodeHistory), node); } _nodeHistory.push_front(node); -}; +} void QmitkDataStorageHistoryModel::ResetHistory() { const std::lock_guard lock(_historyMutex); _nodeHistory.clear(); -}; \ No newline at end of file +} diff --git a/Modules/QtWidgets/src/QmitkDataStorageSelectionHistoryInspector.cpp b/Modules/QtWidgets/src/QmitkDataStorageSelectionHistoryInspector.cpp index e1e4757483..a9fe9b5722 100644 --- a/Modules/QtWidgets/src/QmitkDataStorageSelectionHistoryInspector.cpp +++ b/Modules/QtWidgets/src/QmitkDataStorageSelectionHistoryInspector.cpp @@ -1,67 +1,67 @@ /*============================================================================ 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 QmitkDataStorageSelectionHistoryInspector::QmitkDataStorageSelectionHistoryInspector(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_StorageModel = new QmitkDataStorageHistoryModel(this); m_Controls.view->setModel(m_StorageModel); } QAbstractItemView* QmitkDataStorageSelectionHistoryInspector::GetView() { return m_Controls.view; } const QAbstractItemView* QmitkDataStorageSelectionHistoryInspector::GetView() const { return m_Controls.view; } void QmitkDataStorageSelectionHistoryInspector::Initialize() { m_StorageModel->SetDataStorage(m_DataStorage.Lock()); m_StorageModel->SetNodePredicate(m_NodePredicate); m_Connector->SetView(m_Controls.view); } void QmitkDataStorageSelectionHistoryInspector::SetSelectionMode(SelectionMode mode) { m_Controls.view->setSelectionMode(mode); } QmitkDataStorageSelectionHistoryInspector::SelectionMode QmitkDataStorageSelectionHistoryInspector::GetSelectionMode() const { return m_Controls.view->selectionMode(); } void QmitkDataStorageSelectionHistoryInspector::AddNodeToHistory(mitk::DataNode* node) { QmitkDataStorageHistoryModel::AddNodeToHistory(node); -}; +} void QmitkDataStorageSelectionHistoryInspector::ResetHistory() { QmitkDataStorageHistoryModel::ResetHistory(); -}; \ No newline at end of file +}