diff --git a/Plugins/org.mitk.gui.qt.dicom/src/internal/QmitkDicomTreeViewPreferencePage.cpp b/Plugins/org.mitk.gui.qt.dicom/src/internal/QmitkDicomTreeViewPreferencePage.cpp index cb89c0ba81..62ddbd14e6 100644 --- a/Plugins/org.mitk.gui.qt.dicom/src/internal/QmitkDicomTreeViewPreferencePage.cpp +++ b/Plugins/org.mitk.gui.qt.dicom/src/internal/QmitkDicomTreeViewPreferencePage.cpp @@ -1,215 +1,223 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkDicomTreeViewPreferencePage.h" // DICOM UI #include "mitkDicomType.h" // DICOM browser GUI plugin #include "QmitkDicomBrowser.h" // berry #include #include // MITK #include // Qt #include #include QmitkDicomTreeViewPreferencePage::QmitkDicomTreeViewPreferencePage() : m_Control(nullptr) { // nothing here } void QmitkDicomTreeViewPreferencePage::Init(berry::IWorkbench::Pointer) { // nothing here } void QmitkDicomTreeViewPreferencePage::CreateQtControl(QWidget* parent) { // restore preferences from the previous session // will be used in the 'Update()'-function to set the items in the item list widgets m_DicomTreeViewPreferences = berry::Platform::GetPreferencesService()->GetSystemPreferences()->Node(QmitkDicomBrowser::EDITOR_ID);; m_Controls.setupUi(parent); m_Control = new QWidget(parent); m_Control->setLayout(m_Controls.gridLayout); QSignalMapper* lrSignalMapper = new QSignalMapper(this); lrSignalMapper->setMapping(m_Controls.leftPushButton, QString("left")); lrSignalMapper->setMapping(m_Controls.rightPushButton, QString("right")); QSignalMapper* udSignalMapper = new QSignalMapper(this); udSignalMapper->setMapping(m_Controls.upPushButton, QString("up")); udSignalMapper->setMapping(m_Controls.downPushButton, QString("down")); connect(m_Controls.leftPushButton, SIGNAL(clicked()), lrSignalMapper, SLOT(map())); connect(m_Controls.rightPushButton, SIGNAL(clicked()), lrSignalMapper, SLOT(map())); connect(m_Controls.upPushButton, SIGNAL(clicked()), udSignalMapper, SLOT(map())); connect(m_Controls.downPushButton, SIGNAL(clicked()), udSignalMapper, SLOT(map())); connect(lrSignalMapper, SIGNAL(mapped(const QString&)), this, SLOT(SwapListItem(const QString&))); connect(udSignalMapper, SIGNAL(mapped(const QString&)), this, SLOT(MoveListItem(const QString&))); this->Update(); } QWidget* QmitkDicomTreeViewPreferencePage::GetQtControl() const { return m_Control; } bool QmitkDicomTreeViewPreferencePage::PerformOk() { if (m_DicomTreeViewPreferences.IsNotNull()) { m_DicomTreeViewPreferences->BlockSignals(true); // reset number of items to later invoke the 'OnChanged' signal to be emitted (see after (BlockSignals(false)') m_DicomTreeViewPreferences->PutInt("NumberOfItems", -1); for (int i = 0; i < m_Controls.rightListWidget->count(); ++i) { QString tagName = m_Controls.rightListWidget->item(i)->text(); std::map::iterator it = m_DICOMTagNames.find(tagName); QString DICOMTag; if (it != m_DICOMTagNames.end()) { DICOMTag = QString::fromStdString(it->second); } QString item = "Item " + QString::number(i); // name for the current DICOM tag property m_DicomTreeViewPreferences->Put(item, DICOMTag); } m_DicomTreeViewPreferences->BlockSignals(false); m_DicomTreeViewPreferences->PutInt("NumberOfItems", m_Controls.rightListWidget->count()); return true; } return false; } void QmitkDicomTreeViewPreferencePage::PerformCancel() { // nothing here } void QmitkDicomTreeViewPreferencePage::Update() { ResetLists(); if (m_DicomTreeViewPreferences.IsNotNull()) { int numberOfItems = m_DicomTreeViewPreferences->GetInt("NumberOfItems", 0); if (numberOfItems > 0) { QList foundItems; foundItems.reserve(numberOfItems); for (int i = 0; i < numberOfItems; ++i) { QString item = "Item " + QString::number(i); std::string DICOMTag = m_DicomTreeViewPreferences->Get(item, "").toStdString(); QString tagName = QString::fromStdString(Dicom::DICOMTagToName(DICOMTag)); foundItems.append(m_Controls.leftListWidget->findItems(tagName, Qt::MatchExactly)); // should only get one hit } for (const auto& listWidgetItem : foundItems) { int row = m_Controls.leftListWidget->row(listWidgetItem); m_Controls.leftListWidget->takeItem(row); m_Controls.rightListWidget->addItem(listWidgetItem); } } else { // no preferences stored // write default preferences to the preferences node QList foundItems = m_Controls.leftListWidget->findItems("Patient's Name", Qt::MatchExactly); // should only get one hit foundItems.append(m_Controls.leftListWidget->findItems("Study Description", Qt::MatchExactly)); // should only get one hit foundItems.append(m_Controls.leftListWidget->findItems("Series Description", Qt::MatchExactly)); // should only get one hit for (const auto& listWidgetItem : foundItems) { int row = m_Controls.leftListWidget->row(listWidgetItem); m_Controls.leftListWidget->takeItem(row); m_Controls.rightListWidget->addItem(listWidgetItem); } } } } -void QmitkDicomTreeViewPreferencePage::SwapListItem(const QString& direction) +void QmitkDicomTreeViewPreferencePage::SwapListItem(const QString &direction) { QListWidget* destination; QListWidget* source; - if (direction == "left") + if ("left" == direction) { destination = m_Controls.leftListWidget; source = m_Controls.rightListWidget; } else { destination = m_Controls.rightListWidget; source = m_Controls.leftListWidget; } if (source->count() == 0) return; // no more items left to move QListWidgetItem* widget = source->takeItem(source->currentRow()); destination->addItem(widget); + + if ("right" == direction) + { + // item moved to the left list widget - sort again + m_Controls.leftListWidget->sortItems(); + } } -void QmitkDicomTreeViewPreferencePage::MoveListItem(const QString& direction) +void QmitkDicomTreeViewPreferencePage::MoveListItem(const QString &direction) { QListWidget* listWidget = m_Controls.rightListWidget; int currentRow = listWidget->currentRow(); if ((currentRow <= 0 && direction == "up") || (currentRow >= listWidget->count() - 1 && direction == "down")) { return; // item is at the top or bottom of the list } QListWidgetItem* currentItem = listWidget->takeItem(currentRow); if (direction == "up") { listWidget->insertItem(currentRow - 1, currentItem); listWidget->setCurrentRow(currentRow - 1); } else { listWidget->insertItem(currentRow + 1, currentItem); listWidget->setCurrentRow(currentRow + 1); } } void QmitkDicomTreeViewPreferencePage::ResetLists() { m_Controls.leftListWidget->clear(); m_Controls.rightListWidget->clear(); mitk::DICOMTagPathMapType defaultDICOMTags = mitk::GetDefaultDICOMTagsOfInterest(); for (auto it = defaultDICOMTags.begin(); it != defaultDICOMTags.end(); ++it) { QString tagName = QString::fromStdString(Dicom::DICOMTagPathToName(it->first)); m_Controls.leftListWidget->addItem(tagName); m_DICOMTagNames.insert(std::make_pair(tagName, mitk::DICOMTagPathToPropertyName(it->first))); } + + m_Controls.leftListWidget->sortItems(); } diff --git a/Plugins/org.mitk.gui.qt.dicom/src/internal/QmitkDicomTreeViewPreferencePage.h b/Plugins/org.mitk.gui.qt.dicom/src/internal/QmitkDicomTreeViewPreferencePage.h index 5ba91db02d..b3a685f0f7 100644 --- a/Plugins/org.mitk.gui.qt.dicom/src/internal/QmitkDicomTreeViewPreferencePage.h +++ b/Plugins/org.mitk.gui.qt.dicom/src/internal/QmitkDicomTreeViewPreferencePage.h @@ -1,92 +1,92 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKDICOMTREEVIEWPREFERENCEPAGE_H #define QMITKDICOMTREEVIEWPREFERENCEPAGE_H #include "ui_QmitkDicomTreeViewPreferencePageControls.h" // berry #include #include /** * @brief A preference page to set the DICOM tags for the order of the tree items in a DICOM Tree View * * The preference page contains two list, where the left list shows all available DICOM tags that are currently * not used in a DICOM tree view / model. The right list shows all DICOM tags that are currently used in a DICOM * tree view / model to insert an item in the tree. * When clicking 'Ok', the 'PerformOk'-function is called and the chosen DICOM tags in the right item list are stored * in a preference node, which can be read by the 'QmitkDicomBrowser'. The browser then invokes a reset of the * DICOM tree, which was added as a widget to the 'QmitkDicomExternalDataWidget'. The reset involves a reset / modification * of the sort-by-vector (see 'QmitkDicomTreeWidget'). */ struct QmitkDicomTreeViewPreferencePage : public QObject, public berry::IQtPreferencePage { Q_OBJECT Q_INTERFACES(berry::IPreferencePage) public: QmitkDicomTreeViewPreferencePage(); void Init(berry::IWorkbench::Pointer workbench) override; void CreateQtControl(QWidget* widget) override; QWidget* GetQtControl() const override; /** * @see IPreferencePage::PerformOk() */ virtual bool PerformOk() override; /** * @see IPreferencePage::PerformCancel() */ virtual void PerformCancel() override; /** * @see IPreferencePage::Update() for usage of this function * @brief reset both lists and move the items from the last session from the left list to the right list */ virtual void Update() override; protected Q_SLOTS: /** * @brief move a list item from the left list to the right list and vice versa */ - void SwapListItem(const QString& direction); + void SwapListItem(const QString &direction); /** * @brief move a list item in the right list up and down */ - void MoveListItem(const QString& direction); + void MoveListItem(const QString &direction); private: /** * @brief clear both lists and populate the lists with the default DICOM tags */ void ResetLists(); Ui::QmitkDicomTreeViewPreferencePageControls m_Controls; QWidget* m_Control; berry::IPreferences::Pointer m_DicomTreeViewPreferences; std::map m_DICOMTagNames; }; #endif // QMITKDICOMTREEVIEWPREFERENCEPAGE_H diff --git a/Plugins/org.mitk.gui.qt.dicom/src/internal/QmitkDicomTreeViewPreferencePageControls.ui b/Plugins/org.mitk.gui.qt.dicom/src/internal/QmitkDicomTreeViewPreferencePageControls.ui index 7ddd75291e..031f54ec2a 100644 --- a/Plugins/org.mitk.gui.qt.dicom/src/internal/QmitkDicomTreeViewPreferencePageControls.ui +++ b/Plugins/org.mitk.gui.qt.dicom/src/internal/QmitkDicomTreeViewPreferencePageControls.ui @@ -1,173 +1,177 @@ QmitkDicomTreeViewPreferencePageControls 0 0 700 600 0 0 653 116 16777215 16777215 Form true 0 0 false Patient tree view - DICOM information 0 0 Available DICOM information 0 0 DICOM information used for the tree view - + + + true + + 0 0 0 0 16777215 16777215 Move left 0 0 16777215 16777215 Move right 0 0 Move up 0 0 Move down Sort tree by Qt::AlignCenter