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,7 +47,8 @@ TerminalEditor::TerminalEditor(QETElementEditor* editor, QWidget* parent):
@param parent : @param parent :
QWidget parent de ce widget QWidget parent de ce widget
*/ */
TerminalEditor::TerminalEditor(QETElementEditor *editor, TerminalEditor::TerminalEditor(
QETElementEditor *editor,
QList<PartTerminal *> &terms, QList<PartTerminal *> &terms,
QWidget *parent) : QWidget *parent) :
ElementItemEditor(editor, parent), ElementItemEditor(editor, parent),
@@ -63,6 +64,7 @@ void TerminalEditor::init()
{ {
qle_x = new QDoubleSpinBox(); qle_x = new QDoubleSpinBox();
qle_y = new QDoubleSpinBox(); qle_y = new QDoubleSpinBox();
name = new QLineEdit();
qle_x -> setRange(-5000, 5000); qle_x -> setRange(-5000, 5000);
qle_y -> setRange(-5000, 5000); qle_y -> setRange(-5000, 5000);
@@ -88,6 +90,11 @@ void TerminalEditor::init()
ori -> addWidget(orientation ); ori -> addWidget(orientation );
main_layout -> addLayout(ori); 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(); main_layout -> addStretch();
setLayout(main_layout); setLayout(main_layout);
@@ -239,6 +246,33 @@ void TerminalEditor::updateYPos()
} }
m_locked=false; 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 /// update Number and name, create cancel object
/** /**
@@ -251,6 +285,7 @@ void TerminalEditor::updateForm()
qle_x -> setValue(m_part->property("x").toReal()); qle_x -> setValue(m_part->property("x").toReal());
qle_y -> setValue(m_part->property("y").toReal()); qle_y -> setValue(m_part->property("y").toReal());
orientation -> setCurrentIndex(orientation->findData(m_part->property("orientation"))); orientation -> setCurrentIndex(orientation->findData(m_part->property("orientation")));
name -> setText(m_part->name());
activeConnections(true); activeConnections(true);
} }
@@ -260,13 +295,26 @@ void TerminalEditor::updateForm()
*/ */
void TerminalEditor::activeConnections(bool active) { void TerminalEditor::activeConnections(bool active) {
if (active) { if (active) {
connect(qle_x, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateXPos); connect(qle_x,
connect(qle_y, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateYPos); &QDoubleSpinBox::editingFinished,
connect(orientation, QOverload<int>::of(&QComboBox::activated), this, &TerminalEditor::updateTerminalO); 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 { else {
disconnect(qle_x, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateXPos); disconnect(qle_x, &QDoubleSpinBox::editingFinished,
disconnect(qle_y, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateYPos); this, &TerminalEditor::updateXPos);
disconnect(orientation, QOverload<int>::of(&QComboBox::activated), this, &TerminalEditor::updateTerminalO); 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);
} }
} }

View File

@@ -20,6 +20,8 @@
#include "elementitemeditor.h" #include "elementitemeditor.h"
#include <QLineEdit>
class PartTerminal; class PartTerminal;
class QDoubleSpinBox; class QDoubleSpinBox;
class QComboBox; class QComboBox;
@@ -35,7 +37,8 @@ class TerminalEditor : public ElementItemEditor {
// Constructors, destructor // Constructors, destructor
public: public:
TerminalEditor(QETElementEditor *, TerminalEditor(
QETElementEditor *,
QList<PartTerminal *>& terms, QList<PartTerminal *>& terms,
QWidget * = nullptr); QWidget * = nullptr);
TerminalEditor(QETElementEditor *, QWidget * = nullptr); TerminalEditor(QETElementEditor *, QWidget * = nullptr);
@@ -50,6 +53,7 @@ class TerminalEditor : public ElementItemEditor {
PartTerminal *m_part{nullptr}; PartTerminal *m_part{nullptr};
QDoubleSpinBox *qle_x, *qle_y; QDoubleSpinBox *qle_x, *qle_y;
QComboBox *orientation; QComboBox *orientation;
QLineEdit *name;
bool m_locked{false}; bool m_locked{false};
// methods // methods
@@ -63,6 +67,7 @@ class TerminalEditor : public ElementItemEditor {
void updateTerminalO(); void updateTerminalO();
void updateXPos(); void updateXPos();
void updateYPos(); void updateYPos();
void updateName();
void updateForm() override; void updateForm() override;
private: private: