Create a common widget to edit propertie

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3930 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun 2015-05-02 22:25:01 +00:00
parent a30f51f2ce
commit b7031a0009
9 changed files with 109 additions and 34 deletions

View File

@ -22,7 +22,7 @@
#include "elementtextitem.h" #include "elementtextitem.h"
#include "diagramcommands.h" #include "diagramcommands.h"
#include <QtDebug> #include <QtDebug>
#include <ui/elementpropertieswidget.h> #include <elementpropertiesdialog.h>
#include "elementprovider.h" #include "elementprovider.h"
#include "diagramposition.h" #include "diagramposition.h"
#include "terminal.h" #include "terminal.h"
@ -51,7 +51,7 @@ Element::~Element() {
void Element::editProperty() { void Element::editProperty() {
if (diagram()) if (diagram())
if(!diagram()->isReadOnly()){ 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(editElementRequired(ElementsLocation)), diagram(), SIGNAL(editElementRequired(ElementsLocation)));
connect(&epw, SIGNAL(findElementRequired(ElementsLocation)), diagram(), SIGNAL(findElementRequired(ElementsLocation))); connect(&epw, SIGNAL(findElementRequired(ElementsLocation)), diagram(), SIGNAL(findElementRequired(ElementsLocation)));
epw.exec(); epw.exec();

View File

@ -30,7 +30,7 @@
* @param parent parent widget * @param parent parent widget
*/ */
ElementInfoWidget::ElementInfoWidget(Element *elmt, QWidget *parent) : ElementInfoWidget::ElementInfoWidget(Element *elmt, QWidget *parent) :
QWidget(parent), PropertiesEditorWidget(parent),
ui(new Ui::ElementInfoWidget), ui(new Ui::ElementInfoWidget),
element_(elmt), element_(elmt),
elmt_info(elmt->elementInformations()), elmt_info(elmt->elementInformations()),
@ -55,14 +55,11 @@ ElementInfoWidget::~ElementInfoWidget()
* @brief ElementInfoWidget::apply * @brief ElementInfoWidget::apply
* Apply the new information with a new undo command (got with method associatedUndo) * Apply the new information with a new undo command (got with method associatedUndo)
* pushed to the stack of element project. * pushed to the stack of element project.
* Return true if new info change, else false.
*/ */
bool ElementInfoWidget::apply() { void ElementInfoWidget::apply()
if (QUndoCommand *undo = associatedUndo()) { {
if (QUndoCommand *undo = associatedUndo())
element_ -> diagram() -> undoStack().push(undo); element_ -> diagram() -> undoStack().push(undo);
return true;
}
return false;
} }
/** /**

View File

@ -20,6 +20,7 @@
#include <QWidget> #include <QWidget>
#include "diagramcontext.h" #include "diagramcontext.h"
#include "propertieseditorwidget.h"
class Element; class Element;
class QUndoCommand; class QUndoCommand;
@ -34,7 +35,8 @@ namespace Ui {
* @brief The ElementInfoWidget class * @brief The ElementInfoWidget class
* this class is a widget to edit an element informations. * this class is a widget to edit an element informations.
*/ */
class ElementInfoWidget : public QWidget { class ElementInfoWidget : public PropertiesEditorWidget
{
Q_OBJECT Q_OBJECT
//METHODS //METHODS
@ -42,7 +44,7 @@ class ElementInfoWidget : public QWidget {
explicit ElementInfoWidget(Element *elmt, QWidget *parent = 0); explicit ElementInfoWidget(Element *elmt, QWidget *parent = 0);
~ElementInfoWidget(); ~ElementInfoWidget();
bool apply(); void apply();
QUndoCommand* associatedUndo () const; QUndoCommand* associatedUndo () const;
protected: protected:

View File

@ -15,7 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>. along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "elementpropertieswidget.h" #include "elementpropertiesdialog.h"
#include "ghostelement.h" #include "ghostelement.h"
#include "qeticons.h" #include "qeticons.h"
#include "diagramposition.h" #include "diagramposition.h"
@ -25,12 +25,12 @@
#include "linksingleelementwidget.h" #include "linksingleelementwidget.h"
/** /**
* @brief elementpropertieswidget::elementpropertieswidget * @brief ElementPropertiesDialog::ElementPropertiesDialog
* default constructor * default constructor
* @param elmt * @param elmt
* @param parent * @param parent
*/ */
elementpropertieswidget::elementpropertieswidget(Element *elmt, QWidget *parent) : ElementPropertiesDialog::ElementPropertiesDialog(Element *elmt, QWidget *parent) :
QDialog(parent), QDialog(parent),
element_ (elmt), element_ (elmt),
diagram_ (elmt->diagram()) 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 * build the widget for the tab général
* @return * @return
*/ */
QWidget* elementpropertieswidget::generalWidget() { QWidget* ElementPropertiesDialog::generalWidget() {
CustomElement *custom_element = qobject_cast<CustomElement *>(element_); CustomElement *custom_element = qobject_cast<CustomElement *>(element_);
GhostElement *ghost_element = qobject_cast<GhostElement *>(element_); GhostElement *ghost_element = qobject_cast<GhostElement *>(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 *build the interface of this dialog, the main tab can have
*different tab according to the edited element *different tab according to the edited element
*/ */
void elementpropertieswidget::buildInterface() { void ElementPropertiesDialog::buildInterface() {
setWindowTitle(tr("Propriétés de l'élément")); setWindowTitle(tr("Propriétés de l'élément"));
tab_ = new QTabWidget(this); 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 * apply action when click in the dialog standard button box
* @param button * @param button
* the cliked button * the cliked button
*/ */
void elementpropertieswidget::standardButtonClicked(QAbstractButton *button) { void ElementPropertiesDialog::standardButtonClicked(QAbstractButton *button) {
int answer = dbb -> buttonRole(button); int answer = dbb -> buttonRole(button);
bool accept = false; bool accept = false;
@ -204,10 +204,10 @@ void elementpropertieswidget::standardButtonClicked(QAbstractButton *button) {
} }
/** /**
* @brief elementpropertieswidget::findInPanel * @brief ElementPropertiesDialog::findInPanel
* Slot * Slot
*/ */
void elementpropertieswidget::findInPanel() { void ElementPropertiesDialog::findInPanel() {
if (CustomElement *custom_element = qobject_cast<CustomElement *>(element_)) { if (CustomElement *custom_element = qobject_cast<CustomElement *>(element_)) {
emit findElementRequired(custom_element->location()); emit findElementRequired(custom_element->location());
} }
@ -215,10 +215,10 @@ void elementpropertieswidget::findInPanel() {
} }
/** /**
* @brief elementpropertieswidget::editElement * @brief ElementPropertiesDialog::editElement
* Slot * Slot
*/ */
void elementpropertieswidget::editElement() { void ElementPropertiesDialog::editElement() {
if (CustomElement *custom_element = qobject_cast<CustomElement *>(element_)) { if (CustomElement *custom_element = qobject_cast<CustomElement *>(element_)) {
emit findElementRequired(custom_element->location()); emit findElementRequired(custom_element->location());
emit editElementRequired(custom_element->location()); emit editElementRequired(custom_element->location());

View File

@ -30,11 +30,11 @@ class QAbstractButton;
class QDialogButtonBox; class QDialogButtonBox;
class QTabWidget; class QTabWidget;
class elementpropertieswidget : public QDialog { class ElementPropertiesDialog : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
explicit elementpropertieswidget(Element *elmt, QWidget *parent = 0); explicit ElementPropertiesDialog(Element *elmt, QWidget *parent = 0);
private: private:
QWidget* generalWidget(); QWidget* generalWidget();

View File

@ -31,7 +31,7 @@
* @param parent * @param parent
*/ */
MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) : MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) :
QWidget(parent), PropertiesEditorWidget(parent),
ui(new Ui::MasterPropertiesWidget), ui(new Ui::MasterPropertiesWidget),
element_(elmt) element_(elmt)
{ {
@ -58,12 +58,9 @@ MasterPropertiesWidget::~MasterPropertiesWidget()
* pushed to the stack of element project. * pushed to the stack of element project.
* Return true if link change, else false * Return true if link change, else false
*/ */
bool MasterPropertiesWidget::apply() { void MasterPropertiesWidget::apply() {
if (QUndoCommand *undo = associatedUndo()) { if (QUndoCommand *undo = associatedUndo())
element_ -> diagram() -> undoStack().push(undo); element_ -> diagram() -> undoStack().push(undo);
return true;
}
return false;
} }
/** /**

View File

@ -20,6 +20,7 @@
#include <QWidget> #include <QWidget>
#include <QHash> #include <QHash>
#include <propertieseditorwidget.h>
class QListWidgetItem; class QListWidgetItem;
class Element; class Element;
@ -35,7 +36,7 @@ namespace Ui {
* This class embenddedthe undo/redo command when apply new connection. * This class embenddedthe undo/redo command when apply new connection.
*/ */
class MasterPropertiesWidget : public QWidget class MasterPropertiesWidget : public PropertiesEditorWidget
{ {
Q_OBJECT Q_OBJECT
@ -43,7 +44,7 @@ class MasterPropertiesWidget : public QWidget
explicit MasterPropertiesWidget(Element *elmt, QWidget *parent = 0); explicit MasterPropertiesWidget(Element *elmt, QWidget *parent = 0);
~MasterPropertiesWidget(); ~MasterPropertiesWidget();
bool apply(); void apply();
void reset(); void reset();
QUndoCommand* associatedUndo() const; QUndoCommand* associatedUndo() const;

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "propertieseditorwidget.h"
#include <QUndoCommand>
/**
* @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();
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef PROPERTIESEDITORWIDGET_H
#define PROPERTIESEDITORWIDGET_H
#include <QWidget>
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