From 612f7d34a0ebe13424f3b9d84f2d101ef913abd5 Mon Sep 17 00:00:00 2001 From: Mohammad Rashid Date: Wed, 26 Jun 2019 15:50:05 -0400 Subject: [PATCH] ENH: Creating and registering VR data module widget Creates and registers the VR data module widget (which can be switched to from the VR home widget) KitwareMedical#43 --- VirtualReality/Widgets/CMakeLists.txt | 6 + .../UI/qMRMLVirtualRealityDataModuleWidget.ui | 69 +++++++++++ .../qMRMLVirtualRealityDataModuleWidget.cxx | 112 ++++++++++++++++++ .../qMRMLVirtualRealityDataModuleWidget.h | 76 ++++++++++++ .../Widgets/qMRMLVirtualRealityHomeWidget.cxx | 21 +++- .../Widgets/qMRMLVirtualRealityHomeWidget.h | 3 +- .../Widgets/qMRMLVirtualRealityView.cxx | 4 +- .../Widgets/qMRMLVirtualRealityView_p.h | 2 + 8 files changed, 287 insertions(+), 6 deletions(-) create mode 100644 VirtualReality/Widgets/Resources/UI/qMRMLVirtualRealityDataModuleWidget.ui create mode 100644 VirtualReality/Widgets/qMRMLVirtualRealityDataModuleWidget.cxx create mode 100644 VirtualReality/Widgets/qMRMLVirtualRealityDataModuleWidget.h diff --git a/VirtualReality/Widgets/CMakeLists.txt b/VirtualReality/Widgets/CMakeLists.txt index 07f089c..f3b8e59 100644 --- a/VirtualReality/Widgets/CMakeLists.txt +++ b/VirtualReality/Widgets/CMakeLists.txt @@ -11,6 +11,7 @@ set(${KIT}_EXPORT_DIRECTIVE "Q_SLICER_QTMODULES_${MODULE_NAME_UPPER}_WIDGETS_EXP set(${KIT}_INCLUDE_DIRECTORIES ${vtkSlicerVirtualRealityModuleMRML_INCLUDE_DIRS} ${VTK_INCLUDE_DIRS} + ${qSlicerSubjectHierarchyModuleWidgets_INCLUDE_DIRS} ) set(${KIT}_SRCS @@ -19,16 +20,20 @@ set(${KIT}_SRCS qMRMLVirtualRealityView.h qMRMLVirtualRealityHomeWidget.cxx qMRMLVirtualRealityHomeWidget.h + qMRMLVirtualRealityDataModuleWidget.cxx + qMRMLVirtualRealityDataModuleWidget.h ) set(${KIT}_MOC_SRCS qMRMLVirtualRealityView.h qMRMLVirtualRealityView_p.h qMRMLVirtualRealityHomeWidget.h + qMRMLVirtualRealityDataModuleWidget.h ) set(${KIT}_UI_SRCS Resources/UI/qMRMLVirtualRealityHomeWidget.ui + Resources/UI/qMRMLVirtualRealityDataModuleWidget.ui ) set(${KIT}_RESOURCES @@ -39,6 +44,7 @@ set(${KIT}_TARGET_LIBRARIES vtkSlicer${MODULE_NAME}ModuleMRML vtkSlicerCamerasModuleLogic ${VTK_LIBRARIES} + qSlicerSubjectHierarchyModuleWidgets ) #----------------------------------------------------------------------------- diff --git a/VirtualReality/Widgets/Resources/UI/qMRMLVirtualRealityDataModuleWidget.ui b/VirtualReality/Widgets/Resources/UI/qMRMLVirtualRealityDataModuleWidget.ui new file mode 100644 index 0000000..ba92916 --- /dev/null +++ b/VirtualReality/Widgets/Resources/UI/qMRMLVirtualRealityDataModuleWidget.ui @@ -0,0 +1,69 @@ + + + qMRMLVirtualRealityDataModuleWidget + + + + 0 + 0 + 530 + 263 + + + + VR Data + + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + + + + + qMRMLWidget + QWidget +
qMRMLWidget.h
+ 1 +
+ + qMRMLSubjectHierarchyTreeView + QTreeView +
qMRMLSubjectHierarchyTreeView.h
+
+
+ + + + qMRMLVirtualRealityDataModuleWidget + mrmlSceneChanged(vtkMRMLScene*) + SubjectHierarchyTreeView + setMRMLScene(vtkMRMLScene*) + + + 119 + 1 + + + 152 + 37 + + + + +
diff --git a/VirtualReality/Widgets/qMRMLVirtualRealityDataModuleWidget.cxx b/VirtualReality/Widgets/qMRMLVirtualRealityDataModuleWidget.cxx new file mode 100644 index 0000000..5addeb9 --- /dev/null +++ b/VirtualReality/Widgets/qMRMLVirtualRealityDataModuleWidget.cxx @@ -0,0 +1,112 @@ +/*============================================================================== + + Copyright (c) Laboratory for Percutaneous Surgery (PerkLab) + Queen's University, Kingston, ON, Canada. All Rights Reserved. + + See COPYRIGHT.txt + or http://www.slicer.org/copyright/copyright.txt for details. + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + This file was originally developed by Csaba Pinter, PerkLab, Queen's University + and was supported through the Applied Cancer Research Unit program of Cancer Care + Ontario with funds provided by the Ontario Ministry of Health and Long-Term Care + and CANARIE. + +==============================================================================*/ + +// VirtualReality Widgets includes +#include "qMRMLVirtualRealityDataModuleWidget.h" +#include "ui_qMRMLVirtualRealityDataModuleWidget.h" + +// VirtualReality MRML includes +#include "vtkMRMLVirtualRealityViewNode.h" + +// Qt includes +#include + +//----------------------------------------------------------------------------- +class qMRMLVirtualRealityDataModuleWidgetPrivate : public Ui_qMRMLVirtualRealityDataModuleWidget +{ + Q_DECLARE_PUBLIC(qMRMLVirtualRealityDataModuleWidget); + +protected: + qMRMLVirtualRealityDataModuleWidget* const q_ptr; + +public: + qMRMLVirtualRealityDataModuleWidgetPrivate(qMRMLVirtualRealityDataModuleWidget& object); + virtual ~qMRMLVirtualRealityDataModuleWidgetPrivate(); + + void init(); + +public: + /// Virtual reality view MRML node + vtkWeakPointer VirtualRealityViewNode; +}; + +//----------------------------------------------------------------------------- +qMRMLVirtualRealityDataModuleWidgetPrivate::qMRMLVirtualRealityDataModuleWidgetPrivate(qMRMLVirtualRealityDataModuleWidget& object) + : q_ptr(&object) +{ +} + +//----------------------------------------------------------------------------- +qMRMLVirtualRealityDataModuleWidgetPrivate::~qMRMLVirtualRealityDataModuleWidgetPrivate() +{ +} + +//----------------------------------------------------------------------------- +void qMRMLVirtualRealityDataModuleWidgetPrivate::init() +{ + Q_Q(qMRMLVirtualRealityDataModuleWidget); + this->setupUi(q); +} + +//----------------------------------------------------------------------------- +// qMRMLVirtualRealityDataModuleWidget methods + +//----------------------------------------------------------------------------- +qMRMLVirtualRealityDataModuleWidget::qMRMLVirtualRealityDataModuleWidget(QWidget* _parent) + : qMRMLWidget(_parent) + , d_ptr(new qMRMLVirtualRealityDataModuleWidgetPrivate(*this)) +{ + Q_D(qMRMLVirtualRealityDataModuleWidget); + d->init(); + + this->updateWidgetFromMRML(); +} + +//----------------------------------------------------------------------------- +qMRMLVirtualRealityDataModuleWidget::~qMRMLVirtualRealityDataModuleWidget() += default; + +//----------------------------------------------------------------------------- +vtkMRMLVirtualRealityViewNode* qMRMLVirtualRealityDataModuleWidget::virtualRealityViewNode() const +{ + Q_D(const qMRMLVirtualRealityDataModuleWidget); + return d->VirtualRealityViewNode; +} + +//----------------------------------------------------------------------------- +QString qMRMLVirtualRealityDataModuleWidget::virtualRealityViewNodeID()const +{ + Q_D(const qMRMLVirtualRealityDataModuleWidget); + return (d->VirtualRealityViewNode.GetPointer() ? d->VirtualRealityViewNode->GetID() : QString()); +} + +//----------------------------------------------------------------------------- +void qMRMLVirtualRealityDataModuleWidget::updateWidgetFromMRML() +{ + //Q_D(qMRMLVirtualRealityDataModuleWidget); +} + +//----------------------------------------------------------------------------- +qMRMLSubjectHierarchyTreeView* qMRMLVirtualRealityDataModuleWidget::treeView() +{ + Q_D(qMRMLVirtualRealityDataModuleWidget); + return d->SubjectHierarchyTreeView; +} diff --git a/VirtualReality/Widgets/qMRMLVirtualRealityDataModuleWidget.h b/VirtualReality/Widgets/qMRMLVirtualRealityDataModuleWidget.h new file mode 100644 index 0000000..d01ba7e --- /dev/null +++ b/VirtualReality/Widgets/qMRMLVirtualRealityDataModuleWidget.h @@ -0,0 +1,76 @@ +/*============================================================================== + + Copyright (c) Laboratory for Percutaneous Surgery (PerkLab) + Queen's University, Kingston, ON, Canada. All Rights Reserved. + + See COPYRIGHT.txt + or http://www.slicer.org/copyright/copyright.txt for details. + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + This file was originally developed by Csaba Pinter, PerkLab, Queen's University + and was supported through the Applied Cancer Research Unit program of Cancer Care + Ontario with funds provided by the Ontario Ministry of Health and Long-Term Care + and CANARIE. + +==============================================================================*/ + +#ifndef __qMRMLVirtualRealityDataModuleWidget_h +#define __qMRMLVirtualRealityDataModuleWidget_h + +// VirtualReality Widgets includes +#include "qSlicerVirtualRealityModuleWidgetsExport.h" + +// MRMLWidgets includes +#include "qMRMLWidget.h" + +// CTK includes +#include +#include + +// MRML includes +#include "qMRMLSubjectHierarchyTreeView.h" +#include "qMRMLSubjectHierarchyModel.h" + +class vtkMRMLVirtualRealityViewNode; +class qMRMLVirtualRealityDataModuleWidgetPrivate; + +/// \ingroup SlicerVirtualReality_Widgets +class Q_SLICER_QTMODULES_VIRTUALREALITY_WIDGETS_EXPORT qMRMLVirtualRealityDataModuleWidget : public qMRMLWidget +{ + Q_OBJECT + QVTK_OBJECT + +public: + typedef qMRMLWidget Superclass; + /// Constructor + explicit qMRMLVirtualRealityDataModuleWidget(QWidget* parent = nullptr); + /// Destructor + ~qMRMLVirtualRealityDataModuleWidget() override; + + /// Get virtual reality view MRML node + Q_INVOKABLE vtkMRMLVirtualRealityViewNode* virtualRealityViewNode()const; + Q_INVOKABLE QString virtualRealityViewNodeID()const; + + /// Get subject hierarchy tree view + Q_INVOKABLE qMRMLSubjectHierarchyTreeView* treeView(); + +public slots: + +protected slots: + /// Update widgets from the MRML node + void updateWidgetFromMRML(); + +protected: + QScopedPointer d_ptr; + +private: + Q_DECLARE_PRIVATE(qMRMLVirtualRealityDataModuleWidget); + Q_DISABLE_COPY(qMRMLVirtualRealityDataModuleWidget); +}; + +#endif diff --git a/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.cxx b/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.cxx index bd35834..d623a5d 100644 --- a/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.cxx +++ b/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.cxx @@ -21,11 +21,11 @@ // VirtualReality Widgets includes #include "qMRMLVirtualRealityHomeWidget.h" - #include "ui_qMRMLVirtualRealityHomeWidget.h" // VirtualReality MRML includes #include "vtkMRMLVirtualRealityViewNode.h" +#include "qMRMLVirtualRealityDataModuleWidget.h" // VTK includes #include @@ -53,6 +53,7 @@ class qMRMLVirtualRealityHomeWidgetPrivate : public Ui_qMRMLVirtualRealityHomeWi public: /// Virtual reality view MRML node vtkWeakPointer VirtualRealityViewNode; + qMRMLVirtualRealityDataModuleWidget* DataModuleWidget; }; //----------------------------------------------------------------------------- @@ -60,6 +61,7 @@ qMRMLVirtualRealityHomeWidgetPrivate::qMRMLVirtualRealityHomeWidgetPrivate(qMRML : q_ptr(&object) { this->VirtualRealityViewNode = nullptr; + this->DataModuleWidget = new qMRMLVirtualRealityDataModuleWidget; } //----------------------------------------------------------------------------- @@ -92,6 +94,7 @@ void qMRMLVirtualRealityHomeWidgetPrivate::init() // qMRMLVirtualRealityHomeWidget methods //----------------------------------------------------------------------------- + qMRMLVirtualRealityHomeWidget::qMRMLVirtualRealityHomeWidget(QWidget* _parent) : qMRMLWidget(_parent) , d_ptr(new qMRMLVirtualRealityHomeWidgetPrivate(*this)) @@ -112,6 +115,13 @@ vtkMRMLVirtualRealityViewNode* qMRMLVirtualRealityHomeWidget::virtualRealityView return d->VirtualRealityViewNode; } +//----------------------------------------------------------------------------- +QString qMRMLVirtualRealityHomeWidget::virtualRealityViewNodeID()const +{ + Q_D(const qMRMLVirtualRealityHomeWidget); + return (d->VirtualRealityViewNode.GetPointer() ? d->VirtualRealityViewNode->GetID() : QString()); +} + //----------------------------------------------------------------------------- void qMRMLVirtualRealityHomeWidget::addModuleButton(QWidget* moduleWidget, QIcon& icon) { @@ -174,10 +184,13 @@ void qMRMLVirtualRealityHomeWidget::onBackButtonPressed() } //----------------------------------------------------------------------------- -QString qMRMLVirtualRealityHomeWidget::virtualRealityViewNodeID()const +void qMRMLVirtualRealityHomeWidget::registerDataModule() { - Q_D(const qMRMLVirtualRealityHomeWidget); - return (d->VirtualRealityViewNode.GetPointer() ? d->VirtualRealityViewNode->GetID() : QString()); + Q_D(qMRMLVirtualRealityHomeWidget); + QIcon dataIcon(QPixmap(":/Icons/SubjectHierarchy.png")); + addModuleButton(d->DataModuleWidget, dataIcon); + d->DataModuleWidget->setMRMLScene(this->mrmlScene()); + d->DataModuleWidget->treeView()->setColumnHidden(d->DataModuleWidget->treeView()->model()->idColumn(),true); } //----------------------------------------------------------------------------- diff --git a/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.h b/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.h index 470699f..a1387e2 100644 --- a/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.h +++ b/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.h @@ -73,7 +73,8 @@ public slots: void addModuleButton(QWidget* moduleWidget, QIcon& icon); void onModuleButtonPressed(); void onBackButtonPressed(); - + void registerDataModule(); + protected slots: /// Update widgets from the MRML node void updateWidgetFromMRML(); diff --git a/VirtualReality/Widgets/qMRMLVirtualRealityView.cxx b/VirtualReality/Widgets/qMRMLVirtualRealityView.cxx index bbe351d..3381b44 100644 --- a/VirtualReality/Widgets/qMRMLVirtualRealityView.cxx +++ b/VirtualReality/Widgets/qMRMLVirtualRealityView.cxx @@ -100,6 +100,7 @@ qMRMLVirtualRealityViewPrivate::qMRMLVirtualRealityViewPrivate(qMRMLVirtualReali { this->MRMLVirtualRealityViewNode = 0; this->HomeWidget = new qMRMLVirtualRealityHomeWidget(q_ptr); + this->DataModuleWidget = new qMRMLVirtualRealityDataModuleWidget; } //--------------------------------------------------------------------------- @@ -646,7 +647,8 @@ qMRMLVirtualRealityView::~qMRMLVirtualRealityView() void qMRMLVirtualRealityView::registerModule(QWidget* widget, QIcon& icon) { Q_D(qMRMLVirtualRealityView); - d->HomeWidget->addModuleButton(widget, icon); + + d->HomeWidget->addModuleButton(widget, icon); } //------------------------------------------------------------------------------ diff --git a/VirtualReality/Widgets/qMRMLVirtualRealityView_p.h b/VirtualReality/Widgets/qMRMLVirtualRealityView_p.h index 26c81db..6fcc30f 100644 --- a/VirtualReality/Widgets/qMRMLVirtualRealityView_p.h +++ b/VirtualReality/Widgets/qMRMLVirtualRealityView_p.h @@ -42,6 +42,7 @@ // VirtualReality Widgets includes #include "qMRMLVirtualRealityHomeWidget.h" +#include "qMRMLVirtualRealityDataModuleWidget.h" // qMRML includes #include "qMRMLVirtualRealityView.h" @@ -120,6 +121,7 @@ public slots: QTimer VirtualRealityLoopTimer; qMRMLVirtualRealityHomeWidget* HomeWidget; + qMRMLVirtualRealityDataModuleWidget* DataModuleWidget; }; #endif