From dce83f480c96010f2c8587a8f94c73ff3ca66b14 Mon Sep 17 00:00:00 2001 From: Simon De Backer Date: Mon, 7 Sep 2020 22:35:49 +0200 Subject: [PATCH] Add name to Terminal now it is possible to enter the terminal name --- sources/editor/terminaleditor.cpp | 66 ++++++++++++++++++++++++++----- sources/editor/terminaleditor.h | 11 ++++-- 2 files changed, 65 insertions(+), 12 deletions(-) diff --git a/sources/editor/terminaleditor.cpp b/sources/editor/terminaleditor.cpp index af72d585f..d0857853d 100644 --- a/sources/editor/terminaleditor.cpp +++ b/sources/editor/terminaleditor.cpp @@ -47,9 +47,10 @@ TerminalEditor::TerminalEditor(QETElementEditor* editor, QWidget* parent): @param parent : QWidget parent de ce widget */ -TerminalEditor::TerminalEditor(QETElementEditor *editor, - QList &terms, - QWidget *parent) : +TerminalEditor::TerminalEditor( + QETElementEditor *editor, + QList &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::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 0f9d8d7a6..6bbb482dd 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; @@ -35,9 +37,10 @@ class TerminalEditor : public ElementItemEditor { // Constructors, destructor public: - TerminalEditor(QETElementEditor *, - QList& terms, - QWidget * = nullptr); + TerminalEditor( + QETElementEditor *, + QList& terms, + QWidget * = nullptr); TerminalEditor(QETElementEditor *, QWidget * = nullptr); ~TerminalEditor() override; private: @@ -50,6 +53,7 @@ class TerminalEditor : public ElementItemEditor { PartTerminal *m_part{nullptr}; QDoubleSpinBox *qle_x, *qle_y; QComboBox *orientation; + QLineEdit *name; bool m_locked{false}; // methods @@ -63,6 +67,7 @@ class TerminalEditor : public ElementItemEditor { void updateTerminalO(); void updateXPos(); void updateYPos(); + void updateName(); void updateForm() override; private: