Skip to content

Commit

Permalink
ENH: Add color table mode to terminology selector
Browse files Browse the repository at this point in the history
- If selected terminology context is a color table, then instead of showing the category/type/etc terminology selector, show a simple color table
- Add qMRMLSimpleColorTableView to serve as mentioned simple color table view. It is not editable, and only shows the color, label, and terminology columns. Does not show rows where the terminology is "(none)"

Re Slicer#6975, Slicer#7593
  • Loading branch information
cpinter committed Jan 9, 2025
1 parent 23f0a6a commit 87580be
Show file tree
Hide file tree
Showing 13 changed files with 688 additions and 270 deletions.
18 changes: 0 additions & 18 deletions Modules/Loadable/Colors/Widgets/qSlicerTerminologyEditorDialog.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ void qSlicerTerminologyEditorDialogPrivate::init()

this->SaveButton = new QPushButton("Save");
this->SaveButton->setDefault(true);
//this->SaveButton->setEnabled(false); // Disabled until terminology selection becomes valid //TODO:
buttonsLayout->addWidget(this->SaveButton, 2);

this->CancelButton = new QPushButton("Cancel");
Expand All @@ -95,8 +94,6 @@ void qSlicerTerminologyEditorDialogPrivate::init()
layout->addLayout(buttonsLayout);

// Make connections
//connect(this->EditorWidget, SIGNAL(selectionValidityChanged(bool)), q, SLOT(setSaveButtonEnabled(bool))); //TODO:
connect(this->EditorWidget, SIGNAL(typeDoubleClicked()), this, SLOT(accept()));
connect(this->SaveButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(this->CancelButton, SIGNAL(clicked()), this, SLOT(reject()));
}
Expand Down Expand Up @@ -166,7 +163,6 @@ bool qSlicerTerminologyEditorDialog::getTerminology(vtkSlicerTerminologyEntry* t
terminologyInfo.GetTerminologyEntry()->Copy(terminologyEntry);
// Open terminology dialog and store result
qSlicerTerminologyEditorDialog dialog(terminologyInfo, parent);
//dialog.setOverrideSectionVisible(false);
if (!dialog.exec())
{
return false;
Expand All @@ -190,17 +186,3 @@ void qSlicerTerminologyEditorDialog::setSaveButtonEnabled(bool enabled)
Q_D(qSlicerTerminologyEditorDialog);
d->SaveButton->setEnabled(enabled);
}

////-----------------------------------------------------------------------------
//bool qSlicerTerminologyEditorDialog::overrideSectionVisible() const
//{
// Q_D(const qSlicerTerminologySelectorDialog);
// return d->NavigatorWidget->overrideSectionVisible();
//}
//
////-----------------------------------------------------------------------------
//void qSlicerTerminologyEditorDialog::setOverrideSectionVisible(bool visible)
//{
// Q_D(qSlicerTerminologySelectorDialog);
// d->NavigatorWidget->setOverrideSectionVisible(visible);
//}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class Q_SLICER_MODULE_COLORS_WIDGETS_EXPORT qSlicerTerminologyEditorDialog : pub
{
public:
Q_OBJECT
//Q_PROPERTY(bool overrideSectionVisible READ overrideSectionVisible WRITE setOverrideSectionVisible)

public:
typedef QObject Superclass;
Expand Down Expand Up @@ -77,15 +76,9 @@ class Q_SLICER_MODULE_COLORS_WIDGETS_EXPORT qSlicerTerminologyEditorDialog : pub
/// Python compatibility function for showing dialog (calls \a exec)
Q_INVOKABLE bool execDialog() { return this->exec(); };

///// Get whether name and color override section is visible
//bool overrideSectionVisible() const;

protected slots:
void setSaveButtonEnabled(bool);

///// Show/hide name and color override section
//void setOverrideSectionVisible(bool);

protected:
QScopedPointer<qSlicerTerminologyEditorDialogPrivate> d_ptr;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2563,7 +2563,10 @@ std::vector<std::string> vtkSlicerTerminologiesModuleLogic::FindTerminologyNames
CodeIdentifier(typeModifierCodingSchemeDesignator, typeModifierCodeValue), modifiedTypeObject))
{
foundTerminologyNames.push_back(terminologyName);
foundEntries->AddItem(typeObject);
if (foundEntries)
{
foundEntries->AddItem(typeObject);
}
}
}
}
Expand Down Expand Up @@ -2817,6 +2820,10 @@ bool vtkSlicerTerminologiesModuleLogic::LoadColorTable(vtkMRMLColorNode* colorNo
nodeNameString.SetString(terminologyContextName.c_str(), terminologyContextName.length(), termAllocator);
termDoc->AddMember("SegmentationCategoryTypeContextName", nodeNameString, termAllocator);
termDoc->AddMember("@schema", "https://raw.githubusercontent.com/qiicr/dcmqi/master/doc/segment-context-schema.json#", termAllocator);
std::string colorNodeID(colorNode->GetID());
rapidjson::Value colorNodeIDString(rapidjson::kStringType);
colorNodeIDString.SetString(colorNodeID.c_str(), colorNodeID.length(), termAllocator);
termDoc->AddMember("ColorTableID", colorNodeIDString, termAllocator);

rapidjson::Value segmentationCodesObject(rapidjson::kObjectType);
termDoc->AddMember("SegmentationCodes", segmentationCodesObject, termAllocator);
Expand Down Expand Up @@ -3019,3 +3026,30 @@ bool vtkSlicerTerminologiesModuleLogic::LoadColorTable(vtkMRMLColorNode* colorNo

return true;
}

//---------------------------------------------------------------------------
const char* vtkSlicerTerminologiesModuleLogic::IsTerminologyColorTable(std::string terminologyName)
{
if (terminologyName.empty())
{
return nullptr;
}
rapidjson::Value& root = this->Internal->GetTerminologyRootByName(terminologyName);
if (root.IsNull())
{
vtkErrorMacro("IsTerminologyColorTable: Failed to find terminology root for context name '" << terminologyName << "'");
return nullptr;
}

if (!root.HasMember("ColorTableID"))
{
return nullptr;
}
rapidjson::Value& colorTableId = root["ColorTableID"];
if (colorTableId.IsNull())
{
return nullptr;
}

return colorTableId.GetString();
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ class VTK_SLICER_TERMINOLOGIES_LOGIC_EXPORT vtkSlicerTerminologiesModuleLogic :
std::vector<std::string> preferredAnatomicContextNames,
vtkCollection* foundEntries=nullptr);

/// Determine if terminology is from a color table.
/// \return ID of the color table node if terminology comes from color table, else nullptr.
const char* IsTerminologyColorTable(std::string terminologyName);

/// Get a category with given name from a terminology
/// \param category Output argument containing the details of the found category if any (if return value is true)
/// \return Success flag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ void vtkSlicerTerminologyCategory::Copy(vtkCodedEntry* aCategory)

this->Superclass::Copy(aCategory);

vtkSlicerTerminologyCategory *aTerminologyCategory =
vtkSlicerTerminologyCategory::SafeDownCast(aCategory);
vtkSlicerTerminologyCategory* aTerminologyCategory = vtkSlicerTerminologyCategory::SafeDownCast(aCategory);
if (!aTerminologyCategory)
{
vtkErrorMacro("Copy: Input type is not a vtkSlicerTerminologyCategory");
return;
}

this->SetSNOMEDCTConceptID(aTerminologyCategory->GetSNOMEDCTConceptID());
this->SetUMLSConceptUID(aTerminologyCategory->GetUMLSConceptUID());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void vtkSlicerTerminologyType::Copy(vtkCodedEntry* aType)

this->Superclass::Copy(aType);

vtkSlicerTerminologyType *aTerminologyType = vtkSlicerTerminologyType::SafeDownCast(aType);
vtkSlicerTerminologyType* aTerminologyType = vtkSlicerTerminologyType::SafeDownCast(aType);
if (!aTerminologyType)
{
vtkErrorMacro("Copy: Input type is not a vtkSlicerTerminologyType");
Expand Down
3 changes: 3 additions & 0 deletions Modules/Loadable/Terminologies/Widgets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ set(${KIT}_INCLUDE_DIRECTORIES
)

set(${KIT}_SRCS
qMRMLSimpleColorTableView.cxx
qMRMLSimpleColorTableView.h
qSlicerTerminologyItemDelegate.cxx
qSlicerTerminologyItemDelegate.h
qSlicerTerminologyNavigatorWidget.cxx
Expand All @@ -20,6 +22,7 @@ set(${KIT}_SRCS
)

set(${KIT}_MOC_SRCS
qMRMLSimpleColorTableView.h
qSlicerTerminologyItemDelegate.h
qSlicerTerminologyNavigatorWidget.h
qSlicerTerminologySelectorButton.h
Expand Down
Loading

0 comments on commit 87580be

Please sign in to comment.