From 8cd3ae9c1ca6e9fdcf3a2c912e86b3045bd56611 Mon Sep 17 00:00:00 2001 From: Simon De Backer Date: Thu, 30 Jul 2020 17:29:37 +0200 Subject: [PATCH] Add name to Terminal --- sources/editor/terminaleditor.cpp | 55 +++++++++++++++++++++++++++---- sources/editor/terminaleditor.h | 4 +++ 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/sources/editor/terminaleditor.cpp b/sources/editor/terminaleditor.cpp index 29bfd9ba4..ac297c995 100644 --- a/sources/editor/terminaleditor.cpp +++ b/sources/editor/terminaleditor.cpp @@ -50,6 +50,7 @@ TerminalEditor::TerminalEditor(QETElementEditor *editor, QList & void TerminalEditor::init() { qle_x = new QDoubleSpinBox(); qle_y = new QDoubleSpinBox(); + name = new QLineEdit(); qle_x -> setRange(-5000, 5000); qle_y -> setRange(-5000, 5000); @@ -75,6 +76,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); @@ -215,6 +221,32 @@ 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 /** @@ -226,6 +258,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); } @@ -237,14 +270,24 @@ 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::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::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::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::of(&QComboBox::activated), + this, &TerminalEditor::updateTerminalO); + disconnect(name, &QLineEdit::editingFinished, + this, &TerminalEditor::updateName); } } diff --git a/sources/editor/terminaleditor.h b/sources/editor/terminaleditor.h index 7577a9ffd..8be9db693 100644 --- a/sources/editor/terminaleditor.h +++ b/sources/editor/terminaleditor.h @@ -20,6 +20,8 @@ #include "elementitemeditor.h" +#include + class PartTerminal; class QDoubleSpinBox; class QComboBox; @@ -48,6 +50,7 @@ class TerminalEditor : public ElementItemEditor { PartTerminal *m_part{nullptr}; QDoubleSpinBox *qle_x, *qle_y; QComboBox *orientation; + QLineEdit *name; bool m_locked{false}; // methods @@ -61,6 +64,7 @@ class TerminalEditor : public ElementItemEditor { void updateTerminalO(); void updateXPos(); void updateYPos(); + void updateName(); void updateForm() override; private: -- 2.27.0