diff --git a/Modules/SemanticRelationsUI/files.cmake b/Modules/SemanticRelationsUI/files.cmake index fada33de90..e9fc94045d 100644 --- a/Modules/SemanticRelationsUI/files.cmake +++ b/Modules/SemanticRelationsUI/files.cmake @@ -1,29 +1,31 @@ file(GLOB_RECURSE H_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include/*") set(CPP_FILES mitkModuleActivator.cpp QmitkAbstractSemanticRelationsStorageModel.cpp QmitkControlPointDialog.cpp QmitkLesionTextDialog.cpp QmitkLesionTreeItem.cpp QmitkLesionTreeModel.cpp QmitkPatientTableHeaderView.cpp QmitkPatientTableInspector.cpp QmitkPatientTableModel.cpp QmitkSemanticRelationsUIHelper.cpp + QmitkTableItemThumbnailDelegate.cpp ) set(MOC_H_FILES include/QmitkAbstractSemanticRelationsStorageInspector.h include/QmitkAbstractSemanticRelationsStorageModel.h include/QmitkControlPointDialog.h include/QmitkLesionTextDialog.h include/QmitkLesionTreeModel.h include/QmitkPatientTableHeaderView.h include/QmitkPatientTableInspector.h include/QmitkPatientTableModel.h + include/QmitkTableItemThumbnailDelegate.h ) set(UI_FILES src/QmitkPatientTableInspector.ui ) diff --git a/Modules/SemanticRelationsUI/include/QmitkPatientTableInspector.h b/Modules/SemanticRelationsUI/include/QmitkPatientTableInspector.h index 9d9cc16e0c..26d30501f3 100644 --- a/Modules/SemanticRelationsUI/include/QmitkPatientTableInspector.h +++ b/Modules/SemanticRelationsUI/include/QmitkPatientTableInspector.h @@ -1,88 +1,90 @@ /*=================================================================== 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 QMITKPATIENTTABLEINSPECTOR_H #define QMITKPATIENTTABLEINSPECTOR_H // semantic relations UI module #include "MitkSemanticRelationsUIExports.h" #include "QmitkAbstractSemanticRelationsStorageInspector.h" #include "QmitkPatientTableModel.h" +#include "QmitkTableItemThumbnailDelegate.h" #include "ui_QmitkPatientTableInspector.h" // qt widgets module #include // qt #include /* * @brief The QmitkPatientTableInspector is a QmitkAbstractSemanticRelationsStorageInspector that shows the currently * available data of the semantic relations storage model in a control-point - information type matrix. * * The QmitkPatientTableInspector uses the QmitkSemanticRelationsStorageModel, a QmitkAbstractDataStorageModel that * presents the semantic relations data as a table, showing a QPixmap as thumbnail for the data nodes. */ class MITKSEMANTICRELATIONSUI_EXPORT QmitkPatientTableInspector : public QmitkAbstractSemanticRelationsStorageInspector { Q_OBJECT public: QmitkPatientTableInspector(QWidget* parent = nullptr); virtual QAbstractItemView* GetView() override; virtual const QAbstractItemView* GetView() const override; virtual void SetSelectionMode(SelectionMode mode) override; virtual SelectionMode GetSelectionMode() const override; virtual void SetCaseID(const mitk::SemanticTypes::CaseID& caseID) override; virtual void SetLesion(const mitk::SemanticTypes::Lesion& lesion) override; QItemSelectionModel* GetSelectionModel(); Q_SIGNALS: void DataNodeDoubleClicked(const mitk::DataNode*); void OnContextMenuRequested(const QPoint&); void OnNodeRemoved(const mitk::DataNode*); private Q_SLOTS: void OnModelUpdated(); void OnNodeButtonClicked(const QString&); void OnItemDoubleClicked(const QModelIndex&); protected: virtual void Initialize() override; private: void SetUpConnections(); virtual void keyPressEvent(QKeyEvent* e) override; Ui::QmitkPatientTableInspector m_Controls; QmitkPatientTableModel* m_StorageModel; + QmitkTableItemThumbnailDelegate* m_ItemDelegate; mitk::DataNode* m_SelectedDataNode; }; #endif // QMITKPATIENTTABLEINSPECTOR_H diff --git a/Modules/SemanticRelationsUI/include/QmitkTableItemThumbnailDelegate.h b/Modules/SemanticRelationsUI/include/QmitkTableItemThumbnailDelegate.h new file mode 100644 index 0000000000..c65150847f --- /dev/null +++ b/Modules/SemanticRelationsUI/include/QmitkTableItemThumbnailDelegate.h @@ -0,0 +1,36 @@ +/*=================================================================== + +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 QMITKTABLEITEMTHUMBNAILDELEGATE_H +#define QMITKTABLEITEMTHUMBNAILDELEGATE_H + +#include + +/* +* @brief The QmitkTableItemThumbnailDelegate is a subclass of the QmitkAbstractSemanticRelationsStorageModel +*/ +class QmitkTableItemThumbnailDelegate : public QStyledItemDelegate +{ + Q_OBJECT + +public: + + QmitkTableItemThumbnailDelegate(QObject* parent = nullptr); + + void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override; +}; + +#endif // QMITKTABLEITEMTHUMBNAILDELEGATE_H diff --git a/Modules/SemanticRelationsUI/src/QmitkLesionTreeModel.cpp b/Modules/SemanticRelationsUI/src/QmitkLesionTreeModel.cpp index 19005030f1..9f0a204586 100644 --- a/Modules/SemanticRelationsUI/src/QmitkLesionTreeModel.cpp +++ b/Modules/SemanticRelationsUI/src/QmitkLesionTreeModel.cpp @@ -1,258 +1,270 @@ /*=================================================================== 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. ===================================================================*/ // semantic relations UI module #include "QmitkLesionTreeModel.h" // semantic relations module #include #include #include QmitkLesionTreeModel::QmitkLesionTreeModel(QObject* parent/* = nullptr*/) : QmitkAbstractSemanticRelationsStorageModel(parent) , m_RootItem(std::make_shared(mitk::LesionData())) { // nothing here } QmitkLesionTreeModel::~QmitkLesionTreeModel() { // nothing here } ////////////////////////////////////////////////////////////////////////// // overridden virtual functions from QAbstractItemModel ////////////////////////////////////////////////////////////////////////// QModelIndex QmitkLesionTreeModel::index(int row, int column, const QModelIndex& itemIndex) const { if (!hasIndex(row, column, itemIndex)) { return QModelIndex(); } auto childItem = GetItemByIndex(itemIndex)->GetChildInRow(row); if (nullptr == childItem) { return QModelIndex(); } return createIndex(row, column, childItem.get()); } QModelIndex QmitkLesionTreeModel::parent(const QModelIndex& itemIndex) const { if (!itemIndex.isValid()) { return QModelIndex(); } auto parentItem = GetItemByIndex(itemIndex)->GetParent(); if (parentItem.expired()) { return QModelIndex(); } auto sharedParent = parentItem.lock(); if (sharedParent == m_RootItem) { return QModelIndex(); } return createIndex(sharedParent->GetRow(), 0, sharedParent.get()); } int QmitkLesionTreeModel::rowCount(const QModelIndex& itemIndex/* = QModelIndex()*/) const { return GetItemByIndex(itemIndex)->ChildCount(); } int QmitkLesionTreeModel::columnCount(const QModelIndex&/* itemIndex = QModelIndex() */) const { + if (0 == m_RootItem->ChildCount()) + { + // no lesion items stored, no need to display columns + return 0; + } + return m_ControlPoints.size() + 1; } QVariant QmitkLesionTreeModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) { return QVariant(); } if (index.column() < 0 || index.column() > static_cast(m_ControlPoints.size())) { return QVariant(); } QmitkLesionTreeItem* currentItem = GetItemByIndex(index); if (Qt::DisplayRole == role) { if (currentItem->GetParent().expired()) { return QVariant(); } auto parentItem = currentItem->GetParent().lock(); // parent exists and is the root item -> 1. item of a lesion entry if (m_RootItem == parentItem) { // display role fills the first columns with the lesion UID / name if (0 == index.column()) { std::string itemString = currentItem->GetData().GetLesionName(); if (itemString.empty()) { itemString = currentItem->GetData().GetLesionUID(); } return QString::fromStdString(itemString); } else { // display role fills other columns with the lesion presence info const auto lesionPresence = currentItem->GetData().GetLesionPresence(); if (index.column() - 1 > static_cast(lesionPresence.size())) { return ""; } return QVariant(lesionPresence.at(index.column() - 1)); } } // parent is not the root item -> 2. item of a lesion entry else { // display role fills the first columns with the property name "Volume" if (0 == index.column()) { return "Volume"; } else { // display role fills other columns with the lesion volume info const auto lesionVolume= currentItem->GetData().GetLesionVolume(); if (index.column() - 1 > static_cast(lesionVolume.size())) { return ""; } return QVariant(lesionVolume.at(index.column() - 1)); } } } if (Qt::UserRole == role) { return QVariant::fromValue(currentItem); } return QVariant(); } QVariant QmitkLesionTreeModel::headerData(int section, Qt::Orientation orientation, int role) const { + if (0 == m_RootItem->ChildCount()) + { + // no lesion items stored, no need to display the header + return QVariant(); + } + if (Qt::Horizontal == orientation && Qt::DisplayRole == role) { if (0 == section) { return QVariant("Lesion"); } if (m_ControlPoints.size() >= section) { mitk::SemanticTypes::ControlPoint currentControlPoint = m_ControlPoints.at(section-1); // generate a string from the control point std::string currentControlPointAsString = mitk::GetControlPointAsString(currentControlPoint); return QVariant(QString::fromStdString(currentControlPointAsString)); } } return QVariant(); } void QmitkLesionTreeModel::NodePredicateChanged() { // does not react to node predicate changes } void QmitkLesionTreeModel::NodeAdded(const mitk::DataNode* node) { // does not react to data storage changes } void QmitkLesionTreeModel::NodeChanged(const mitk::DataNode* node) { // does not react to data storage changes } void QmitkLesionTreeModel::NodeRemoved(const mitk::DataNode* node) { // does not react to data storage changes } void QmitkLesionTreeModel::SetData() { m_RootItem = std::make_shared(mitk::LesionData()); // get all control points of current case m_ControlPoints = m_SemanticRelations->GetAllControlPointsOfCase(m_CaseID); // sort the vector of control points for the timeline std::sort(m_ControlPoints.begin(), m_ControlPoints.end()); SetLesionData(); } void QmitkLesionTreeModel::SetLesionData() { std::vector allLesions = m_SemanticRelations->GetAllLesionsOfCase(m_CaseID); for (auto& lesion : allLesions) { AddLesion(lesion); } } void QmitkLesionTreeModel::AddLesion(const mitk::SemanticTypes::Lesion& lesion) { if (nullptr == m_SemanticRelations) { return; } // create new lesion tree item data and modify it according to the control point data mitk::LesionData lesionData(lesion); mitk::GenerateAdditionalLesionData(lesionData, m_CaseID, m_SemanticRelations); // add the 1. level lesion item to the root item std::shared_ptr newLesionTreeItem = std::make_shared(lesionData); m_RootItem->AddChild(newLesionTreeItem); // add the 2. level lesion item to the 1. level lesion item std::shared_ptr newChildItem = std::make_shared(lesionData); newLesionTreeItem->AddChild(newChildItem); } QmitkLesionTreeItem* QmitkLesionTreeModel::GetItemByIndex(const QModelIndex& index) const { if (index.isValid()) { auto item = static_cast(index.internalPointer()); if (nullptr != item) { return item; } } return m_RootItem.get(); } diff --git a/Modules/SemanticRelationsUI/src/QmitkPatientTableHeaderView.cpp b/Modules/SemanticRelationsUI/src/QmitkPatientTableHeaderView.cpp index 4f7bcb766e..e35970cd00 100644 --- a/Modules/SemanticRelationsUI/src/QmitkPatientTableHeaderView.cpp +++ b/Modules/SemanticRelationsUI/src/QmitkPatientTableHeaderView.cpp @@ -1,237 +1,244 @@ /*=================================================================== 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. ===================================================================*/ // semantic relations UI module #include "QmitkPatientTableHeaderView.h" // qt #include #include QmitkPatientTableHeaderView::QmitkPatientTableHeaderView(QWidget* parent/* = nullptr*/) : QHeaderView(Qt::Horizontal, parent) , m_HeaderModel(nullptr) { // nothing here } QmitkPatientTableHeaderView::~QmitkPatientTableHeaderView() { // nothing here } void QmitkPatientTableHeaderView::setModel(QAbstractItemModel* model) { // retrieve the header model from the given table model QVariant variant = model->data(QModelIndex(), HorizontalHeaderDataRole); if (variant.isValid() && variant.canConvert()) { m_HeaderModel = variant.value(); } QHeaderView::setModel(model); } void QmitkPatientTableHeaderView::paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const { if (rect.isValid()) { int top = rect.y(); QModelIndex leafIndex = HeaderIndex(logicalIndex); QModelIndexList indexes = ParentIndexList(leafIndex); for (const auto& index : indexes) { top = PaintHeader(painter, index, logicalIndex, rect, top); } return; } QHeaderView::paintSection(painter, rect, logicalIndex); } QSize QmitkPatientTableHeaderView::sectionSizeFromContents(int logicalIndex) const { if (nullptr != m_HeaderModel) { - QModelIndex leafIndex = HeaderIndex(logicalIndex); - if (leafIndex.isValid()) + QModelIndex headerIndex = HeaderIndex(logicalIndex); + if (headerIndex.isValid()) { - QSize headerSize = HeaderSize(leafIndex); - leafIndex = leafIndex.parent(); - while (leafIndex.isValid()) + QSize headerSize = HeaderSize(headerIndex); + headerIndex = headerIndex.parent(); + while (headerIndex.isValid()) { - headerSize.rheight() += HeaderSize(leafIndex).height(); - leafIndex = leafIndex.parent(); + QSize currentHeaderSize = HeaderSize(headerIndex); + headerSize.rheight() += currentHeaderSize.height(); + if (currentHeaderSize.width() > headerSize.width()) + { + headerSize.rwidth() = currentHeaderSize.width(); + } + + headerIndex = headerIndex.parent(); } return headerSize; } } return QHeaderView::sectionSizeFromContents(logicalIndex); } int QmitkPatientTableHeaderView::PaintHeader(QPainter* painter, const QModelIndex& currentIndex, int logicalIndex, const QRect& sectionRect, int top) const { QModelIndex headerIndex = HeaderIndex(logicalIndex); int height = HeaderSize(currentIndex).height(); if (currentIndex == headerIndex) { height = sectionRect.height() - top; } int left = CurrentHeaderLeft(currentIndex, headerIndex, logicalIndex, sectionRect.left()); int width = CurrentHeaderWidth(currentIndex, headerIndex, logicalIndex); QStyleOptionHeader headerStyleOptions; initStyleOption(&headerStyleOptions); headerStyleOptions.text = currentIndex.data(Qt::DisplayRole).toString(); headerStyleOptions.textAlignment = Qt::AlignCenter; painter->save(); QRect rect(left, top, width, height); headerStyleOptions.rect = rect; style()->drawControl(QStyle::CE_Header, &headerStyleOptions, painter, this); painter->restore(); return top + height; } QSize QmitkPatientTableHeaderView::HeaderSize(const QModelIndex& index) const { QFont font = this->font(); + font.setBold(true); QFontMetrics fontMetrics(font); QSize fontSize = fontMetrics.size(0, index.data(Qt::DisplayRole).toString()); QSize emptyFontSize = fontMetrics.size(0, ""); return fontSize + emptyFontSize; } int QmitkPatientTableHeaderView::CurrentHeaderLeft(const QModelIndex& currentIndex, const QModelIndex& headerIndex, int sectionIndex, int left) const { QModelIndexList headerList = ListHeader(currentIndex); if (!headerList.empty()) { int index = headerList.indexOf(headerIndex); int firstHeaderSectionIndex = sectionIndex - index; --index; for (; index >= 0; --index) { left -= sectionSize(firstHeaderSectionIndex + index); } } return left; } int QmitkPatientTableHeaderView::CurrentHeaderWidth(const QModelIndex& currentIndex, const QModelIndex& headerIndex, int sectionIndex) const { QModelIndexList headerList = ListHeader(currentIndex); if (headerList.empty()) { return sectionSize(sectionIndex); } int width = 0; int index = headerList.indexOf(headerIndex); int firstHeaderSectionIndex = sectionIndex - index; for (int i = 0; i < headerList.size(); ++i) { width += sectionSize(firstHeaderSectionIndex + i); } return width; } QModelIndexList QmitkPatientTableHeaderView::ParentIndexList(QModelIndex index) const { QModelIndexList indexList; while (index.isValid()) { indexList.push_front(index); index = index.parent(); } return indexList; } QModelIndex QmitkPatientTableHeaderView::HeaderIndex(int sectionIndex) const { if (nullptr != m_HeaderModel) { int currentHeaderIndex = -1; for (int i = 0; i < m_HeaderModel->columnCount(); ++i) { QModelIndex modelIndex = FindHeader(m_HeaderModel->index(0, i), sectionIndex, currentHeaderIndex); if (modelIndex.isValid()) { return modelIndex; } } } return QModelIndex(); } QModelIndex QmitkPatientTableHeaderView::FindHeader(const QModelIndex& currentIndex, int sectionIndex, int& currentHeaderIndex) const { if (currentIndex.isValid()) { int childCount = currentIndex.model()->columnCount(currentIndex); if (childCount > 0) { for (int i = 0; i < childCount; ++i) { QModelIndex modelIndex = FindHeader(currentIndex.child(0, i), sectionIndex, currentHeaderIndex); if (modelIndex.isValid()) { return modelIndex; } } } else { ++currentHeaderIndex; if (currentHeaderIndex == sectionIndex) { return currentIndex; } } } return QModelIndex(); } QModelIndexList QmitkPatientTableHeaderView::ListHeader(const QModelIndex& currentIndex) const { QModelIndexList headerList; if (currentIndex.isValid()) { int childCount = currentIndex.model()->columnCount(currentIndex); if (childCount > 0) { for (int i = 0; i < childCount; ++i) { headerList += ListHeader(currentIndex.child(0, i)); } } else { headerList.push_back(currentIndex); } } return headerList; } diff --git a/Modules/SemanticRelationsUI/src/QmitkPatientTableInspector.cpp b/Modules/SemanticRelationsUI/src/QmitkPatientTableInspector.cpp index 5d01d78a9a..041999b5f3 100644 --- a/Modules/SemanticRelationsUI/src/QmitkPatientTableInspector.cpp +++ b/Modules/SemanticRelationsUI/src/QmitkPatientTableInspector.cpp @@ -1,166 +1,168 @@ /*=================================================================== 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. ===================================================================*/ // semantic relations UI module #include "QmitkPatientTableInspector.h" #include "QmitkPatientTableHeaderView.h" // mitk qt widgets module #include "QmitkCustomVariants.h" #include "QmitkEnums.h" // qt #include #include QmitkPatientTableInspector::QmitkPatientTableInspector(QWidget* parent/* =nullptr*/) { m_Controls.setupUi(this); QmitkPatientTableHeaderView* patientTableHeaderView = new QmitkPatientTableHeaderView(m_Controls.tableView); m_Controls.tableView->setHorizontalHeader(patientTableHeaderView); m_Controls.tableView->horizontalHeader()->setHighlightSections(false); m_Controls.tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); m_Controls.tableView->verticalHeader()->setHighlightSections(false); m_Controls.tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed); m_Controls.tableView->setSelectionMode(QAbstractItemView::SingleSelection); m_Controls.tableView->setSelectionBehavior(QAbstractItemView::SelectItems); m_Controls.tableView->setContextMenuPolicy(Qt::CustomContextMenu); - m_StorageModel = new QmitkPatientTableModel(this); + m_StorageModel = new QmitkPatientTableModel(m_Controls.tableView); m_Controls.tableView->setModel(m_StorageModel); + m_ItemDelegate = new QmitkTableItemThumbnailDelegate(m_Controls.tableView); + //m_Controls.tableView->setItemDelegate(m_ItemDelegate); SetUpConnections(); } QAbstractItemView* QmitkPatientTableInspector::GetView() { return m_Controls.tableView; } const QAbstractItemView* QmitkPatientTableInspector::GetView() const { return m_Controls.tableView; } void QmitkPatientTableInspector::SetSelectionMode(SelectionMode mode) { m_Controls.tableView->setSelectionMode(mode); } QmitkPatientTableInspector::SelectionMode QmitkPatientTableInspector::GetSelectionMode() const { return m_Controls.tableView->selectionMode(); } void QmitkPatientTableInspector::SetCaseID(const mitk::SemanticTypes::CaseID& caseID) { m_StorageModel->SetCaseID(caseID); } void QmitkPatientTableInspector::SetLesion(const mitk::SemanticTypes::Lesion& lesion) { m_StorageModel->SetLesion(lesion); } QItemSelectionModel* QmitkPatientTableInspector::GetSelectionModel() { return m_Controls.tableView->selectionModel(); } void QmitkPatientTableInspector::Initialize() { if (m_DataStorage.IsExpired()) { return; } auto dataStorage = m_DataStorage.Lock(); m_StorageModel->SetDataStorage(dataStorage); m_StorageModel->SetNodePredicate(m_NodePredicate); m_Connector->SetView(m_Controls.tableView); } void QmitkPatientTableInspector::OnModelUpdated() { m_Controls.tableView->resizeRowsToContents(); m_Controls.tableView->resizeColumnsToContents(); } void QmitkPatientTableInspector::OnNodeButtonClicked(const QString& nodeType) { m_StorageModel->SetNodeType(nodeType.toStdString()); } void QmitkPatientTableInspector::OnItemDoubleClicked(const QModelIndex& itemIndex) { if (itemIndex.isValid()) { QVariant qvariantDataNode = m_StorageModel->data(itemIndex, QmitkDataNodeRawPointerRole); if (qvariantDataNode.canConvert()) { mitk::DataNode* dataNode = qvariantDataNode.value(); emit DataNodeDoubleClicked(dataNode); } } } void QmitkPatientTableInspector::SetUpConnections() { connect(m_StorageModel, &QmitkPatientTableModel::ModelUpdated, this, &QmitkPatientTableInspector::OnModelUpdated); connect(m_Controls.tableView, &QTableView::customContextMenuRequested, this, &QmitkPatientTableInspector::OnContextMenuRequested); QSignalMapper* nodeButtonSignalMapper = new QSignalMapper(this); nodeButtonSignalMapper->setMapping(m_Controls.imageNodeButton, QString("Image")); nodeButtonSignalMapper->setMapping(m_Controls.segmentationNodeButton, QString("Segmentation")); connect(nodeButtonSignalMapper, static_cast(&QSignalMapper::mapped), this, &QmitkPatientTableInspector::OnNodeButtonClicked); connect(m_Controls.imageNodeButton, SIGNAL(clicked()), nodeButtonSignalMapper, SLOT(map())); connect(m_Controls.segmentationNodeButton, SIGNAL(clicked()), nodeButtonSignalMapper, SLOT(map())); m_Controls.imageNodeButton->setChecked(true); connect(m_Controls.tableView, &QTableView::doubleClicked, this, &QmitkPatientTableInspector::OnItemDoubleClicked); } void QmitkPatientTableInspector::keyPressEvent(QKeyEvent* e) { mitk::DataNode* dataNode = nullptr; QModelIndex selectedIndex = m_Controls.tableView->currentIndex(); if (selectedIndex.isValid()) { QVariant qvariantDataNode = m_StorageModel->data(selectedIndex, QmitkDataNodeRawPointerRole); if (qvariantDataNode.canConvert()) { dataNode = qvariantDataNode.value(); } } if (nullptr == dataNode) { return; } int key = e->key(); switch (key) { case Qt::Key_Delete: emit OnNodeRemoved(dataNode); break; default: break; } } diff --git a/Modules/SemanticRelationsUI/src/QmitkTableItemThumbnailDelegate.cpp b/Modules/SemanticRelationsUI/src/QmitkTableItemThumbnailDelegate.cpp new file mode 100644 index 0000000000..f0ea252f5c --- /dev/null +++ b/Modules/SemanticRelationsUI/src/QmitkTableItemThumbnailDelegate.cpp @@ -0,0 +1,47 @@ +/*=================================================================== + +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. + +===================================================================*/ + +// semantic relations UI module +#include "QmitkTableItemThumbnailDelegate.h" + +// qt +#include +#include +#include + +QmitkTableItemThumbnailDelegate::QmitkTableItemThumbnailDelegate(QObject* parent /*= nullptr*/) + : QStyledItemDelegate(parent) +{ + // nothing here +} + +void QmitkTableItemThumbnailDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + QPixmap pixmap = index.data(Qt::DecorationRole).value(); + QRect rect = option.rect; + QPoint point = option.rect.center() - pixmap.rect().center(); + painter->save(); + + if (option.state & QStyle::State_Selected) + { + painter->setBrush(option.palette.highlightedText()); + const QWidget* widget = option.widget; + QStyle* style = widget ? widget->style() : QApplication::style(); + style->drawControl(QStyle::CE_ItemViewItem, &option, painter, widget); + } + painter->drawPixmap(point, pixmap); + painter->restore(); +}