diff --git a/sources/PropertiesEditor/propertieseditordockwidget.cpp b/sources/PropertiesEditor/propertieseditordockwidget.cpp index db3d52859..438a9f130 100644 --- a/sources/PropertiesEditor/propertieseditordockwidget.cpp +++ b/sources/PropertiesEditor/propertieseditordockwidget.cpp @@ -104,6 +104,14 @@ bool PropertiesEditorDockWidget::addEditor(PropertiesEditorWidget *editor, int i return true; } +/** + * @brief PropertiesEditorDockWidget::editors + * @return all editor used in this dock + */ +QList PropertiesEditorDockWidget::editors() const { + return m_editor_list; +} + /** * @brief PropertiesEditorDockWidget::removeEditor * Remove @editor from this dock. The editor wasn't delete a the end of this method diff --git a/sources/PropertiesEditor/propertieseditordockwidget.h b/sources/PropertiesEditor/propertieseditordockwidget.h index 6542d2891..c3f8bd8a0 100644 --- a/sources/PropertiesEditor/propertieseditordockwidget.h +++ b/sources/PropertiesEditor/propertieseditordockwidget.h @@ -39,6 +39,7 @@ class PropertiesEditorDockWidget : public QDockWidget virtual void apply(); virtual void reset(); bool addEditor (PropertiesEditorWidget *editor, int index = 0); + QList editors() const; bool removeEditor (PropertiesEditorWidget *editor); void setDisabledButtonBox(bool b = true); void setEnabledButtonBox (bool b = true); diff --git a/sources/ui/abstractelementpropertieseditorwidget.cpp b/sources/ui/abstractelementpropertieseditorwidget.cpp new file mode 100644 index 000000000..670c56968 --- /dev/null +++ b/sources/ui/abstractelementpropertieseditorwidget.cpp @@ -0,0 +1,23 @@ +/* + 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 "abstractelementpropertieseditorwidget.h" + +AbstractElementPropertiesEditorWidget::AbstractElementPropertiesEditorWidget(QWidget *parent) : + PropertiesEditorWidget(parent), + m_element (nullptr) +{} diff --git a/sources/ui/abstractelementpropertieseditorwidget.h b/sources/ui/abstractelementpropertieseditorwidget.h new file mode 100644 index 000000000..e355ca621 --- /dev/null +++ b/sources/ui/abstractelementpropertieseditorwidget.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 ABSTRACTELEMENTPROPERTIESEDITORWIDGET_H +#define ABSTRACTELEMENTPROPERTIESEDITORWIDGET_H + +#include "PropertiesEditor/propertieseditorwidget.h" + +class Element; + +/** + * @brief The AbstractElementPropertiesEditorWidget class + * This class provide common method for all widget used to edit some properties of an element + */ +class AbstractElementPropertiesEditorWidget : public PropertiesEditorWidget +{ + Q_OBJECT + public: + explicit AbstractElementPropertiesEditorWidget(QWidget *parent = 0); + virtual void setElement(Element *element) =0; + + protected: + Element *m_element; + + +}; + +#endif // ABSTRACTELEMENTPROPERTIESEDITORWIDGET_H diff --git a/sources/ui/diagrampropertieseditordockwidget.cpp b/sources/ui/diagrampropertieseditordockwidget.cpp index 1f158580e..ad7e003c1 100644 --- a/sources/ui/diagrampropertieseditordockwidget.cpp +++ b/sources/ui/diagrampropertieseditordockwidget.cpp @@ -29,7 +29,8 @@ */ DiagramPropertiesEditorDockWidget::DiagramPropertiesEditorDockWidget(QWidget *parent) : PropertiesEditorDockWidget(parent), - m_diagram(nullptr) + m_diagram(nullptr), + m_edited_qgi_type(UnknowQGIType) {} /** @@ -43,7 +44,6 @@ DiagramPropertiesEditorDockWidget::DiagramPropertiesEditorDockWidget(QWidget *pa void DiagramPropertiesEditorDockWidget::setDiagram(Diagram *diagram) { if (m_diagram == diagram) return; - clear(); if (m_diagram) { @@ -59,7 +59,10 @@ void DiagramPropertiesEditorDockWidget::setDiagram(Diagram *diagram) selectionChanged(); } else + { m_diagram = nullptr; + clear(); + } } /** @@ -70,17 +73,37 @@ void DiagramPropertiesEditorDockWidget::setDiagram(Diagram *diagram) void DiagramPropertiesEditorDockWidget::selectionChanged() { if (!m_diagram) return; - clear(); - if (m_diagram->selectedItems().size() == 1) + if (m_diagram->selectedItems().size() == 1) //We can open an editor only when there is one selected item { QGraphicsItem *item = m_diagram->selectedItems().first(); if (Element *elmt = dynamic_cast(item)) + { + if (m_edited_qgi_type == ElementQGIType && editors().size() == 1) + { + ElementPropertiesWidget *epw = dynamic_cast(editors().first()); + if (epw) //In this case we only update each editor widget with the new element instead of create new widget. + { + epw->setElement(elmt); + return; + } + } + clear(); + m_edited_qgi_type = ElementQGIType; addEditor(new ElementPropertiesWidget(elmt, this)); + } else if (DiagramImageItem *image = dynamic_cast(item)) + { + clear(); + m_edited_qgi_type = ImageQGIType; addEditor(new ImagePropertiesWidget(image, this)); + } + else + clear(); } + else + clear(); } /** diff --git a/sources/ui/diagrampropertieseditordockwidget.h b/sources/ui/diagrampropertieseditordockwidget.h index 0922de050..a599aea82 100644 --- a/sources/ui/diagrampropertieseditordockwidget.h +++ b/sources/ui/diagrampropertieseditordockwidget.h @@ -21,6 +21,7 @@ #include "PropertiesEditor/propertieseditordockwidget.h" class Diagram; +class QGraphicsItem; class DiagramPropertiesEditorDockWidget : public PropertiesEditorDockWidget { @@ -36,7 +37,9 @@ class DiagramPropertiesEditorDockWidget : public PropertiesEditorDockWidget void diagramWasDeleted(); private: + enum EditedQGIType {UnknowQGIType, ElementQGIType, ImageQGIType}; Diagram *m_diagram; + EditedQGIType m_edited_qgi_type; }; #endif // DIAGRAMPROPERTIESEDITORDOCKWIDGET_H diff --git a/sources/ui/elementinfowidget.cpp b/sources/ui/elementinfowidget.cpp index 1136312c6..f6075164f 100644 --- a/sources/ui/elementinfowidget.cpp +++ b/sources/ui/elementinfowidget.cpp @@ -30,15 +30,13 @@ * @param parent parent widget */ ElementInfoWidget::ElementInfoWidget(Element *elmt, QWidget *parent) : - PropertiesEditorWidget(parent), + AbstractElementPropertiesEditorWidget(parent), ui(new Ui::ElementInfoWidget), - element_(elmt), - elmt_info(elmt->elementInformations()), m_first_activation (false) { ui->setupUi(this); buildInterface(); - fillInfo(); + setElement(elmt); } /** @@ -51,6 +49,19 @@ ElementInfoWidget::~ElementInfoWidget() delete ui; } +/** + * @brief ElementInfoWidget::setElement + * Set @element to be the edited element + * @param element + */ +void ElementInfoWidget::setElement(Element *element) +{ + if (m_element == element) return; + m_element = element; + m_element_info = m_element->elementInformations(); + fillInfo(); +} + /** * @brief ElementInfoWidget::apply * Apply the new information with a new undo command (got with method associatedUndo) @@ -59,7 +70,7 @@ ElementInfoWidget::~ElementInfoWidget() void ElementInfoWidget::apply() { if (QUndoCommand *undo = associatedUndo()) - element_ -> diagram() -> undoStack().push(undo); + m_element -> diagram() -> undoStack().push(undo); } /** @@ -71,7 +82,7 @@ void ElementInfoWidget::apply() */ QUndoCommand* ElementInfoWidget::associatedUndo() const { DiagramContext new_info; - DiagramContext old_info = element_ -> elementInformations(); + DiagramContext old_info = m_element -> elementInformations(); foreach (ElementInfoPartWidget *eipw, eipw_list) { //add value only if they're something to store @@ -82,7 +93,7 @@ QUndoCommand* ElementInfoWidget::associatedUndo() const { } if (old_info != new_info) { - return (new ChangeElementInformationCommand(element_, old_info, new_info)); + return (new ChangeElementInformationCommand(m_element, old_info, new_info)); } return nullptr; } @@ -122,19 +133,19 @@ void ElementInfoWidget::buildInterface() { /** * @brief ElementInfoWidget::fillInfo - * fill information fetch in elmt_info to the + * fill information fetch in m_element_info to the * corresponding line edit */ void ElementInfoWidget::fillInfo() { foreach (ElementInfoPartWidget *eipw, eipw_list) { - eipw -> setText (elmt_info[eipw->key()].toString()); - eipw -> setShow (elmt_info.keyMustShow(eipw->key())); + eipw -> setText (m_element_info[eipw->key()].toString()); + eipw -> setShow (m_element_info.keyMustShow(eipw->key())); //If the current eipw is for label or comment and the text is empty //we force the checkbox to ckecked if (eipw -> key() == "label" || eipw -> key() == "comment") { - if (elmt_info[eipw->key()].toString().isEmpty()) + if (m_element_info[eipw->key()].toString().isEmpty()) eipw->setShow(true); } else //< for other eipw we hide the checkbox diff --git a/sources/ui/elementinfowidget.h b/sources/ui/elementinfowidget.h index d3ef9a5a6..5e6473349 100644 --- a/sources/ui/elementinfowidget.h +++ b/sources/ui/elementinfowidget.h @@ -20,7 +20,7 @@ #include #include "diagramcontext.h" -#include "PropertiesEditor/propertieseditorwidget.h" +#include "abstractelementpropertieseditorwidget.h" class Element; class QUndoCommand; @@ -35,7 +35,7 @@ namespace Ui { * @brief The ElementInfoWidget class * this class is a widget to edit an element informations. */ -class ElementInfoWidget : public PropertiesEditorWidget +class ElementInfoWidget : public AbstractElementPropertiesEditorWidget { Q_OBJECT @@ -44,6 +44,7 @@ class ElementInfoWidget : public PropertiesEditorWidget explicit ElementInfoWidget(Element *elmt, QWidget *parent = 0); ~ElementInfoWidget(); + void setElement(Element *element); void apply(); QUndoCommand *associatedUndo () const; QString title() const {return tr("Informations");} @@ -61,8 +62,7 @@ class ElementInfoWidget : public PropertiesEditorWidget //ATTRIBUTES private: Ui::ElementInfoWidget *ui; - Element *element_; - DiagramContext elmt_info; + DiagramContext m_element_info; QList eipw_list; bool m_first_activation; }; diff --git a/sources/ui/elementpropertieswidget.cpp b/sources/ui/elementpropertieswidget.cpp index d31ed2ffc..05c9dba88 100644 --- a/sources/ui/elementpropertieswidget.cpp +++ b/sources/ui/elementpropertieswidget.cpp @@ -36,12 +36,40 @@ * @param parent */ ElementPropertiesWidget::ElementPropertiesWidget(Element *elmt, QWidget *parent) : - PropertiesEditorWidget (parent), - m_element (elmt), + AbstractElementPropertiesEditorWidget (parent), m_diagram (elmt->diagram()), - m_tab (nullptr) + m_tab (nullptr), + m_general_widget(nullptr) { buildGui(); + setElement(elmt); +} + +/** + * @brief ElementPropertiesWidget::setElement + * Set @element to be the edited element + * @param element + */ +void ElementPropertiesWidget::setElement(Element *element) +{ + if (m_element == element) return; + Element *previous_element = m_element; + m_element = element; + + if (previous_element) + { + //If previous element is same type as new element we just call setElement for each editor + if(previous_element->linkType() == m_element->linkType()) + { + foreach (AbstractElementPropertiesEditorWidget *aepew, m_list_editor) + { + aepew->setElement(m_element); + addGeneralWidget(); + } + return; + } + } + updateUi(); } /** @@ -109,6 +137,26 @@ void ElementPropertiesWidget::editElement() void ElementPropertiesWidget::buildGui() { m_tab = new QTabWidget(this); + QVBoxLayout *main_layout = new QVBoxLayout(this); + main_layout -> addWidget(m_tab); + setLayout(main_layout); +} + +/** + * @brief ElementPropertiesWidget::updateUi + * Update the content of this widget + */ +void ElementPropertiesWidget::updateUi() +{ + //We keep the current title of the tab, to return to the same tab + //if possible, at the end of this method + QString tab_text; + tab_text = m_tab->tabText(m_tab->currentIndex()); + + //Purge the tab widget and delete all widget + m_tab->clear(); + qDeleteAll(m_list_editor); m_list_editor.clear(); + if(m_general_widget) delete m_general_widget; m_general_widget = nullptr; //Add tab according to the element switch (m_element -> linkType()) @@ -136,11 +184,36 @@ void ElementPropertiesWidget::buildGui() } foreach (PropertiesEditorWidget *pew, m_list_editor) m_tab->addTab(pew, pew->title()); - m_tab -> addTab(generalWidget(), tr("Général")); + addGeneralWidget(); - QVBoxLayout *main_layout = new QVBoxLayout(this); - main_layout -> addWidget(m_tab); - setLayout(main_layout); + if (!tab_text.isEmpty()) + { + for(int i=0 ; icount() ; ++i) + { + if (tab_text == m_tab->tabBar()->tabText(i)) + { + m_tab->setCurrentIndex(i); + break; + } + } + } +} + +/** + * @brief ElementPropertiesWidget::addGeneralWidget + * Add or update the general widget on this tab widget + */ +void ElementPropertiesWidget::addGeneralWidget() +{ + int index = m_tab->currentIndex(); + if (m_general_widget) + { + m_tab->removeTab(m_tab->indexOf(m_general_widget)); + delete m_general_widget; + } + m_general_widget = generalWidget(); + m_tab -> addTab(m_general_widget, tr("Général")); + m_tab->setCurrentIndex(index); } /** diff --git a/sources/ui/elementpropertieswidget.h b/sources/ui/elementpropertieswidget.h index 531ece4c5..d214ea2f5 100644 --- a/sources/ui/elementpropertieswidget.h +++ b/sources/ui/elementpropertieswidget.h @@ -18,7 +18,7 @@ #ifndef ELEMENTPROPERTIESWIDGET_H #define ELEMENTPROPERTIESWIDGET_H -#include "PropertiesEditor/propertieseditorwidget.h" +#include "abstractelementpropertieseditorwidget.h" class Element; class Diagram; @@ -26,12 +26,13 @@ class QTabWidget; class ElementsLocation; -class ElementPropertiesWidget : public PropertiesEditorWidget +class ElementPropertiesWidget : public AbstractElementPropertiesEditorWidget { Q_OBJECT public: explicit ElementPropertiesWidget(Element *elmt, QWidget *parent = 0); + void setElement(Element *element); void apply(); void reset(); @@ -41,6 +42,8 @@ class ElementPropertiesWidget : public PropertiesEditorWidget private: void buildGui(); + void updateUi(); + void addGeneralWidget(); QWidget *generalWidget(); signals: @@ -50,10 +53,10 @@ class ElementPropertiesWidget : public PropertiesEditorWidget void editElementRequired(const ElementsLocation &); private: - Element *m_element; Diagram *m_diagram; QTabWidget *m_tab; - QList m_list_editor; + QList m_list_editor; + QWidget *m_general_widget; }; #endif // ELEMENTPROPERTIESWIDGET_H diff --git a/sources/ui/linksingleelementwidget.cpp b/sources/ui/linksingleelementwidget.cpp index 9f5e146d3..9be37ccff 100644 --- a/sources/ui/linksingleelementwidget.cpp +++ b/sources/ui/linksingleelementwidget.cpp @@ -31,9 +31,8 @@ * the parent widget */ LinkSingleElementWidget::LinkSingleElementWidget(Element *elmt, QWidget *parent) : - PropertiesEditorWidget(parent), + AbstractElementPropertiesEditorWidget(parent), ui(new Ui::LinkSingleElementWidget), - m_element(nullptr), esw_(0), unlink_widget(0), unlink_(false), diff --git a/sources/ui/linksingleelementwidget.h b/sources/ui/linksingleelementwidget.h index 270fc67f8..d94303a71 100644 --- a/sources/ui/linksingleelementwidget.h +++ b/sources/ui/linksingleelementwidget.h @@ -18,8 +18,9 @@ #ifndef LINKSINGLEELEMENTWIDGET_H #define LINKSINGLEELEMENTWIDGET_H -#include "PropertiesEditor/propertieseditorwidget.h" #include "element.h" +#include "abstractelementpropertieseditorwidget.h" + class Diagram; class QLineEdit; @@ -39,7 +40,7 @@ namespace Ui { * If the element is already linked, the widget ask user to unlink. * This widget embedded the diagram command for undo/redo the action */ -class LinkSingleElementWidget : public PropertiesEditorWidget +class LinkSingleElementWidget : public AbstractElementPropertiesEditorWidget { Q_OBJECT @@ -72,7 +73,6 @@ class LinkSingleElementWidget : public PropertiesEditorWidget ///Attributes private: Ui::LinkSingleElementWidget *ui; - Element *m_element; ElementSelectorWidget *esw_; QList diagram_list; QWidget *unlink_widget; diff --git a/sources/ui/masterpropertieswidget.cpp b/sources/ui/masterpropertieswidget.cpp index 1ca43ecf0..53e0a0b13 100644 --- a/sources/ui/masterpropertieswidget.cpp +++ b/sources/ui/masterpropertieswidget.cpp @@ -31,22 +31,15 @@ * @param parent */ MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) : - PropertiesEditorWidget(parent), + AbstractElementPropertiesEditorWidget(parent), ui(new Ui::MasterPropertiesWidget), - m_element(elmt), m_showed_element (nullptr), m_project(nullptr) { - if(Q_LIKELY(elmt->diagram() && elmt->diagram()->project())) - { - m_project = elmt->diagram()->project(); - connect(m_project, SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(diagramWasdeletedFromProject())); - } - ui->setupUi(this); connect(ui->free_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showElementFromLWI(QListWidgetItem*))); connect(ui->linked_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showElementFromLWI(QListWidgetItem*))); - buildInterface(); + setElement(elmt); } /** @@ -68,6 +61,15 @@ void MasterPropertiesWidget::setElement(Element *element) { if (m_element == element) return; if (m_showed_element) {m_showed_element->setHighlighted(false); m_showed_element = nullptr;} + if (m_project) disconnect(m_project, SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(diagramWasdeletedFromProject())); + + if(Q_LIKELY(element->diagram() && element->diagram()->project())) + { + m_project = element->diagram()->project(); + connect(m_project, SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(diagramWasdeletedFromProject())); + } + else m_project = nullptr; + m_element = element; buildInterface(); } diff --git a/sources/ui/masterpropertieswidget.h b/sources/ui/masterpropertieswidget.h index 59bf65819..d0ac9be6b 100644 --- a/sources/ui/masterpropertieswidget.h +++ b/sources/ui/masterpropertieswidget.h @@ -20,7 +20,7 @@ #include #include -#include "PropertiesEditor/propertieseditorwidget.h" +#include "abstractelementpropertieseditorwidget.h" class QListWidgetItem; class Element; @@ -38,7 +38,7 @@ namespace Ui { * This class embenddedthe undo/redo command when apply new connection. */ -class MasterPropertiesWidget : public PropertiesEditorWidget +class MasterPropertiesWidget : public AbstractElementPropertiesEditorWidget { Q_OBJECT @@ -62,7 +62,6 @@ class MasterPropertiesWidget : public PropertiesEditorWidget private: Ui::MasterPropertiesWidget *ui; - Element *m_element; QHash lwi_hash; Element *m_showed_element; QETProject *m_project;