QElectroTech  0.70
terminaleditor.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "terminaleditor.h"
19 #include "partterminal.h"
20 #include "qeticons.h"
22 #include <QDoubleSpinBox>
23 #include <QComboBox>
24 #include <QVBoxLayout>
25 #include <QHBoxLayout>
26 #include <QLabel>
27 
35  ElementItemEditor(editor, parent),
36  part(term),
37  m_locked(false)
38 {
39  qle_x = new QDoubleSpinBox();
40  qle_y = new QDoubleSpinBox();
41 
42  qle_x -> setRange(-5000, 5000);
43  qle_y -> setRange(-5000, 5000);
44 
45  orientation = new QComboBox();
46  orientation -> addItem(QET::Icons::North, tr("Nord"), Qet::North);
47  orientation -> addItem(QET::Icons::East, tr("Est"), Qet::East);
48  orientation -> addItem(QET::Icons::South, tr("Sud"), Qet::South);
49  orientation -> addItem(QET::Icons::West, tr("Ouest"), Qet::West);
50 
51  QVBoxLayout *main_layout = new QVBoxLayout();
52  main_layout -> addWidget(new QLabel(tr("Position : ")));
53 
54  QHBoxLayout *position = new QHBoxLayout();
55  position -> addWidget(new QLabel(tr("x : ")));
56  position -> addWidget(qle_x );
57  position -> addWidget(new QLabel(tr("y : ")));
58  position -> addWidget(qle_y );
59  main_layout -> addLayout(position);
60 
61  QHBoxLayout *ori = new QHBoxLayout();
62  ori -> addWidget(new QLabel(tr("Orientation : ")));
63  ori -> addWidget(orientation );
64  main_layout -> addLayout(ori);
65 
66  main_layout -> addStretch();
67  setLayout(main_layout);
68 
69  activeConnections(true);
70  updateForm();
71 }
72 
75 };
76 
86 {
87  if (!new_part)
88  {
89  if (part)
91  part = nullptr;
92  return(true);
93  }
94  if (PartTerminal *part_terminal = dynamic_cast<PartTerminal *>(new_part))
95  {
96  if(part == part_terminal) return true;
97  if (part)
99  part = part_terminal;
100  updateForm();
102  return(true);
103  }
104  return(false);
105 }
106 
111  return(part);
112 }
113 
116 {
117  if (m_locked) return;
118  m_locked = true;
119  QVariant var(orientation -> itemData(orientation -> currentIndex()));
120  if (var != part->property("orientation"))
121  {
122  QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "orientation", part->property("orientation"), var);
123  undo->setText(tr("Modifier l'orientation d'une borne"));
124  undoStack().push(undo);
125  }
126  m_locked = false;
127 }
128 
130 {
131  if (m_locked) return;
132  m_locked = true;
133  QPointF new_pos(qle_x->value(), qle_y->value());
134  if (new_pos != part->pos())
135  {
136  QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "pos", part->property("pos"), new_pos);
137  undo->setText(tr("Déplacer une borne"));
138  undo->enableAnimation();
139  undoStack().push(undo);
140  }
141  m_locked=false;
142 }
144 
149  if (!part) return;
150  activeConnections(false);
151  qle_x -> setValue(part->property("x").toReal());
152  qle_y -> setValue(part->property("y").toReal());
153  orientation -> setCurrentIndex(orientation->findData(part->property("orientation")));
154  activeConnections(true);
155 }
156 
162 {
163  if (active)
164  {
165  connect(qle_x, SIGNAL(editingFinished()), this, SLOT(updatePos()));
166  connect(qle_y, SIGNAL(editingFinished()), this, SLOT(updatePos()));
167  connect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO()));
168  }
169  else
170  {
171  disconnect(qle_x, SIGNAL(editingFinished()), this, SLOT(updatePos()));
172  disconnect(qle_y, SIGNAL(editingFinished()), this, SLOT(updatePos()));
173  disconnect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO()));
174  }
175 }
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
bool setPart(CustomElementPart *) override
QDoubleSpinBox * qle_x
QIcon South
Definition: qeticons.cpp:161
Definition: qet.h:207
QIcon West
Definition: qeticons.cpp:174
QComboBox * orientation
PartTerminal * part
void enableAnimation(bool animate=true)
QPropertyUndoCommand::enableAnimation True to enable animation.
TerminalEditor(QETElementEditor *, PartTerminal *=nullptr, QWidget *=nullptr)
CustomElementPart * currentPart() const override
QIcon North
Definition: qeticons.cpp:122
QIcon tr
Definition: qeticons.cpp:204
QVariant property(const char *name) const override
QIcon East
Definition: qeticons.cpp:61
~TerminalEditor() override
Destructeur.
Definition: qet.h:205
QDoubleSpinBox * qle_y
void activeConnections(bool)
void updateForm() override
update Number and name, create cancel object
void updateTerminalO()
Met a jour l&#39;orientation de la borne et cree un objet d&#39;annulation.
void orientationChanged()
virtual QUndoStack & undoStack() const