diff --git a/Libs/MRML/Core/Testing/vtkMRMLSliceNodeTest1.cxx b/Libs/MRML/Core/Testing/vtkMRMLSliceNodeTest1.cxx index fd40b346f5b..0c49212a9be 100644 --- a/Libs/MRML/Core/Testing/vtkMRMLSliceNodeTest1.cxx +++ b/Libs/MRML/Core/Testing/vtkMRMLSliceNodeTest1.cxx @@ -32,6 +32,8 @@ int GetSliceOrientationPresetTest(); int GetSliceOrientationPresetNameTest(); int SetOrientationTest(); int InitializeDefaultMatrixTest(); +int SliceOrientationPresetPrefixTest(); +int SliceOrientationPresetTooltipTest(); //---------------------------------------------------------------------------- int vtkMRMLSliceNodeTest1(int , char * [] ) @@ -48,6 +50,8 @@ int vtkMRMLSliceNodeTest1(int , char * [] ) CHECK_EXIT_SUCCESS(GetSliceOrientationPresetNameTest()); CHECK_EXIT_SUCCESS(SetOrientationTest()); CHECK_EXIT_SUCCESS(InitializeDefaultMatrixTest()); + CHECK_EXIT_SUCCESS(SliceOrientationPresetPrefixTest()); + CHECK_EXIT_SUCCESS(SliceOrientationPresetTooltipTest()); return EXIT_SUCCESS; } @@ -426,3 +430,59 @@ int InitializeDefaultMatrixTest() return EXIT_SUCCESS; } + +//---------------------------------------------------------------------------- +int SliceOrientationPresetPrefixTest() +{ + vtkNew sliceNode; + + vtkNew testMatrix; + sliceNode->AddSliceOrientationPreset("test_prefix", testMatrix.GetPointer()); + CHECK_STD_STRING(sliceNode->GetSliceOrientationPresetPrefix("test_prefix"), ""); + CHECK_STD_STRING(sliceNode->GetSliceOrientationPresetPrefix("Reformat"), ""); + + TESTING_OUTPUT_ASSERT_ERRORS_BEGIN(); + CHECK_BOOL(sliceNode->RenameSliceOrientationPresetPrefix("", "t:"), false); + TESTING_OUTPUT_ASSERT_ERRORS_END(); + + TESTING_OUTPUT_ASSERT_ERRORS_BEGIN(); + CHECK_BOOL(sliceNode->RenameSliceOrientationPresetPrefix("wrong name", "t:"), false); + TESTING_OUTPUT_ASSERT_ERRORS_END(); + + TESTING_OUTPUT_ASSERT_ERRORS_BEGIN(); + CHECK_BOOL(sliceNode->RenameSliceOrientationPresetPrefix("Reformat", "t:"), false); + TESTING_OUTPUT_ASSERT_ERRORS_END(); + + CHECK_BOOL(sliceNode->RenameSliceOrientationPresetPrefix("test_prefix", "t:"), true); + CHECK_STD_STRING(sliceNode->GetSliceOrientationPresetPrefix("test_prefix"), "t:"); + + return EXIT_SUCCESS; +} + +//---------------------------------------------------------------------------- +int SliceOrientationPresetTooltipTest() +{ + vtkNew sliceNode; + + vtkNew testMatrix; + sliceNode->AddSliceOrientationPreset("test_tooltip", testMatrix.GetPointer()); + CHECK_STD_STRING(sliceNode->GetSliceOrientationPresetTooltip("test_tooltip"), "Oblique"); + CHECK_STD_STRING(sliceNode->GetSliceOrientationPresetTooltip("Reformat"), "Oblique"); + + TESTING_OUTPUT_ASSERT_ERRORS_BEGIN(); + CHECK_BOOL(sliceNode->RenameSliceOrientationPresetTooltip("", "this is a tip"), false); + TESTING_OUTPUT_ASSERT_ERRORS_END(); + + TESTING_OUTPUT_ASSERT_ERRORS_BEGIN(); + CHECK_BOOL(sliceNode->RenameSliceOrientationPresetTooltip("wrong name", "this is a tip"), false); + TESTING_OUTPUT_ASSERT_ERRORS_END(); + + TESTING_OUTPUT_ASSERT_ERRORS_BEGIN(); + CHECK_BOOL(sliceNode->RenameSliceOrientationPresetTooltip("Reformat", "this is a tip"), false); + TESTING_OUTPUT_ASSERT_ERRORS_END(); + + CHECK_BOOL(sliceNode->RenameSliceOrientationPresetTooltip("test_tooltip", "this is a tip"), true); + CHECK_STD_STRING(sliceNode->GetSliceOrientationPresetTooltip("test_tooltip"), "this is a tip"); + + return EXIT_SUCCESS; +} diff --git a/Libs/MRML/Core/vtkMRMLSliceNode.cxx b/Libs/MRML/Core/vtkMRMLSliceNode.cxx index 3edad59d417..256e3e1cc8f 100644 --- a/Libs/MRML/Core/vtkMRMLSliceNode.cxx +++ b/Libs/MRML/Core/vtkMRMLSliceNode.cxx @@ -339,17 +339,8 @@ bool vtkMRMLSliceNode::MatrixAreEqual(const vtkMatrix4x4 *matrix, //---------------------------------------------------------------------------- vtkMatrix3x3 *vtkMRMLSliceNode::GetSliceOrientationPreset(const std::string &name) { - std::vector< OrientationPresetType >::iterator it; - for (it = this->OrientationMatrices.begin(); it != this->OrientationMatrices.end(); ++it) - { - if (it->first == name) - { - return it->second; - } - } - - vtkErrorMacro("GetSliceOrientationPreset: invalid orientation preset name: " << name); - return NULL; + OrientationPresetType* preset = this->GetOrientationPreset(name); + return preset ? preset->Orientation : nullptr; } //---------------------------------------------------------------------------- @@ -366,11 +357,9 @@ std::string vtkMRMLSliceNode::GetSliceOrientationPresetName(vtkMatrix3x3* orient it != this->OrientationMatrices.rend(); ++it) { - std::string presetName = it->first; - vtkMatrix3x3* presetOrientationMatrix = this->GetSliceOrientationPreset(presetName); - if (vtkAddonMathUtilities::MatrixAreEqual(orientationMatrix, presetOrientationMatrix)) + if (vtkAddonMathUtilities::MatrixAreEqual(orientationMatrix, it->Orientation)) { - return presetName; + return it->Name; } } return std::string(); @@ -391,6 +380,30 @@ std::string vtkMRMLSliceNode::GetOrientation(vtkMatrix4x4 *sliceToRAS) return "Reformat"; } +//---------------------------------------------------------------------------- +std::string vtkMRMLSliceNode::GetSliceOrientationPresetPrefix(const std::string& name) +{ + if (name == "Reformat") + { + return ""; + } + + OrientationPresetType* preset = this->GetOrientationPreset(name); + return preset ? preset->Prefix : ""; +} + +//---------------------------------------------------------------------------- +std::string vtkMRMLSliceNode::GetSliceOrientationPresetTooltip(const std::string& name) +{ + if (name == "Reformat") + { + return "Oblique"; + } + + OrientationPresetType* preset = this->GetOrientationPreset(name); + return preset ? preset->Tooltip : ""; +} + //---------------------------------------------------------------------------- void vtkMRMLSliceNode::GetSliceOrientationPresetNames(vtkStringArray *presetOrientationNames) { @@ -408,7 +421,7 @@ void vtkMRMLSliceNode::GetSliceOrientationPresetNames(vtkStringArray *presetOrie it != this->OrientationMatrices.end(); ++it) { - presetOrientationNames->SetValue(id, it->first); + presetOrientationNames->SetValue(id, it->Name); id++; } } @@ -420,7 +433,9 @@ int vtkMRMLSliceNode::GetNumberOfSliceOrientationPresets() const } //---------------------------------------------------------------------------- -bool vtkMRMLSliceNode::AddSliceOrientationPreset(const std::string &name, vtkMatrix3x3 *orientationMatrix) +bool vtkMRMLSliceNode::AddSliceOrientationPreset( + const std::string &name, vtkMatrix3x3 *orientationMatrix, + const std::string &prefix, const std::string &tooltip) { if (name == "Reformat") { @@ -429,17 +444,19 @@ bool vtkMRMLSliceNode::AddSliceOrientationPreset(const std::string &name, vtkMat return false; } - std::vector< OrientationPresetType >::iterator it; - for (it = this->OrientationMatrices.begin(); it != this->OrientationMatrices.end(); ++it) + if (this->GetOrientationPreset(name, false)) { - if (it->first == name) - { - vtkDebugMacro("AddSliceOrientationPreset: the orientation preset " << name << " is already stored."); - return false; - } + vtkDebugMacro("AddSliceOrientationPreset: the orientation preset " << name << " is already stored."); + return false; } - this->OrientationMatrices.push_back(OrientationPresetType(name, orientationMatrix)); + OrientationPresetType newOrientation; + newOrientation.Name = name; + newOrientation.Orientation = orientationMatrix; + newOrientation.Prefix = prefix; + newOrientation.Tooltip = tooltip; + + this->OrientationMatrices.push_back(newOrientation); return true; } @@ -449,7 +466,7 @@ bool vtkMRMLSliceNode::RemoveSliceOrientationPreset(const std::string &name) std::vector< OrientationPresetType >::iterator it; for (it = this->OrientationMatrices.begin(); it != this->OrientationMatrices.end(); ++it) { - if (it->first == name) + if (it->Name == name) { this->OrientationMatrices.erase(it); return true; @@ -460,6 +477,26 @@ bool vtkMRMLSliceNode::RemoveSliceOrientationPreset(const std::string &name) return false; } +//---------------------------------------------------------------------------- +OrientationPresetType* vtkMRMLSliceNode::GetOrientationPreset(const std::string &name, bool error) +{ + std::vector< OrientationPresetType >::iterator it; + for (it = this->OrientationMatrices.begin(); it != this->OrientationMatrices.end(); ++it) + { + if (it->Name == name) + { + return &(*it); + } + } + + if (error) + { + vtkErrorMacro("GetOrientationPreset: The orientation preset " + "'" << name << "' does NOT exist."); + } + return nullptr; +} + //---------------------------------------------------------------------------- bool vtkMRMLSliceNode::RenameSliceOrientationPreset(const std::string &name, const std::string &updatedName) { @@ -479,43 +516,63 @@ bool vtkMRMLSliceNode::RenameSliceOrientationPreset(const std::string &name, con this->SetOrientationReference(updatedName.c_str()); } - std::vector< OrientationPresetType >::iterator it; - for (it = this->OrientationMatrices.begin(); it != this->OrientationMatrices.end(); ++it) + OrientationPresetType* preset = this->GetOrientationPreset(name); + if (preset) { - if (it->first == name) - { - it->first = updatedName; - return true; - } + preset->Name = updatedName; + return true; } - - vtkErrorMacro("RenameSliceOrientationPreset: The orientation preset " - "'" << name << "' does NOT exist."); return false; } //---------------------------------------------------------------------------- -bool vtkMRMLSliceNode::HasSliceOrientationPreset(const std::string &name) +bool vtkMRMLSliceNode::RenameSliceOrientationPresetPrefix(const std::string &name, const std::string &prefix) { if (name == "Reformat") { - vtkWarningMacro("HasSliceOrientationPreset: 'Reformat' refers to any " - "arbitrary orientation. It can NOT be used as a preset name."); + vtkErrorMacro("RenameSliceOrientationPresetPrefix: 'Reformat' refers to any " + "arbitrary orientation. It can NOT be used as a preset name."); return false; + } + OrientationPresetType* preset = this->GetOrientationPreset(name); + if (preset && preset->Prefix.compare(prefix) != 0) + { + preset->Prefix = prefix; + return true; } + return false; +} - std::vector< OrientationPresetType >::iterator it; - for (it = this->OrientationMatrices.begin(); it != this->OrientationMatrices.end(); ++it) +//---------------------------------------------------------------------------- +bool vtkMRMLSliceNode::RenameSliceOrientationPresetTooltip(const std::string &name, const std::string &tip) +{ + if (name == "Reformat") { - if (it->first == name) - { - return true; - } + vtkErrorMacro("RenameSliceOrientationPresetTooltip: 'Reformat' refers to any " + "arbitrary orientation. It can NOT be used as a preset name."); + return false; + } + OrientationPresetType* preset = this->GetOrientationPreset(name); + if (preset && preset->Tooltip.compare(tip) != 0) + { + preset->Tooltip = tip; + return true; } - return false; } +//---------------------------------------------------------------------------- +bool vtkMRMLSliceNode::HasSliceOrientationPreset(const std::string &name) +{ + if (name == "Reformat") + { + vtkWarningMacro("HasSliceOrientationPreset: 'Reformat' refers to any " + "arbitrary orientation. It can NOT be used as a preset name."); + return false; + } + return this->GetOrientationPreset(name, false) != nullptr; +} + //---------------------------------------------------------------------------- void vtkMRMLSliceNode::InitializeAxialMatrix(vtkMatrix3x3* orientationMatrix) { @@ -596,9 +653,12 @@ void vtkMRMLSliceNode::AddDefaultSliceOrientationPresets(vtkMRMLScene* scene) scene->AddDefaultNode(defaultNode); } vtkMRMLSliceNode * defaultSliceNode = vtkMRMLSliceNode::SafeDownCast(defaultNode); - defaultSliceNode->AddSliceOrientationPreset("Axial", axialSliceToRAS.GetPointer()); - defaultSliceNode->AddSliceOrientationPreset("Sagittal", sagittalSliceToRAS.GetPointer()); - defaultSliceNode->AddSliceOrientationPreset("Coronal", coronalSliceToRAS.GetPointer()); + defaultSliceNode->AddSliceOrientationPreset( + "Axial", axialSliceToRAS.GetPointer(), "S: ", "I <-----> S"); + defaultSliceNode->AddSliceOrientationPreset( + "Sagittal", sagittalSliceToRAS.GetPointer(), "R: ", "L <-----> R"); + defaultSliceNode->AddSliceOrientationPreset( + "Coronal", coronalSliceToRAS.GetPointer(), "A: ", "P <-----> A"); } //---------------------------------------------------------------------------- @@ -878,14 +938,17 @@ void vtkMRMLSliceNode::WriteXML(ostream& of, int nIndent) { for (j=0; j<3; j++) { - ss << it->second->GetElement(i,j); + ss << it->Orientation->GetElement(i,j); if ( !( i==2 && j==2) ) { ss << " "; } } } - of << " orientationMatrix"<< this->URLEncodeString(it->first.c_str()) <<"=\"" << ss.str().c_str() << "\""; + of << " orientationMatrix"<< this->URLEncodeString(it->Name.c_str()) <<"=\"" << ss.str().c_str() + << " " << this->URLEncodeString(it->Prefix.c_str()) + << " " << this->URLEncodeString(it->Tooltip.c_str()) + << "\""; } of << " orientation=\"" << this->GetOrientation() << "\""; @@ -1173,8 +1236,17 @@ void vtkMRMLSliceNode::ReadXMLAttributes(const char** atts) orientationMatrix->SetElement(i,j,val); } } + std::string prefix; + ss >> prefix; + + std::string tooltip; + ss >> tooltip; + name.erase(0,17); - this->AddSliceOrientationPreset(name, orientationMatrix.GetPointer()); + this->AddSliceOrientationPreset( + name, orientationMatrix.GetPointer(), + this->URLDecodeString(prefix.c_str()), + this->URLDecodeString(tooltip.c_str())); } else if (!strcmp(attName, "prescribedSliceSpacing")) { @@ -1286,8 +1358,11 @@ void vtkMRMLSliceNode::Copy(vtkMRMLNode *anode) for (int i = 0; i < namedOrientations->GetNumberOfValues(); i++) { - this->AddSliceOrientationPreset(namedOrientations->GetValue(i), - node->GetSliceOrientationPreset(namedOrientations->GetValue(i))); + std::string name = namedOrientations->GetValue(i); + this->AddSliceOrientationPreset(name, + node->GetSliceOrientationPreset(name), + node->GetSliceOrientationPresetPrefix(name), + node->GetSliceOrientationPresetTooltip(name)); } std::string orientation = node->GetOrientation(); @@ -1427,8 +1502,10 @@ void vtkMRMLSliceNode::PrintSelf(ostream& os, vtkIndent indent) std::vector< OrientationPresetType >::iterator it; for (it = this->OrientationMatrices.begin(); it != this->OrientationMatrices.end(); ++it) { - os << indent << "OrientationMatrix"<< this->URLEncodeString(it->first.c_str()) <<": \n"; - it->second->PrintSelf(os, indent.GetNextIndent()); + os << indent << "OrientationMatrix"<< this->URLEncodeString(it->Name.c_str()) <<": \n"; + it->Orientation->PrintSelf(os, indent.GetNextIndent()); + os << indent.GetNextIndent() << "Prefix: " << this->URLEncodeString(it->Prefix.c_str()) << "\n"; + os << indent.GetNextIndent() << "Tooltip: " << this->URLEncodeString(it->Tooltip.c_str()) << "\n"; } os << indent << "XYToRAS: \n"; diff --git a/Libs/MRML/Core/vtkMRMLSliceNode.h b/Libs/MRML/Core/vtkMRMLSliceNode.h index b5857b204df..f96c8a24a57 100644 --- a/Libs/MRML/Core/vtkMRMLSliceNode.h +++ b/Libs/MRML/Core/vtkMRMLSliceNode.h @@ -23,6 +23,15 @@ class vtkMRMLVolumeNode; class vtkMatrix3x3; class vtkMatrix4x4; +/// \brief Structure to store preset orientation information. +struct OrientationPresetType +{ + std::string Name; + vtkSmartPointer Orientation; + std::string Prefix; + std::string Tooltip; +}; + /// \brief MRML node for storing a slice through RAS space. /// /// This node stores the information about how to map from RAS space to @@ -157,7 +166,9 @@ class VTK_MRML_EXPORT vtkMRMLSliceNode : public vtkMRMLAbstractViewNode /// Valid \a orientations are known as presets and are easily added, /// removed or renamed. /// - /// \sa AddSliceOrientationPreset(const std::string& name, vtkMatrix4x4* sliceToRAS) + /// \sa AddSliceOrientationPreset( + /// const std::string& name, vtkMatrix3x3* sliceToRAS, + /// const std::string& prefix, const std::string& tooltip) /// \sa UpdateMatrices() bool SetOrientation(const char* orientation); @@ -186,6 +197,16 @@ class VTK_MRML_EXPORT vtkMRMLSliceNode : public vtkMRMLAbstractViewNode /// preset. std::string GetSliceOrientationPresetName(vtkMatrix3x3* orientationMatrix); + /// \brief Return the preset prefix corresponding to a preset \a name. + /// + /// Returns an empty string if the preset with the given \a name doesn't exist. + std::string GetSliceOrientationPresetPrefix(const std::string& name); + + /// \brief Return the preset tooltip corresponding to a preset \a name. + /// + /// Returns an empty string if the tooltip with the given \a name doesn't exist. + std::string GetSliceOrientationPresetTooltip(const std::string& name); + /// \brief Return all the orientation preset names. void GetSliceOrientationPresetNames(vtkStringArray* presetOrientationNames); @@ -197,21 +218,46 @@ class VTK_MRML_EXPORT vtkMRMLSliceNode : public vtkMRMLAbstractViewNode /// /// \sa RenameSliceOrientationPreset(const std::string& name, const std::string& updatedName) /// \sa RemoveSliceOrientationPreset(const std::string& name) - bool AddSliceOrientationPreset(const std::string& name, vtkMatrix3x3* orientationMatrix); + /// \sa RenameSliceOrientationPresetPrefix(const std::string& name, const std::string& prefix) + /// \sa RenameSliceOrientationPresetTooltip(const std::string& name, const std::string& tip) + bool AddSliceOrientationPreset(const std::string& name, + vtkMatrix3x3* orientationMatrix, + const std::string& prefix="", + const std::string& tooltip = "Oblique"); /// \brief Remove an orientation preset. /// - /// \sa AddSliceOrientationPreset(const std::string& name, vtkMatrix4x4* sliceToRAS) + /// \sa AddSliceOrientationPreset( + /// const std::string& name, vtkMatrix3x3* sliceToRAS, + /// const std::string& prefix, const std::string& tooltip) bool RemoveSliceOrientationPreset(const std::string& name); /// \brief Rename an orientation preset. /// - /// \sa AddSliceOrientationPreset(const std::string& name, vtkMatrix4x4* sliceToRAS) + /// \sa AddSliceOrientationPreset( + /// const std::string& name, vtkMatrix3x3* sliceToRAS, + /// const std::string& prefix, const std::string& tooltip) bool RenameSliceOrientationPreset(const std::string& name, const std::string& updatedName); + /// \brief Rename an orientation prefix. + /// + /// \sa AddSliceOrientationPreset( + /// const std::string& name, vtkMatrix3x3* sliceToRAS, + /// const std::string& prefix, const std::string& tooltip) + bool RenameSliceOrientationPresetPrefix(const std::string& name, const std::string& prefix); + + /// \brief Rename an orientation prefix. + /// + /// \sa AddSliceOrientationPreset( + /// const std::string& name, vtkMatrix3x3* sliceToRAS, + /// const std::string& prefix, const std::string& tooltip) + bool RenameSliceOrientationPresetTooltip(const std::string& name, const std::string& tip); + /// \brief Return True if an orientation preset is stored. /// - /// \sa AddSliceOrientationPreset(const std::string& name, vtkMatrix4x4* sliceToRAS) + /// \sa AddSliceOrientationPreset( + /// const std::string& name, vtkMatrix3x3* sliceToRAS, + /// const std::string& prefix, const std::string& tooltip) bool HasSliceOrientationPreset(const std::string& name); /// \brief Initialize \a orientationMatrix as an `Axial` orientation matrix. @@ -509,8 +555,8 @@ class VTK_MRML_EXPORT vtkMRMLSliceNode : public vtkMRMLAbstractViewNode vtkSmartPointer UVWToSlice; vtkSmartPointer UVWToRAS; - typedef std::pair > OrientationPresetType; std::vector< OrientationPresetType > OrientationMatrices; + OrientationPresetType* GetOrientationPreset(const std::string& name, bool error=true); int JumpMode; diff --git a/Libs/MRML/Widgets/Testing/qMRMLSliceControllerWidgetTest.cxx b/Libs/MRML/Widgets/Testing/qMRMLSliceControllerWidgetTest.cxx index a7e9414df37..6ef821fedba 100644 --- a/Libs/MRML/Widgets/Testing/qMRMLSliceControllerWidgetTest.cxx +++ b/Libs/MRML/Widgets/Testing/qMRMLSliceControllerWidgetTest.cxx @@ -28,6 +28,7 @@ // MRML includes #include "qMRMLNodeComboBox.h" #include "qMRMLSliceControllerWidget.h" +#include "qMRMLSliderWidget.h" #include #include #include @@ -71,6 +72,9 @@ private slots: void testSetLabelVolumeWithNoLinkedControl(); void testUpdateSliceOrientationSelector(); + + void testPrefix(); + void testTooltip(); }; // ---------------------------------------------------------------------------- @@ -351,6 +355,48 @@ void qMRMLSliceControllerWidgetTester::testUpdateSliceOrientationSelector() } +// ---------------------------------------------------------------------------- +void qMRMLSliceControllerWidgetTester::testPrefix() +{ + qMRMLSliceControllerWidget sliceControllerWidget; + vtkNew testMatrix; + this->MRMLSliceNode->AddSliceOrientationPreset( + "Test", testMatrix.GetPointer(), "Prefix_test"); + + sliceControllerWidget.setMRMLScene(this->MRMLScene); + sliceControllerWidget.setMRMLSliceNode(this->MRMLSliceNode); + this->MRMLSliceNode->SetOrientation("Test"); + QCOMPARE(sliceControllerWidget.sliceOrientation(), QString("Test")); + + qMRMLSliderWidget* sliderWidget = + sliceControllerWidget.findChild(); + Q_ASSERT(sliderWidget); + + QCOMPARE(sliderWidget->prefix(), QString("Prefix_test")); + QCOMPARE(sliderWidget->toolTip(), QString("Oblique")); +} + +// ---------------------------------------------------------------------------- +void qMRMLSliceControllerWidgetTester::testTooltip() +{ + qMRMLSliceControllerWidget sliceControllerWidget; + vtkNew testMatrix; + this->MRMLSliceNode->AddSliceOrientationPreset( + "Test", testMatrix.GetPointer(), "t:", "This is a tooltip test"); + + sliceControllerWidget.setMRMLScene(this->MRMLScene); + sliceControllerWidget.setMRMLSliceNode(this->MRMLSliceNode); + this->MRMLSliceNode->SetOrientation("Test"); + QCOMPARE(sliceControllerWidget.sliceOrientation(), QString("Test")); + + qMRMLSliderWidget* sliderWidget = + sliceControllerWidget.findChild(); + Q_ASSERT(sliderWidget); + + QCOMPARE(sliderWidget->prefix(), QString("t:")); + QCOMPARE(sliderWidget->toolTip(), QString("This is a tooltip test")); +} + // ---------------------------------------------------------------------------- CTK_TEST_MAIN(qMRMLSliceControllerWidgetTest) #include "moc_qMRMLSliceControllerWidgetTest.cxx" diff --git a/Libs/MRML/Widgets/qMRMLSliceControllerWidget.cxx b/Libs/MRML/Widgets/qMRMLSliceControllerWidget.cxx index e185e4a39b5..09925d24093 100644 --- a/Libs/MRML/Widgets/qMRMLSliceControllerWidget.cxx +++ b/Libs/MRML/Widgets/qMRMLSliceControllerWidget.cxx @@ -71,16 +71,6 @@ qMRMLSliceControllerWidgetPrivate::qMRMLSliceControllerWidgetPrivate(qMRMLSliceC this->ControllerButtonGroup = 0; - qMRMLOrientation axialOrientation = {qMRMLSliceControllerWidget::tr("S: "), qMRMLSliceControllerWidget::tr("I <-----> S")}; - qMRMLOrientation sagittalOrientation = {qMRMLSliceControllerWidget::tr("R: "), qMRMLSliceControllerWidget::tr("L <-----> R")}; - qMRMLOrientation coronalOrientation = {qMRMLSliceControllerWidget::tr("A: "), qMRMLSliceControllerWidget::tr("P <-----> A")}; - qMRMLOrientation obliqueOrientation = {qMRMLSliceControllerWidget::tr(""), qMRMLSliceControllerWidget::tr("Oblique")}; - - this->SliceOrientationToDescription["Axial"] = axialOrientation; - this->SliceOrientationToDescription["Sagittal"] = sagittalOrientation; - this->SliceOrientationToDescription["Coronal"] = coronalOrientation; - this->SliceOrientationToDescription["Reformat"] = obliqueOrientation; - this->LastLabelMapOpacity = 1.; this->LastForegroundOpacity = 1.; this->LastBackgroundOpacity = 1.; @@ -873,10 +863,11 @@ void qMRMLSliceControllerWidgetPrivate::updateWidgetFromMRMLSliceNode() Self::updateSliceOrientationSelector(this->MRMLSliceNode, this->SliceOrientationSelector); // Update slice offset slider tooltip - qMRMLOrientation orientation = this->mrmlOrientation( - QString::fromStdString(this->MRMLSliceNode->GetOrientation().c_str())); - this->SliceOffsetSlider->setToolTip(orientation.ToolTip); - this->SliceOffsetSlider->setPrefix(orientation.Prefix); + std::string orientation = this->MRMLSliceNode->GetOrientation(); + this->SliceOffsetSlider->setToolTip( + qMRMLSliceControllerWidget::tr(this->MRMLSliceNode->GetSliceOrientationPresetTooltip(orientation).c_str())); + this->SliceOffsetSlider->setPrefix( + qMRMLSliceControllerWidget::tr(this->MRMLSliceNode->GetSliceOrientationPresetPrefix(orientation).c_str())); // Update slice visibility toggle this->actionShow_in_3D->setChecked(this->MRMLSliceNode->GetSliceVisible()); @@ -1512,18 +1503,6 @@ void qMRMLSliceControllerWidgetPrivate::setupRulerMenu() rulerMenu->addActions(rulerTypesActions->actions()); } -// -------------------------------------------------------------------------- -qMRMLOrientation qMRMLSliceControllerWidgetPrivate::mrmlOrientation(const QString &name) -{ - QHash::iterator it = this->SliceOrientationToDescription.find(name); - if (it != this->SliceOrientationToDescription.end()) - { - return it.value(); - } - qMRMLOrientation obliqueOrientation = {qMRMLSliceControllerWidget::tr(""), qMRMLSliceControllerWidget::tr("Oblique")}; - return obliqueOrientation; -} - // -------------------------------------------------------------------------- void qMRMLSliceControllerWidgetPrivate::onSegmentVisibilitySelectionChanged(QStringList selectedSegmentIDs) { diff --git a/Libs/MRML/Widgets/qMRMLSliceControllerWidget_p.h b/Libs/MRML/Widgets/qMRMLSliceControllerWidget_p.h index b8c4876aa58..e14e3653dd0 100644 --- a/Libs/MRML/Widgets/qMRMLSliceControllerWidget_p.h +++ b/Libs/MRML/Widgets/qMRMLSliceControllerWidget_p.h @@ -60,13 +60,6 @@ class vtkMRMLSliceNode; class vtkObject; class vtkMRMLSegmentationDisplayNode; -//----------------------------------------------------------------------------- -struct QMRML_WIDGETS_EXPORT qMRMLOrientation -{ - QString Prefix; - QString ToolTip; -}; - //----------------------------------------------------------------------------- class QMRML_WIDGETS_EXPORT qMRMLSliceControllerWidgetPrivate : public qMRMLViewControllerBarPrivate @@ -97,8 +90,6 @@ class QMRML_WIDGETS_EXPORT qMRMLSliceControllerWidgetPrivate void setupOrientationMarkerMenu(); void setupRulerMenu(); - qMRMLOrientation mrmlOrientation(const QString& name); - vtkSmartPointer saveNodesForUndo(const QString& nodeTypes); void enableLayerWidgets(); @@ -171,7 +162,6 @@ public slots: vtkSmartPointer SliceLogic; vtkCollection* SliceLogics; vtkWeakPointer ImageDataConnection; - QHash SliceOrientationToDescription; QString SliceViewName; QButtonGroup* ControllerButtonGroup;