From 07f54f60bb592b1c33ea9246d0482e4bfa68009a Mon Sep 17 00:00:00 2001 From: Csaba Pinter Date: Thu, 11 Jul 2019 15:39:07 -0400 Subject: [PATCH] BUG: Fix issues in VR home widget and the data widget --- .../UI/qMRMLVirtualRealityDataModuleWidget.ui | 20 +- .../UI/qMRMLVirtualRealityHomeWidget.ui | 52 ++--- .../qMRMLVirtualRealityDataModuleWidget.cxx | 28 +-- .../qMRMLVirtualRealityDataModuleWidget.h | 8 - .../Widgets/qMRMLVirtualRealityHomeWidget.cxx | 179 ++++++++++-------- .../Widgets/qMRMLVirtualRealityHomeWidget.h | 15 +- .../Widgets/qMRMLVirtualRealityView.cxx | 6 + .../Widgets/qMRMLVirtualRealityView_p.h | 2 - 8 files changed, 160 insertions(+), 150 deletions(-) diff --git a/VirtualReality/Widgets/Resources/UI/qMRMLVirtualRealityDataModuleWidget.ui b/VirtualReality/Widgets/Resources/UI/qMRMLVirtualRealityDataModuleWidget.ui index ba92916..1872872 100644 --- a/VirtualReality/Widgets/Resources/UI/qMRMLVirtualRealityDataModuleWidget.ui +++ b/VirtualReality/Widgets/Resources/UI/qMRMLVirtualRealityDataModuleWidget.ui @@ -6,8 +6,8 @@ 0 0 - 530 - 263 + 413 + 256 @@ -18,16 +18,16 @@ 4 - 4 + 0 - 4 + 0 - 4 + 0 - 4 + 0 @@ -56,12 +56,12 @@ setMRMLScene(vtkMRMLScene*) - 119 - 1 + 300 + 2 - 152 - 37 + 301 + 26 diff --git a/VirtualReality/Widgets/Resources/UI/qMRMLVirtualRealityHomeWidget.ui b/VirtualReality/Widgets/Resources/UI/qMRMLVirtualRealityHomeWidget.ui index 8cd2672..e846504 100644 --- a/VirtualReality/Widgets/Resources/UI/qMRMLVirtualRealityHomeWidget.ui +++ b/VirtualReality/Widgets/Resources/UI/qMRMLVirtualRealityHomeWidget.ui @@ -7,7 +7,7 @@ 0 0 532 - 262 + 263 @@ -48,26 +48,26 @@ - - + + 1 - + 0.500000000000000 - + 2.000000000000000 - + 0.100000000000000 - + 10.000000000000000 - + 1.660000000000000 - + m/s @@ -145,17 +145,17 @@ - - + + 0 - + 100.000000000000000 - + 50.000000000000000 - + % @@ -163,17 +163,6 @@ - - - - QFrame::NoFrame - - - QFrame::Raised - - - - @@ -186,6 +175,19 @@ + + + + QFrame::NoFrame + + + QFrame::Raised + + + 0 + + + diff --git a/VirtualReality/Widgets/qMRMLVirtualRealityDataModuleWidget.cxx b/VirtualReality/Widgets/qMRMLVirtualRealityDataModuleWidget.cxx index 5addeb9..9a41f32 100644 --- a/VirtualReality/Widgets/qMRMLVirtualRealityDataModuleWidget.cxx +++ b/VirtualReality/Widgets/qMRMLVirtualRealityDataModuleWidget.cxx @@ -42,10 +42,6 @@ class qMRMLVirtualRealityDataModuleWidgetPrivate : public Ui_qMRMLVirtualReality virtual ~qMRMLVirtualRealityDataModuleWidgetPrivate(); void init(); - -public: - /// Virtual reality view MRML node - vtkWeakPointer VirtualRealityViewNode; }; //----------------------------------------------------------------------------- @@ -64,6 +60,9 @@ void qMRMLVirtualRealityDataModuleWidgetPrivate::init() { Q_Q(qMRMLVirtualRealityDataModuleWidget); this->setupUi(q); + + // Customize widget contents + this->SubjectHierarchyTreeView->setColumnHidden(this->SubjectHierarchyTreeView->model()->idColumn(), true); } //----------------------------------------------------------------------------- @@ -84,29 +83,8 @@ qMRMLVirtualRealityDataModuleWidget::qMRMLVirtualRealityDataModuleWidget(QWidget 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 index d01ba7e..16173b1 100644 --- a/VirtualReality/Widgets/qMRMLVirtualRealityDataModuleWidget.h +++ b/VirtualReality/Widgets/qMRMLVirtualRealityDataModuleWidget.h @@ -36,7 +36,6 @@ #include "qMRMLSubjectHierarchyTreeView.h" #include "qMRMLSubjectHierarchyModel.h" -class vtkMRMLVirtualRealityViewNode; class qMRMLVirtualRealityDataModuleWidgetPrivate; /// \ingroup SlicerVirtualReality_Widgets @@ -51,13 +50,6 @@ class Q_SLICER_QTMODULES_VIRTUALREALITY_WIDGETS_EXPORT qMRMLVirtualRealityDataMo 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: diff --git a/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.cxx b/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.cxx index d623a5d..1109042 100644 --- a/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.cxx +++ b/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.cxx @@ -22,10 +22,10 @@ // VirtualReality Widgets includes #include "qMRMLVirtualRealityHomeWidget.h" #include "ui_qMRMLVirtualRealityHomeWidget.h" +#include "qMRMLVirtualRealityDataModuleWidget.h" // VirtualReality MRML includes #include "vtkMRMLVirtualRealityViewNode.h" -#include "qMRMLVirtualRealityDataModuleWidget.h" // VTK includes #include @@ -48,6 +48,7 @@ class qMRMLVirtualRealityHomeWidgetPrivate : public Ui_qMRMLVirtualRealityHomeWi void init(); + /// Association between VR module buttons and the corresponding widgets QMap ModuleWidgetsMap; public: @@ -61,12 +62,13 @@ qMRMLVirtualRealityHomeWidgetPrivate::qMRMLVirtualRealityHomeWidgetPrivate(qMRML : q_ptr(&object) { this->VirtualRealityViewNode = nullptr; - this->DataModuleWidget = new qMRMLVirtualRealityDataModuleWidget; + this->DataModuleWidget = nullptr; } //----------------------------------------------------------------------------- qMRMLVirtualRealityHomeWidgetPrivate::~qMRMLVirtualRealityHomeWidgetPrivate() { + this->VirtualRealityViewNode = nullptr; } //----------------------------------------------------------------------------- @@ -87,7 +89,15 @@ void qMRMLVirtualRealityHomeWidgetPrivate::init() QObject::connect(this->SyncViewToReferenceViewButton, SIGNAL(clicked()), q, SLOT(updateViewFromReferenceViewCamera())); //QObject::connect(this->LockMagnificationCheckBox, SIGNAL(toggled(bool)), q, SLOT(setMagnificationLock(bool))); - //TODO: Magnification lock of view node not implemented yet + //TODO: Magnification lock of view node not implemented yet + + // Hide module widget frame. It appears with the module when a module button is clicked + this->ModuleWidgetFrame->setVisible(false); + // Setup module widget frame layout + QVBoxLayout* moduleWidgetFrameLayout = new QVBoxLayout(this->ModuleWidgetFrame); + + // Register default VR modules + q->registerDefaultModules(); } //----------------------------------------------------------------------------- @@ -122,77 +132,6 @@ QString qMRMLVirtualRealityHomeWidget::virtualRealityViewNodeID()const return (d->VirtualRealityViewNode.GetPointer() ? d->VirtualRealityViewNode->GetID() : QString()); } -//----------------------------------------------------------------------------- -void qMRMLVirtualRealityHomeWidget::addModuleButton(QWidget* moduleWidget, QIcon& icon) -{ - Q_D(qMRMLVirtualRealityHomeWidget); - - if (!moduleWidget) - { - qCritical() << Q_FUNC_INFO << "Failed: widget is null"; - return; - } - - QPushButton* moduleButton = new QPushButton(d->ModulesGroupBox); - d->ModulesGroupBoxLayout->addWidget(moduleButton); - moduleButton->setIcon(icon); - - moduleWidget->setParent(d->ModuleWidgetFrame); - d->ModuleWidgetsMap[moduleButton] = moduleWidget; - - QObject::connect(moduleButton, SIGNAL(clicked()), this, SLOT(onModuleButtonPressed())); - QObject::connect(d->backButton, SIGNAL(clicked()), this, SLOT(onBackButtonPressed())); - - moduleButton->setVisible(true); - moduleWidget->setVisible(false); - d->backButton->setVisible(false); -} - -//----------------------------------------------------------------------------- -void qMRMLVirtualRealityHomeWidget::onModuleButtonPressed() -{ - Q_D(qMRMLVirtualRealityHomeWidget); - - QPushButton* moduleButton = qobject_cast(sender()); - - if (!moduleButton) - { - qCritical() << Q_FUNC_INFO << "Failed: moduleButton is null"; - return; - } - - d->HomeWidgetFrame->setVisible(false); - d->ModulesGroupBox->setVisible(false); - d->ModuleWidgetsMap[moduleButton]->setVisible(true); - d->backButton->setVisible(true); -} - -//----------------------------------------------------------------------------- -void qMRMLVirtualRealityHomeWidget::onBackButtonPressed() -{ - Q_D(qMRMLVirtualRealityHomeWidget); - d->HomeWidgetFrame->setVisible(true); - d->ModulesGroupBox->setVisible(true); - d->backButton->setVisible(false); - - QMap::const_iterator iteratorForMap; - for (iteratorForMap = d->ModuleWidgetsMap.constBegin(); iteratorForMap != d->ModuleWidgetsMap.constEnd(); ++iteratorForMap) - { - iteratorForMap.value()->setVisible(false); - } - -} - -//----------------------------------------------------------------------------- -void qMRMLVirtualRealityHomeWidget::registerDataModule() -{ - 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); -} - //----------------------------------------------------------------------------- void qMRMLVirtualRealityHomeWidget::setVirtualRealityViewNode(vtkMRMLVirtualRealityViewNode* node) { @@ -374,7 +313,95 @@ void qMRMLVirtualRealityHomeWidget::setMagnificationLock(bool active) qCritical() << Q_FUNC_INFO << " Failed: view node is null"; return; } - vrViewNode->????(active); //TODO: Implement magnification lock for view node - + + vrViewNode->????(active); //TODO: Implement magnification lock for view node } */ + +//----------------------------------------------------------------------------- +void qMRMLVirtualRealityHomeWidget::addModuleButton(QWidget* moduleWidget, QIcon& icon) +{ + Q_D(qMRMLVirtualRealityHomeWidget); + + if (!moduleWidget) + { + qCritical() << Q_FUNC_INFO << ": Invalid module widget given"; + return; + } + + // Create button for the new module + QPushButton* moduleButton = new QPushButton(d->ModulesGroupBox); + d->ModulesGroupBoxLayout->addWidget(moduleButton); + moduleButton->setIcon(icon); + + // Setup module widget within home widget + moduleWidget->setParent(d->ModuleWidgetFrame); + moduleWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); + moduleWidget->setVisible(false); + d->ModuleWidgetFrame->layout()->addWidget(moduleWidget); + d->ModuleWidgetsMap[moduleButton] = moduleWidget; + + // Handle scene if a MRML widget is given + qMRMLWidget* moduleMrmlWidget = qobject_cast(moduleWidget); + if (moduleMrmlWidget) + { + moduleMrmlWidget->setMRMLScene(this->mrmlScene()); + QObject::connect(this, SIGNAL(mrmlSceneChanged(vtkMRMLScene*)), moduleWidget, SLOT(setMRMLScene(vtkMRMLScene*))); + } + + QObject::connect(moduleButton, SIGNAL(clicked()), this, SLOT(onModuleButtonClicked())); + QObject::connect(d->backButton, SIGNAL(clicked()), this, SLOT(onBackButtonClicked())); + + moduleButton->setVisible(true); + d->backButton->setVisible(false); +} + +//----------------------------------------------------------------------------- +void qMRMLVirtualRealityHomeWidget::onModuleButtonClicked() +{ + Q_D(qMRMLVirtualRealityHomeWidget); + + QPushButton* moduleButton = qobject_cast(sender()); + if (!moduleButton) + { + qCritical() << Q_FUNC_INFO << ": Failed to access clicked button"; + return; + } + + d->HomeWidgetFrame->setVisible(false); + d->ModulesGroupBox->setVisible(false); + + d->ModuleWidgetFrame->setVisible(true); + d->ModuleWidgetsMap[moduleButton]->setVisible(true); + d->backButton->setVisible(true); +} + +//----------------------------------------------------------------------------- +void qMRMLVirtualRealityHomeWidget::onBackButtonClicked() +{ + Q_D(qMRMLVirtualRealityHomeWidget); + + QMap::const_iterator buttonIt; + for (buttonIt = d->ModuleWidgetsMap.constBegin(); buttonIt != d->ModuleWidgetsMap.constEnd(); ++buttonIt) + { + buttonIt.value()->setVisible(false); + } + d->ModuleWidgetFrame->setVisible(false); + d->backButton->setVisible(false); + + d->HomeWidgetFrame->setVisible(true); + d->ModulesGroupBox->setVisible(true); +} + +//----------------------------------------------------------------------------- +void qMRMLVirtualRealityHomeWidget::registerDefaultModules() +{ + Q_D(qMRMLVirtualRealityHomeWidget); + + d->DataModuleWidget = new qMRMLVirtualRealityDataModuleWidget(this); + d->DataModuleWidget->setMRMLScene(this->mrmlScene()); + + QIcon dataIcon(QPixmap(":/Icons/SubjectHierarchy.png")); + + this->addModuleButton(d->DataModuleWidget, dataIcon); +} diff --git a/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.h b/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.h index a1387e2..59e44e0 100644 --- a/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.h +++ b/VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.h @@ -54,8 +54,17 @@ class Q_SLICER_QTMODULES_VIRTUALREALITY_WIDGETS_EXPORT qMRMLVirtualRealityHomeWi /// Get virtual reality view MRML node Q_INVOKABLE vtkMRMLVirtualRealityViewNode* virtualRealityViewNode()const; + /// Get virtual reality view MRML node ID Q_INVOKABLE QString virtualRealityViewNodeID()const; + /// Add new button for a given VR module widget + /// \param moduleWidget The widget that appears in place of the home widget when its button is pressed + /// \param icon The icon that appears on the button in the home widget + Q_INVOKABLE void addModuleButton(QWidget* moduleWidget, QIcon& icon); + + /// Register default modules: Data + Q_INVOKABLE void registerDefaultModules(); + public slots: /// Set virtual reality view MRML node void setVirtualRealityViewNode(vtkMRMLVirtualRealityViewNode* node); @@ -70,10 +79,8 @@ public slots: //void updateViewFromReferenceViewCamera(); //void setMagnificationLock(bool); - void addModuleButton(QWidget* moduleWidget, QIcon& icon); - void onModuleButtonPressed(); - void onBackButtonPressed(); - void registerDataModule(); + void onModuleButtonClicked(); + void onBackButtonClicked(); protected slots: /// Update widgets from the MRML node diff --git a/VirtualReality/Widgets/qMRMLVirtualRealityView.cxx b/VirtualReality/Widgets/qMRMLVirtualRealityView.cxx index 3a68085..6006722 100644 --- a/VirtualReality/Widgets/qMRMLVirtualRealityView.cxx +++ b/VirtualReality/Widgets/qMRMLVirtualRealityView.cxx @@ -108,6 +108,8 @@ namespace qMRMLVirtualRealityViewPrivate::qMRMLVirtualRealityViewPrivate(qMRMLVirtualRealityView& object) : q_ptr(&object) , CamerasLogic(nullptr) + , MRMLVirtualRealityViewNode(nullptr) + , HomeWidget(nullptr) { this->MRMLVirtualRealityViewNode = nullptr; this->HomeWidget = new qMRMLVirtualRealityHomeWidget(q_ptr); @@ -123,6 +125,10 @@ qMRMLVirtualRealityViewPrivate::~qMRMLVirtualRealityViewPrivate() void qMRMLVirtualRealityViewPrivate::init() { QObject::connect(&this->VirtualRealityLoopTimer, SIGNAL(timeout()), this, SLOT(doOpenVirtualReality())); + + // Setup VR home widget + this->HomeWidget = new qMRMLVirtualRealityHomeWidget(q_ptr); + QObject::connect(this, SIGNAL(mrmlSceneChanged(vtkMRMLScene*)), this->HomeWidget, SLOT(setMRMLScene(vtkMRMLScene*))); } //---------------------------------------------------------------------------- diff --git a/VirtualReality/Widgets/qMRMLVirtualRealityView_p.h b/VirtualReality/Widgets/qMRMLVirtualRealityView_p.h index 174cd9e..652015c 100644 --- a/VirtualReality/Widgets/qMRMLVirtualRealityView_p.h +++ b/VirtualReality/Widgets/qMRMLVirtualRealityView_p.h @@ -42,7 +42,6 @@ // VirtualReality Widgets includes #include "qMRMLVirtualRealityHomeWidget.h" -#include "qMRMLVirtualRealityDataModuleWidget.h" // qMRML includes #include "qMRMLVirtualRealityView.h" @@ -123,7 +122,6 @@ public slots: QTimer VirtualRealityLoopTimer; qMRMLVirtualRealityHomeWidget* HomeWidget; - qMRMLVirtualRealityDataModuleWidget* DataModuleWidget; }; #endif