mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
WIP
This commit is contained in:
committed by
Laurent Trinques
parent
451d5c8f58
commit
b85b341941
@@ -613,11 +613,48 @@ void QETElementEditor::slot_updateInformations()
|
|||||||
QList<CustomElementPart *> cep_list;
|
QList<CustomElementPart *> cep_list;
|
||||||
bool style_editable = false;
|
bool style_editable = false;
|
||||||
|
|
||||||
|
bool same_xml_name = true;
|
||||||
|
CustomElementPart* part = dynamic_cast<CustomElementPart *>(selected_qgis.first());
|
||||||
|
QString selection_xml_name;
|
||||||
|
if (part) {
|
||||||
|
selection_xml_name = part->xmlName();
|
||||||
|
for (auto itm: selected_qgis) {
|
||||||
|
CustomElementPart *selection = dynamic_cast<CustomElementPart *>(itm);
|
||||||
|
if (selection -> xmlName() != selection_xml_name) {
|
||||||
|
same_xml_name = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
same_xml_name = false;
|
||||||
|
|
||||||
|
if (same_xml_name) {
|
||||||
|
if (selection_xml_name == "terminal") {
|
||||||
|
clearToolsDock();
|
||||||
|
//We add the editor widget
|
||||||
|
TerminalEditor *editor = static_cast<TerminalEditor*>(m_editors[selection_xml_name]);
|
||||||
|
if (editor)
|
||||||
|
{
|
||||||
|
if (editor->setTerminals(selection))
|
||||||
|
{
|
||||||
|
m_tools_dock_stack->insertWidget(1, selection_editor);
|
||||||
|
m_tools_dock_stack -> setCurrentIndex(1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug() << "Editor refused part.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Test if part are editable by style editor
|
//Test if part are editable by style editor
|
||||||
if (selected_qgis.size() >= 2)
|
if (selected_qgis.size() >= 2)
|
||||||
{
|
{
|
||||||
style_editable = true;
|
style_editable = true;
|
||||||
foreach (QGraphicsItem *qgi, selected_qgis)
|
for (QGraphicsItem *qgi: selected_qgis)
|
||||||
{
|
{
|
||||||
if (CustomElementPart *cep = dynamic_cast<CustomElementPart *>(qgi))
|
if (CustomElementPart *cep = dynamic_cast<CustomElementPart *>(qgi))
|
||||||
cep_list << cep;
|
cep_list << cep;
|
||||||
|
|||||||
@@ -548,7 +548,7 @@ bool StyleEditor::isStyleEditable(QList<CustomElementPart *> cep_list)
|
|||||||
QStringList str;
|
QStringList str;
|
||||||
str << "arc" << "ellipse" << "line" << "polygon" << "rect";
|
str << "arc" << "ellipse" << "line" << "polygon" << "rect";
|
||||||
|
|
||||||
foreach (CustomElementPart *cep, cep_list)
|
for (CustomElementPart *cep: cep_list)
|
||||||
if (!str.contains(cep -> xmlName()))
|
if (!str.contains(cep -> xmlName()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -25,51 +25,65 @@
|
|||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
|
||||||
|
TerminalEditor::TerminalEditor(QETElementEditor* editor, QWidget* parent):
|
||||||
|
ElementItemEditor(editor, parent)
|
||||||
|
{
|
||||||
|
m_part = nullptr;
|
||||||
|
m_terminals.clear();
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@param editor L'editeur d'element concerne
|
@param editor L'editeur d'element concerne
|
||||||
@param term La borne a editer
|
@param term La borne a editer
|
||||||
@param parent QWidget parent de ce widget
|
@param parent QWidget parent de ce widget
|
||||||
*/
|
*/
|
||||||
TerminalEditor::TerminalEditor(QETElementEditor *editor, PartTerminal *term, QWidget *parent) :
|
TerminalEditor::TerminalEditor(QETElementEditor *editor, QList<PartTerminal *> &terms, QWidget *parent) :
|
||||||
ElementItemEditor(editor, parent),
|
ElementItemEditor(editor, parent),
|
||||||
part(term),
|
m_terminals(terms),
|
||||||
m_locked(false)
|
m_part(terms.first())
|
||||||
{
|
{
|
||||||
qle_x = new QDoubleSpinBox();
|
init();
|
||||||
qle_y = new QDoubleSpinBox();
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
main_layout -> addStretch();
|
|
||||||
setLayout(main_layout);
|
|
||||||
|
|
||||||
activeConnections(true);
|
|
||||||
updateForm();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TerminalEditor::init() {
|
||||||
|
qle_x = new QDoubleSpinBox();
|
||||||
|
qle_y = new QDoubleSpinBox();
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
main_layout -> addStretch();
|
||||||
|
setLayout(main_layout);
|
||||||
|
|
||||||
|
activeConnections(true);
|
||||||
|
updateForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
TerminalEditor::~TerminalEditor() {
|
TerminalEditor::~TerminalEditor() {
|
||||||
};
|
};
|
||||||
@@ -82,33 +96,59 @@ TerminalEditor::~TerminalEditor() {
|
|||||||
@param new_part Nouvelle primitive a editer
|
@param new_part Nouvelle primitive a editer
|
||||||
@return true si l'editeur a accepter d'editer la primitive, false sinon
|
@return true si l'editeur a accepter d'editer la primitive, false sinon
|
||||||
*/
|
*/
|
||||||
bool TerminalEditor::setPart(CustomElementPart *new_part)
|
bool TerminalEditor::setPart(CustomElementPart* new_part)
|
||||||
{
|
{
|
||||||
|
m_terminals.clear();
|
||||||
if (!new_part)
|
if (!new_part)
|
||||||
{
|
{
|
||||||
if (part)
|
if (m_part)
|
||||||
disconnect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
||||||
part = nullptr;
|
m_part = nullptr;
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
if (PartTerminal *part_terminal = dynamic_cast<PartTerminal *>(new_part))
|
if (PartTerminal *part_terminal = dynamic_cast<PartTerminal *>(new_part))
|
||||||
{
|
{
|
||||||
if(part == part_terminal) return true;
|
if(m_part == part_terminal) return true;
|
||||||
if (part)
|
if (m_part)
|
||||||
disconnect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
||||||
part = part_terminal;
|
m_part = part_terminal;
|
||||||
updateForm();
|
updateForm();
|
||||||
connect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
connect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TerminalEditor::setTerminals(QList<PartTerminal *> terminals)
|
||||||
|
{
|
||||||
|
if (terminals.isEmpty())
|
||||||
|
{
|
||||||
|
m_terminals.clear();
|
||||||
|
if (m_part)
|
||||||
|
disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
||||||
|
m_part = nullptr;
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PartTerminal *part_terminal = dynamic_cast<PartTerminal *>(terminals.first()))
|
||||||
|
{
|
||||||
|
if(m_part == part_terminal) return true;
|
||||||
|
if (m_part)
|
||||||
|
disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
||||||
|
m_part = part_terminal;
|
||||||
|
m_terminals = terminals;
|
||||||
|
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
|
@return la primitive actuellement editee, ou 0 si ce widget n'en edite pas
|
||||||
*/
|
*/
|
||||||
CustomElementPart *TerminalEditor::currentPart() const {
|
CustomElementPart *TerminalEditor::currentPart() const {
|
||||||
return(part);
|
return(m_part);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Met a jour l'orientation de la borne et cree un objet d'annulation
|
/// Met a jour l'orientation de la borne et cree un objet d'annulation
|
||||||
@@ -117,12 +157,15 @@ void TerminalEditor::updateTerminalO()
|
|||||||
if (m_locked) return;
|
if (m_locked) return;
|
||||||
m_locked = true;
|
m_locked = true;
|
||||||
QVariant var(orientation -> itemData(orientation -> currentIndex()));
|
QVariant var(orientation -> itemData(orientation -> currentIndex()));
|
||||||
if (var != part->property("orientation"))
|
|
||||||
{
|
for (auto term: m_terminals) {
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "orientation", part->property("orientation"), var);
|
if (var != term->property("orientation"))
|
||||||
undo->setText(tr("Modifier l'orientation d'une borne"));
|
{
|
||||||
undoStack().push(undo);
|
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;
|
m_locked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,13 +174,15 @@ void TerminalEditor::updatePos()
|
|||||||
if (m_locked) return;
|
if (m_locked) return;
|
||||||
m_locked = true;
|
m_locked = true;
|
||||||
QPointF new_pos(qle_x->value(), qle_y->value());
|
QPointF new_pos(qle_x->value(), qle_y->value());
|
||||||
if (new_pos != part->pos())
|
|
||||||
{
|
for (auto term: m_terminals) {
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "pos", part->property("pos"), new_pos);
|
if (term->pos() != new_pos) {
|
||||||
undo->setText(tr("Déplacer une borne"));
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(term, "pos", term->property("pos"), new_pos);
|
||||||
undo->enableAnimation();
|
undo->setText(tr("Déplacer une borne"));
|
||||||
undoStack().push(undo);
|
undo->enableAnimation();
|
||||||
}
|
undoStack().push(undo);
|
||||||
|
}
|
||||||
|
}
|
||||||
m_locked=false;
|
m_locked=false;
|
||||||
}
|
}
|
||||||
/// update Number and name, create cancel object
|
/// update Number and name, create cancel object
|
||||||
@@ -146,11 +191,11 @@ void TerminalEditor::updatePos()
|
|||||||
Met a jour le formulaire d'edition
|
Met a jour le formulaire d'edition
|
||||||
*/
|
*/
|
||||||
void TerminalEditor::updateForm() {
|
void TerminalEditor::updateForm() {
|
||||||
if (!part) return;
|
if (!m_part) return;
|
||||||
activeConnections(false);
|
activeConnections(false);
|
||||||
qle_x -> setValue(part->property("x").toReal());
|
qle_x -> setValue(m_part->property("x").toReal());
|
||||||
qle_y -> setValue(part->property("y").toReal());
|
qle_y -> setValue(m_part->property("y").toReal());
|
||||||
orientation -> setCurrentIndex(orientation->findData(part->property("orientation")));
|
orientation -> setCurrentIndex(orientation->findData(m_part->property("orientation")));
|
||||||
activeConnections(true);
|
activeConnections(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,21 +31,27 @@ class TerminalEditor : public ElementItemEditor {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
// Constructors, destructor
|
// Constructors, destructor
|
||||||
public:
|
public:
|
||||||
TerminalEditor(QETElementEditor *, PartTerminal * = nullptr, QWidget * = nullptr);
|
TerminalEditor(QETElementEditor *, QList<PartTerminal *>& terms, QWidget * = nullptr);
|
||||||
|
TerminalEditor(QETElementEditor *, QWidget * = nullptr);
|
||||||
|
|
||||||
~TerminalEditor() override;
|
~TerminalEditor() override;
|
||||||
private:
|
private:
|
||||||
TerminalEditor(const TerminalEditor &);
|
TerminalEditor(const TerminalEditor &);
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
private:
|
private:
|
||||||
PartTerminal *part;
|
QList<PartTerminal *> m_terminals;
|
||||||
|
PartTerminal *m_part{nullptr};
|
||||||
QDoubleSpinBox *qle_x, *qle_y;
|
QDoubleSpinBox *qle_x, *qle_y;
|
||||||
QComboBox *orientation;
|
QComboBox *orientation;
|
||||||
bool m_locked;
|
bool m_locked{false};
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
public:
|
public:
|
||||||
bool setPart(CustomElementPart *) override;
|
bool setPart(CustomElementPart *) override;
|
||||||
|
bool setTerminals(QList<PartTerminal*> terminals);
|
||||||
CustomElementPart *currentPart() const override;
|
CustomElementPart *currentPart() const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|||||||
Reference in New Issue
Block a user