diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 85c2093c0..f8f368f4f 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -22,7 +22,7 @@ #include "elementtextitem.h" #include "diagramcommands.h" #include -#include +#include #include "elementprovider.h" #include "diagramposition.h" #include "terminal.h" @@ -51,7 +51,7 @@ Element::~Element() { void Element::editProperty() { if (diagram()) if(!diagram()->isReadOnly()){ - elementpropertieswidget epw (this, diagram()->views().first()); + 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(); diff --git a/sources/ui/elementinfowidget.cpp b/sources/ui/elementinfowidget.cpp index 42c44ab81..89b5c590e 100644 --- a/sources/ui/elementinfowidget.cpp +++ b/sources/ui/elementinfowidget.cpp @@ -30,7 +30,7 @@ * @param parent parent widget */ ElementInfoWidget::ElementInfoWidget(Element *elmt, QWidget *parent) : - QWidget(parent), + PropertiesEditorWidget(parent), ui(new Ui::ElementInfoWidget), element_(elmt), elmt_info(elmt->elementInformations()), @@ -55,14 +55,11 @@ ElementInfoWidget::~ElementInfoWidget() * @brief ElementInfoWidget::apply * Apply the new information with a new undo command (got with method associatedUndo) * pushed to the stack of element project. - * Return true if new info change, else false. */ -bool ElementInfoWidget::apply() { - if (QUndoCommand *undo = associatedUndo()) { +void ElementInfoWidget::apply() +{ + if (QUndoCommand *undo = associatedUndo()) element_ -> diagram() -> undoStack().push(undo); - return true; - } - return false; } /** diff --git a/sources/ui/elementinfowidget.h b/sources/ui/elementinfowidget.h index 8ffa81aa3..ff413983d 100644 --- a/sources/ui/elementinfowidget.h +++ b/sources/ui/elementinfowidget.h @@ -20,6 +20,7 @@ #include #include "diagramcontext.h" +#include "propertieseditorwidget.h" class Element; class QUndoCommand; @@ -34,7 +35,8 @@ namespace Ui { * @brief The ElementInfoWidget class * this class is a widget to edit an element informations. */ -class ElementInfoWidget : public QWidget { +class ElementInfoWidget : public PropertiesEditorWidget +{ Q_OBJECT //METHODS @@ -42,7 +44,7 @@ class ElementInfoWidget : public QWidget { explicit ElementInfoWidget(Element *elmt, QWidget *parent = 0); ~ElementInfoWidget(); - bool apply(); + void apply(); QUndoCommand* associatedUndo () const; protected: diff --git a/sources/ui/elementpropertieswidget.cpp b/sources/ui/elementpropertiesdialog.cpp similarity index 90% rename from sources/ui/elementpropertieswidget.cpp rename to sources/ui/elementpropertiesdialog.cpp index 9f35123fb..f380dc026 100644 --- a/sources/ui/elementpropertieswidget.cpp +++ b/sources/ui/elementpropertiesdialog.cpp @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with QElectroTech. If not, see . */ -#include "elementpropertieswidget.h" +#include "elementpropertiesdialog.h" #include "ghostelement.h" #include "qeticons.h" #include "diagramposition.h" @@ -25,12 +25,12 @@ #include "linksingleelementwidget.h" /** - * @brief elementpropertieswidget::elementpropertieswidget + * @brief ElementPropertiesDialog::ElementPropertiesDialog * default constructor * @param elmt * @param parent */ -elementpropertieswidget::elementpropertieswidget(Element *elmt, QWidget *parent) : +ElementPropertiesDialog::ElementPropertiesDialog(Element *elmt, QWidget *parent) : QDialog(parent), element_ (elmt), diagram_ (elmt->diagram()) @@ -42,11 +42,11 @@ elementpropertieswidget::elementpropertieswidget(Element *elmt, QWidget *parent) } /** - * @brief elementpropertieswidget::generalWidget + * @brief ElementPropertiesDialog::generalWidget * build the widget for the tab général * @return */ -QWidget* elementpropertieswidget::generalWidget() { +QWidget* ElementPropertiesDialog::generalWidget() { CustomElement *custom_element = qobject_cast(element_); GhostElement *ghost_element = qobject_cast(element_); @@ -102,11 +102,11 @@ QWidget* elementpropertieswidget::generalWidget() { } /** - * @brief elementpropertieswidget::buildInterface + * @brief ElementPropertiesDialog::buildInterface *build the interface of this dialog, the main tab can have *different tab according to the edited element */ -void elementpropertieswidget::buildInterface() { +void ElementPropertiesDialog::buildInterface() { setWindowTitle(tr("Propriétés de l'élément")); tab_ = new QTabWidget(this); @@ -154,12 +154,12 @@ void elementpropertieswidget::buildInterface() { } /** - * @brief elementpropertieswidget::standardButtonClicked + * @brief ElementPropertiesDialog::standardButtonClicked * apply action when click in the dialog standard button box * @param button * the cliked button */ -void elementpropertieswidget::standardButtonClicked(QAbstractButton *button) { +void ElementPropertiesDialog::standardButtonClicked(QAbstractButton *button) { int answer = dbb -> buttonRole(button); bool accept = false; @@ -204,10 +204,10 @@ void elementpropertieswidget::standardButtonClicked(QAbstractButton *button) { } /** - * @brief elementpropertieswidget::findInPanel + * @brief ElementPropertiesDialog::findInPanel * Slot */ -void elementpropertieswidget::findInPanel() { +void ElementPropertiesDialog::findInPanel() { if (CustomElement *custom_element = qobject_cast(element_)) { emit findElementRequired(custom_element->location()); } @@ -215,10 +215,10 @@ void elementpropertieswidget::findInPanel() { } /** - * @brief elementpropertieswidget::editElement + * @brief ElementPropertiesDialog::editElement * Slot */ -void elementpropertieswidget::editElement() { +void ElementPropertiesDialog::editElement() { if (CustomElement *custom_element = qobject_cast(element_)) { emit findElementRequired(custom_element->location()); emit editElementRequired(custom_element->location()); diff --git a/sources/ui/elementpropertieswidget.h b/sources/ui/elementpropertiesdialog.h similarity index 94% rename from sources/ui/elementpropertieswidget.h rename to sources/ui/elementpropertiesdialog.h index 012b09566..8e8848a2e 100644 --- a/sources/ui/elementpropertieswidget.h +++ b/sources/ui/elementpropertiesdialog.h @@ -30,11 +30,11 @@ class QAbstractButton; class QDialogButtonBox; class QTabWidget; -class elementpropertieswidget : public QDialog { +class ElementPropertiesDialog : public QDialog { Q_OBJECT public: - explicit elementpropertieswidget(Element *elmt, QWidget *parent = 0); + explicit ElementPropertiesDialog(Element *elmt, QWidget *parent = 0); private: QWidget* generalWidget(); diff --git a/sources/ui/masterpropertieswidget.cpp b/sources/ui/masterpropertieswidget.cpp index 5c4456ee1..21853848a 100644 --- a/sources/ui/masterpropertieswidget.cpp +++ b/sources/ui/masterpropertieswidget.cpp @@ -31,7 +31,7 @@ * @param parent */ MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) : - QWidget(parent), + PropertiesEditorWidget(parent), ui(new Ui::MasterPropertiesWidget), element_(elmt) { @@ -58,12 +58,9 @@ MasterPropertiesWidget::~MasterPropertiesWidget() * pushed to the stack of element project. * Return true if link change, else false */ -bool MasterPropertiesWidget::apply() { - if (QUndoCommand *undo = associatedUndo()) { +void MasterPropertiesWidget::apply() { + if (QUndoCommand *undo = associatedUndo()) element_ -> diagram() -> undoStack().push(undo); - return true; - } - return false; } /** diff --git a/sources/ui/masterpropertieswidget.h b/sources/ui/masterpropertieswidget.h index 3411714f5..4879cbda3 100644 --- a/sources/ui/masterpropertieswidget.h +++ b/sources/ui/masterpropertieswidget.h @@ -20,6 +20,7 @@ #include #include +#include class QListWidgetItem; class Element; @@ -35,7 +36,7 @@ namespace Ui { * This class embenddedthe undo/redo command when apply new connection. */ -class MasterPropertiesWidget : public QWidget +class MasterPropertiesWidget : public PropertiesEditorWidget { Q_OBJECT @@ -43,7 +44,7 @@ class MasterPropertiesWidget : public QWidget explicit MasterPropertiesWidget(Element *elmt, QWidget *parent = 0); ~MasterPropertiesWidget(); - bool apply(); + void apply(); void reset(); QUndoCommand* associatedUndo() const; diff --git a/sources/ui/propertieseditorwidget.cpp b/sources/ui/propertieseditorwidget.cpp new file mode 100644 index 000000000..dc9550a65 --- /dev/null +++ b/sources/ui/propertieseditorwidget.cpp @@ -0,0 +1,37 @@ +/* + 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 "propertieseditorwidget.h" +#include + +/** + * @brief PropertiesEditorWidget::PropertiesEditorWidget + * Constructor + * @param parent : parent widget + */ +PropertiesEditorWidget::PropertiesEditorWidget(QWidget *parent) : + QWidget(parent) +{} + +/** + * @brief PropertiesEditorWidget::assosiatedUndo + * By default, return an empty undo command + * @return an empty undo command + */ +QUndoCommand *PropertiesEditorWidget::assosiatedUndo() { + return new QUndoCommand(); +} diff --git a/sources/ui/propertieseditorwidget.h b/sources/ui/propertieseditorwidget.h new file mode 100644 index 000000000..42d861fc4 --- /dev/null +++ b/sources/ui/propertieseditorwidget.h @@ -0,0 +1,41 @@ +/* + 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 PROPERTIESEDITORWIDGET_H +#define PROPERTIESEDITORWIDGET_H + +#include + +class QUndoCommand; + +/** + * @brief The PropertiesEditorWidget class + * This class extend QWidget method for have common way + * to edit propertie. + */ +class PropertiesEditorWidget : public QWidget +{ + Q_OBJECT + public: + explicit PropertiesEditorWidget(QWidget *parent = 0); + + void apply() {} + void reset() {} + virtual QUndoCommand *assosiatedUndo (); +}; + +#endif // PROPERTIESEDITORWIDGET_H