diff --git a/sources/PropertiesEditor/PropertiesEditor.pri b/sources/PropertiesEditor/PropertiesEditor.pri index 05f6deea2..cb4088536 100755 --- a/sources/PropertiesEditor/PropertiesEditor.pri +++ b/sources/PropertiesEditor/PropertiesEditor.pri @@ -3,7 +3,8 @@ FORMS += \ HEADERS += \ $$PWD/propertieseditordockwidget.h \ - $$PWD/propertieseditorwidget.h + $$PWD/propertieseditorwidget.h \ + $$PWD/propertieseditordialog.h SOURCES += \ $$PWD/propertieseditordockwidget.cpp \ diff --git a/sources/PropertiesEditor/propertieseditordialog.h b/sources/PropertiesEditor/propertieseditordialog.h new file mode 100644 index 000000000..e90520860 --- /dev/null +++ b/sources/PropertiesEditor/propertieseditordialog.h @@ -0,0 +1,80 @@ +/* + 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 PROPERTIESEDITORDIALOG_H +#define PROPERTIESEDITORDIALOG_H + +#include +#include +#include +#include + +/** + * @brief The PropertiesEditorDialog class + * Create a dialog to edit some properties of a thing. + * Only create a instance of this class and call exec, all is done for you in this class. + * The first argument (a template) must be a subclass of QWidget and provide the 3 methods bellow : + * QString::title() + * void::apply() + * void::reset() + * You can subclass the interface PropertiesEditorWidget who provide all this methods. + * This dialog take ownership of the editor, so the editor will be deleted by this dialog + */ +class PropertiesEditorDialog : public QDialog +{ + Q_OBJECT + public: + template + PropertiesEditorDialog(T editor, QWidget *parent = 0) : + QDialog (parent) + { + //Set dialog title + setWindowTitle(editor->title()); + //Reparent the editor, to be deleted at the same time of this dialog + editor->setParent(this); + + //Build the dialog + QVBoxLayout *vlayout = new QVBoxLayout(this); + vlayout->addWidget(editor); + QDialogButtonBox *button_box = new QDialogButtonBox (QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::Reset, this); + vlayout->addWidget(button_box); + + //Setup connection between button box and the editor + connect(button_box, &QDialogButtonBox::clicked, [editor, button_box, this](QAbstractButton *button) + { + switch(button_box->buttonRole(button)) + { + case QDialogButtonBox::RejectRole: + editor->reset(); + this->reject(); + break; + case QDialogButtonBox::ResetRole: + editor->reset(); + break; + case QDialogButtonBox::ApplyRole: + editor->apply(); + this->accept(); + break; + default: + editor->reset(); + this->reject(); + } + }); + } +}; + +#endif // PROPERTIESEDITORDIALOG_H diff --git a/sources/qetgraphicsitem/diagramimageitem.cpp b/sources/qetgraphicsitem/diagramimageitem.cpp index 2ec56c1a9..81a79a1b8 100644 --- a/sources/qetgraphicsitem/diagramimageitem.cpp +++ b/sources/qetgraphicsitem/diagramimageitem.cpp @@ -17,7 +17,8 @@ */ #include "diagramimageitem.h" #include "diagram.h" -#include "imagepropertiesdialog.h" +#include "PropertiesEditor/propertieseditordialog.h" +#include "imagepropertieswidget.h" /** * @brief DiagramImageItem::DiagramImageItem @@ -85,7 +86,7 @@ void DiagramImageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * void DiagramImageItem::editProperty() { if (diagram() -> isReadOnly()) return; - ImagePropertiesDialog dialog(this, QApplication::activeWindow()); + PropertiesEditorDialog dialog(new ImagePropertiesWidget(this), QApplication::activeWindow()); dialog.exec(); } diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index fdb24fb6b..d6d82653f 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -22,10 +22,11 @@ #include "elementtextitem.h" #include "diagramcommands.h" #include -#include #include "elementprovider.h" #include "diagramposition.h" #include "terminal.h" +#include "PropertiesEditor/propertieseditordialog.h" +#include "elementpropertieswidget.h" /** Constructeur pour un element sans scene ni parent @@ -48,14 +49,15 @@ Element::Element(QGraphicsItem *parent) : Element::~Element() { } -void Element::editProperty() { - if (diagram()) - if(!diagram()->isReadOnly()){ - ElementPropertiesDialog epw (this, diagram()->views().first()); - connect(&epw, SIGNAL(editElementRequired(ElementsLocation)), diagram(), SIGNAL(editElementRequired(ElementsLocation))); - connect(&epw, SIGNAL(findElementRequired(ElementsLocation)), diagram(), SIGNAL(findElementRequired(ElementsLocation))); - epw.exec(); - } +void Element::editProperty() +{ + if (diagram() && !diagram()->isReadOnly()) + { + ElementPropertiesWidget *epw = new ElementPropertiesWidget(this); + PropertiesEditorDialog dialog(epw, QApplication::activeWindow()); + connect(epw, &ElementPropertiesWidget::findEditClicked, &dialog, &QDialog::reject); + dialog.exec(); + } } diff --git a/sources/qetgraphicsitem/qetshapeitem.cpp b/sources/qetgraphicsitem/qetshapeitem.cpp index d5d4f5e5f..c752af165 100644 --- a/sources/qetgraphicsitem/qetshapeitem.cpp +++ b/sources/qetgraphicsitem/qetshapeitem.cpp @@ -20,6 +20,7 @@ #include "diagram.h" #include "qet.h" #include "shapegraphicsitempropertieswidget.h" +#include "PropertiesEditor/propertieseditordialog.h" /** @@ -359,24 +360,8 @@ void QetShapeItem::editProperty() { if (diagram() -> isReadOnly()) return; - //the dialog - QDialog property_dialog(diagram()->views().at(0)); - property_dialog.setWindowTitle(tr("Éditer les propriétés d'une shape, Zone ", "window title")); - //the main layout - QVBoxLayout dialog_layout(&property_dialog); - ShapeGraphicsItemPropertiesWidget *sgipw = new ShapeGraphicsItemPropertiesWidget(this, &property_dialog); - dialog_layout.addWidget(sgipw); - - //dialog button, box - QDialogButtonBox dbb(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - dialog_layout.addWidget(&dbb); - connect(&dbb, SIGNAL(accepted()), &property_dialog, SLOT(accept())); - connect(&dbb, SIGNAL(rejected()), &property_dialog, SLOT(reject())); - - if (property_dialog.exec() == QDialog::Accepted) - sgipw->apply(); - else - sgipw->reset(); + PropertiesEditorDialog ped(new ShapeGraphicsItemPropertiesWidget(this), diagram()->views().at(0)); + ped.exec(); } /** diff --git a/sources/ui/diagrampropertieseditordockwidget.cpp b/sources/ui/diagrampropertieseditordockwidget.cpp index 8b95df62b..57424235f 100644 --- a/sources/ui/diagrampropertieseditordockwidget.cpp +++ b/sources/ui/diagrampropertieseditordockwidget.cpp @@ -98,10 +98,7 @@ void DiagramPropertiesEditorDockWidget::selectionChanged() clear(); m_edited_qgi_type = type_; - ElementPropertiesWidget *epw = new ElementPropertiesWidget(static_cast(item), this); - connect (epw, &ElementPropertiesWidget::editElementRequired , m_diagram, &Diagram::editElementRequired); - connect (epw, &ElementPropertiesWidget::findElementRequired, m_diagram, &Diagram::findElementRequired); - addEditor(epw); + addEditor(new ElementPropertiesWidget(static_cast(item), this)); break; } case DiagramImageItem::Type: { diff --git a/sources/ui/elementpropertiesdialog.cpp b/sources/ui/elementpropertiesdialog.cpp deleted file mode 100644 index 356c87731..000000000 --- a/sources/ui/elementpropertiesdialog.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - 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 "elementpropertiesdialog.h" -#include "elementpropertieswidget.h" - -#include -#include - -/** - * @brief ElementPropertiesDialog::ElementPropertiesDialog - * default constructor - * @param elmt - * @param parent - */ -ElementPropertiesDialog::ElementPropertiesDialog(Element *elmt, QWidget *parent) : - QDialog(parent), - element_ (elmt) -{ - m_editor = new ElementPropertiesWidget(elmt, this); - - connect(m_editor, SIGNAL(editElementRequired(ElementsLocation)), this , SLOT(editElement(ElementsLocation))); - connect(m_editor, SIGNAL(findElementRequired(ElementsLocation)), this, SLOT(findInPanel(ElementsLocation))); - - dbb = new QDialogButtonBox(QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::Reset, Qt::Horizontal, this); - connect(dbb, SIGNAL(clicked(QAbstractButton*)), this, SLOT(standardButtonClicked(QAbstractButton*))); - - QVBoxLayout *main_layout = new QVBoxLayout(this); - main_layout -> addWidget(m_editor); - main_layout -> addWidget(dbb); - setLayout(main_layout); -} - -/** - * @brief ElementPropertiesDialog::standardButtonClicked - * apply action when click in the dialog standard button box - * @param button - * the cliked button - */ -void ElementPropertiesDialog::standardButtonClicked(QAbstractButton *button) { - int answer = dbb -> buttonRole(button); - - switch (answer) { - case QDialogButtonBox::ResetRole: - m_editor->reset(); - break; - case QDialogButtonBox::ApplyRole: - m_editor->apply(); - accept(); - break; - default: - reject(); - break; - } -} - -/** - * @brief ElementPropertiesDialog::findInPanel - * Slot - */ -void ElementPropertiesDialog::findInPanel(const ElementsLocation &location) -{ - emit findElementRequired(location); - reject(); -} - -/** - * @brief ElementPropertiesDialog::editElement - * Slot - */ -void ElementPropertiesDialog::editElement(const ElementsLocation &location) -{ - emit findElementRequired(location); - emit editElementRequired(location); - reject(); -} diff --git a/sources/ui/elementpropertiesdialog.h b/sources/ui/elementpropertiesdialog.h deleted file mode 100644 index 47da944e5..000000000 --- a/sources/ui/elementpropertiesdialog.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - 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 ELEMENTPROPERTIESDIALOG_H -#define ELEMENTPROPERTIESDIALOG_H - -#include - -class Element; -class ElementsLocation; -class QAbstractButton; -class QDialogButtonBox; -class ElementPropertiesWidget; - -/** - * @brief The ElementPropertiesDialog class - * Display the element properties widget in a QDialog - */ -class ElementPropertiesDialog : public QDialog -{ - Q_OBJECT - - public: - explicit ElementPropertiesDialog(Element *elmt, QWidget *parent = 0); - - signals: - /// Signal emitted when users wish to locate an element from the diagram within elements collection - void findElementRequired(const ElementsLocation &); - /// Signal emitted when users wish to edit an element from the diagram - void editElementRequired(const ElementsLocation &); - - public slots: - void standardButtonClicked (QAbstractButton *); - void findInPanel (const ElementsLocation &); - void editElement (const ElementsLocation &); - - private: - Element *element_; - QDialogButtonBox *dbb; - ElementPropertiesWidget *m_editor; -}; - -#endif // ELEMENTPROPERTIESDIALOG_H diff --git a/sources/ui/elementpropertieswidget.cpp b/sources/ui/elementpropertieswidget.cpp index 77b05ba26..776df298c 100644 --- a/sources/ui/elementpropertieswidget.cpp +++ b/sources/ui/elementpropertieswidget.cpp @@ -124,8 +124,12 @@ bool ElementPropertiesWidget::setLiveEdit(bool live_edit) */ void ElementPropertiesWidget::findInPanel() { - if (CustomElement *custom_element = qobject_cast(m_element)) - emit findElementRequired(custom_element->location()); + CustomElement *custom_element = qobject_cast(m_element); + if (custom_element && m_diagram) + { + m_diagram->findElementRequired(custom_element->location()); + emit findEditClicked(); + } } /** @@ -134,10 +138,12 @@ void ElementPropertiesWidget::findInPanel() */ void ElementPropertiesWidget::editElement() { - if (CustomElement *custom_element = qobject_cast(m_element)) + CustomElement *custom_element = qobject_cast(m_element); + if (custom_element && m_diagram) { - emit findElementRequired(custom_element->location()); - emit editElementRequired(custom_element->location()); + m_diagram->findElementRequired(custom_element->location()); + m_diagram->editElementRequired(custom_element->location()); + emit findEditClicked(); } } diff --git a/sources/ui/elementpropertieswidget.h b/sources/ui/elementpropertieswidget.h index e2f53e951..931106756 100644 --- a/sources/ui/elementpropertieswidget.h +++ b/sources/ui/elementpropertieswidget.h @@ -48,10 +48,7 @@ class ElementPropertiesWidget : public AbstractElementPropertiesEditorWidget QWidget *generalWidget(); signals: - /// Signal emitted when users wish to locate an element from the diagram within elements collection - void findElementRequired(const ElementsLocation &); - /// Signal emitted when users wish to edit an element from the diagram - void editElementRequired(const ElementsLocation &); + void findEditClicked(); private: Diagram *m_diagram; diff --git a/sources/ui/imagepropertiesdialog.cpp b/sources/ui/imagepropertiesdialog.cpp deleted file mode 100644 index acb0f0c96..000000000 --- a/sources/ui/imagepropertiesdialog.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "imagepropertiesdialog.h" -#include "ui_imagepropertiesdialog.h" -#include "imagepropertieswidget.h" -#include "diagramimageitem.h" - -ImagePropertiesDialog::ImagePropertiesDialog(DiagramImageItem *image, QWidget *parent) : - QDialog(parent), - ui(new Ui::ImagePropertiesDialog) -{ - ui->setupUi(this); - m_editor = new ImagePropertiesWidget(image, this); - ui->verticalLayout->insertWidget(0, m_editor); -} - -ImagePropertiesDialog::~ImagePropertiesDialog() { - delete ui; -} - -void ImagePropertiesDialog::setImageItem(DiagramImageItem *image) { - m_editor->setImageItem(image); -} - -void ImagePropertiesDialog::on_buttonBox_accepted() { - m_editor->apply(); -} - -void ImagePropertiesDialog::on_buttonBox_rejected() { - m_editor->reset(); -} diff --git a/sources/ui/imagepropertiesdialog.h b/sources/ui/imagepropertiesdialog.h deleted file mode 100644 index 6f750c236..000000000 --- a/sources/ui/imagepropertiesdialog.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef IMAGEPROPERTIESDIALOG_H -#define IMAGEPROPERTIESDIALOG_H - -#include - -class ImagePropertiesWidget; -class DiagramImageItem; - -namespace Ui { - class ImagePropertiesDialog; -} - -class ImagePropertiesDialog : public QDialog -{ - Q_OBJECT - - public: - explicit ImagePropertiesDialog(DiagramImageItem *image = nullptr, QWidget *parent = 0); - ~ImagePropertiesDialog(); - void setImageItem (DiagramImageItem *image); - - private slots: - void on_buttonBox_accepted(); - void on_buttonBox_rejected(); - - private: - Ui::ImagePropertiesDialog *ui; - ImagePropertiesWidget *m_editor; -}; - -#endif // IMAGEPROPERTIESDIALOG_H diff --git a/sources/ui/imagepropertiesdialog.ui b/sources/ui/imagepropertiesdialog.ui deleted file mode 100644 index 3023b647a..000000000 --- a/sources/ui/imagepropertiesdialog.ui +++ /dev/null @@ -1,67 +0,0 @@ - - - ImagePropertiesDialog - - - - 0 - 0 - 194 - 52 - - - - Éditer les propriétés de image - - - - QLayout::SetMinimumSize - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - buttonBox - accepted() - ImagePropertiesDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - ImagePropertiesDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - -