From 7ef8cbc0dbe770449089f9b9a4f54d5ca828c4ca Mon Sep 17 00:00:00 2001 From: blacksun Date: Thu, 7 May 2015 22:15:00 +0000 Subject: [PATCH] Diagram editor : add dock widget for edit the current selection. For the moment only work with element git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3943 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- qelectrotech.pro | 2 + sources/PropertiesEditor/PropertiesEditor.pri | 10 ++ .../propertieseditordockwidget.cpp | 160 ++++++++++++++++++ .../propertieseditordockwidget.h | 57 +++++++ .../propertieseditordockwidget.ui | 52 ++++++ .../propertieseditorwidget.cpp | 0 .../propertieseditorwidget.h | 0 sources/qetdiagrameditor.cpp | 32 +++- sources/qetdiagrameditor.h | 4 + .../ui/diagrampropertieseditordockwidget.cpp | 88 ++++++++++ .../ui/diagrampropertieseditordockwidget.h | 42 +++++ sources/ui/elementinfowidget.h | 2 +- sources/ui/elementpropertieswidget.h | 2 +- sources/ui/elementselectorwidget.cpp | 15 +- sources/ui/elementselectorwidget.h | 5 +- sources/ui/linksingleelementwidget.h | 2 +- sources/ui/masterpropertieswidget.cpp | 31 +++- sources/ui/masterpropertieswidget.h | 10 +- 18 files changed, 494 insertions(+), 20 deletions(-) create mode 100755 sources/PropertiesEditor/PropertiesEditor.pri create mode 100644 sources/PropertiesEditor/propertieseditordockwidget.cpp create mode 100644 sources/PropertiesEditor/propertieseditordockwidget.h create mode 100644 sources/PropertiesEditor/propertieseditordockwidget.ui rename sources/{ui => PropertiesEditor}/propertieseditorwidget.cpp (100%) rename sources/{ui => PropertiesEditor}/propertieseditorwidget.h (100%) create mode 100644 sources/ui/diagrampropertieseditordockwidget.cpp create mode 100644 sources/ui/diagrampropertieseditordockwidget.h diff --git a/qelectrotech.pro b/qelectrotech.pro index 9a6dec8b0..725feee9f 100644 --- a/qelectrotech.pro +++ b/qelectrotech.pro @@ -61,6 +61,8 @@ DEFINES += QET_ALLOW_OVERRIDE_CD_OPTION ###################################################################### +include(sources/PropertiesEditor/PropertiesEditor.pri) + TEMPLATE = app DEPENDPATH += . INCLUDEPATH += sources \ diff --git a/sources/PropertiesEditor/PropertiesEditor.pri b/sources/PropertiesEditor/PropertiesEditor.pri new file mode 100755 index 000000000..05f6deea2 --- /dev/null +++ b/sources/PropertiesEditor/PropertiesEditor.pri @@ -0,0 +1,10 @@ +FORMS += \ + $$PWD/propertieseditordockwidget.ui + +HEADERS += \ + $$PWD/propertieseditordockwidget.h \ + $$PWD/propertieseditorwidget.h + +SOURCES += \ + $$PWD/propertieseditordockwidget.cpp \ + $$PWD/propertieseditorwidget.cpp diff --git a/sources/PropertiesEditor/propertieseditordockwidget.cpp b/sources/PropertiesEditor/propertieseditordockwidget.cpp new file mode 100644 index 000000000..db3d52859 --- /dev/null +++ b/sources/PropertiesEditor/propertieseditordockwidget.cpp @@ -0,0 +1,160 @@ +/* + Copyright 2006-2015 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "propertieseditordockwidget.h" +#include "ui_propertieseditordockwidget.h" +#include "propertieseditorwidget.h" + +#include + +/** + * @brief PropertiesEditorDockWidget::PropertiesEditorDockWidget + * Constructor + * @param parent : parent widget + */ +PropertiesEditorDockWidget::PropertiesEditorDockWidget(QWidget *parent) : + QDockWidget(parent), + ui(new Ui::PropertiesEditorDockWidget) +{ + ui->setupUi(this); + ui->m_main_vlayout->setAlignment(ui->buttonBox, Qt::AlignBottom); + ui->buttonBox->setDisabled(true); +} + +/** + * @brief PropertiesEditorDockWidget::~PropertiesEditorDockWidget + * Destructor + */ +PropertiesEditorDockWidget::~PropertiesEditorDockWidget() +{ + clear(); + delete ui; +} + +/** + * @brief PropertiesEditorDockWidget::clear + * Remove all editor present in this dock and delete it. + * They also disabled the button box at the bottom of this dock + */ +void PropertiesEditorDockWidget::clear() +{ + foreach (PropertiesEditorWidget *editor, m_editor_list) + { + m_editor_list.removeOne(editor); + ui->m_main_vlayout->removeWidget(editor); + editor->deleteLater(); + } + + m_editor_list.clear(); + + ui->buttonBox->setDisabled(true); +} + +/** + * @brief PropertiesEditorDockWidget::apply + * Call the apply method for each editor present in this dock + */ +void PropertiesEditorDockWidget::apply() +{ + foreach(PropertiesEditorWidget *editor, m_editor_list) + editor->apply(); +} + +/** + * @brief PropertiesEditorDockWidget::reset + * Call the reset method for each editor present in this widget + */ +void PropertiesEditorDockWidget::reset() +{ + foreach(PropertiesEditorWidget *editor, m_editor_list) + editor->reset(); +} + +/** + * @brief PropertiesEditorDockWidget::addEditor + * Add an @editor in this dock at @index in the main vertical layout (note the button box + * are displayed at bottom of this layout by default) + * When an editor is added, we enable the button box + * @param editor : editor to add; + * @param index : index of editor in the layout + * @return true if was added (or already add) or false if can't be add (editor = nullptr) + */ +bool PropertiesEditorDockWidget::addEditor(PropertiesEditorWidget *editor, int index) +{ + if (!editor) return false; + if (m_editor_list.contains(editor)) return true; + + ui -> m_main_vlayout -> insertWidget(index, editor); + m_editor_list << editor; + setEnabledButtonBox(true); + return true; +} + +/** + * @brief PropertiesEditorDockWidget::removeEditor + * Remove @editor from this dock. The editor wasn't delete a the end of this method + * If the editor was the last on this widget, we disabled the button box + * @param editor : editor to remove + * @return true on success, else false + */ +bool PropertiesEditorDockWidget::removeEditor(PropertiesEditorWidget *editor) +{ + bool result = m_editor_list.removeOne(editor); + if (result) + ui -> m_main_vlayout -> removeWidget(editor); + + if (m_editor_list.isEmpty()) + setDisabledButtonBox(true); + return result; +} + +/** + * @brief PropertiesEditorDockWidget::setDisabledButtonBox + * Disabled the button box at bottom of dock + * @param b + */ +void PropertiesEditorDockWidget::setDisabledButtonBox(bool b) { + ui -> buttonBox -> setDisabled(b); +} + +/** + * @brief PropertiesEditorDockWidget::setEnabledButtonBox + * Enabled button box at bottom of dock + * @param b + */ +void PropertiesEditorDockWidget::setEnabledButtonBox(bool b) { + ui -> buttonBox -> setEnabled(b); +} + +/** + * @brief PropertiesEditorDockWidget::on_buttonBox_clicked + * Action when button box button is clciked. + * If button is ApplyRole : call the apply() method + * If button is ResetRole : call the reset() method + * @param button + */ +void PropertiesEditorDockWidget::on_buttonBox_clicked(QAbstractButton *button) +{ + int answer = ui->buttonBox->buttonRole(button); + + switch (answer) + { + case QDialogButtonBox::ApplyRole: apply(); break; + case QDialogButtonBox::ResetRole: reset(); break; + default: break; + } +} diff --git a/sources/PropertiesEditor/propertieseditordockwidget.h b/sources/PropertiesEditor/propertieseditordockwidget.h new file mode 100644 index 000000000..6542d2891 --- /dev/null +++ b/sources/PropertiesEditor/propertieseditordockwidget.h @@ -0,0 +1,57 @@ +/* + Copyright 2006-2015 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef SELECTIONPROPERTIESDOCKWIDGET_H +#define SELECTIONPROPERTIESDOCKWIDGET_H + +#include + +class PropertiesEditorWidget; +class QAbstractButton; + +namespace Ui { + class PropertiesEditorDockWidget; +} + +class PropertiesEditorDockWidget : public QDockWidget +{ + Q_OBJECT + + public: + explicit PropertiesEditorDockWidget(QWidget *parent = 0); + ~PropertiesEditorDockWidget(); + + virtual void clear(); + virtual void apply(); + virtual void reset(); + bool addEditor (PropertiesEditorWidget *editor, int index = 0); + bool removeEditor (PropertiesEditorWidget *editor); + void setDisabledButtonBox(bool b = true); + void setEnabledButtonBox (bool b = true); + + + private slots: + void on_buttonBox_clicked(QAbstractButton *button); + + protected: + QList m_editor_list; + + private: + Ui::PropertiesEditorDockWidget *ui; +}; + +#endif // SELECTIONPROPERTIESDOCKWIDGET_H diff --git a/sources/PropertiesEditor/propertieseditordockwidget.ui b/sources/PropertiesEditor/propertieseditordockwidget.ui new file mode 100644 index 000000000..1eaf839ab --- /dev/null +++ b/sources/PropertiesEditor/propertieseditordockwidget.ui @@ -0,0 +1,52 @@ + + + PropertiesEditorDockWidget + + + + 0 + 0 + 400 + 300 + + + + Propriété de la séléction + + + + + QLayout::SetMaximumSize + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + QDialogButtonBox::Apply|QDialogButtonBox::RestoreDefaults + + + false + + + + + + + + + + + diff --git a/sources/ui/propertieseditorwidget.cpp b/sources/PropertiesEditor/propertieseditorwidget.cpp similarity index 100% rename from sources/ui/propertieseditorwidget.cpp rename to sources/PropertiesEditor/propertieseditorwidget.cpp diff --git a/sources/ui/propertieseditorwidget.h b/sources/PropertiesEditor/propertieseditorwidget.h similarity index 100% rename from sources/ui/propertieseditorwidget.h rename to sources/PropertiesEditor/propertieseditorwidget.h diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index a8035f39b..02b649a67 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -39,6 +39,7 @@ #include "dveventaddshape.h" #include "dveventaddtext.h" #include "reportproperties.h" +#include "diagrampropertieseditordockwidget.h" #include "ui/dialogautonum.h" @@ -82,6 +83,7 @@ QETDiagramEditor::QETDiagramEditor(const QStringList &files, QWidget *parent) : setUpElementsPanel(); setUpUndoStack(); + setUpSelectionPropertiesEditor(); setUpActions(); setUpToolBar(); setUpMenu(); @@ -172,6 +174,17 @@ void QETDiagramEditor::setUpUndoStack() { addDockWidget(Qt::LeftDockWidgetArea, qdw_undo); } +/** + * @brief QETDiagramEditor::setUpSelectionPropertiesEditor + * Setup the dock for edit the current selection + */ +void QETDiagramEditor::setUpSelectionPropertiesEditor() +{ + m_selection_properties_editor = new DiagramPropertiesEditorDockWidget(this); + m_selection_properties_editor -> setObjectName("diagram_properties_editor_dock_widget"); + addDockWidget(Qt::RightDockWidgetArea, m_selection_properties_editor); +} + /** * @brief QETDiagramEditor::setUpActions * Set up all Qaction @@ -727,7 +740,7 @@ bool QETDiagramEditor::openProject() { bool QETDiagramEditor::closeProject(ProjectView *project_view) { if (project_view) { activateProject(project_view); - if (QMdiSubWindow *sub_window = subWindowForWidget(project_view)) { + if (QMdiSubWindow *sub_window = subWindowForWidget(project_view)){ return(sub_window -> close()); } } @@ -1217,7 +1230,7 @@ void QETDiagramEditor::slot_updateUndoStack() void QETDiagramEditor::slot_updateComplexActions() { DiagramView *dv = currentDiagram(); bool editable_diagram = (dv && !dv -> diagram() -> isReadOnly()); - + //Number of selected conductors int selected_conductors_count = dv ? dv -> diagram() -> selectedConductors().count() : 0; conductor_reset -> setEnabled(editable_diagram && selected_conductors_count); @@ -1961,7 +1974,7 @@ void QETDiagramEditor::removeDiagramFromProject() { */ void QETDiagramEditor::diagramWasAdded(DiagramView *dv) { - connect(dv, SIGNAL(selectionChanged()), this, SLOT(slot_updateComplexActions())); + connect(dv, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); connect(dv, SIGNAL(modeChanged()), this, SLOT(slot_updateModeActions())); connect(dv, SIGNAL(itemAdded()), this, SLOT(addItemFinish())); } @@ -2071,6 +2084,19 @@ void QETDiagramEditor::subWindowActivated(QMdiSubWindow *subWindows) slot_updateWindowsMenu(); } +/** + * @brief QETDiagramEditor::selectionChanged + * This slot is called when a diagram selection was changed. + */ +void QETDiagramEditor::selectionChanged() +{ + slot_updateComplexActions(); + + DiagramView *dv = currentDiagram(); + if (dv && dv->diagram()) + m_selection_properties_editor->setDiagram(dv->diagram()); +} + /** * @brief QETDiagramEditor::activeUndoStackCleanChanged * Enable the QAction save_file when @clean is set to false diff --git a/sources/qetdiagrameditor.h b/sources/qetdiagrameditor.h index 3ff17453c..8ecefc455 100644 --- a/sources/qetdiagrameditor.h +++ b/sources/qetdiagrameditor.h @@ -30,6 +30,7 @@ class Element; class ElementsPanelWidget; class ElementsLocation; class RecentFiles; +class DiagramPropertiesEditorDockWidget; /** This class represents the main window of the QElectroTech diagram editor and, ipso facto, the most important part of the QElectroTech user interface. @@ -48,6 +49,7 @@ class QETDiagramEditor : public QETMainWindow { private: void setUpElementsPanel (); void setUpUndoStack (); + void setUpSelectionPropertiesEditor(); void setUpActions (); void setUpToolBar (); void setUpMenu (); @@ -161,6 +163,7 @@ class QETDiagramEditor : public QETMainWindow { void subWindowActivated(QMdiSubWindow *subWindows); private slots: + void selectionChanged(); void activeUndoStackCleanChanged (bool clean); // attributes @@ -225,6 +228,7 @@ class QETDiagramEditor : public QETMainWindow { QDockWidget *qdw_pa; /// Dock for the undo list QDockWidget *qdw_undo; + DiagramPropertiesEditorDockWidget *m_selection_properties_editor; /// Elements panel ElementsPanelWidget *pa; QMenu *windows_menu; diff --git a/sources/ui/diagrampropertieseditordockwidget.cpp b/sources/ui/diagrampropertieseditordockwidget.cpp new file mode 100644 index 000000000..6851ed1d3 --- /dev/null +++ b/sources/ui/diagrampropertieseditordockwidget.cpp @@ -0,0 +1,88 @@ +/* + Copyright 2006-2015 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "diagrampropertieseditordockwidget.h" +#include "elementpropertieswidget.h" +#include "diagram.h" +#include "element.h" + +/** + * @brief DiagramPropertiesEditorDockWidget::DiagramPropertiesEditorDockWidget + * Constructor + * @param parent : parent widget + */ +DiagramPropertiesEditorDockWidget::DiagramPropertiesEditorDockWidget(QWidget *parent) : + PropertiesEditorDockWidget(parent), + m_diagram(nullptr) +{} + +/** + * @brief DiagramPropertiesEditorDockWidget::setDiagram + * Set the diagram to edit the selection. + * Connect the diagram signal selectionChanged() to this slot selectionChanged(); + * If diagram = nullptr, we just disconnect all signal and remove editor. + * @param diagram + * @param diagram + */ +void DiagramPropertiesEditorDockWidget::setDiagram(Diagram *diagram) +{ + if (m_diagram == diagram) return; + clear(); + + if (m_diagram) + { + disconnect(m_diagram, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); + disconnect(m_diagram, SIGNAL(destroyed()), this, SLOT(diagramWasDeleted())); + } + + if (diagram) + { + m_diagram = diagram; + connect(m_diagram, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); + connect(m_diagram, SIGNAL(destroyed()), this, SLOT(diagramWasDeleted())); + selectionChanged(); + } + else + m_diagram = nullptr; +} + +/** + * @brief DiagramPropertiesEditorDockWidget::selectionChanged + * The current selection of diagram was changed. + * We fill the dock with the appropriate ElementPropertiesWidget of the current selection. + */ +void DiagramPropertiesEditorDockWidget::selectionChanged() +{ + if (!m_diagram) return; + clear(); + if (m_diagram->selectedItems().size() == 1) + { + QGraphicsItem *item = m_diagram->selectedItems().first(); + if (Element *elmt = dynamic_cast(item)) + addEditor(new ElementPropertiesWidget(elmt, this)); + } +} + +/** + * @brief DiagramPropertiesEditorDockWidget::diagramWasDeleted + * Remove current editor and set m_diagram to nullptr. + */ +void DiagramPropertiesEditorDockWidget::diagramWasDeleted() +{ + m_diagram = nullptr; + clear(); +} diff --git a/sources/ui/diagrampropertieseditordockwidget.h b/sources/ui/diagrampropertieseditordockwidget.h new file mode 100644 index 000000000..0922de050 --- /dev/null +++ b/sources/ui/diagrampropertieseditordockwidget.h @@ -0,0 +1,42 @@ +/* + Copyright 2006-2015 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef DIAGRAMPROPERTIESEDITORDOCKWIDGET_H +#define DIAGRAMPROPERTIESEDITORDOCKWIDGET_H + +#include "PropertiesEditor/propertieseditordockwidget.h" + +class Diagram; + +class DiagramPropertiesEditorDockWidget : public PropertiesEditorDockWidget +{ + Q_OBJECT + + public: + DiagramPropertiesEditorDockWidget(QWidget *parent = nullptr); + + void setDiagram(Diagram *diagram); + + private slots: + void selectionChanged(); + void diagramWasDeleted(); + + private: + Diagram *m_diagram; +}; + +#endif // DIAGRAMPROPERTIESEDITORDOCKWIDGET_H diff --git a/sources/ui/elementinfowidget.h b/sources/ui/elementinfowidget.h index 4f053cac6..d3ef9a5a6 100644 --- a/sources/ui/elementinfowidget.h +++ b/sources/ui/elementinfowidget.h @@ -20,7 +20,7 @@ #include #include "diagramcontext.h" -#include "propertieseditorwidget.h" +#include "PropertiesEditor/propertieseditorwidget.h" class Element; class QUndoCommand; diff --git a/sources/ui/elementpropertieswidget.h b/sources/ui/elementpropertieswidget.h index da50d78e2..531ece4c5 100644 --- a/sources/ui/elementpropertieswidget.h +++ b/sources/ui/elementpropertieswidget.h @@ -18,7 +18,7 @@ #ifndef ELEMENTPROPERTIESWIDGET_H #define ELEMENTPROPERTIESWIDGET_H -#include "propertieseditorwidget.h" +#include "PropertiesEditor/propertieseditorwidget.h" class Element; class Diagram; diff --git a/sources/ui/elementselectorwidget.cpp b/sources/ui/elementselectorwidget.cpp index 23d7269a5..ba075f6d7 100644 --- a/sources/ui/elementselectorwidget.cpp +++ b/sources/ui/elementselectorwidget.cpp @@ -62,10 +62,15 @@ ElementSelectorWidget::~ElementSelectorWidget() * @param elmt */ void ElementSelectorWidget::showElement(Element *elmt) { - if (showed_element) showed_element->setHighlighted(false); + if (showed_element) + { + disconnect(showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted())); + showed_element->setHighlighted(false); + } elmt->diagram()->showMe(); elmt->setHighlighted(true); showed_element = elmt; + connect(showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted())); } /** @@ -224,6 +229,14 @@ void ElementSelectorWidget::showElementFromList(const int i) { showElement(elements_list.at(i)); } +/** + * @brief ElementSelectorWidget::showedElementWasDeleted + * Set to nullptr the current showed element when he was deleted + */ +void ElementSelectorWidget::showedElementWasDeleted() { + showed_element = nullptr; +} + /** * @brief ElementSelectorWidget::filter * @return A stringlist with all available value diff --git a/sources/ui/elementselectorwidget.h b/sources/ui/elementselectorwidget.h index 461084267..85133c4c5 100644 --- a/sources/ui/elementselectorwidget.h +++ b/sources/ui/elementselectorwidget.h @@ -55,8 +55,9 @@ class ElementSelectorWidget : public QWidget void buildInterface(); private slots: - void setSelectedElement (const int i) {selected_element = elements_list.at(i);} - void showElementFromList (const int i); + void setSelectedElement (const int i) {selected_element = elements_list.at(i);} + void showElementFromList (const int i); + void showedElementWasDeleted (); ///Attributes diff --git a/sources/ui/linksingleelementwidget.h b/sources/ui/linksingleelementwidget.h index dd1f972e9..eb1a52ced 100644 --- a/sources/ui/linksingleelementwidget.h +++ b/sources/ui/linksingleelementwidget.h @@ -18,7 +18,7 @@ #ifndef LINKSINGLEELEMENTWIDGET_H #define LINKSINGLEELEMENTWIDGET_H -#include "propertieseditorwidget.h" +#include "PropertiesEditor/propertieseditorwidget.h" #include "element.h" class Diagram; diff --git a/sources/ui/masterpropertieswidget.cpp b/sources/ui/masterpropertieswidget.cpp index 21853848a..08158d854 100644 --- a/sources/ui/masterpropertieswidget.cpp +++ b/sources/ui/masterpropertieswidget.cpp @@ -33,7 +33,8 @@ MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) : PropertiesEditorWidget(parent), ui(new Ui::MasterPropertiesWidget), - element_(elmt) + element_(elmt), + m_showed_element (nullptr) { ui->setupUi(this); buildInterface(); @@ -47,7 +48,8 @@ MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) : */ MasterPropertiesWidget::~MasterPropertiesWidget() { - foreach(Element *elmt, lwi_hash.values()) elmt->setHighlighted(false); + if (m_showed_element) m_showed_element->setHighlighted(false); + //foreach(Element *elmt, lwi_hash.values()) elmt->setHighlighted(false); delete ui; } @@ -184,9 +186,24 @@ void MasterPropertiesWidget::on_unlink_button_clicked() { * Show the element corresponding to the given QListWidgetItem * @param lwi */ -void MasterPropertiesWidget::showElementFromLWI(QListWidgetItem *lwi) { - foreach(Element *elmt, lwi_hash.values()) elmt->setHighlighted(false); - Element *elmt = lwi_hash[lwi]; - elmt->diagram()->showMe(); - elmt->setHighlighted(true); +void MasterPropertiesWidget::showElementFromLWI(QListWidgetItem *lwi) +{ + if (m_showed_element) + { + disconnect(m_showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted())); + m_showed_element -> setHighlighted(false); + } + + m_showed_element = lwi_hash[lwi]; + m_showed_element->diagram()->showMe(); + m_showed_element->setHighlighted(true); + connect(m_showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted())); +} + +/** + * @brief MasterPropertiesWidget::showedElementWasDeleted + * Set to nullptr the current showed element when he was deleted + */ +void MasterPropertiesWidget::showedElementWasDeleted() { + m_showed_element = nullptr; } diff --git a/sources/ui/masterpropertieswidget.h b/sources/ui/masterpropertieswidget.h index 21c102c96..1c9f564f0 100644 --- a/sources/ui/masterpropertieswidget.h +++ b/sources/ui/masterpropertieswidget.h @@ -20,7 +20,7 @@ #include #include -#include +#include "PropertiesEditor/propertieseditorwidget.h" class QListWidgetItem; class Element; @@ -53,14 +53,16 @@ class MasterPropertiesWidget : public PropertiesEditorWidget void buildInterface(); private slots: - void on_link_button_clicked(); - void on_unlink_button_clicked(); - void showElementFromLWI(QListWidgetItem *lwi); + void on_link_button_clicked(); + void on_unlink_button_clicked(); + void showElementFromLWI(QListWidgetItem *lwi); + void showedElementWasDeleted (); private: Ui::MasterPropertiesWidget *ui; Element *element_; QHash lwi_hash; + Element *m_showed_element; }; #endif // MASTERPROPERTIESWIDGET_H