diff --git a/sources/PropertiesEditor/propertieseditorwidget.h b/sources/PropertiesEditor/propertieseditorwidget.h index 64237a9b5..04765ad5b 100644 --- a/sources/PropertiesEditor/propertieseditorwidget.h +++ b/sources/PropertiesEditor/propertieseditorwidget.h @@ -42,7 +42,7 @@ class PropertiesEditorWidget : public QWidget virtual bool setLiveEdit (bool live_edit); bool isLiveEdit() const; - private: + protected: virtual void enableLiveEdit() {} virtual void disableLiveEdit() {} diff --git a/sources/ui/masterpropertieswidget.cpp b/sources/ui/masterpropertieswidget.cpp index 53e0a0b13..cb1ecbcdc 100644 --- a/sources/ui/masterpropertieswidget.cpp +++ b/sources/ui/masterpropertieswidget.cpp @@ -70,8 +70,12 @@ void MasterPropertiesWidget::setElement(Element *element) } else m_project = nullptr; + //Keep up to date this widget when the linked elements of m_element change + if (m_element) disconnect(m_element, &Element::linkedElementChanged, this, &MasterPropertiesWidget::updateUi); m_element = element; - buildInterface(); + connect(m_element, &Element::linkedElementChanged, this, &MasterPropertiesWidget::updateUi); + + updateUi(); } /** @@ -95,7 +99,7 @@ void MasterPropertiesWidget::reset() { delete lwi; } lwi_hash.clear(); - buildInterface(); + updateUi(); } /** @@ -145,10 +149,22 @@ QUndoCommand* MasterPropertiesWidget::associatedUndo() const { } /** - * @brief MasterPropertiesWidget::buildInterface + * @brief MasterPropertiesWidget::setLiveEdit + * @param live_edit = true : live edit is enable + * else false : live edit is disable. + * @return always true because live edit is handled by this editor widget + */ +bool MasterPropertiesWidget::setLiveEdit(bool live_edit) +{ + m_live_edit = live_edit; + return true; +} + +/** + * @brief MasterPropertiesWidget::updateUi * Build the interface of the widget */ -void MasterPropertiesWidget::buildInterface() +void MasterPropertiesWidget::updateUi() { ui->free_list->clear(); ui->linked_list->clear(); @@ -193,22 +209,28 @@ void MasterPropertiesWidget::buildInterface() * @brief MasterPropertiesWidget::on_link_button_clicked * move curent item in the free_list to linked_list */ -void MasterPropertiesWidget::on_link_button_clicked() { - //take the curent item from free_list and push it to linked_list +void MasterPropertiesWidget::on_link_button_clicked() +{ + //take the curent item from free_list and push it to linked_list ui->linked_list->addItem( ui->free_list->takeItem( ui->free_list->currentRow())); + + if(m_live_edit) apply(); } /** * @brief MasterPropertiesWidget::on_unlink_button_clicked * move curent item in linked_list to free_list */ -void MasterPropertiesWidget::on_unlink_button_clicked() { - //take the curent item from linked_list and push it to free_list +void MasterPropertiesWidget::on_unlink_button_clicked() +{ + //take the curent item from linked_list and push it to free_list ui->free_list->addItem( ui->linked_list->takeItem( ui->linked_list->currentRow())); + + if(m_live_edit) apply(); } /** @@ -247,5 +269,5 @@ void MasterPropertiesWidget::diagramWasdeletedFromProject() { //We use a timer because if the removed diagram contain slave element linked to the edited element //we must to wait for this elements be unlinked, else the linked list provide deleted elements. - QTimer::singleShot(10, this, SLOT(buildInterface())); + QTimer::singleShot(10, this, SLOT(updateUi())); } diff --git a/sources/ui/masterpropertieswidget.h b/sources/ui/masterpropertieswidget.h index d0ac9be6b..c26636c68 100644 --- a/sources/ui/masterpropertieswidget.h +++ b/sources/ui/masterpropertieswidget.h @@ -43,17 +43,20 @@ class MasterPropertiesWidget : public AbstractElementPropertiesEditorWidget Q_OBJECT public: - explicit MasterPropertiesWidget(Element *elmt, QWidget *parent = 0); - ~MasterPropertiesWidget(); + explicit MasterPropertiesWidget(Element *elmt, QWidget *parent = 0); + ~MasterPropertiesWidget(); - void setElement (Element *element); - void apply(); - void reset(); - QUndoCommand *associatedUndo () const; - QString title() const {return tr("Référence croisée (maitre)");} + void setElement (Element *element); + void apply(); + void reset(); + QUndoCommand *associatedUndo () const; + QString title() const {return tr("Référence croisée (maitre)");} + bool setLiveEdit(bool live_edit); + + public slots: + void updateUi(); private slots: - void buildInterface(); void on_link_button_clicked(); void on_unlink_button_clicked(); void showElementFromLWI(QListWidgetItem *lwi);