mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-21 16:50:53 +01:00
Use PropertiesEditorWidget instead of QWidget for some widget (widget used to edit propertie of element)
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3932 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -45,7 +45,8 @@ class ElementInfoWidget : public PropertiesEditorWidget
|
|||||||
~ElementInfoWidget();
|
~ElementInfoWidget();
|
||||||
|
|
||||||
void apply();
|
void apply();
|
||||||
QUndoCommand* associatedUndo () const;
|
QUndoCommand *associatedUndo () const;
|
||||||
|
QString title() const {return tr("Informations");}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool event(QEvent *event);
|
virtual bool event(QEvent *event);
|
||||||
|
|||||||
@@ -16,13 +16,10 @@
|
|||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "elementpropertiesdialog.h"
|
#include "elementpropertiesdialog.h"
|
||||||
#include "ghostelement.h"
|
#include "elementpropertieswidget.h"
|
||||||
#include "qeticons.h"
|
|
||||||
#include "diagramposition.h"
|
#include <QDialogButtonBox>
|
||||||
#include "diagram.h"
|
#include <QVBoxLayout>
|
||||||
#include "elementinfowidget.h"
|
|
||||||
#include "masterpropertieswidget.h"
|
|
||||||
#include "linksingleelementwidget.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementPropertiesDialog::ElementPropertiesDialog
|
* @brief ElementPropertiesDialog::ElementPropertiesDialog
|
||||||
@@ -32,123 +29,18 @@
|
|||||||
*/
|
*/
|
||||||
ElementPropertiesDialog::ElementPropertiesDialog(Element *elmt, QWidget *parent) :
|
ElementPropertiesDialog::ElementPropertiesDialog(Element *elmt, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
element_ (elmt),
|
element_ (elmt)
|
||||||
diagram_ (elmt->diagram())
|
|
||||||
{
|
{
|
||||||
eiw_ = 0;
|
m_editor = new ElementPropertiesWidget(elmt, this);
|
||||||
mpw_ = 0;
|
|
||||||
lsew_ = 0;
|
|
||||||
buildInterface();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
connect(m_editor, SIGNAL(editElementRequired(ElementsLocation)), this , SLOT(editElement(ElementsLocation)));
|
||||||
* @brief ElementPropertiesDialog::generalWidget
|
connect(m_editor, SIGNAL(findElementRequired(ElementsLocation)), this, SLOT(findInPanel(ElementsLocation)));
|
||||||
* build the widget for the tab général
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
QWidget* ElementPropertiesDialog::generalWidget() {
|
|
||||||
CustomElement *custom_element = qobject_cast<CustomElement *>(element_);
|
|
||||||
GhostElement *ghost_element = qobject_cast<GhostElement *>(element_);
|
|
||||||
|
|
||||||
// type de l'element
|
dbb = new QDialogButtonBox(QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::Reset, Qt::Horizontal, this);
|
||||||
QString description_string;
|
|
||||||
if (ghost_element) {
|
|
||||||
description_string += tr("Élément manquant");
|
|
||||||
} else {
|
|
||||||
description_string += tr("Élément");
|
|
||||||
}
|
|
||||||
description_string += "\n";
|
|
||||||
|
|
||||||
// some element characteristic
|
|
||||||
description_string += QString(tr("Nom : %1\n")).arg(element_ -> name());
|
|
||||||
int folio_index = diagram_ -> folioIndex();
|
|
||||||
if (folio_index != -1) {
|
|
||||||
description_string += QString(tr("Folio : %1\n")).arg(folio_index + 1);
|
|
||||||
}
|
|
||||||
description_string += QString(tr("Position : %1\n")).arg(diagram_ -> convertPosition(element_ -> scenePos()).toString());
|
|
||||||
description_string += QString(tr("Dimensions : %1*%2\n")).arg(element_ -> size().width()).arg(element_ -> size().height());
|
|
||||||
description_string += QString(tr("Bornes : %1\n")).arg(element_ -> terminals().count());
|
|
||||||
description_string += QString(tr("Champs de texte : %1\n")).arg(element_ -> texts().count());
|
|
||||||
|
|
||||||
if (custom_element) {
|
|
||||||
description_string += QString(tr("Emplacement : %1\n")).arg(custom_element -> location().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
// widget himself
|
|
||||||
QWidget *general_widget = new QWidget (tab_);
|
|
||||||
QVBoxLayout *vlayout_ = new QVBoxLayout (general_widget);
|
|
||||||
general_widget -> setLayout(vlayout_);
|
|
||||||
|
|
||||||
//widget for the text
|
|
||||||
vlayout_->addWidget(new QLabel (description_string, general_widget));
|
|
||||||
|
|
||||||
//widget for the pixmap
|
|
||||||
QLabel *pix = new QLabel(general_widget);
|
|
||||||
pix->setPixmap(element_->pixmap());
|
|
||||||
vlayout_->addWidget(pix, 0, Qt::AlignHCenter);
|
|
||||||
vlayout_ -> addStretch();
|
|
||||||
|
|
||||||
//button widget
|
|
||||||
find_in_panel = new QPushButton(QET::Icons::ZoomDraw, tr("Retrouver dans le panel"), general_widget);
|
|
||||||
connect(find_in_panel, SIGNAL(clicked()), this, SLOT(findInPanel()));
|
|
||||||
edit_element = new QPushButton(QET::Icons::ElementEdit, tr("Éditer l'élément"), general_widget);
|
|
||||||
connect(edit_element, SIGNAL(clicked()), this, SLOT(editElement()));
|
|
||||||
QHBoxLayout *hlayout_ = new QHBoxLayout;
|
|
||||||
hlayout_->addWidget(find_in_panel);
|
|
||||||
hlayout_->addWidget(edit_element);
|
|
||||||
|
|
||||||
vlayout_->addLayout(hlayout_);
|
|
||||||
return general_widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief ElementPropertiesDialog::buildInterface
|
|
||||||
*build the interface of this dialog, the main tab can have
|
|
||||||
*different tab according to the edited element
|
|
||||||
*/
|
|
||||||
void ElementPropertiesDialog::buildInterface() {
|
|
||||||
|
|
||||||
setWindowTitle(tr("Propriétés de l'élément"));
|
|
||||||
tab_ = new QTabWidget(this);
|
|
||||||
|
|
||||||
//Add tab according to the element
|
|
||||||
switch (element_ -> linkType()) {
|
|
||||||
case Element::Simple:
|
|
||||||
eiw_ = new ElementInfoWidget(element_, this);
|
|
||||||
tab_ -> addTab(eiw_, tr("Information"));
|
|
||||||
break;
|
|
||||||
case Element::NextReport:
|
|
||||||
lsew_ = new LinkSingleElementWidget(element_, this);
|
|
||||||
tab_ -> addTab(lsew_, tr("Report de folio"));
|
|
||||||
break;
|
|
||||||
case Element::PreviousReport:
|
|
||||||
lsew_ = new LinkSingleElementWidget(element_, this);
|
|
||||||
tab_ -> addTab(lsew_, tr("Report de folio"));
|
|
||||||
break;
|
|
||||||
case Element::Master:
|
|
||||||
mpw_ = new MasterPropertiesWidget(element_, this);
|
|
||||||
tab_ -> addTab(mpw_, tr("Référence croisée (maitre)"));
|
|
||||||
eiw_ = new ElementInfoWidget(element_, this);
|
|
||||||
tab_ -> addTab(eiw_, tr("Informations"));
|
|
||||||
break;
|
|
||||||
case Element::Slave:
|
|
||||||
lsew_ = new LinkSingleElementWidget(element_, this);
|
|
||||||
tab_ -> addTab(lsew_, tr("Référence croisée (esclave)"));
|
|
||||||
break;
|
|
||||||
case Element::Terminale:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
tab_ -> addTab(generalWidget(), tr("Général"));
|
|
||||||
|
|
||||||
dbb = new QDialogButtonBox(QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::Reset,
|
|
||||||
Qt::Horizontal, this);
|
|
||||||
connect(dbb, SIGNAL(clicked(QAbstractButton*)), this, SLOT(standardButtonClicked(QAbstractButton*)));
|
connect(dbb, SIGNAL(clicked(QAbstractButton*)), this, SLOT(standardButtonClicked(QAbstractButton*)));
|
||||||
|
|
||||||
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
||||||
main_layout -> addWidget(tab_);
|
main_layout -> addWidget(m_editor);
|
||||||
main_layout -> addWidget(dbb);
|
main_layout -> addWidget(dbb);
|
||||||
setLayout(main_layout);
|
setLayout(main_layout);
|
||||||
}
|
}
|
||||||
@@ -161,56 +53,28 @@ void ElementPropertiesDialog::buildInterface() {
|
|||||||
*/
|
*/
|
||||||
void ElementPropertiesDialog::standardButtonClicked(QAbstractButton *button) {
|
void ElementPropertiesDialog::standardButtonClicked(QAbstractButton *button) {
|
||||||
int answer = dbb -> buttonRole(button);
|
int answer = dbb -> buttonRole(button);
|
||||||
bool accept = false;
|
|
||||||
|
|
||||||
switch (answer) {
|
switch (answer) {
|
||||||
case QDialogButtonBox::ResetRole:
|
case QDialogButtonBox::ResetRole:
|
||||||
if (mpw_) mpw_->reset();
|
m_editor->reset();
|
||||||
break;
|
break;
|
||||||
case QDialogButtonBox::ApplyRole:
|
case QDialogButtonBox::ApplyRole:
|
||||||
accept = true;
|
m_editor->apply();
|
||||||
break;
|
accept();
|
||||||
case QDialogButtonBox::RejectRole:
|
|
||||||
this -> reject();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this -> reject();
|
reject();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accept) {
|
|
||||||
QUndoCommand *a = nullptr;
|
|
||||||
QUndoCommand *b = nullptr;
|
|
||||||
|
|
||||||
if (eiw_) a = eiw_ -> associatedUndo();
|
|
||||||
if (mpw_) b = mpw_ -> associatedUndo();
|
|
||||||
if (lsew_) lsew_ -> apply();
|
|
||||||
|
|
||||||
//If two undo, we push it in a macro
|
|
||||||
if (a && b) {
|
|
||||||
QUndoStack &stack = element_ -> diagram() -> undoStack();
|
|
||||||
stack.beginMacro(a -> text() + " + " + b -> text());
|
|
||||||
stack.push(a);
|
|
||||||
stack.push(b);
|
|
||||||
stack.endMacro();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (a) element_ -> diagram() -> undoStack().push(a);
|
|
||||||
if (b) element_ -> diagram() -> undoStack().push(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
this -> accept();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementPropertiesDialog::findInPanel
|
* @brief ElementPropertiesDialog::findInPanel
|
||||||
* Slot
|
* Slot
|
||||||
*/
|
*/
|
||||||
void ElementPropertiesDialog::findInPanel() {
|
void ElementPropertiesDialog::findInPanel(const ElementsLocation &location)
|
||||||
if (CustomElement *custom_element = qobject_cast<CustomElement *>(element_)) {
|
{
|
||||||
emit findElementRequired(custom_element->location());
|
emit findElementRequired(location);
|
||||||
}
|
|
||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,10 +82,9 @@ void ElementPropertiesDialog::findInPanel() {
|
|||||||
* @brief ElementPropertiesDialog::editElement
|
* @brief ElementPropertiesDialog::editElement
|
||||||
* Slot
|
* Slot
|
||||||
*/
|
*/
|
||||||
void ElementPropertiesDialog::editElement() {
|
void ElementPropertiesDialog::editElement(const ElementsLocation &location)
|
||||||
if (CustomElement *custom_element = qobject_cast<CustomElement *>(element_)) {
|
{
|
||||||
emit findElementRequired(custom_element->location());
|
emit findElementRequired(location);
|
||||||
emit editElementRequired(custom_element->location());
|
emit editElementRequired(location);
|
||||||
}
|
|
||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,31 +15,28 @@
|
|||||||
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/>.
|
||||||
*/
|
*/
|
||||||
#ifndef ELEMENTPROPERTIESWIDGET_H
|
#ifndef ELEMENTPROPERTIESDIALOG_H
|
||||||
#define ELEMENTPROPERTIESWIDGET_H
|
#define ELEMENTPROPERTIESDIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
class Diagram;
|
|
||||||
class Element;
|
class Element;
|
||||||
class ElementsLocation;
|
class ElementsLocation;
|
||||||
class ElementInfoWidget;
|
|
||||||
class MasterPropertiesWidget;
|
|
||||||
class LinkSingleElementWidget;
|
|
||||||
class QAbstractButton;
|
class QAbstractButton;
|
||||||
class QDialogButtonBox;
|
class QDialogButtonBox;
|
||||||
class QTabWidget;
|
class ElementPropertiesWidget;
|
||||||
|
|
||||||
class ElementPropertiesDialog : public QDialog {
|
/**
|
||||||
|
* @brief The ElementPropertiesDialog class
|
||||||
|
* Display the element properties widget in a QDialog
|
||||||
|
*/
|
||||||
|
class ElementPropertiesDialog : public QDialog
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ElementPropertiesDialog(Element *elmt, QWidget *parent = 0);
|
explicit ElementPropertiesDialog(Element *elmt, QWidget *parent = 0);
|
||||||
|
|
||||||
private:
|
|
||||||
QWidget* generalWidget();
|
|
||||||
void buildInterface();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/// Signal emitted when users wish to locate an element from the diagram within elements collection
|
/// Signal emitted when users wish to locate an element from the diagram within elements collection
|
||||||
void findElementRequired(const ElementsLocation &);
|
void findElementRequired(const ElementsLocation &);
|
||||||
@@ -48,19 +45,13 @@ class ElementPropertiesDialog : public QDialog {
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void standardButtonClicked (QAbstractButton *);
|
void standardButtonClicked (QAbstractButton *);
|
||||||
void findInPanel ();
|
void findInPanel (const ElementsLocation &);
|
||||||
void editElement ();
|
void editElement (const ElementsLocation &);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Element *element_;
|
Element *element_;
|
||||||
Diagram *diagram_;
|
|
||||||
QTabWidget *tab_;
|
|
||||||
QPushButton *find_in_panel,
|
|
||||||
*edit_element;
|
|
||||||
QDialogButtonBox *dbb;
|
QDialogButtonBox *dbb;
|
||||||
ElementInfoWidget *eiw_;
|
ElementPropertiesWidget *m_editor;
|
||||||
MasterPropertiesWidget *mpw_;
|
|
||||||
LinkSingleElementWidget *lsew_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ELEMENTPROPERTIESWIDGET_H
|
#endif // ELEMENTPROPERTIESDIALOG_H
|
||||||
|
|||||||
203
sources/ui/elementpropertieswidget.cpp
Normal file
203
sources/ui/elementpropertieswidget.cpp
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
/*
|
||||||
|
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 "elementpropertieswidget.h"
|
||||||
|
#include "element.h"
|
||||||
|
#include "elementinfowidget.h"
|
||||||
|
#include "masterpropertieswidget.h"
|
||||||
|
#include "linksingleelementwidget.h"
|
||||||
|
#include "ghostelement.h"
|
||||||
|
#include "diagram.h"
|
||||||
|
#include "diagramposition.h"
|
||||||
|
#include "qeticons.h"
|
||||||
|
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QUndoStack>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementPropertiesWidget::ElementPropertiesWidget
|
||||||
|
* Default constructor
|
||||||
|
* @param elmt
|
||||||
|
* @param parent
|
||||||
|
*/
|
||||||
|
ElementPropertiesWidget::ElementPropertiesWidget(Element *elmt, QWidget *parent) :
|
||||||
|
PropertiesEditorWidget (parent),
|
||||||
|
m_element (elmt),
|
||||||
|
m_diagram (elmt->diagram()),
|
||||||
|
m_tab (nullptr)
|
||||||
|
{
|
||||||
|
buildGui();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementPropertiesWidget::apply
|
||||||
|
* Apply the new properties by pushing an undo command
|
||||||
|
* to the parent project's undo stack of element
|
||||||
|
*/
|
||||||
|
void ElementPropertiesWidget::apply()
|
||||||
|
{
|
||||||
|
QList <QUndoCommand *> undo_list;
|
||||||
|
|
||||||
|
foreach (PropertiesEditorWidget *pew, m_list_editor)
|
||||||
|
if (pew->associatedUndo())
|
||||||
|
undo_list << pew->associatedUndo();
|
||||||
|
|
||||||
|
if (undo_list.isEmpty()) return;
|
||||||
|
|
||||||
|
QString str;
|
||||||
|
foreach(QUndoCommand *uc, undo_list) str += uc->text() += " ";
|
||||||
|
|
||||||
|
QUndoStack &stack = m_element -> diagram() -> undoStack();
|
||||||
|
stack.beginMacro(str);
|
||||||
|
foreach(QUndoCommand *uc, undo_list) stack.push(uc);
|
||||||
|
stack.endMacro();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementPropertiesWidget::reset
|
||||||
|
* Reset the edited properties
|
||||||
|
*/
|
||||||
|
void ElementPropertiesWidget::reset() {
|
||||||
|
foreach (PropertiesEditorWidget *pew, m_list_editor) pew->reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementPropertiesWidget::findInPanel
|
||||||
|
* If m_element is a custom element, emit findElementRequired
|
||||||
|
*/
|
||||||
|
void ElementPropertiesWidget::findInPanel()
|
||||||
|
{
|
||||||
|
if (CustomElement *custom_element = qobject_cast<CustomElement *>(m_element))
|
||||||
|
emit findElementRequired(custom_element->location());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementPropertiesWidget::editElement
|
||||||
|
* If m_element is a custom element, emit findElementRequired and editElementRequired
|
||||||
|
*/
|
||||||
|
void ElementPropertiesWidget::editElement()
|
||||||
|
{
|
||||||
|
if (CustomElement *custom_element = qobject_cast<CustomElement *>(m_element))
|
||||||
|
{
|
||||||
|
emit findElementRequired(custom_element->location());
|
||||||
|
emit editElementRequired(custom_element->location());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementPropertiesWidget::build
|
||||||
|
* Build the content of this widget
|
||||||
|
*/
|
||||||
|
void ElementPropertiesWidget::buildGui()
|
||||||
|
{
|
||||||
|
m_tab = new QTabWidget(this);
|
||||||
|
|
||||||
|
//Add tab according to the element
|
||||||
|
switch (m_element -> linkType())
|
||||||
|
{
|
||||||
|
case Element::Simple:
|
||||||
|
m_list_editor << new ElementInfoWidget(m_element, this);
|
||||||
|
break;
|
||||||
|
case Element::NextReport:
|
||||||
|
m_list_editor << new LinkSingleElementWidget(m_element, this);
|
||||||
|
break;
|
||||||
|
case Element::PreviousReport:
|
||||||
|
m_list_editor << new LinkSingleElementWidget(m_element, this);
|
||||||
|
break;
|
||||||
|
case Element::Master:
|
||||||
|
m_list_editor << new MasterPropertiesWidget(m_element, this);
|
||||||
|
m_list_editor << new ElementInfoWidget(m_element, this);
|
||||||
|
break;
|
||||||
|
case Element::Slave:
|
||||||
|
m_list_editor << new LinkSingleElementWidget(m_element, this);
|
||||||
|
break;
|
||||||
|
case Element::Terminale:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (PropertiesEditorWidget *pew, m_list_editor) m_tab->addTab(pew, pew->title());
|
||||||
|
m_tab -> addTab(generalWidget(), tr("Général"));
|
||||||
|
|
||||||
|
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
||||||
|
main_layout -> addWidget(m_tab);
|
||||||
|
setLayout(main_layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementPropertiesWidget::generalWidget
|
||||||
|
* @return build and return the "general" widget
|
||||||
|
*/
|
||||||
|
QWidget *ElementPropertiesWidget::generalWidget()
|
||||||
|
{
|
||||||
|
CustomElement *custom_element = qobject_cast<CustomElement *>(m_element);
|
||||||
|
GhostElement *ghost_element = qobject_cast<GhostElement *>(m_element);
|
||||||
|
|
||||||
|
// type de l'element
|
||||||
|
QString description_string;
|
||||||
|
if (ghost_element) {
|
||||||
|
description_string += tr("Élément manquant");
|
||||||
|
} else {
|
||||||
|
description_string += tr("Élément");
|
||||||
|
}
|
||||||
|
description_string += "\n";
|
||||||
|
|
||||||
|
// some element characteristic
|
||||||
|
description_string += QString(tr("Nom : %1\n")).arg(m_element -> name());
|
||||||
|
int folio_index = m_diagram -> folioIndex();
|
||||||
|
if (folio_index != -1) {
|
||||||
|
description_string += QString(tr("Folio : %1\n")).arg(folio_index + 1);
|
||||||
|
}
|
||||||
|
description_string += QString(tr("Position : %1\n")).arg(m_diagram -> convertPosition(m_element -> scenePos()).toString());
|
||||||
|
description_string += QString(tr("Dimensions : %1*%2\n")).arg(m_element -> size().width()).arg(m_element -> size().height());
|
||||||
|
description_string += QString(tr("Bornes : %1\n")).arg(m_element -> terminals().count());
|
||||||
|
description_string += QString(tr("Champs de texte : %1\n")).arg(m_element -> texts().count());
|
||||||
|
|
||||||
|
if (custom_element) {
|
||||||
|
description_string += QString(tr("Emplacement : %1\n")).arg(custom_element -> location().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
// widget himself
|
||||||
|
QWidget *general_widget = new QWidget (m_tab);
|
||||||
|
QVBoxLayout *vlayout_ = new QVBoxLayout (general_widget);
|
||||||
|
general_widget -> setLayout(vlayout_);
|
||||||
|
|
||||||
|
//widget for the text
|
||||||
|
QLabel *label = new QLabel (description_string, general_widget);
|
||||||
|
label->setWordWrap(true);
|
||||||
|
vlayout_->addWidget(label);
|
||||||
|
|
||||||
|
//widget for the pixmap
|
||||||
|
QLabel *pix = new QLabel(general_widget);
|
||||||
|
pix->setPixmap(m_element->pixmap());
|
||||||
|
vlayout_->addWidget(pix, 0, Qt::AlignHCenter);
|
||||||
|
vlayout_ -> addStretch();
|
||||||
|
|
||||||
|
//button widget
|
||||||
|
QPushButton *find_in_panel = new QPushButton(QET::Icons::ZoomDraw, tr("Retrouver dans le panel"), general_widget);
|
||||||
|
connect(find_in_panel, SIGNAL(clicked()), this, SLOT(findInPanel()));
|
||||||
|
QPushButton *edit_element = new QPushButton(QET::Icons::ElementEdit, tr("Éditer l'élément"), general_widget);
|
||||||
|
connect(edit_element, SIGNAL(clicked()), this, SLOT(editElement()));
|
||||||
|
QHBoxLayout *hlayout_ = new QHBoxLayout;
|
||||||
|
hlayout_->addWidget(find_in_panel);
|
||||||
|
hlayout_->addWidget(edit_element);
|
||||||
|
|
||||||
|
vlayout_->addLayout(hlayout_);
|
||||||
|
return general_widget;
|
||||||
|
}
|
||||||
59
sources/ui/elementpropertieswidget.h
Normal file
59
sources/ui/elementpropertieswidget.h
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
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 ELEMENTPROPERTIESWIDGET_H
|
||||||
|
#define ELEMENTPROPERTIESWIDGET_H
|
||||||
|
|
||||||
|
#include "propertieseditorwidget.h"
|
||||||
|
|
||||||
|
class Element;
|
||||||
|
class Diagram;
|
||||||
|
class QTabWidget;
|
||||||
|
class ElementsLocation;
|
||||||
|
|
||||||
|
|
||||||
|
class ElementPropertiesWidget : public PropertiesEditorWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ElementPropertiesWidget(Element *elmt, QWidget *parent = 0);
|
||||||
|
void apply();
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void findInPanel ();
|
||||||
|
void editElement ();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void buildGui();
|
||||||
|
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 &);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Element *m_element;
|
||||||
|
Diagram *m_diagram;
|
||||||
|
QTabWidget *m_tab;
|
||||||
|
QList <PropertiesEditorWidget *> m_list_editor;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ELEMENTPROPERTIESWIDGET_H
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
* the parent widget
|
* the parent widget
|
||||||
*/
|
*/
|
||||||
LinkSingleElementWidget::LinkSingleElementWidget(Element *elmt, QWidget *parent) :
|
LinkSingleElementWidget::LinkSingleElementWidget(Element *elmt, QWidget *parent) :
|
||||||
QWidget(parent),
|
PropertiesEditorWidget(parent),
|
||||||
ui(new Ui::LinkSingleElementWidget),
|
ui(new Ui::LinkSingleElementWidget),
|
||||||
element_(elmt),
|
element_(elmt),
|
||||||
esw_(0),
|
esw_(0),
|
||||||
@@ -67,10 +67,32 @@ LinkSingleElementWidget::~LinkSingleElementWidget()
|
|||||||
* Apply the new property of the edited element
|
* Apply the new property of the edited element
|
||||||
*/
|
*/
|
||||||
void LinkSingleElementWidget::apply() {
|
void LinkSingleElementWidget::apply() {
|
||||||
|
QUndoCommand *undo = associatedUndo();
|
||||||
|
if (undo)
|
||||||
|
element_->diagram()->undoStack().push(undo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief LinkSingleElementWidget::associatedUndo
|
||||||
|
* @return the undo command associated to the current edition
|
||||||
|
* if there isn't change, return nulptr
|
||||||
|
*/
|
||||||
|
QUndoCommand *LinkSingleElementWidget::associatedUndo() const
|
||||||
|
{
|
||||||
if (esw_->selectedElement())
|
if (esw_->selectedElement())
|
||||||
element_->diagram()->undoStack().push(new LinkElementsCommand(element_, esw_->selectedElement()));
|
return new LinkElementsCommand(element_, esw_->selectedElement());
|
||||||
else if (unlink_)
|
else if (unlink_)
|
||||||
element_->diagram()->undoStack().push(new unlinkElementsCommand(element_));
|
return new unlinkElementsCommand(element_);
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString LinkSingleElementWidget::title() const
|
||||||
|
{
|
||||||
|
if (element_->linkType() == Element::AllReport)
|
||||||
|
return tr("Report de folio");
|
||||||
|
else
|
||||||
|
return tr("Référence croisée (esclave)");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
#ifndef LINKSINGLEELEMENTWIDGET_H
|
#ifndef LINKSINGLEELEMENTWIDGET_H
|
||||||
#define LINKSINGLEELEMENTWIDGET_H
|
#define LINKSINGLEELEMENTWIDGET_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include "propertieseditorwidget.h"
|
||||||
#include "element.h"
|
#include "element.h"
|
||||||
|
|
||||||
class Diagram;
|
class Diagram;
|
||||||
@@ -39,7 +39,7 @@ namespace Ui {
|
|||||||
* If the element is already linked, the widget ask user to unlink.
|
* If the element is already linked, the widget ask user to unlink.
|
||||||
* This widget embedded the diagram command for undo/redo the action
|
* This widget embedded the diagram command for undo/redo the action
|
||||||
*/
|
*/
|
||||||
class LinkSingleElementWidget : public QWidget
|
class LinkSingleElementWidget : public PropertiesEditorWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -47,7 +47,10 @@ class LinkSingleElementWidget : public QWidget
|
|||||||
public:
|
public:
|
||||||
explicit LinkSingleElementWidget(Element *elmt, QWidget *parent = 0);
|
explicit LinkSingleElementWidget(Element *elmt, QWidget *parent = 0);
|
||||||
~LinkSingleElementWidget();
|
~LinkSingleElementWidget();
|
||||||
|
|
||||||
void apply();
|
void apply();
|
||||||
|
QUndoCommand *associatedUndo() const;
|
||||||
|
QString title() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void buildInterface();
|
void buildInterface();
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ class MasterPropertiesWidget : public PropertiesEditorWidget
|
|||||||
|
|
||||||
void apply();
|
void apply();
|
||||||
void reset();
|
void reset();
|
||||||
QUndoCommand* associatedUndo() const;
|
QUndoCommand *associatedUndo () const;
|
||||||
|
QString title() const {return tr("Référence croisée (maitre)");}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void buildInterface();
|
void buildInterface();
|
||||||
|
|||||||
@@ -28,10 +28,19 @@ PropertiesEditorWidget::PropertiesEditorWidget(QWidget *parent) :
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief PropertiesEditorWidget::assosiatedUndo
|
* @brief PropertiesEditorWidget::associatedUndo
|
||||||
* By default, return an empty undo command
|
* By default, return a nullptr
|
||||||
* @return an empty undo command
|
* @return nullptr
|
||||||
*/
|
*/
|
||||||
QUndoCommand *PropertiesEditorWidget::assosiatedUndo() {
|
QUndoCommand *PropertiesEditorWidget::associatedUndo() const{
|
||||||
return new QUndoCommand();
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief PropertiesEditorWidget::title
|
||||||
|
* @return the title of this editor
|
||||||
|
*/
|
||||||
|
QString PropertiesEditorWidget::title() const
|
||||||
|
{
|
||||||
|
return QString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,9 +33,10 @@ class PropertiesEditorWidget : public QWidget
|
|||||||
public:
|
public:
|
||||||
explicit PropertiesEditorWidget(QWidget *parent = 0);
|
explicit PropertiesEditorWidget(QWidget *parent = 0);
|
||||||
|
|
||||||
void apply() {}
|
virtual void apply() {}
|
||||||
void reset() {}
|
virtual void reset() {}
|
||||||
virtual QUndoCommand *assosiatedUndo ();
|
virtual QUndoCommand *associatedUndo () const;
|
||||||
|
virtual QString title() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PROPERTIESEDITORWIDGET_H
|
#endif // PROPERTIESEDITORWIDGET_H
|
||||||
|
|||||||
Reference in New Issue
Block a user