diff --git a/Modules/QtWidgets/include/QmitkNodeDetailsDialog.h b/Modules/QtWidgets/include/QmitkNodeDetailsDialog.h index a70e0982cc..769bbf085e 100644 --- a/Modules/QtWidgets/include/QmitkNodeDetailsDialog.h +++ b/Modules/QtWidgets/include/QmitkNodeDetailsDialog.h @@ -1,56 +1,60 @@ /*=================================================================== 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 QMITKNODEDETAILSDIALOG_H #define QMITKNODEDETAILSDIALOG_H #include #include #include class QLineEdit; class QTextBrowser; class MITKQTWIDGETS_EXPORT QmitkNodeDetailsDialog : public QDialog { Q_OBJECT public: + QmitkNodeDetailsDialog(const QList& nodes, QWidget* parent = nullptr, Qt::WindowFlags flags = nullptr); QmitkNodeDetailsDialog(const QList& nodes, QWidget* parent = nullptr, Qt::WindowFlags flags = nullptr); public Q_SLOTS: void OnSelectionChanged(const mitk::DataNode*); void OnSearchButtonClicked(bool checked = false); void OnCancelButtonClicked(bool checked = false); void KeyWordTextChanged(const QString& text); protected: bool eventFilter(QObject* obj, QEvent* event) override; protected: QLineEdit* m_KeyWord; QPushButton* m_SearchButton; QTextBrowser* m_TextBrowser; +private: + void InitWidgets(const QList& nodes); + }; #endif // QMITKNODEDETAILSDIALOG_H diff --git a/Modules/QtWidgets/include/QmitkOverlayWidget.h b/Modules/QtWidgets/include/QmitkOverlayWidget.h index 580eb64c76..34e746c9d3 100644 --- a/Modules/QtWidgets/include/QmitkOverlayWidget.h +++ b/Modules/QtWidgets/include/QmitkOverlayWidget.h @@ -1,49 +1,49 @@ /*=================================================================== 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 QMITK_OVERLAY_WIDGET_H #define QMITK_OVERLAY_WIDGET_H #include #include /** Simple widget that can be used to achive overlays. The overlay will lie above its parent. * This implementation just renders a semi transparent black background. To add content to the * overlay derive from this class.*/ class MITKQTWIDGETS_EXPORT QmitkOverlayWidget : public QWidget { Q_OBJECT Q_PROPERTY(bool transparentForMouseEvents READ isTransparentForMouseEvents WRITE setTransparentForMouseEvents) public: explicit QmitkOverlayWidget(QWidget* parent = nullptr); virtual ~QmitkOverlayWidget(); bool isTransparentForMouseEvents() const; void setTransparentForMouseEvents(bool transparent = true); protected: - virtual bool event(QEvent* e) override; - virtual bool eventFilter(QObject* watched, QEvent* event) override; - virtual void paintEvent(QPaintEvent* event) override; + bool event(QEvent* e) override; + bool eventFilter(QObject* watched, QEvent* event) override; + void paintEvent(QPaintEvent* event) override; private: void installEventFilterOnParent(); void removeEventFilterFromParent(); }; #endif diff --git a/Modules/QtWidgets/src/QmitkNodeDetailsDialog.cpp b/Modules/QtWidgets/src/QmitkNodeDetailsDialog.cpp index 7bf52a09ca..262d9c5053 100644 --- a/Modules/QtWidgets/src/QmitkNodeDetailsDialog.cpp +++ b/Modules/QtWidgets/src/QmitkNodeDetailsDialog.cpp @@ -1,127 +1,145 @@ /*=================================================================== 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 "QmitkNodeDetailsDialog.h" #include "QmitkDataStorageComboBox.h" #include #include #include #include #include #include #include QmitkNodeDetailsDialog::QmitkNodeDetailsDialog(const QList& nodes, QWidget* parent /*= nullptr*/, Qt::WindowFlags flags /*= nullptr */) : QDialog(parent, flags) +{ + QList constNodes; + + for (auto& node : nodes) + { + constNodes.append(node.GetPointer()); + } + + InitWidgets(constNodes); +} + +QmitkNodeDetailsDialog::QmitkNodeDetailsDialog(const QList& nodes, QWidget* parent /*= nullptr*/, Qt::WindowFlags flags /*= nullptr */) + : QDialog(parent, flags) +{ + InitWidgets(nodes); +} + +void QmitkNodeDetailsDialog::InitWidgets(const QList& nodes) { auto parentLayout = new QGridLayout; auto dataStorageComboBox = new QmitkDataStorageComboBox(this, true); m_KeyWord = new QLineEdit; m_KeyWord->installEventFilter(this); m_SearchButton = new QPushButton("Search (F3)", this); m_SearchButton->installEventFilter(this); m_TextBrowser = new QTextBrowser(this); QPushButton* cancelButton = new QPushButton("Cancel", this); setMinimumSize(512, 512); setLayout(parentLayout); setSizeGripEnabled(true); setModal(true); parentLayout->addWidget(dataStorageComboBox, 0, 0, 1, 2); parentLayout->addWidget(m_KeyWord, 1, 0); parentLayout->addWidget(m_SearchButton, 1, 1); parentLayout->addWidget(m_TextBrowser, 2, 0, 1, 2); parentLayout->addWidget(cancelButton, 3, 0, 1, 2); connect(dataStorageComboBox, &QmitkDataStorageComboBox::OnSelectionChanged, this, &QmitkNodeDetailsDialog::OnSelectionChanged); - for(auto& node : nodes) + for (auto& node : nodes) { dataStorageComboBox->AddNode(node); } connect(m_KeyWord, &QLineEdit::textChanged, this, &QmitkNodeDetailsDialog::KeyWordTextChanged); connect(m_SearchButton, &QPushButton::clicked, this, &QmitkNodeDetailsDialog::OnSearchButtonClicked); connect(cancelButton, &QPushButton::clicked, this, &QmitkNodeDetailsDialog::OnCancelButtonClicked); cancelButton->setDefault(true); -} +}; void QmitkNodeDetailsDialog::OnSelectionChanged(const mitk::DataNode* node) { if (nullptr == node) { return; } std::ostringstream s; itk::Indent i(2); mitk::BaseData* baseData = node->GetData(); if (nullptr != baseData) { baseData->Print(s, i); } m_TextBrowser->setPlainText(QString::fromStdString(s.str())); } void QmitkNodeDetailsDialog::OnSearchButtonClicked(bool /*checked*/ /*= false */) { QString keyWord = m_KeyWord->text(); QString text = m_TextBrowser->toPlainText(); if (keyWord.isEmpty() || text.isEmpty()) { return; } m_TextBrowser->find(keyWord); m_SearchButton->setText("Search Next(F3)"); } void QmitkNodeDetailsDialog::OnCancelButtonClicked(bool /*checked*/ /*= false */) { done(0); } bool QmitkNodeDetailsDialog::eventFilter(QObject* obj, QEvent* event) { if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast(event); if (keyEvent->key() == Qt::Key_F3 || keyEvent->key() == Qt::Key_Return) { // trigger deletion of selected node(s) OnSearchButtonClicked(true); // return true: this means the delete key event is not send to the table return true; } } // standard event processing return QObject::eventFilter(obj, event); } void QmitkNodeDetailsDialog::KeyWordTextChanged(const QString& /*text*/) { QTextCursor textCursor = m_TextBrowser->textCursor(); textCursor.setPosition(0); m_TextBrowser->setTextCursor(textCursor); m_SearchButton->setText("Search (F3)"); } diff --git a/Plugins/org.mitk.gui.qt.common/src/QmitkMultiNodeSelectionWidget.cpp b/Plugins/org.mitk.gui.qt.common/src/QmitkMultiNodeSelectionWidget.cpp index 5f94c42764..ac829d2695 100644 --- a/Plugins/org.mitk.gui.qt.common/src/QmitkMultiNodeSelectionWidget.cpp +++ b/Plugins/org.mitk.gui.qt.common/src/QmitkMultiNodeSelectionWidget.cpp @@ -1,254 +1,254 @@ /*=================================================================== 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 "QmitkMultiNodeSelectionWidget.h" #include #include "QmitkNodeSelectionDialog.h" #include "QmitkCustomVariants.h" #include "internal/QmitkNodeSelectionListItemWidget.h" QmitkMultiNodeSelectionWidget::QmitkMultiNodeSelectionWidget(QWidget* parent) : QmitkAbstractNodeSelectionWidget(parent) { m_Controls.setupUi(this); m_Overlay = new QmitkSimpleTextOverlayWidget(m_Controls.list); m_Overlay->setVisible(false); m_CheckFunction = [](const NodeList &) { return ""; }; this->UpdateList(); this->UpdateInfo(); connect(m_Controls.btnChange, SIGNAL(clicked(bool)), this, SLOT(OnEditSelection())); } QmitkMultiNodeSelectionWidget::NodeList QmitkMultiNodeSelectionWidget::CompileEmitSelection() const { NodeList result; for (int i = 0; i < m_Controls.list->count(); ++i) { QListWidgetItem* item = m_Controls.list->item(i); auto node = item->data(Qt::UserRole).value(); result.append(node); } if (!m_SelectOnlyVisibleNodes) { for (auto node : m_CurrentSelection) { if (!result.contains(node)) { result.append(node); } } } return result; } void QmitkMultiNodeSelectionWidget::OnNodePredicateChanged(mitk::NodePredicateBase* /*newPredicate*/) { this->UpdateInfo(); this->UpdateList(); }; void QmitkMultiNodeSelectionWidget::OnDataStorageChanged() { this->UpdateInfo(); this->UpdateList(); }; QmitkMultiNodeSelectionWidget::NodeList QmitkMultiNodeSelectionWidget::GetSelectedNodes() const { return m_CurrentSelection; }; void QmitkMultiNodeSelectionWidget::SetSelectionCheckFunction(const SelectionCheckFunctionType &checkFunction) { m_CheckFunction = checkFunction; auto newEmission = this->CompileEmitSelection(); auto newCheckResponse = m_CheckFunction(newEmission); if (newCheckResponse.empty() && !m_CheckResponse.empty()) { emit CurrentSelectionChanged(newEmission); } m_CheckResponse = newCheckResponse; this->UpdateInfo(); }; void QmitkMultiNodeSelectionWidget::OnEditSelection() { QmitkNodeSelectionDialog* dialog = new QmitkNodeSelectionDialog(this, m_PopUpTitel, m_PopUpHint); dialog->SetDataStorage(m_DataStorage.Lock()); dialog->SetNodePredicate(m_NodePredicate); dialog->SetCurrentSelection(this->CompileEmitSelection()); dialog->SetSelectOnlyVisibleNodes(m_SelectOnlyVisibleNodes); dialog->SetSelectionMode(QAbstractItemView::MultiSelection); m_Controls.btnChange->setChecked(true); if (dialog->exec()) { auto lastEmission = this->CompileEmitSelection(); m_CurrentSelection = dialog->GetSelectedNodes(); this->UpdateList(); auto newEmission = this->CompileEmitSelection(); m_CheckResponse = m_CheckFunction(newEmission); this->UpdateInfo(); if (!EqualNodeSelections(lastEmission, newEmission)) { if (m_CheckResponse.empty()) { emit CurrentSelectionChanged(newEmission); } } } m_Controls.btnChange->setChecked(false); delete dialog; }; void QmitkMultiNodeSelectionWidget::UpdateInfo() { if (!m_Controls.list->count()) { if (m_IsOptional) { m_Overlay->SetOverlayText(m_EmptyInfo); } else { m_Overlay->SetOverlayText(m_InvalidInfo); } } else { if (!m_CheckResponse.empty()) { m_Overlay->SetOverlayText(QString::fromStdString(m_CheckResponse)); } } m_Overlay->setVisible(m_Controls.list->count() == 0 || !m_CheckResponse.empty()); for (auto i = 0; i < m_Controls.list->count(); ++i) { auto item = m_Controls.list->item(i); auto widget = qobject_cast(m_Controls.list->itemWidget(item)); widget->SetClearAllowed(m_IsOptional || m_CurrentSelection.size() > 1); } }; void QmitkMultiNodeSelectionWidget::UpdateList() { m_Controls.list->clear(); for (auto node : m_CurrentSelection) { if (m_NodePredicate.IsNull() || m_NodePredicate->CheckNode(node)) { QListWidgetItem *newItem = new QListWidgetItem; newItem->setSizeHint(QSize(0, 40)); QmitkNodeSelectionListItemWidget* widget = new QmitkNodeSelectionListItemWidget; widget->SetSelectedNode(node); widget->SetClearAllowed(m_IsOptional || m_CurrentSelection.size() > 1); - connect(widget, SIGNAL(ClearSelection(mitk::DataNode*)), this, SLOT(OnClearSelection(mitk::DataNode*))); + connect(widget, &QmitkNodeSelectionListItemWidget::ClearSelection, this, &QmitkMultiNodeSelectionWidget::OnClearSelection); newItem->setData(Qt::UserRole, QVariant::fromValue(node)); m_Controls.list->addItem(newItem); m_Controls.list->setItemWidget(newItem, widget); } } }; void QmitkMultiNodeSelectionWidget::SetSelectOnlyVisibleNodes(bool selectOnlyVisibleNodes) { auto lastEmission = this->CompileEmitSelection(); m_SelectOnlyVisibleNodes = selectOnlyVisibleNodes; auto newEmission = this->CompileEmitSelection(); if (!EqualNodeSelections(lastEmission, newEmission)) { m_CheckResponse = m_CheckFunction(newEmission); if (m_CheckResponse.empty()) { emit CurrentSelectionChanged(newEmission); } this->UpdateList(); this->UpdateInfo(); } }; void QmitkMultiNodeSelectionWidget::SetCurrentSelection(NodeList selectedNodes) { auto lastEmission = this->CompileEmitSelection(); m_CurrentSelection = selectedNodes; this->UpdateList(); auto newEmission = this->CompileEmitSelection(); if (!EqualNodeSelections(lastEmission, newEmission)) { m_CheckResponse = m_CheckFunction(newEmission); if (m_CheckResponse.empty()) { emit CurrentSelectionChanged(newEmission); } this->UpdateInfo(); } }; void QmitkMultiNodeSelectionWidget::OnClearSelection(const mitk::DataNode* node) { auto finding = std::find(std::begin(m_CurrentSelection), std::end(m_CurrentSelection), node); m_CurrentSelection.erase(finding); this->UpdateList(); auto newEmission = this->CompileEmitSelection(); m_CheckResponse = m_CheckFunction(newEmission); if (m_CheckResponse.empty()) { emit CurrentSelectionChanged(newEmission); } this->UpdateInfo(); }; void QmitkMultiNodeSelectionWidget::NodeRemovedFromStorage(const mitk::DataNode* node) { auto finding = std::find(std::begin(m_CurrentSelection), std::end(m_CurrentSelection), node); if (finding != std::end(m_CurrentSelection)) { this->OnClearSelection(node); } } \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionButton.cpp b/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionButton.cpp index 08bb6248cf..981651861d 100644 --- a/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionButton.cpp +++ b/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionButton.cpp @@ -1,181 +1,181 @@ /*=================================================================== 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 "QmitkNodeSelectionButton.h" // berry includes #include #include #include "QPainter" #include "QTextDocument" #include #include // mitk core #include #include #include #include #include #include // vtk #include QPixmap GetPixmapFromImageNode(const mitk::DataNode* dataNode, int height) { if (nullptr == dataNode) { return QPixmap(); } const mitk::Image* image = dynamic_cast(dataNode->GetData()); if ((nullptr == image || !image->IsInitialized()) || // -> must be an image (image->GetPixelType().GetNumberOfComponents() != 1)) // -> for now only single component are allowed { auto descManager = QmitkNodeDescriptorManager::GetInstance(); auto desc = descManager->GetDescriptor(dataNode); auto icon = desc->GetIcon(dataNode); auto fallBackMap = icon.pixmap(height, height); return fallBackMap; } mitk::PlaneGeometry::Pointer planeGeometry = mitk::PlaneGeometry::New(); int sliceNumber = image->GetDimension(2) / 2; planeGeometry->InitializeStandardPlane(image->GetGeometry(), mitk::PlaneGeometry::Axial, sliceNumber); mitk::ExtractSliceFilter::Pointer extractSliceFilter = mitk::ExtractSliceFilter::New(); extractSliceFilter->SetInput(image); extractSliceFilter->SetInterpolationMode(mitk::ExtractSliceFilter::RESLICE_CUBIC); extractSliceFilter->SetResliceTransformByGeometry(image->GetGeometry()); extractSliceFilter->SetWorldGeometry(planeGeometry); extractSliceFilter->SetOutputDimensionality(2); extractSliceFilter->SetVtkOutputRequest(true); extractSliceFilter->Update(); vtkImageData* imageData = extractSliceFilter->GetVtkOutput(); mitk::LevelWindow levelWindow; dataNode->GetLevelWindow(levelWindow); vtkSmartPointer lookupTable = vtkSmartPointer::New(); lookupTable->SetRange(levelWindow.GetLowerWindowBound(), levelWindow.GetUpperWindowBound()); lookupTable->SetSaturationRange(0.0, 0.0); lookupTable->SetValueRange(0.0, 1.0); lookupTable->SetHueRange(0.0, 0.0); lookupTable->SetRampToLinear(); vtkSmartPointer levelWindowFilter = vtkSmartPointer::New(); levelWindowFilter->SetLookupTable(lookupTable); levelWindowFilter->SetInputData(imageData); levelWindowFilter->SetMinOpacity(0.0); levelWindowFilter->SetMaxOpacity(1.0); int dims[3]; imageData->GetDimensions(dims); double clippingBounds[] = { 0.0, static_cast(dims[0]), 0.0, static_cast(dims[1]) }; levelWindowFilter->SetClippingBounds(clippingBounds); levelWindowFilter->Update(); imageData = levelWindowFilter->GetOutput(); QImage thumbnailImage(reinterpret_cast(imageData->GetScalarPointer()), dims[0], dims[1], QImage::Format_ARGB32); thumbnailImage = thumbnailImage.scaledToHeight(height,Qt::SmoothTransformation).rgbSwapped(); return QPixmap::fromImage(thumbnailImage); } QmitkNodeSelectionButton::QmitkNodeSelectionButton(QWidget *parent) : QPushButton(parent), m_OutDatedThumpNail(true) { } QmitkNodeSelectionButton::~QmitkNodeSelectionButton() { this->m_SelectedNode = nullptr; } -mitk::DataNode::Pointer QmitkNodeSelectionButton::GetSelectedNode() const +const mitk::DataNode* QmitkNodeSelectionButton::GetSelectedNode() const { return m_SelectedNode; } -void QmitkNodeSelectionButton::SetSelectedNode(mitk::DataNode* node) +void QmitkNodeSelectionButton::SetSelectedNode(const mitk::DataNode* node) { if (m_SelectedNode != node) { this->m_SelectedNode = node; this->m_OutDatedThumpNail = true; } this->update(); }; void QmitkNodeSelectionButton::SetNodeInfo(QString info) { this->m_Info = info; this->update(); }; void QmitkNodeSelectionButton::paintEvent(QPaintEvent *p) { QString stylesheet; ctkPluginContext* context = berry::WorkbenchPlugin::GetDefault()->GetPluginContext(); ctkServiceReference styleManagerRef = context->getServiceReference(); if (styleManagerRef) { auto styleManager = context->getService(styleManagerRef); stylesheet = styleManager->GetStylesheet(); } QPushButton::paintEvent(p); QPainter painter(this); QTextDocument td(this); td.setDefaultStyleSheet(stylesheet); auto widgetSize = this->size(); QPoint origin = QPoint(5, 5); if (this->m_SelectedNode) { auto iconLength = widgetSize.height() - 10; auto node = this->m_SelectedNode; if (this->m_OutDatedThumpNail) { this->m_ThumpNail = GetPixmapFromImageNode(node, iconLength); this->m_OutDatedThumpNail = false; } painter.drawPixmap(origin, m_ThumpNail); origin.setX(origin.x() + iconLength + 5); td.setHtml(QString::fromStdString(""+node->GetName()+"")); } else { td.setHtml(m_Info); } auto textSize = td.size(); origin.setY( (widgetSize.height() - textSize.height()) / 2.); painter.translate(origin); td.drawContents(&painter); } diff --git a/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionButton.h b/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionButton.h index a8d78302ce..8d7b63ec38 100644 --- a/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionButton.h +++ b/Plugins/org.mitk.gui.qt.common/src/QmitkNodeSelectionButton.h @@ -1,58 +1,58 @@ /*=================================================================== 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 QMITK_NODE_SELECTION_BUTTON_H #define QMITK_NODE_SELECTION_BUTTON_H #include #include #include "org_mitk_gui_qt_common_Export.h" #include "QPushButton" #include "QPixmap" /** Button class that can be used to display informations about a passed node. * If the passed node is a null ptr the node info text will be shown. * In difference to the normal push button text property. The node info can * be formated text (e.g. HTML code; like the tooltip text).*/ class MITK_QT_COMMON QmitkNodeSelectionButton : public QPushButton { Q_OBJECT public: explicit QmitkNodeSelectionButton(QWidget *parent = nullptr); ~QmitkNodeSelectionButton(); - mitk::DataNode::Pointer GetSelectedNode() const; + const mitk::DataNode* GetSelectedNode() const; public Q_SLOTS : - virtual void SetSelectedNode(mitk::DataNode* node); + virtual void SetSelectedNode(const mitk::DataNode* node); virtual void SetNodeInfo(QString info); protected: void paintEvent(QPaintEvent *p) override; - mitk::DataNode::Pointer m_SelectedNode; + mitk::DataNode::ConstPointer m_SelectedNode; QString m_Info; bool m_OutDatedThumpNail; QPixmap m_ThumpNail; }; #endif // QmitkSingleNodeSelectionWidget_H diff --git a/Plugins/org.mitk.gui.qt.common/src/internal/QmitkNodeSelectionListItemWidget.cpp b/Plugins/org.mitk.gui.qt.common/src/internal/QmitkNodeSelectionListItemWidget.cpp index cba2d8d983..4f3c142955 100644 --- a/Plugins/org.mitk.gui.qt.common/src/internal/QmitkNodeSelectionListItemWidget.cpp +++ b/Plugins/org.mitk.gui.qt.common/src/internal/QmitkNodeSelectionListItemWidget.cpp @@ -1,94 +1,94 @@ /*=================================================================== 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 "QmitkNodeSelectionListItemWidget.h" #include #include #include "QmitkNodeDetailsDialog.h" QmitkNodeSelectionListItemWidget::QmitkNodeSelectionListItemWidget(QWidget *parent) : QWidget(parent) { m_Controls.setupUi(this); m_Controls.btnSelect->installEventFilter(this); m_Controls.btnSelect->setVisible(true); m_Controls.btnSelect->SetNodeInfo("No valid selection"); m_Controls.btnClear->setVisible(false); m_Controls.btnClear->setIcon(berry::QtStyleManager::ThemeIcon(QStringLiteral(":/org.mitk.gui.qt.common/times.svg"))); connect(m_Controls.btnClear, SIGNAL(clicked(bool)), this, SLOT(OnClearSelection())); } QmitkNodeSelectionListItemWidget::~QmitkNodeSelectionListItemWidget() { } -mitk::DataNode::Pointer QmitkNodeSelectionListItemWidget::GetSelectedNode() const +const mitk::DataNode* QmitkNodeSelectionListItemWidget::GetSelectedNode() const { return m_Controls.btnSelect->GetSelectedNode(); }; -void QmitkNodeSelectionListItemWidget::SetSelectedNode(mitk::DataNode* node) +void QmitkNodeSelectionListItemWidget::SetSelectedNode(const mitk::DataNode* node) { m_Controls.btnSelect->SetSelectedNode(node); this->update(); }; void QmitkNodeSelectionListItemWidget::SetClearAllowed(bool allowed) { m_Controls.btnClear->setVisible(allowed); }; void QmitkNodeSelectionListItemWidget::OnClearSelection() { emit ClearSelection(this->GetSelectedNode()); }; bool QmitkNodeSelectionListItemWidget::eventFilter(QObject *obj, QEvent *ev) { if (obj == m_Controls.btnSelect) { if (ev->type() == QEvent::MouseButtonRelease) { auto mouseEv = dynamic_cast(ev); if (!mouseEv) { return false; } if (mouseEv->button() == Qt::RightButton) { auto selection = this->GetSelectedNode(); - if (selection.IsNotNull()) + if (selection != nullptr) { - QList selectionList({ this->GetSelectedNode() }); + QList selectionList({ this->GetSelectedNode() }); QmitkNodeDetailsDialog infoDialog(selectionList, this); infoDialog.exec(); return true; } } } } return false; } diff --git a/Plugins/org.mitk.gui.qt.common/src/internal/QmitkNodeSelectionListItemWidget.h b/Plugins/org.mitk.gui.qt.common/src/internal/QmitkNodeSelectionListItemWidget.h index 05c7b22696..46f2acdd10 100644 --- a/Plugins/org.mitk.gui.qt.common/src/internal/QmitkNodeSelectionListItemWidget.h +++ b/Plugins/org.mitk.gui.qt.common/src/internal/QmitkNodeSelectionListItemWidget.h @@ -1,56 +1,56 @@ /*=================================================================== 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 QMITK_NODE_SELECTION_LIST_ITEM_WIDGET_H #define QMITK_NODE_SELECTION_LIST_ITEM_WIDGET_H #include #include #include "ui_QmitkNodeSelectionListItemWidget.h" #include "org_mitk_gui_qt_common_Export.h" class MITK_QT_COMMON QmitkNodeSelectionListItemWidget : public QWidget { Q_OBJECT public: explicit QmitkNodeSelectionListItemWidget(QWidget* parent = nullptr); ~QmitkNodeSelectionListItemWidget(); - mitk::DataNode::Pointer GetSelectedNode() const; + const mitk::DataNode* GetSelectedNode() const; public Q_SLOTS : - virtual void SetSelectedNode(mitk::DataNode* node); + virtual void SetSelectedNode(const mitk::DataNode* node); virtual void SetClearAllowed(bool allowed); signals: - void ClearSelection(mitk::DataNode* node); + void ClearSelection(const mitk::DataNode* node); protected Q_SLOTS: void OnClearSelection(); protected: virtual bool eventFilter(QObject *obj, QEvent *ev) override; Ui_QmitkNodeSelectionListItemWidget m_Controls; }; #endif // QMITK_NODE_SELECTION_LIST_ITEM_WIDGET_H diff --git a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/internal/QmitkDataStorageViewerTestView.cpp b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/internal/QmitkDataStorageViewerTestView.cpp index 3fe521c862..902d116470 100644 --- a/Plugins/org.mitk.gui.qt.datastorageviewertest/src/internal/QmitkDataStorageViewerTestView.cpp +++ b/Plugins/org.mitk.gui.qt.datastorageviewertest/src/internal/QmitkDataStorageViewerTestView.cpp @@ -1,278 +1,278 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical Image Computing. 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. ===================================================================*/ // data storage viewer test plugin #include "QmitkDataStorageViewerTestView.h" #include "mitkNodePredicateDataType.h" // berry #include // qt #include const std::string QmitkDataStorageViewerTestView::VIEW_ID = "org.mitk.views.datastorageviewertest"; void QmitkDataStorageViewerTestView::SetFocus() { // nothing here } void QmitkDataStorageViewerTestView::CreateQtPartControl(QWidget* parent) { // create GUI widgets m_Controls.setupUi(parent); m_DataStorageDefaultListModel = new QmitkDataStorageDefaultListModel(this); m_DataStorageDefaultListModel->SetDataStorage(GetDataStorage()); m_Controls.selectionListView->setSelectionMode(QAbstractItemView::ExtendedSelection); m_Controls.selectionListView->setSelectionBehavior(QAbstractItemView::SelectRows); m_Controls.selectionListView->setAlternatingRowColors(true); m_Controls.selectionListView->setModel(m_DataStorageDefaultListModel); m_DataStorageDefaultListModel2 = new QmitkDataStorageDefaultListModel(this); m_DataStorageDefaultListModel2->SetDataStorage(GetDataStorage()); m_Controls.selectionListView2->setSelectionMode(QAbstractItemView::ExtendedSelection); m_Controls.selectionListView2->setSelectionBehavior(QAbstractItemView::SelectRows); m_Controls.selectionListView2->setAlternatingRowColors(true); m_Controls.selectionListView2->setModel(m_DataStorageDefaultListModel2); m_Controls.singleSlot->SetDataStorage(GetDataStorage()); m_Controls.singleSlot->SetEmptyInfo(QString("EmptyInfo: Set this to display info in empty state")); m_Controls.singleSlot->SetInvalidInfo(QString("InvalidInfo: is displayed for invalid states")); m_Controls.singleSlot->SetPopUpTitel(QString("This is the definable caption. Choose your data now!")); m_Controls.singleSlot->SetPopUpHint(QString("I am an optional hint, that can be set by the developer

If not set the widget is invisible.")); m_Controls.multiSlot->SetDataStorage(GetDataStorage()); m_Controls.multiSlot->SetEmptyInfo(QString("EmptyInfo: Set this to display info in empty state")); m_Controls.multiSlot->SetInvalidInfo(QString("InvalidInfo: is displayed for invalid states")); m_Controls.multiSlot->SetPopUpTitel(QString("This is the definable caption. Choose your data now!")); m_Controls.multiSlot->SetPopUpHint(QString("I am an optional hint, that can be set by the developer

If not set the widget is invisible.")); m_ModelViewSelectionConnector = std::make_unique(); try { m_ModelViewSelectionConnector->SetView(m_Controls.selectionListView); } catch (mitk::Exception& e) { mitkReThrow(e) << "Cannot connect the model-view pair signals and slots."; } m_SelectionServiceConnector = std::make_unique(); m_ModelViewSelectionConnector2 = std::make_unique(); try { m_ModelViewSelectionConnector2->SetView(m_Controls.selectionListView2); } catch (mitk::Exception& e) { mitkReThrow(e) << "Cannot connect the model-view pair signals and slots."; } m_SelectionServiceConnector2 = std::make_unique(); m_SelectionServiceConnector3 = std::make_unique(); m_SelectionServiceConnector4 = std::make_unique(); connect(m_Controls.selectionProviderCheckBox, SIGNAL(toggled(bool)), this, SLOT(SetAsSelectionProvider1(bool))); connect(m_Controls.selectionProviderCheckBox2, SIGNAL(toggled(bool)), this, SLOT(SetAsSelectionProvider2(bool))); connect(m_Controls.selectionListenerCheckBox, SIGNAL(toggled(bool)), this, SLOT(SetAsSelectionListener1(bool))); connect(m_Controls.selectionListenerCheckBox2, SIGNAL(toggled(bool)), this, SLOT(SetAsSelectionListener2(bool))); connect(m_Controls.selectionProviderCheckBox3, SIGNAL(toggled(bool)), this, SLOT(SetAsSelectionProvider3(bool))); connect(m_Controls.selectionListenerCheckBox3, SIGNAL(toggled(bool)), this, SLOT(SetAsSelectionListener3(bool))); connect(m_Controls.checkOnlyVisible, SIGNAL(toggled(bool)), m_Controls.singleSlot, SLOT(SetSelectOnlyVisibleNodes(bool))); connect(m_Controls.checkOptional, SIGNAL(toggled(bool)), m_Controls.singleSlot, SLOT(SetSelectionIsOptional(bool))); connect(m_Controls.checkOnlyImages, SIGNAL(toggled(bool)), this, SLOT(OnOnlyImages(bool))); connect(m_Controls.selectionProviderCheckBox4, SIGNAL(toggled(bool)), this, SLOT(SetAsSelectionProvider4(bool))); connect(m_Controls.selectionListenerCheckBox4, SIGNAL(toggled(bool)), this, SLOT(SetAsSelectionListener4(bool))); connect(m_Controls.checkOnlyVisible_2, SIGNAL(toggled(bool)), m_Controls.multiSlot, SLOT(SetSelectOnlyVisibleNodes(bool))); connect(m_Controls.checkOptional_2, SIGNAL(toggled(bool)), m_Controls.multiSlot, SLOT(SetSelectionIsOptional(bool))); connect(m_Controls.checkOnlyImages_2, SIGNAL(toggled(bool)), this, SLOT(OnOnlyImages2(bool))); connect(m_Controls.checkOnlyUneven, SIGNAL(toggled(bool)), this, SLOT(OnOnlyUneven(bool))); } void QmitkDataStorageViewerTestView::SetAsSelectionProvider1(bool checked) { if (checked) { m_SelectionServiceConnector->SetAsSelectionProvider(GetSite()->GetSelectionProvider().Cast().GetPointer()); connect(m_ModelViewSelectionConnector.get(), SIGNAL(CurrentSelectionChanged(QList)), m_SelectionServiceConnector.get(), SLOT(ChangeServiceSelection(QList))); } else { m_SelectionServiceConnector->RemoveAsSelectionProvider(); disconnect(m_ModelViewSelectionConnector.get(), SIGNAL(CurrentSelectionChanged(QList)), m_SelectionServiceConnector.get(), SLOT(ChangeServiceSelection(QList))); } } void QmitkDataStorageViewerTestView::SetAsSelectionListener1(bool checked) { if (checked) { m_SelectionServiceConnector->AddPostSelectionListener(GetSite()->GetWorkbenchWindow()->GetSelectionService()); connect(m_SelectionServiceConnector.get(), SIGNAL(ServiceSelectionChanged(QList)), m_ModelViewSelectionConnector.get(), SLOT(SetCurrentSelection(QList))); } else { m_SelectionServiceConnector->RemovePostSelectionListener(); disconnect(m_SelectionServiceConnector.get(), SIGNAL(ServiceSelectionChanged(QList)), m_ModelViewSelectionConnector.get(), SLOT(SetCurrentSelection(QList))); } } void QmitkDataStorageViewerTestView::SetAsSelectionProvider2(bool checked) { if (checked) { m_SelectionServiceConnector2->SetAsSelectionProvider(GetSite()->GetSelectionProvider().Cast().GetPointer()); connect(m_ModelViewSelectionConnector2.get(), SIGNAL(CurrentSelectionChanged(QList)), m_SelectionServiceConnector2.get(), SLOT(ChangeServiceSelection(QList))); } else { m_SelectionServiceConnector2->RemoveAsSelectionProvider(); disconnect(m_ModelViewSelectionConnector2.get(), SIGNAL(CurrentSelectionChanged(QList)), m_SelectionServiceConnector2.get(), SLOT(ChangeServiceSelection(QList))); } } void QmitkDataStorageViewerTestView::SetAsSelectionListener2(bool checked) { if (checked) { m_SelectionServiceConnector2->AddPostSelectionListener(GetSite()->GetWorkbenchWindow()->GetSelectionService()); connect(m_SelectionServiceConnector2.get(), SIGNAL(ServiceSelectionChanged(QList)), m_ModelViewSelectionConnector2.get(), SLOT(SetCurrentSelection(QList))); } else { m_SelectionServiceConnector2->RemovePostSelectionListener(); disconnect(m_SelectionServiceConnector2.get(), SIGNAL(ServiceSelectionChanged(QList)), m_ModelViewSelectionConnector2.get(), SLOT(SetCurrentSelection(QList))); } } void QmitkDataStorageViewerTestView::SetAsSelectionProvider3(bool checked) { if (checked) { m_SelectionServiceConnector3->SetAsSelectionProvider(GetSite()->GetSelectionProvider().Cast().GetPointer()); connect(m_Controls.singleSlot, SIGNAL(CurrentSelectionChanged(QList)), m_SelectionServiceConnector3.get(), SLOT(ChangeServiceSelection(QList))); } else { m_SelectionServiceConnector3->RemoveAsSelectionProvider(); disconnect(m_Controls.singleSlot, SIGNAL(CurrentSelectionChanged(QList)), m_SelectionServiceConnector3.get(), SLOT(ChangeServiceSelection(QList))); } } void QmitkDataStorageViewerTestView::SetAsSelectionListener3(bool checked) { if (checked) { m_SelectionServiceConnector3->AddPostSelectionListener(GetSite()->GetWorkbenchWindow()->GetSelectionService()); connect(m_SelectionServiceConnector3.get(), &QmitkSelectionServiceConnector::ServiceSelectionChanged, m_Controls.singleSlot, &QmitkSingleNodeSelectionWidget::SetCurrentSelection); } else { m_SelectionServiceConnector3->RemovePostSelectionListener(); disconnect(m_SelectionServiceConnector3.get(), &QmitkSelectionServiceConnector::ServiceSelectionChanged, m_Controls.singleSlot, &QmitkSingleNodeSelectionWidget::SetCurrentSelection); } } void QmitkDataStorageViewerTestView::SetAsSelectionProvider4(bool checked) { if (checked) { m_SelectionServiceConnector4->SetAsSelectionProvider(GetSite()->GetSelectionProvider().Cast().GetPointer()); connect(m_Controls.multiSlot, SIGNAL(CurrentSelectionChanged(QList)), m_SelectionServiceConnector4.get(), SLOT(ChangeServiceSelection(QList))); } else { m_SelectionServiceConnector4->RemoveAsSelectionProvider(); disconnect(m_Controls.multiSlot, SIGNAL(CurrentSelectionChanged(QList)), m_SelectionServiceConnector4.get(), SLOT(ChangeServiceSelection(QList))); } } void QmitkDataStorageViewerTestView::SetAsSelectionListener4(bool checked) { if (checked) { m_SelectionServiceConnector4->AddPostSelectionListener(GetSite()->GetWorkbenchWindow()->GetSelectionService()); connect(m_SelectionServiceConnector4.get(), &QmitkSelectionServiceConnector::ServiceSelectionChanged, m_Controls.multiSlot, &QmitkMultiNodeSelectionWidget::SetCurrentSelection); } else { m_SelectionServiceConnector4->RemovePostSelectionListener(); disconnect(m_SelectionServiceConnector4.get(), &QmitkSelectionServiceConnector::ServiceSelectionChanged, m_Controls.multiSlot, &QmitkMultiNodeSelectionWidget::SetCurrentSelection); } } void QmitkDataStorageViewerTestView::OnOnlyImages(bool checked) { if (checked) { m_Controls.singleSlot->SetNodePredicate(mitk::NodePredicateDataType::New("Image")); } else { m_Controls.singleSlot->SetNodePredicate(nullptr); } }; void QmitkDataStorageViewerTestView::OnOnlyImages2(bool checked) { if (checked) { m_Controls.multiSlot->SetNodePredicate(mitk::NodePredicateDataType::New("Image")); m_Controls.multiSlot->SetInvalidInfo(QString("InvalidInfo: is displayed for invalid states. Only images allowed!")); } else { m_Controls.multiSlot->SetNodePredicate(nullptr); m_Controls.multiSlot->SetInvalidInfo(QString("InvalidInfo: is displayed for invalid states")); } }; void QmitkDataStorageViewerTestView::OnOnlyUneven(bool checked) { if (checked) { auto checkFunction = [](const QmitkMultiNodeSelectionWidget::NodeList & nodes) { if (!(nodes.size() % 2)) { std::stringstream ss; - ss << "

Invalid selection.

The number of selected nodes must be even! the current number is " << nodes.size() << ".

"; + ss << "

Invalid selection.

The number of selected nodes must be uneven! the current number is " << nodes.size() << ".

"; return ss.str(); } return std::string(); }; m_Controls.multiSlot->SetSelectionCheckFunction(checkFunction); } else { auto checkFunction = [](const QmitkMultiNodeSelectionWidget::NodeList & /*nodes*/) { return std::string(); }; m_Controls.multiSlot->SetSelectionCheckFunction(checkFunction); } };