From a1779d1a7a5f072ff39816cbe9468dddec5cfc8f Mon Sep 17 00:00:00 2001 From: joshua Date: Fri, 12 Feb 2021 19:28:07 +0100 Subject: [PATCH] Rewrite terminaleditor with ui file. Write terminal editor with ui file. The terminalData::type of a terminal can be edited with the terminal editor. --- sources/editor/graphicspart/partterminal.cpp | 16 +- sources/editor/graphicspart/partterminal.h | 12 +- sources/editor/terminaleditor.cpp | 322 ------------------- sources/editor/terminaleditor.h | 76 ----- sources/editor/ui/qetelementeditor.cpp | 23 +- sources/editor/ui/terminaleditor.cpp | 254 +++++++++++++++ sources/editor/ui/terminaleditor.h | 64 ++++ sources/editor/ui/terminaleditor.ui | 98 ++++++ sources/properties/terminaldata.cpp | 33 +- sources/properties/terminaldata.h | 30 +- 10 files changed, 504 insertions(+), 424 deletions(-) delete mode 100644 sources/editor/terminaleditor.cpp delete mode 100644 sources/editor/terminaleditor.h create mode 100644 sources/editor/ui/terminaleditor.cpp create mode 100644 sources/editor/ui/terminaleditor.h create mode 100644 sources/editor/ui/terminaleditor.ui diff --git a/sources/editor/graphicspart/partterminal.cpp b/sources/editor/graphicspart/partterminal.cpp index 0335ab974..3c5539f1a 100644 --- a/sources/editor/graphicspart/partterminal.cpp +++ b/sources/editor/graphicspart/partterminal.cpp @@ -72,7 +72,7 @@ void PartTerminal::paint( const QStyleOptionGraphicsItem *options, QWidget *widget) { - Q_UNUSED(widget); + Q_UNUSED(widget) painter -> save(); // annulation des renderhints @@ -161,6 +161,20 @@ void PartTerminal::setName(QString& name) { emit nameChanged(); } +/** + * @brief PartTerminal::setTerminalType + * Set the type of terminal to 'type' + * @param type + */ +void PartTerminal::setTerminalType(TerminalData::Type type) +{ + if (d->m_type == type) { + return; + } + d->m_type = type; + emit terminalTypeChanged(); +} + void PartTerminal::setNewUuid() { d -> m_uuid = QUuid::createUuid(); diff --git a/sources/editor/graphicspart/partterminal.h b/sources/editor/graphicspart/partterminal.h index e4f807966..ad023f0b6 100644 --- a/sources/editor/graphicspart/partterminal.h +++ b/sources/editor/graphicspart/partterminal.h @@ -27,10 +27,13 @@ This class represents a terminal which may be used to compose the drawing of an electrical element within the element editor. */ -class PartTerminal : public CustomElementGraphicPart { +class PartTerminal : public CustomElementGraphicPart +{ Q_OBJECT + Q_PROPERTY(Qet::Orientation orientation READ orientation WRITE setOrientation) Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(TerminalData::Type terminal_type READ terminalType WRITE setTerminalType) public: // constructors, destructor @@ -42,6 +45,7 @@ class PartTerminal : public CustomElementGraphicPart { signals: void orientationChanged(); void nameChanged(); + void terminalTypeChanged(); // methods public: @@ -51,7 +55,6 @@ class PartTerminal : public CustomElementGraphicPart { @return the QGraphicsItem type */ int type() const override { return Type; } - QString name() const override { return d -> m_name; } QString xmlName() const override { return(QString("terminal")); } void fromXml(const QDomElement &) override; const QDomElement toXml(QDomDocument &) const override; @@ -71,7 +74,12 @@ class PartTerminal : public CustomElementGraphicPart { Qet::Orientation orientation() const {return d -> m_orientation;} void setOrientation(Qet::Orientation ori); + QString name() const override { return d -> m_name; } void setName(QString& name); + + TerminalData::Type terminalType() const {return d->m_type;} + void setTerminalType(TerminalData::Type type); + void setNewUuid(); private: diff --git a/sources/editor/terminaleditor.cpp b/sources/editor/terminaleditor.cpp deleted file mode 100644 index bd5893132..000000000 --- a/sources/editor/terminaleditor.cpp +++ /dev/null @@ -1,322 +0,0 @@ -/* - Copyright 2006-2021 The QElectroTech Team - This file is part of QElectroTech. - - QElectroTech is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - QElectroTech is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with QElectroTech. If not, see . -*/ -#include "terminaleditor.h" - -#include "../QPropertyUndoCommand/qpropertyundocommand.h" -#include "../editor/graphicspart/partterminal.h" -#include "../qeticons.h" - -#include -#include -#include -#include -#include - -/** - @brief TerminalEditor::TerminalEditor - @param editor - @param parent -*/ -TerminalEditor::TerminalEditor(QETElementEditor* editor, QWidget* parent): - ElementItemEditor(editor, parent) { - m_part = nullptr; - m_terminals.clear(); - init(); -} - -/** - @brief TerminalEditor::TerminalEditor - Constructeur - @param editor : - L'editeur d'element concerne - @param terms : - La borne a editer - @param parent : - QWidget parent de ce widget -*/ -TerminalEditor::TerminalEditor( - QETElementEditor *editor, - QList &terms, - QWidget *parent) : - ElementItemEditor(editor, parent), - m_terminals(terms), - m_part(terms.first()) { - init(); -} - -/** - @brief TerminalEditor::init -*/ -void TerminalEditor::init() -{ - qle_x = new QDoubleSpinBox(); - qle_y = new QDoubleSpinBox(); - name = new QLineEdit(); - - qle_x -> setRange(-5000, 5000); - qle_y -> setRange(-5000, 5000); - - orientation = new QComboBox(); - orientation -> addItem(QET::Icons::North, tr("Nord"), Qet::North); - orientation -> addItem(QET::Icons::East, tr("Est"), Qet::East); - orientation -> addItem(QET::Icons::South, tr("Sud"), Qet::South); - orientation -> addItem(QET::Icons::West, tr("Ouest"), Qet::West); - - QVBoxLayout *main_layout = new QVBoxLayout(); - main_layout -> addWidget(new QLabel(tr("Position : "))); - - QHBoxLayout *position = new QHBoxLayout(); - position -> addWidget(new QLabel(tr("x : "))); - position -> addWidget(qle_x ); - position -> addWidget(new QLabel(tr("y : "))); - position -> addWidget(qle_y ); - main_layout -> addLayout(position); - - QHBoxLayout *ori = new QHBoxLayout(); - ori -> addWidget(new QLabel(tr("Orientation : "))); - 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); - - activeConnections(true); - updateForm(); -} - -/** - @brief TerminalEditor::~TerminalEditor - Destructeur -*/ -TerminalEditor::~TerminalEditor() -{ -} - -/** - Permet de specifier a cet editeur quelle primitive il doit editer. A noter - qu'un editeur peut accepter ou refuser d'editer une primitive. - L'editeur de borne acceptera d'editer la primitive new_part s'il s'agit d'un - objet de la classe PartTerminal. - @param new_part Nouvelle primitive a editer - @return true si l'editeur a accepter d'editer la primitive, false sinon -*/ -bool TerminalEditor::setPart(CustomElementPart* new_part) { - m_terminals.clear(); - if (!new_part) { - if (m_part) { - disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); - } - m_part = nullptr; - return(true); - } - if (PartTerminal *part_terminal = static_cast(new_part)) { - if(m_part == part_terminal) return true; - if (m_part) { - disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); - } - m_part = part_terminal; - updateForm(); - connect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); - return(true); - } - return(false); -} - -bool TerminalEditor::setParts(QList parts) { - if (parts.isEmpty()) { - m_terminals.clear(); - if (m_part) { - disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); - } - m_part = nullptr; - return(true); - } - - if (PartTerminal *part_terminal = static_cast(parts.first())) { - if (m_part) { - disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); - } - m_part = part_terminal; - m_terminals.clear(); - m_terminals.append(part_terminal); - for (int i=1; i < parts.length(); i++) { - m_terminals.append(static_cast(parts[i])); - } - updateForm(); - connect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); - return(true); - } - return(false); -} - -/** - @return la primitive actuellement editee, ou 0 si ce widget n'en edite pas -*/ -CustomElementPart *TerminalEditor::currentPart() const -{ - return(m_part); -} - -QList TerminalEditor::currentParts() const -{ - QList parts; - for (auto term: m_terminals) { - parts.append(static_cast(term)); - } - return parts; -} - -/// Met a jour l'orientation de la borne et cree un objet d'annulation -void TerminalEditor::updateTerminalO() -{ - if (m_locked) return; - m_locked = true; - QVariant var(orientation -> itemData(orientation -> currentIndex())); - - for (int i=0; i < m_terminals.length(); i++) { - PartTerminal* term = m_terminals[i]; - if (var != term->property("orientation")) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(term, "orientation", term->property("orientation"), var); - undo->setText(tr("Modifier l'orientation d'une borne")); - undoStack().push(undo); - } - } - m_locked = false; -} - -/** - @brief TerminalEditor::updateXPos -*/ -void TerminalEditor::updateXPos() -{ - if (m_locked) return; - m_locked = true; - QPointF new_pos(qle_x->value(), 0); - - for (int i=0; i < m_terminals.length(); i++) { - PartTerminal* term = m_terminals[i]; - new_pos.setY(term->pos().y()); // change only x value - if (term->pos() != new_pos) { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(term, "pos", term->property("pos"), new_pos); - undo->setText(tr("Déplacer une borne")); - undo->enableAnimation(); - undoStack().push(undo); - } - } - m_locked=false; -} - -/** - @brief TerminalEditor::updateYPos -*/ -void TerminalEditor::updateYPos() -{ - if (m_locked) return; - m_locked = true; - QPointF new_pos(0, qle_y->value()); // change only y value - - for (int i=0; i < m_terminals.length(); i++) { - PartTerminal* term = m_terminals[i]; - new_pos.setX(term->pos().x()); - if (term->pos() != new_pos) { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(term, "pos", term->property("pos"), new_pos); - undo->setText(tr("Déplacer une borne")); - undo->enableAnimation(); - undoStack().push(undo); - } - } - 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("Modifier le nom du terminal")); - undoStack().push(undo); - } - } - m_locked=false; - -} - -/// update Number and name, create cancel object - -/** - Met a jour le formulaire d'edition -*/ -void TerminalEditor::updateForm() -{ - if (!m_part) return; - activeConnections(false); - 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); -} - -/** - Active ou desactive les connexionx signaux/slots entre les widgets internes. - @param active true pour activer les connexions, false pour les desactiver -*/ -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(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(name, &QLineEdit::editingFinished, - this, &TerminalEditor::updateName); - } -} diff --git a/sources/editor/terminaleditor.h b/sources/editor/terminaleditor.h deleted file mode 100644 index 0efeddbdd..000000000 --- a/sources/editor/terminaleditor.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - Copyright 2006-2021 The QElectroTech Team - This file is part of QElectroTech. - - QElectroTech is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - QElectroTech is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with QElectroTech. If not, see . -*/ -#ifndef TERMINAL_EDITOR_H -#define TERMINAL_EDITOR_H - -#include "elementitemeditor.h" - -#include - -class PartTerminal; -class QDoubleSpinBox; -class QComboBox; - -/** - @brief The TerminalEditor class - This class provides a widget to edit terminals within the element editor. - The class is capable to change the values of multiple parts of the same time. - The displayed values are from the first selected element -*/ -class TerminalEditor : public ElementItemEditor { - Q_OBJECT - - // Constructors, destructor - public: - TerminalEditor( - QETElementEditor *, - QList& terms, - QWidget * = nullptr); - TerminalEditor(QETElementEditor *, QWidget * = nullptr); - ~TerminalEditor() override; - private: - TerminalEditor(const TerminalEditor &); - void init(); - - // attributes - private: - QList m_terminals; - PartTerminal *m_part{nullptr}; - QDoubleSpinBox *qle_x, *qle_y; - QComboBox *orientation; - QLineEdit *name; - bool m_locked{false}; - - // methods - public: - bool setPart(CustomElementPart *) override; - bool setParts(QList parts) override; - CustomElementPart *currentPart() const override; - QList currentParts() const override; - - public slots: - void updateTerminalO(); - void updateXPos(); - void updateYPos(); - void updateName(); - void updateForm() override; - - private: - void activeConnections(bool); -}; -#endif diff --git a/sources/editor/ui/qetelementeditor.cpp b/sources/editor/ui/qetelementeditor.cpp index ec79a0739..63b4c5650 100644 --- a/sources/editor/ui/qetelementeditor.cpp +++ b/sources/editor/ui/qetelementeditor.cpp @@ -41,7 +41,7 @@ #include "lineeditor.h" #include "polygoneditor.h" #include "rectangleeditor.h" -#include "../terminaleditor.h" +#include "terminaleditor.h" #include "texteditor.h" #include "dynamictextfieldeditor.h" #include "../../newelementwizard.h" @@ -553,14 +553,15 @@ void QETElementEditor::updateInformations() style_editable = StyleEditor::isStyleEditable(cep_list); } - if (same_xml_name) { - if (selection_xml_name == "terminal" || - selection_xml_name == "text" || - selection_xml_name == "dynamic_text" || - selection_xml_name == "line" || - selection_xml_name == "rect" || - selection_xml_name == "ellipse" || - selection_xml_name == "arc") { + if (same_xml_name) + { + if ( selection_xml_name == "text" + || selection_xml_name == "dynamic_text" + || selection_xml_name == "line" + || selection_xml_name == "rect" + || selection_xml_name == "ellipse" + || selection_xml_name == "arc") + { clearToolsDock(); //We add the editor widget ElementItemEditor *editor = static_cast(m_editors[selection_xml_name]); @@ -605,7 +606,9 @@ void QETElementEditor::updateInformations() } return; } - else if (selection_xml_name == "polygon" && cep_list.length() == 1) { + else if (cep_list.length() == 1 && + (selection_xml_name == "polygon" || selection_xml_name == "terminal")) + { #if TODO_LIST #pragma message("@TODO maybe allowing multipart edit when number of points is the same?") #endif diff --git a/sources/editor/ui/terminaleditor.cpp b/sources/editor/ui/terminaleditor.cpp new file mode 100644 index 000000000..a3edf8e54 --- /dev/null +++ b/sources/editor/ui/terminaleditor.cpp @@ -0,0 +1,254 @@ +/* + Copyright 2006-2021 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "terminaleditor.h" +#include "ui_terminaleditor.h" +#include "../../qeticons.h" +#include "../../qet.h" +#include "../graphicspart/partterminal.h" +#include "../../QPropertyUndoCommand/qpropertyundocommand.h" + +/** + * @brief TerminalEditor::TerminalEditor + * Default constructor + * @param editor : element editor of which this terminal editor belong + * @param parent : parent widget + */ +TerminalEditor::TerminalEditor(QETElementEditor *editor, QWidget *parent) : + ElementItemEditor(editor, parent), + ui(new Ui::TerminalEditor) +{ + ui->setupUi(this); + init(); +} + +/** + * @brief TerminalEditor::~TerminalEditor + * Destructor + */ +TerminalEditor::~TerminalEditor() +{ + delete ui; +} + +/** + * @brief TerminalEditor::updateForm + * Reimplemented from ElementItemEditor + * Update the content of this widget + */ +void TerminalEditor::updateForm() +{ + if (!m_part) { + return; + } + activeConnections(false); + + ui->m_x_dsb->setValue(m_part->property("x").toReal()); + ui->m_y_dsb->setValue(m_part->property("y").toReal()); + ui->m_orientation_cb->setCurrentIndex(ui->m_orientation_cb->findData(m_part->property("orientation"))); + ui->m_name_le->setText(m_part->name()); + ui->m_type_cb->setCurrentIndex(ui->m_orientation_cb->findData(m_part->terminalType())); + + activeConnections(true); +} + +/** + * @brief TerminalEditor::setPart + * Set the part to edit. + * The part must be a PartTerminal, in other case return false. + * @param new_part : the part to edit + * @return true if the part can be edited. + */ +bool TerminalEditor::setPart(CustomElementPart *new_part) +{ + if (m_part == new_part) { + return true; + } + + activeChangeConnections(false); + + if (!new_part) + { + m_part = nullptr; + return(true); + } + + if (PartTerminal *part_terminal = dynamic_cast(new_part)) + { + m_part = part_terminal; + updateForm(); + activeChangeConnections(true); + return(true); + } + return(false); +} + +/** + * @brief TerminalEditor::currentPart + * @return the current edited part + * or nullptr if there is no part or several part + * @see QList TerminalEditor::currentParts() const + */ +CustomElementPart *TerminalEditor::currentPart() const +{ + return m_part; +} + +/** + * @brief TerminalEditor::init + * Some init about this class + */ +void TerminalEditor::init() +{ + ui->m_orientation_cb->addItem(QET::Icons::North, tr("Nord"), Qet::North); + ui->m_orientation_cb->addItem(QET::Icons::East, tr("Est"), Qet::East); + ui->m_orientation_cb->addItem(QET::Icons::South, tr("Sud"), Qet::South); + ui->m_orientation_cb->addItem(QET::Icons::West, tr("Ouest"), Qet::West); + + ui->m_type_cb->addItem(tr("Générique"), TerminalData::Generic); + ui->m_type_cb->addItem(tr("Bornier intérieur"), TerminalData::Inner); + ui->m_type_cb->addItem(tr("Bornier extérieur"), TerminalData::Outer); +} + +/** + * @brief TerminalEditor::posEdited + */ +void TerminalEditor::posEdited() +{ + if (m_locked) { + return; + } + m_locked = true; + + QPointF new_pos(ui->m_x_dsb->value(), + ui->m_y_dsb->value()); + + if (m_part->pos() != new_pos) + { + auto undo = new QPropertyUndoCommand(m_part, "pos", m_part->property("pos"), new_pos); + undo->setText(tr("Déplacer une borne")); + undo->setAnimated(true, false); + undoStack().push(undo); + } + + m_locked = false; +} + +/** + * @brief TerminalEditor::orientationEdited + */ +void TerminalEditor::orientationEdited() +{ + if (m_locked) { + return; + } + m_locked = true; + + auto ori_ = ui->m_orientation_cb->currentData(); + if (m_part->orientation() != ori_) + { + auto undo = new QPropertyUndoCommand(m_part, "orientation", m_part->property("orientation"), ori_); + undo->setText(tr("Modifier l'orientation d'une borne")); + undoStack().push(undo); + } + + m_locked = false; +} + +/** + * @brief TerminalEditor::nameEdited + */ +void TerminalEditor::nameEdited() +{ + if (m_locked) { + return; + } + + m_locked = true; + QString name_(ui->m_name_le->text()); + + if (m_part->name() != name_) + { + auto undo = new QPropertyUndoCommand(m_part, "name", m_part->property("name"), name_); + undo->setText(tr("Modifier le nom du terminal")); + undoStack().push(undo); + } + m_locked=false; +} + +/** + * @brief TerminalEditor::typeEdited + */ +void TerminalEditor::typeEdited() +{ + if (m_locked) { + return; + } + m_locked = true; + + auto type = ui->m_type_cb->currentData(); + if (type != m_part->terminalType()) { + auto undo = new QPropertyUndoCommand(m_part, "terminal_type", m_part->terminalType(), type); + undo->setText(tr("Modifier le type d'une borne")); + undoStack().push(undo); + } + m_locked = false; +} + +/** + * @brief TerminalEditor::activeConnections + * Active connection between the widgets used in this editor + * and method of this class. + * @param active + */ +void TerminalEditor::activeConnections(bool active) +{ + if (active) { + m_editor_connections << connect(ui->m_x_dsb, QOverload::of(&QDoubleSpinBox::valueChanged), + this, &TerminalEditor::posEdited); + m_editor_connections << connect(ui->m_y_dsb, QOverload::of(&QDoubleSpinBox::valueChanged), + this, &TerminalEditor::posEdited); + m_editor_connections << connect(ui->m_orientation_cb, QOverload::of(&QComboBox::activated), + this, &TerminalEditor::orientationEdited); + m_editor_connections << connect(ui->m_name_le, &QLineEdit::editingFinished, + this, &TerminalEditor::nameEdited); + m_editor_connections << connect(ui->m_type_cb, QOverload::of(&QComboBox::activated), + this, &TerminalEditor::typeEdited); + } else { + for (auto const & con : qAsConst(m_editor_connections)) { + QObject::disconnect(con); + } + m_editor_connections.clear(); + } +} + +void TerminalEditor::activeChangeConnections(bool active) +{ + if (active) + { + m_change_connections << connect(m_part, &PartTerminal::xChanged, this, &TerminalEditor::updateForm); + m_change_connections << connect(m_part, &PartTerminal::yChanged, this, &TerminalEditor::updateForm); + m_change_connections << connect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); + m_change_connections << connect(m_part, &PartTerminal::nameChanged, this, &TerminalEditor::updateForm); + m_change_connections << connect(m_part, &PartTerminal::terminalTypeChanged, this, &TerminalEditor::updateForm); + } else { + for (auto &con : m_change_connections) { + QObject::disconnect(con); + } + m_change_connections.clear(); + } +} diff --git a/sources/editor/ui/terminaleditor.h b/sources/editor/ui/terminaleditor.h new file mode 100644 index 000000000..2a708add9 --- /dev/null +++ b/sources/editor/ui/terminaleditor.h @@ -0,0 +1,64 @@ +/* + Copyright 2006-2021 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef TERMINALEDITOR_H +#define TERMINALEDITOR_H + +#include +#include "../elementitemeditor.h" + +namespace Ui { + class TerminalEditor; +} + +class PartTerminal; + +/** + * @brief The TerminalEditor class + * Provide a widget used to edit the properties of a PartTerminal + */ +class TerminalEditor : public ElementItemEditor +{ + Q_OBJECT + + public: + TerminalEditor(QETElementEditor *editor, QWidget *parent = nullptr); + ~TerminalEditor() override; + + void updateForm() override; + bool setPart(CustomElementPart *new_part) override; + CustomElementPart *currentPart() const override; + QList currentParts() const override {return QList();} + + private: + void init(); + void posEdited(); + void orientationEdited(); + void nameEdited(); + void typeEdited(); + void activeConnections(bool active); + void activeChangeConnections(bool active); + + private: + Ui::TerminalEditor *ui; + QVector m_editor_connections, + m_change_connections; + PartTerminal *m_part = nullptr; + bool m_locked = false; +}; + +#endif // TERMINALEDITOR_H diff --git a/sources/editor/ui/terminaleditor.ui b/sources/editor/ui/terminaleditor.ui new file mode 100644 index 000000000..2d423ca77 --- /dev/null +++ b/sources/editor/ui/terminaleditor.ui @@ -0,0 +1,98 @@ + + + TerminalEditor + + + + 0 + 0 + 511 + 236 + + + + Form + + + + + + y : + + + + + + + -5000.000000000000000 + + + 5000.000000000000000 + + + + + + + -5000.000000000000000 + + + 5000.000000000000000 + + + + + + + Orientation : + + + + + + + + + + + + + x : + + + + + + + Nom : + + + + + + + Type : + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/sources/properties/terminaldata.cpp b/sources/properties/terminaldata.cpp index 6a388c3c7..791cec88b 100644 --- a/sources/properties/terminaldata.cpp +++ b/sources/properties/terminaldata.cpp @@ -1,3 +1,20 @@ +/* + Copyright 2006-2021 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ #include "terminaldata.h" #include @@ -150,10 +167,10 @@ QString TerminalData::typeToString(TerminalData::Type type) switch (type) { case Generic: return QString("Generic"); - case TerminalInner : - return QString("TerminalInner"); - case TerminalOuter : - return QString("TerminalOuter"); + case Inner : + return QString("Inner"); + case Outer : + return QString("Outer"); } } @@ -167,10 +184,10 @@ TerminalData::Type TerminalData::typeFromString(const QString &string) { if (string == "Generic") { return TerminalData::Generic; - } else if (string == "TerminalInner") { - return TerminalData::TerminalInner; - } else if (string == "TerminalOuter") { - return TerminalData::TerminalOuter; + } else if (string == "Inner") { + return TerminalData::Inner; + } else if (string == "Outer") { + return TerminalData::Outer; } else { qDebug() << "TerminalData::typeFromString, argument string is invalid" " failsafe type 'TerminalData::Generic' is returned"; diff --git a/sources/properties/terminaldata.h b/sources/properties/terminaldata.h index 521e1b2e7..4f8c8c30a 100644 --- a/sources/properties/terminaldata.h +++ b/sources/properties/terminaldata.h @@ -1,3 +1,20 @@ +/* + Copyright 2006-2021 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ #ifndef TERMINALDATA_H #define TERMINALDATA_H @@ -18,13 +35,16 @@ class QGraphicsObject; */ class TerminalData : public PropertiesInterface { - enum Type { - Generic, - TerminalInner, - TerminalOuter - }; + Q_GADGET public: + enum Type { + Generic, + Inner, + Outer + }; + Q_ENUM(Type) + TerminalData(); TerminalData(QGraphicsObject* parent); ~TerminalData() override;