Commit 3571e27e authored by Emmanuel Promayon's avatar Emmanuel Promayon

FIXED closes #32 (no refreshInterfaceNode needed anymore)

That cleans up the Viewer abstract class and this little breach in CamiTK
architecture principle
parent 3e9cdd74
......@@ -170,11 +170,11 @@ void MMLComponent::connectPml() {
delete pmlComponent;
pmlComponent = nullptr;
deleteChildren();
refreshInterfaceNode();
// this gives the ownership of pml pointer to the PML Component, use takePml() not getPml()
pmlComponent = new PMLComponent(mmlGUI->getMonitoringManager()->takePml(), mmlGUI->getMonitoringManager()->getPmlFileName().c_str());
addChild(pmlComponent);
refreshInterfaceNode();
refresh();
// This is forced refresh (bad, breaking rules)
// TODO: refresh should be called in the MMLDisplay connectPml() method instead)
......
......@@ -326,6 +326,11 @@ int Application::exec() {
void Application::refresh() {
if (mainWindow != nullptr)
mainWindow->refresh();
// now that every viewer was refresh, clear the interface node modification flag
for(Component *c: Application::getAllComponents()) {
c->setNodeModified(false);
}
}
// ----------------- showStatusBarMessage --------------------
......
This diff is collapsed.
......@@ -289,7 +289,7 @@ class Frame;
* to update the internal state of your object when a dynamic property has been changed.
* @see ObjComponent for a good example
*
* It is extensively using Qt Meta-Object system (concepts and implementation).
* It extensively uses Qt Meta-Object system (concepts and implementation).
* see http://doc.qt.nokia.com/latest/metaobjects.html
*
*
......@@ -368,7 +368,7 @@ public:
///@cond
/**
* TODO CAMITK_API_DEPRECATED. This section list all the methods marked as deprecated. They are to be removed in CamiTK 5.0
* TODO CAMITK_API_DEPRECATED. This section list the methods marked as deprecated. They are to be removed in CamiTK 5.0
* @deprecated
*
* DEPRECATED (CamiTK 5.0) -> to be removed
......@@ -388,16 +388,27 @@ public:
virtual bool getVisibility(QString) const;
/// refresh all the viewer that are currently displaying this Component
virtual void refresh() const;
/// At the end the InterfaceNode modification flag is reset.
virtual void refresh();
///@cond
/**
* TODO CAMITK_API_DEPRECATED. This section list the methods marked as deprecated. They are to be removed in CamiTK 5.0
* @deprecated
*
* DEPRECATED (CamiTK 5.0) -> to be removed
* refreshInterfaceNode() is not required anymore. Everything should now be done transparently (if it does work, use setNodeModified(true) to force a specific InterfaceNode refresh instead)
*/
/** Asks all viewers that are currently displaying this Component to
* rebuild the representation of the InterfaceNode for this Component.
* It calls the method update(Component *) of the class Viewer.
* This method does nothing except for the Explorer where it does not only refresh,
* but remove this and re-load the Component.
*/
virtual void refreshInterfaceNode();
CAMITK_API_DEPRECATED("refreshInterfaceNode() is not required anymore. Everything should now be done transparently (if it does work, use setNodeModified(true) to force a specific InterfaceNode refresh instead)") virtual void refreshInterfaceNode();
///@endcond
/// Check if this data component is selected
virtual bool isSelected() const;
......@@ -475,7 +486,7 @@ public:
* @see PropertyExplorer
**/
inline void setIndexOfPropertyExplorerTab(unsigned int index) override {
this->indexOfPropertyExplorerTab = index;
indexOfPropertyExplorerTab = index;
}
/**
......@@ -486,7 +497,7 @@ public:
* @see PropertyExplorer
**/
inline unsigned int getIndexOfPropertyExplorerTab() override {
return this->indexOfPropertyExplorerTab;
return indexOfPropertyExplorerTab;
}
/** Get a Property given its name
......@@ -513,25 +524,31 @@ public:
* All the implemented InterfaceNode methods
*/
///@{
//-- the methods below are commented because the default comment in InterfaceNode lacks some information...
void addChild(InterfaceNode*) override;
void attachChild(InterfaceNode*) override;
/** remove from the the sub item vector.
* This method automatically update the parentComponent of (set to NULL).
/** remove a child node.
* This method automatically update the parentComponent of the given InterfaceNode (it is set to nullptr).
*/
void removeChild(InterfaceNode*) override;
/// set the parent Component. This method automatically remove this Component from its previous (if already had one parent Component)
/// set the parent Component.
/// This method automatically remove this Component from its previous parent (if it already had one parent Component)
void setParent(InterfaceNode*) override;
//--not commented because Doxygen automatically use the inherited documentation (set INHERIT_DOCS flag to YES in the Doxyfile)
/// This method is called each time the InterfaceNode is double clicked by
/// the user.
/// It returns false by default. You must overload this method in Components to change its behaviour.
bool doubleClicked() override;
//-- not commented because Doxygen automatically use the inherited documentation (set INHERIT_DOCS flag to YES in the Doxyfile)
void addChild(InterfaceNode*) override;
void attachChild(InterfaceNode*) override;
void deleteChildren() override;
QString getName() const override;
void setName(const QString&) override;
const ComponentList& getChildren() override;
bool doubleClicked() override;
InterfaceNode* getParent() override;
QPixmap getIcon() override;
void setNodeModified(bool) override;
bool getNodeModified() const override;
/** A component name is not displayed in italic by default.
* You must redefine this method in you inherited Component to change this behaviour.
......@@ -642,8 +659,6 @@ public:
*/
void cellPicked(vtkIdType, bool) override {}
// --
/// compute the object's bounding box [xmin,xmax, ymin,ymax, zmin,zmax], see Component.cpp
void getBounds(double* bounds) override;
......@@ -816,7 +831,7 @@ protected:
/// tells if this particular Component is selected or not
bool isSelectedFlag;
/// the modificatio flag (could be extended to manage a undo/redo list)
/// the modification flag (could be extended to manage a undo/redo list)
bool modifiedFlag;
/// the file name from which the Component is loaded
......@@ -857,6 +872,10 @@ private:
/// list of CamiTK property decorating the dynamic properties
QMap<QString, Property*> propertyMap;
/// the InterfaceNode modification flag, if set to true, this means something changed in value linked to the Node interface
bool interfaceNodeModifiedFlag;
///@}
};
......@@ -869,7 +888,6 @@ inline bool Component::isSelected() const {
// -------------------- doubleClicked --------------------
inline bool Component::doubleClicked() {
// always false by default. You must overload this method in Components to change its behaviour.
return false;
}
......@@ -910,6 +928,8 @@ inline void Component::setName(const QString& n) {
if (myGeometry) {
myGeometry->setLabel(n);
}
setNodeModified(true);
}
// -------------------- setModified --------------------
......@@ -926,11 +946,22 @@ inline bool Component::getModified() const {
inline const QString Component::getLabel() const {
return getName();
}
// -------------------- getModified --------------------
inline void Component::setLabel(QString newName) {
setLabel(newName);
}
// -------------------- setNodeModified --------------------
inline void Component::setNodeModified(bool nodeModified) {
interfaceNodeModifiedFlag = nodeModified;
}
// -------------------- getNodeModified --------------------
inline bool Component::getNodeModified() const {
return interfaceNodeModifiedFlag;
}
}
#endif
......
......@@ -74,15 +74,7 @@ public:
* This is to be used with care. The preferred method to add a child component is
* to use the Component's constructor with the parent parameter: Component(Component *, const QString &, Representation rep) .
*
* \note
* If the use of this method does not update the new child in the Explorer, then you may
* need to force the rebuild of the explorer nodes by calling Component::refreshInterfaceNode() as follows:
* \code
* this->addChild(otherComponent);
* this->refreshInterfaceNode(); // check first without this, it should work in most of the cases.
* \endcode
*
* see attachChild() Component::refreshInterfaceNode()
* @see attachChild()
*/
virtual void addChild(InterfaceNode*) = 0;
......@@ -148,6 +140,13 @@ public:
/// get the popup menu to display (or NULL if inexistant)
virtual QMenu* getPopupMenu(QWidget* parent = nullptr) = 0;
/// Set up the node modification flag. This means that the name(s) or children hierarchy were modified
/// This can be useful information when a viewer, such as the Explorer viewer, needs to know what to refresh
virtual void setNodeModified(bool) = 0;
/// Get the current modification flag
virtual bool getNodeModified() const = 0;
};
......
......@@ -209,7 +209,6 @@ void ImageComponent::updateProperty(QString name, QVariant value) {
else
if (name == "Image Name") {
setName(value.toString());
refreshInterfaceNode();
}
// bypass read-only properties
// (other specific properties are read only and should not be sent up to Component::updateProperty)
......@@ -441,11 +440,7 @@ void ImageComponent::replaceImageData(vtkSmartPointer<vtkImageData> anImageData,
volumeRenderingChild = nullptr;
}
refreshInterfaceNode();
setImageData(anImageData, copy, initialOrientation);
refreshInterfaceNode();
}
// -------------------- getAxialSlices --------------------
......@@ -775,8 +770,8 @@ void ImageComponent::getLastPointPickedWorldCoords(double* x, double* y, double*
}
// -------------------- refresh --------------------
void ImageComponent::refresh() const {
foreach (const Component* dc, childrenComponent) {
void ImageComponent::refresh() {
foreach (Component* dc, childrenComponent) {
dc->refresh();
}
}
......
......@@ -187,9 +187,9 @@ public:
/// get the current lookup table
virtual vtkSmartPointer<vtkWindowLevelLookupTable> getLut();
/// force refresh of all interactive viewers that are displayng sub-components
/// force refresh of all interactive viewers that are displaying sub-components
/// as ImageComponent is not itself displayed by any viewer
void refresh() const override;
void refresh() override;
/** Returns the axial slice */
SingleImageComponent* getAxialSlices();
......
......@@ -182,10 +182,6 @@ public:
/// get the viewer icon
virtual QPixmap getIcon();
/// Update the whole tree of the representation of the Component.
/// Is actually useful (and defined) in Explorer.
virtual void refreshInterfaceNode(Component*) {};
/// get the list of Component class manages by this viewer
/// (default is set to "Component", i.e. all type of Component)
QStringList getComponents();
......
......@@ -163,14 +163,10 @@ void Explorer::refresh(Viewer* whoIsAsking) {
explorerTree->blockSignals(false);
}
//-- check the Component names
QMapIterator<QTreeWidgetItem*, Component*> it(itemComponentMap);
while (it.hasNext()) {
it.next();
if (it.key()->text(0) != it.value()->getName()) {
it.key()->setText(0, it.value()->getName());
// check if the InterfaceNode was modified
for(Component *c: Application::getAllComponents()) {
if (c->getNodeModified()) {
refreshInterfaceNode(c);
}
}
......
......@@ -82,14 +82,6 @@ public:
/// get the explorer menu
QMenu* getMenu() override;
/** Update the interface node representation of a given Component, (creates a new sub-item for all the new
* sub items and delete all the sub-item which are not sub items any more).
* Call this method when the Component has created a new sub-item or when it has removed one of
* its sub items.
* If the component was not displayed in the explorer, this method does nothing.
* @param comp The InterfaceNode provider to update list.
*/
void refreshInterfaceNode(camitk::Component* comp) override;
///@}
public slots :
......@@ -143,6 +135,14 @@ private:
*/
void removeTopLevel(camitk::Component* comp);
/** Update the interface node representation of a given Component, (creates a new sub-item for all the new
* sub items and delete all the sub-item which are not sub items any more).
* Call this method when the Component has created a new sub-item or when it has removed one of
* its sub items.
* If the component was not displayed in the explorer, this method does nothing.
* @param comp The InterfaceNode provider to update list.
*/
void refreshInterfaceNode(camitk::Component* comp);
/// the list view
QTreeWidget* explorerTree;
......
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