Commit a80dfa4a authored by finetjul's avatar finetjul

ENH: Cleanup qSlicerMouseModeToolBar

Allows to programatically set the default action without activating
the place mode:
 - vtkMRMLSelectionNode::SetActiveAnnotationID
Don't listen to unnecessary events like ActiveAnnotationIDChangedEvent,
AnnotationIDListModifiedEvent, InteractionModePersistenceChangedEvent.
Listening to ModifiedEvent is enough.
Todo: remove the unnecessary events.

git-svn-id: http://svn.slicer.org/Slicer4/trunk@21555 3bd1e089-480b-0410-8dfb-8563597acbee
parent 332bd65b
This diff is collapsed.
......@@ -33,12 +33,16 @@ class vtkMRMLScene;
class vtkSlicerApplicationLogic;
///
/// qSlicerMouseModeToolBar is a toolbar that can be used to switch between
/// qSlicerMouseModeToolBar is a toolbar that can be used to switch between
/// mouse modes: PickMode, PickModePersistent, PlaceMode, PlaceModePersistent, TransformMode
/// \note The toolbar expects qSlicerCoreApplication::mrmlApplicationLogic() to return a valid object
/// qSlicerMouseModeToolBar observes the singletons selection node and
/// interaction node to control its state.
class Q_SLICER_BASE_QTGUI_EXPORT qSlicerMouseModeToolBar: public QToolBar
{
Q_OBJECT
/// "vtkMRMLAnnotationFiducialNode" by default.
Q_PROPERTY(QString defaultAnnotation READ defaultAnnotation WRITE setDefaultAnnotation)
public:
typedef QToolBar Superclass;
......@@ -51,10 +55,16 @@ public:
/// For testing, return the active action text
QString activeActionText();
QString defaultAnnotation()const;
void setDefaultAnnotation(const QString& annotation);
public slots:
/// Set the application logic. It is used to retrieve the selection and
/// interaction nodes.
void setApplicationLogic(vtkSlicerApplicationLogic* logic);
/// Observe the mrml scene to prevent updates in batch processing modes.
void setMRMLScene(vtkMRMLScene* newScene);
void switchToViewTransformMode();
......@@ -70,7 +80,7 @@ public slots:
protected:
QScopedPointer<qSlicerMouseModeToolBarPrivate> d_ptr;
bool isActionTextInMenu(QString actionText, QMenu *menu);
QAction* actionFromText(QString actionText, QMenu *menu);
private:
Q_DECLARE_PRIVATE(qSlicerMouseModeToolBar);
Q_DISABLE_COPY(qSlicerMouseModeToolBar);
......
......@@ -63,22 +63,20 @@ public:
void init();
void setMRMLScene(vtkMRMLScene* newScene);
void updateWidgetFromMRML();
void updateWidgetFromSelectionNode();
/// given an annotation id, find the action associated with it and set it
/// checked, update the cursor, update the icon on the button
void updateWidgetToAnnotation(const char *annotationID);
public slots:
void OnMRMLSceneStartClose();
void OnMRMLSceneEndImport();
void OnMRMLSceneEndClose();
void onMRMLSceneStartBatchProcess();
void onMRMLSceneEndBatchProcess();
void updateWidgetFromSelectionNode();
void updateWidgetFromInteractionNode();
void onInteractionNodeModeChangedEvent();
void onInteractionNodeModePersistenceChanged();
void onActiveAnnotationIDChangedEvent();
void onAnnotationIDListModifiedEvent();
public:
vtkSmartPointer<vtkMRMLScene> MRMLScene;
......@@ -94,6 +92,7 @@ public:
/// Group the place actions together so that they're exclusive
QActionGroup* ActionGroup;
QString DefaultAnnotation;
};
#endif
......@@ -75,6 +75,7 @@ void vtkMRMLInteractionNode::SetPlaceModePersistence ( int val )
{
this->PlaceModePersistence = val;
this->InvokeEvent(this->InteractionModePersistenceChangedEvent, NULL);
this->Modified();
}
}
......@@ -85,6 +86,7 @@ void vtkMRMLInteractionNode::SetTransformModePersistence ( int val )
{
this->TransformModePersistence = val;
this->InvokeEvent(this->InteractionModePersistenceChangedEvent, NULL);
this->Modified();
}
}
......@@ -125,6 +127,7 @@ void vtkMRMLInteractionNode::SetCurrentInteractionMode ( int mode )
default:
break;
}
this->Modified();
}
//----------------------------------------------------------------------------
......
......@@ -356,6 +356,7 @@ void vtkMRMLSelectionNode::AddNewAnnotationIDToList(const char *newID, const cha
this->InvokeEvent(vtkMRMLSelectionNode::AnnotationIDListModifiedEvent);
}
}
this->Modified();
}
//----------------------------------------------------------------------------
......@@ -387,7 +388,9 @@ void vtkMRMLSelectionNode::RemoveAnnotationIDFromList(const char *id)
this->SetActiveAnnotationID(NULL);
}
this->InvokeEvent(vtkMRMLSelectionNode::AnnotationIDListModifiedEvent);
}
this->Modified();
}
//----------------------------------------------------------------------------
std::string vtkMRMLSelectionNode::GetAnnotationIDByIndex(int n)
{
......@@ -443,3 +446,10 @@ std::string vtkMRMLSelectionNode::GetAnnotationResourceByID(std::string id)
}
return resource;
}
//----------------------------------------------------------------------------
void vtkMRMLSelectionNode::SetReferenceActiveAnnotationID (const char *id)
{
this->SetActiveAnnotationID(id);
this->InvokeEvent(vtkMRMLSelectionNode::ActiveAnnotationIDChangedEvent);
}
......@@ -89,11 +89,15 @@ class VTK_MRML_EXPORT vtkMRMLSelectionNode : public vtkMRMLNode
void SetActiveFiducialListID(const char* id);
void SetReferenceActiveFiducialListID (const char *id) { this->SetActiveFiducialListID(id); };
///
/// the ID of a MRMLAnnotationNode
/// Set/Get the classname of the active annotation type.
/// The active annotation is used to control what annotation is being
/// dropped by the user.
vtkGetStringMacro (ActiveAnnotationID);
void SetActiveAnnotationID(const char* id);
void SetReferenceActiveAnnotationID (const char *id) { this->SetActiveAnnotationID(id); this->InvokeEvent(vtkMRMLSelectionNode::ActiveAnnotationIDChangedEvent); };
/// Set the active annotation id and fire the event
/// ActiveAnnotationIDChangedEvent.
void SetReferenceActiveAnnotationID (const char *id);
/// the ID of a MRMLROIList
vtkGetStringMacro (ActiveROIListID);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment