2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2015-02-20 14:56:22 +00:00
|
|
|
Copyright 2006-2015 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)
|
|
|
|
{
|
2014-05-29 13:46:04 +00:00
|
|
|
qle_x = new QDoubleSpinBox();
|
|
|
|
qle_y = new QDoubleSpinBox();
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2014-05-29 13:46:04 +00:00
|
|
|
qle_x -> setRange(-1000, 1000);
|
|
|
|
qle_y -> setRange(-1000, 1000);
|
2007-12-17 20:37:10 +00:00
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
orientation = new QComboBox();
|
2014-05-29 13:46:04 +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);
|
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
|
|
|
|
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;
|
2014-05-29 13:46:04 +00:00
|
|
|
part -> setPos(qle_x -> value(), qle_y -> value());
|
2007-06-30 17:41:07 +00:00
|
|
|
part -> setOrientation(
|
2014-05-29 13:46:04 +00:00
|
|
|
static_cast<Qet::Orientation>(
|
2007-06-30 17:41:07 +00:00
|
|
|
orientation -> itemData(
|
|
|
|
orientation -> currentIndex()
|
|
|
|
).toInt()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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
|
2014-05-29 13:46:04 +00:00
|
|
|
void TerminalEditor::updateTerminalX() { addChangePartCommand(tr("abscisse"), part, "x", qle_x -> value()); }
|
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
|
2014-05-29 13:46:04 +00:00
|
|
|
void TerminalEditor::updateTerminalY() { addChangePartCommand(tr("ordonn\351e"), part, "y", qle_y -> value()); }
|
2007-12-05 21:16:01 +00:00
|
|
|
/// Met a jour l'orientation de la borne et cree un objet d'annulation
|
2014-05-29 13:46:04 +00:00
|
|
|
void TerminalEditor::updateTerminalO() { addChangePartCommand(tr("orientation"), part, "orientation", orientation -> itemData(orientation -> currentIndex())); }
|
2013-11-16 19:20:15 +00:00
|
|
|
/// update Number and name, create cancel object
|
2014-05-29 13:46:04 +00:00
|
|
|
|
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);
|
2014-05-29 13:46:04 +00:00
|
|
|
qle_x -> setValue(part->property("x").toReal());
|
|
|
|
qle_y -> setValue(part->property("y").toReal());
|
|
|
|
orientation -> setCurrentIndex(orientation->findData(part->property("orientation")));
|
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()));
|
|
|
|
} 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()));
|
|
|
|
}
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|