2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2014-01-29 18:37:45 +00:00
|
|
|
Copyright 2006-2014 The QElectroTech Team
|
2007-12-01 10:47:15 +00:00
|
|
|
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/>.
|
|
|
|
*/
|
2007-06-30 17:41:07 +00:00
|
|
|
#include "terminaleditor.h"
|
|
|
|
#include "partterminal.h"
|
2009-05-01 14:41:33 +00:00
|
|
|
#include "qeticons.h"
|
2007-06-30 17:41:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
2007-12-05 21:16:01 +00:00
|
|
|
@param editor L'editeur d'element concerne
|
|
|
|
@param term La borne a editer
|
2007-06-30 17:41:07 +00:00
|
|
|
@param parent QWidget parent de ce widget
|
|
|
|
*/
|
2010-02-18 00:42:41 +00:00
|
|
|
TerminalEditor::TerminalEditor(QETElementEditor *editor, PartTerminal *term, QWidget *parent) :
|
|
|
|
ElementItemEditor(editor, parent),
|
|
|
|
part(term)
|
|
|
|
{
|
2007-06-30 17:41:07 +00:00
|
|
|
qle_x = new QLineEdit();
|
|
|
|
qle_y = new QLineEdit();
|
|
|
|
|
2007-12-17 20:37:10 +00:00
|
|
|
qle_x -> setValidator(new QDoubleValidator(qle_x));
|
|
|
|
qle_y -> setValidator(new QDoubleValidator(qle_y));
|
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
orientation = new QComboBox();
|
2009-05-01 14:41:33 +00:00
|
|
|
orientation -> addItem(QET::Icons::North, tr("Nord"), QET::North);
|
|
|
|
orientation -> addItem(QET::Icons::East, tr("Est"), QET::East);
|
|
|
|
orientation -> addItem(QET::Icons::South, tr("Sud"), QET::South);
|
|
|
|
orientation -> addItem(QET::Icons::West, tr("Ouest"), QET::West);
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2013-11-16 19:20:15 +00:00
|
|
|
qle_number = new QLineEdit();
|
|
|
|
qle_name = new QLineEdit();
|
2013-11-21 16:25:56 +00:00
|
|
|
qcheck_name_visible = new QCheckBox(tr("Visible"));
|
2013-11-16 19:20:15 +00:00
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
QVBoxLayout *main_layout = new QVBoxLayout();
|
2007-09-05 22:11:45 +00:00
|
|
|
main_layout -> addWidget(new QLabel(tr("Position : ")));
|
2007-06-30 17:41:07 +00:00
|
|
|
|
|
|
|
QHBoxLayout *position = new QHBoxLayout();
|
|
|
|
position -> addWidget(new QLabel(tr("x : ")));
|
|
|
|
position -> addWidget(qle_x );
|
|
|
|
position -> addWidget(new QLabel(tr("y : ")));
|
|
|
|
position -> addWidget(qle_y );
|
|
|
|
main_layout -> addLayout(position);
|
|
|
|
|
|
|
|
QHBoxLayout *ori = new QHBoxLayout();
|
|
|
|
ori -> addWidget(new QLabel(tr("Orientation : ")));
|
|
|
|
ori -> addWidget(orientation );
|
|
|
|
main_layout -> addLayout(ori);
|
2013-11-16 19:20:15 +00:00
|
|
|
|
2013-11-21 16:25:56 +00:00
|
|
|
QHBoxLayout *name = new QHBoxLayout();
|
|
|
|
name -> addWidget(new QLabel(tr("Nom : ")));
|
|
|
|
name -> addWidget(qle_name );
|
|
|
|
name -> addWidget(qcheck_name_visible );
|
|
|
|
main_layout -> addLayout(name);
|
|
|
|
|
2013-11-16 19:20:15 +00:00
|
|
|
QHBoxLayout *num = new QHBoxLayout();
|
|
|
|
num -> addWidget(new QLabel(tr("Num\351ro : ")));
|
|
|
|
num -> addWidget(qle_number );
|
|
|
|
main_layout -> addLayout(num);
|
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
main_layout -> addStretch();
|
|
|
|
setLayout(main_layout);
|
|
|
|
|
2007-08-25 03:43:05 +00:00
|
|
|
activeConnections(true);
|
2007-06-30 17:41:07 +00:00
|
|
|
updateForm();
|
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/// Destructeur
|
2007-06-30 17:41:07 +00:00
|
|
|
TerminalEditor::~TerminalEditor() {
|
|
|
|
};
|
|
|
|
|
2010-02-18 00:42:41 +00:00
|
|
|
/**
|
|
|
|
Permet de specifier a cet editeur quelle primitive il doit editer. A noter
|
|
|
|
qu'un editeur peut accepter ou refuser d'editer une primitive.
|
|
|
|
L'editeur de borne acceptera d'editer la primitive new_part s'il s'agit d'un
|
|
|
|
objet de la classe PartTerminal.
|
|
|
|
@param new_part Nouvelle primitive a editer
|
|
|
|
@return true si l'editeur a accepter d'editer la primitive, false sinon
|
|
|
|
*/
|
|
|
|
bool TerminalEditor::setPart(CustomElementPart *new_part) {
|
|
|
|
if (!new_part) {
|
|
|
|
part = 0;
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
if (PartTerminal *part_terminal = dynamic_cast<PartTerminal *>(new_part)) {
|
|
|
|
part = part_terminal;
|
|
|
|
updateForm();
|
|
|
|
return(true);
|
|
|
|
} else {
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return la primitive actuellement editee, ou 0 si ce widget n'en edite pas
|
|
|
|
*/
|
|
|
|
CustomElementPart *TerminalEditor::currentPart() const {
|
|
|
|
return(part);
|
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
|
|
|
Met a jour la borne a partir des donnees du formulaire
|
|
|
|
*/
|
2007-06-30 17:41:07 +00:00
|
|
|
void TerminalEditor::updateTerminal() {
|
2010-02-18 00:42:41 +00:00
|
|
|
if (!part) return;
|
2007-06-30 17:41:07 +00:00
|
|
|
part -> setPos(qle_x -> text().toDouble(), qle_y -> text().toDouble());
|
|
|
|
part -> setOrientation(
|
|
|
|
static_cast<QET::Orientation>(
|
|
|
|
orientation -> itemData(
|
|
|
|
orientation -> currentIndex()
|
|
|
|
).toInt()
|
|
|
|
)
|
|
|
|
);
|
2013-11-16 19:20:15 +00:00
|
|
|
part -> setNumber( qle_number->text() );
|
|
|
|
part -> setName ( qle_name->text() );
|
2013-11-21 16:25:56 +00:00
|
|
|
part -> setNameHidden( !qcheck_name_visible ->isChecked() );
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
|
|
|
|
2013-11-21 16:25:56 +00:00
|
|
|
/// WARNING!!!! on addChangePartCommand the prop accept only the simple string! (NOT /:;,?...)
|
2007-12-05 21:16:01 +00:00
|
|
|
/// Met a jour l'abscisse de la position de la borne et cree un objet d'annulation
|
2007-08-25 03:43:05 +00:00
|
|
|
void TerminalEditor::updateTerminalX() { addChangePartCommand(tr("abscisse"), part, "x", qle_x -> text().toDouble()); updateForm(); }
|
2007-12-05 21:16:01 +00:00
|
|
|
/// Met a jour l'ordonnee de la position de la borne et cree un objet d'annulation
|
2007-08-25 03:43:05 +00:00
|
|
|
void TerminalEditor::updateTerminalY() { addChangePartCommand(tr("ordonn\351e"), part, "y", qle_y -> text().toDouble()); updateForm(); }
|
2007-12-05 21:16:01 +00:00
|
|
|
/// Met a jour l'orientation de la borne et cree un objet d'annulation
|
2007-08-25 03:43:05 +00:00
|
|
|
void TerminalEditor::updateTerminalO() { addChangePartCommand(tr("orientation"), part, "orientation", orientation -> itemData(orientation -> currentIndex()).toInt()); }
|
2013-11-16 19:20:15 +00:00
|
|
|
/// update Number and name, create cancel object
|
2013-11-21 16:25:56 +00:00
|
|
|
void TerminalEditor::updateTerminalNum() {
|
|
|
|
addChangePartCommand(tr("num\351ro: ")+qle_number -> text(), part, "number", qle_number -> text());
|
|
|
|
updateForm();
|
|
|
|
}
|
|
|
|
void TerminalEditor::updateTerminalName() {
|
|
|
|
addChangePartCommand(tr("nom: ")+qle_name -> text(), part, "name", qle_name -> text());
|
|
|
|
updateForm();
|
|
|
|
}
|
|
|
|
void TerminalEditor::updateTerminalNameVisible() {
|
|
|
|
addChangePartCommand(tr("nom visible: ")+QString::number( qcheck_name_visible->isChecked()), part, "nameHidden", !qcheck_name_visible -> isChecked());
|
|
|
|
updateForm();
|
|
|
|
}
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
|
|
|
Met a jour le formulaire d'edition
|
|
|
|
*/
|
2007-06-30 17:41:07 +00:00
|
|
|
void TerminalEditor::updateForm() {
|
2010-02-18 00:42:41 +00:00
|
|
|
if (!part) return;
|
2007-08-25 03:43:05 +00:00
|
|
|
activeConnections(false);
|
|
|
|
qle_x -> setText(part -> property("x").toString());
|
|
|
|
qle_y -> setText(part -> property("y").toString());
|
2007-06-30 17:41:07 +00:00
|
|
|
orientation -> setCurrentIndex(static_cast<int>(part -> orientation()));
|
2013-11-16 19:20:15 +00:00
|
|
|
qle_number -> setText(part -> number() );
|
|
|
|
qle_name -> setText(part -> nameOfTerminal() );
|
2013-11-21 16:25:56 +00:00
|
|
|
qcheck_name_visible ->setChecked( !part -> nameIsHidden() );
|
2007-08-25 03:43:05 +00:00
|
|
|
activeConnections(true);
|
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
|
|
|
Active ou desactive les connexionx signaux/slots entre les widgets internes.
|
|
|
|
@param active true pour activer les connexions, false pour les desactiver
|
|
|
|
*/
|
2007-08-25 03:43:05 +00:00
|
|
|
void TerminalEditor::activeConnections(bool active) {
|
|
|
|
if (active) {
|
|
|
|
connect(qle_x, SIGNAL(editingFinished()), this, SLOT(updateTerminalX()));
|
|
|
|
connect(qle_y, SIGNAL(editingFinished()), this, SLOT(updateTerminalY()));
|
|
|
|
connect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO()));
|
2013-11-16 19:20:15 +00:00
|
|
|
connect(qle_number, SIGNAL(editingFinished()), this, SLOT(updateTerminalNum()));
|
|
|
|
connect(qle_name, SIGNAL(editingFinished()), this, SLOT(updateTerminalName()));
|
2013-11-21 16:25:56 +00:00
|
|
|
connect(qcheck_name_visible, SIGNAL(stateChanged ( int)), this, SLOT(updateTerminalNameVisible()));
|
2007-08-25 03:43:05 +00:00
|
|
|
} else {
|
|
|
|
disconnect(qle_x, SIGNAL(editingFinished()), this, SLOT(updateTerminalX()));
|
|
|
|
disconnect(qle_y, SIGNAL(editingFinished()), this, SLOT(updateTerminalY()));
|
|
|
|
disconnect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO()));
|
2013-11-16 19:20:15 +00:00
|
|
|
disconnect(qle_number, SIGNAL(editingFinished()), this, SLOT(updateTerminalNum()));
|
|
|
|
disconnect(qle_name, SIGNAL(editingFinished()), this, SLOT(updateTerminalName()));
|
2013-11-21 16:25:56 +00:00
|
|
|
disconnect(qcheck_name_visible, SIGNAL(stateChanged ( int)), this, SLOT(updateTerminalNameVisible()));
|
2007-08-25 03:43:05 +00:00
|
|
|
}
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|