Add name to Terminal

now it is possible to enter the terminal name
This commit is contained in:
Simon De Backer
2020-09-07 22:35:49 +02:00
parent 5d92393ee7
commit dce83f480c
2 changed files with 65 additions and 12 deletions

View File

@@ -47,9 +47,10 @@ TerminalEditor::TerminalEditor(QETElementEditor* editor, QWidget* parent):
@param parent :
QWidget parent de ce widget
*/
TerminalEditor::TerminalEditor(QETElementEditor *editor,
QList<PartTerminal *> &terms,
QWidget *parent) :
TerminalEditor::TerminalEditor(
QETElementEditor *editor,
QList<PartTerminal *> &terms,
QWidget *parent) :
ElementItemEditor(editor, parent),
m_terminals(terms),
m_part(terms.first()) {
@@ -63,6 +64,7 @@ void TerminalEditor::init()
{
qle_x = new QDoubleSpinBox();
qle_y = new QDoubleSpinBox();
name = new QLineEdit();
qle_x -> setRange(-5000, 5000);
qle_y -> setRange(-5000, 5000);
@@ -88,6 +90,11 @@ void TerminalEditor::init()
ori -> addWidget(orientation );
main_layout -> addLayout(ori);
QHBoxLayout *lay_name = new QHBoxLayout();
lay_name -> addWidget(new QLabel(tr("Name : ")));
lay_name -> addWidget(name);
main_layout -> addLayout(lay_name);
main_layout -> addStretch();
setLayout(main_layout);
@@ -239,6 +246,33 @@ void TerminalEditor::updateYPos()
}
m_locked=false;
}
/**
@brief TerminalEditor::updateName
SLOT set name to Terminal
*/
void TerminalEditor::updateName() {
if (m_locked) return;
m_locked = true;
QVariant var(name->text());
for (int i=0; i < m_terminals.length(); i++) {
PartTerminal* term = m_terminals[i];
if (var != term->property("name"))
{
QPropertyUndoCommand *undo;
undo = new QPropertyUndoCommand(term,
"name",
term->property("name"),
var);
undo->setText(tr("Modify name of the terminal"));
undoStack().push(undo);
}
}
m_locked=false;
}
/// update Number and name, create cancel object
/**
@@ -251,6 +285,7 @@ void TerminalEditor::updateForm()
qle_x -> setValue(m_part->property("x").toReal());
qle_y -> setValue(m_part->property("y").toReal());
orientation -> setCurrentIndex(orientation->findData(m_part->property("orientation")));
name -> setText(m_part->name());
activeConnections(true);
}
@@ -260,13 +295,26 @@ void TerminalEditor::updateForm()
*/
void TerminalEditor::activeConnections(bool active) {
if (active) {
connect(qle_x, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateXPos);
connect(qle_y, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateYPos);
connect(orientation, QOverload<int>::of(&QComboBox::activated), this, &TerminalEditor::updateTerminalO);
connect(qle_x,
&QDoubleSpinBox::editingFinished,
this, &TerminalEditor::updateXPos);
connect(qle_y,
&QDoubleSpinBox::editingFinished,
this, &TerminalEditor::updateYPos);
connect(orientation,
QOverload<int>::of(&QComboBox::activated),
this, &TerminalEditor::updateTerminalO);
connect(name, &QLineEdit::editingFinished,
this, &TerminalEditor::updateName);
}
else {
disconnect(qle_x, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateXPos);
disconnect(qle_y, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateYPos);
disconnect(orientation, QOverload<int>::of(&QComboBox::activated), this, &TerminalEditor::updateTerminalO);
disconnect(qle_x, &QDoubleSpinBox::editingFinished,
this, &TerminalEditor::updateXPos);
disconnect(qle_y, &QDoubleSpinBox::editingFinished,
this, &TerminalEditor::updateYPos);
disconnect(orientation, QOverload<int>::of(&QComboBox::activated),
this, &TerminalEditor::updateTerminalO);
disconnect(name, &QLineEdit::editingFinished,
this, &TerminalEditor::updateName);
}
}