diff --git a/sources/ui/elementinfowidget.cpp b/sources/ui/elementinfowidget.cpp index 4611155f5..786c03f71 100644 --- a/sources/ui/elementinfowidget.cpp +++ b/sources/ui/elementinfowidget.cpp @@ -59,12 +59,12 @@ void ElementInfoWidget::setElement(Element *element) if (m_element == element) return; if (m_element) - disconnect(m_element, &Element::elementInfoChange, this, &ElementInfoWidget::updateUi); + disconnect(m_element, &Element::elementInfoChange, this, &ElementInfoWidget::elementInfoChange); m_element = element; updateUi(); - connect(m_element, &Element::elementInfoChange, this, &ElementInfoWidget::updateUi); + connect(m_element, &Element::elementInfoChange, this, &ElementInfoWidget::elementInfoChange); } /** @@ -87,18 +87,9 @@ void ElementInfoWidget::apply() */ QUndoCommand* ElementInfoWidget::associatedUndo() const { - DiagramContext new_info; + DiagramContext new_info = currentInfo(); DiagramContext old_info = m_element -> elementInformations(); - foreach (ElementInfoPartWidget *eipw, m_eipw_list) - { - //add value only if they're something to store - if (!eipw->text().isEmpty()) - new_info.addValue(eipw->key(), - eipw->text(), - eipw->mustShow()); - } - if (old_info != new_info) return (new ChangeElementInformationCommand(m_element, old_info, new_info)); @@ -214,6 +205,21 @@ void ElementInfoWidget::updateUi() if (m_live_edit) enableLiveEdit(); } +/** + * @brief ElementInfoWidget::currentInfo + * @return the info currently edited + */ +DiagramContext ElementInfoWidget::currentInfo() const +{ + DiagramContext info_; + + foreach (ElementInfoPartWidget *eipw, m_eipw_list) + if (!eipw->text().isEmpty()) //add value only if they're something to store + info_.addValue(eipw->key(), eipw->text(), eipw->mustShow()); + + return info_; +} + /** * @brief ElementInfoWidget::firstActivated * Slot activated when this widget is show. @@ -222,3 +228,13 @@ void ElementInfoWidget::updateUi() void ElementInfoWidget::firstActivated() { m_eipw_list.first() -> setFocusTolineEdit(); } + +/** + * @brief ElementInfoWidget::elementInfoChange + * This slot is called when m_element::elementInformation change. + */ +void ElementInfoWidget::elementInfoChange() +{ + if(currentInfo() != m_element->elementInformations()) + updateUi(); +} diff --git a/sources/ui/elementinfowidget.h b/sources/ui/elementinfowidget.h index cedaa2d4b..d1615225f 100644 --- a/sources/ui/elementinfowidget.h +++ b/sources/ui/elementinfowidget.h @@ -20,6 +20,7 @@ #include #include "abstractelementpropertieseditorwidget.h" +#include "diagramcontext.h" class Element; class QUndoCommand; @@ -49,6 +50,8 @@ class ElementInfoWidget : public AbstractElementPropertiesEditorWidget QString title() const {return tr("Informations");} bool setLiveEdit(bool live_edit); virtual void updateUi(); + DiagramContext currentInfo() const; + protected: virtual bool event(QEvent *event); @@ -60,6 +63,7 @@ class ElementInfoWidget : public AbstractElementPropertiesEditorWidget private slots: void firstActivated(); + void elementInfoChange(); //ATTRIBUTES private: