multiterminal change

This commit is contained in:
Martin Marmsoler
2020-05-28 17:48:52 +02:00
committed by Laurent Trinques
parent 304ea00d7b
commit 4bae1b902d
3 changed files with 79 additions and 86 deletions

View File

@@ -610,34 +610,50 @@ void QETElementEditor::slot_setNoDragToView() {
void QETElementEditor::slot_updateInformations() void QETElementEditor::slot_updateInformations()
{ {
QList<QGraphicsItem *> selected_qgis = m_elmt_scene -> selectedItems(); QList<QGraphicsItem *> selected_qgis = m_elmt_scene -> selectedItems();
QList<CustomElementPart *> cep_list; if (selected_qgis.isEmpty()) {
bool style_editable = false; clearToolsDock();
m_default_informations -> setText(tr("%n partie(s) sélectionnée(s).",
"",
selected_qgis.size()));
m_default_informations -> setAlignment(Qt::AlignHCenter | Qt::AlignTop);
m_tools_dock_stack -> setCurrentIndex(0);
return;
}
QList<CustomElementPart *> cep_list;
bool same_xml_name = true;
CustomElementPart* part = dynamic_cast<CustomElementPart *>(selected_qgis.first()); CustomElementPart* part = dynamic_cast<CustomElementPart *>(selected_qgis.first());
QString selection_xml_name; QString selection_xml_name = part->xmlName();
if (part) { bool same_xml_name = true;
selection_xml_name = part->xmlName(); bool style_editable = true;
for (auto itm: selected_qgis) { for (QGraphicsItem *qgi: selected_qgis) {
CustomElementPart *selection = dynamic_cast<CustomElementPart *>(itm); if (CustomElementPart *cep = dynamic_cast<CustomElementPart *>(qgi)) {
if (selection -> xmlName() != selection_xml_name) { cep_list << cep;
if (cep->xmlName() != selection_xml_name)
same_xml_name = false; same_xml_name = false;
break;
}
}
} else } else
same_xml_name = false; style_editable = false;
}
if (style_editable)
style_editable = StyleEditor::isStyleEditable(cep_list);
if (same_xml_name) { if (same_xml_name) {
//The current editor already edit the selected part
// Expensive for a list of elements
// if (QWidget *widget = m_tools_dock_stack->widget(1))
// if (ElementItemEditor *editor = dynamic_cast<ElementItemEditor *>(widget))
// if(editor->currentPart() == cep_list.first())
// return;
if (selection_xml_name == "terminal") { if (selection_xml_name == "terminal") {
clearToolsDock(); clearToolsDock();
//We add the editor widget //We add the editor widget
TerminalEditor *editor = static_cast<TerminalEditor*>(m_editors[selection_xml_name]); TerminalEditor *editor = static_cast<TerminalEditor*>(m_editors[selection_xml_name]);
if (editor) if (editor)
{ {
if (editor->setTerminals(selection)) if (editor->setParts(cep_list))
{ {
m_tools_dock_stack->insertWidget(1, selection_editor); m_tools_dock_stack->insertWidget(1, editor);
m_tools_dock_stack -> setCurrentIndex(1); m_tools_dock_stack -> setCurrentIndex(1);
} }
else else
@@ -645,59 +661,13 @@ void QETElementEditor::slot_updateInformations()
qDebug() << "Editor refused part."; qDebug() << "Editor refused part.";
} }
} }
}
}
//Test if part are editable by style editor
if (selected_qgis.size() >= 2)
{
style_editable = true;
for (QGraphicsItem *qgi: selected_qgis)
{
if (CustomElementPart *cep = dynamic_cast<CustomElementPart *>(qgi))
cep_list << cep;
else
style_editable = false;
}
if (style_editable)
style_editable = StyleEditor::isStyleEditable(cep_list);
}
//There's one selected item
if (selected_qgis.size() == 1)
{
QGraphicsItem *qgi = selected_qgis.first();
if (CustomElementPart *selection = dynamic_cast<CustomElementPart *>(qgi))
{
//The current editor already edit the selected part
if (QWidget *widget = m_tools_dock_stack->widget(1))
if (ElementItemEditor *editor = dynamic_cast<ElementItemEditor *>(widget))
if(editor->currentPart() == selection)
return; return;
}
clearToolsDock();
//We add the editor widget
QString selection_xml_name = selection -> xmlName();
ElementItemEditor *selection_editor = m_editors[selection_xml_name];
if (selection_editor)
{
if (selection_editor->setPart(selection))
{
m_tools_dock_stack->insertWidget(1, selection_editor);
m_tools_dock_stack -> setCurrentIndex(1);
}
else
{
qDebug() << "Editor refused part.";
}
}
}
} }
//There's several parts selecteds and all can be edited by style editor. //There's several parts selecteds and all can be edited by style editor.
else if (style_editable) if (style_editable)
{ {
clearToolsDock(); clearToolsDock();
ElementItemEditor *selection_editor = m_editors["style"]; ElementItemEditor *selection_editor = m_editors["style"];

View File

@@ -119,9 +119,9 @@ bool TerminalEditor::setPart(CustomElementPart* new_part)
return(false); return(false);
} }
bool TerminalEditor::setTerminals(QList<PartTerminal *> terminals) bool TerminalEditor::setParts(QList<CustomElementPart *> parts)
{ {
if (terminals.isEmpty()) if (parts.isEmpty())
{ {
m_terminals.clear(); m_terminals.clear();
if (m_part) if (m_part)
@@ -130,13 +130,15 @@ bool TerminalEditor::setTerminals(QList<PartTerminal *> terminals)
return(true); return(true);
} }
if (PartTerminal *part_terminal = dynamic_cast<PartTerminal *>(terminals.first())) if (PartTerminal *part_terminal = static_cast<PartTerminal *>(parts.first()))
{ {
if(m_part == part_terminal) return true;
if (m_part) if (m_part)
disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
m_part = part_terminal; m_part = part_terminal;
m_terminals = terminals; m_terminals.clear();
m_terminals.append(part_terminal);
for (int i=1; i < parts.length(); i++)
m_terminals.append(static_cast<PartTerminal*>(parts[i]));
updateForm(); updateForm();
connect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); connect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
return(true); return(true);
@@ -169,13 +171,31 @@ void TerminalEditor::updateTerminalO()
m_locked = false; m_locked = false;
} }
void TerminalEditor::updatePos() void TerminalEditor::updateXPos() {
{
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(), 0);
int i=0;
for (PartTerminal* term: m_terminals) {
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;
}
void TerminalEditor::updateYPos() {
if (m_locked) return;
m_locked = true;
QPointF new_pos(0, qle_y->value()); // change only y value
for (auto term: m_terminals) { for (auto term: m_terminals) {
new_pos.setX(term->pos().x());
if (term->pos() != new_pos) { if (term->pos() != new_pos) {
QPropertyUndoCommand *undo = new QPropertyUndoCommand(term, "pos", term->property("pos"), new_pos); QPropertyUndoCommand *undo = new QPropertyUndoCommand(term, "pos", term->property("pos"), new_pos);
undo->setText(tr("Déplacer une borne")); undo->setText(tr("Déplacer une borne"));
@@ -207,14 +227,14 @@ void TerminalEditor::activeConnections(bool active)
{ {
if (active) if (active)
{ {
connect(qle_x, SIGNAL(editingFinished()), this, SLOT(updatePos())); connect(qle_x, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateXPos);
connect(qle_y, SIGNAL(editingFinished()), this, SLOT(updatePos())); connect(qle_y, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateYPos);
connect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO())); connect(orientation, QOverload<int>::of(&QComboBox::activated), this, &TerminalEditor::updateTerminalO);
} }
else else
{ {
disconnect(qle_x, SIGNAL(editingFinished()), this, SLOT(updatePos())); disconnect(qle_x, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateXPos);
disconnect(qle_y, SIGNAL(editingFinished()), this, SLOT(updatePos())); disconnect(qle_y, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateYPos);
disconnect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO())); disconnect(orientation, QOverload<int>::of(&QComboBox::activated), this, &TerminalEditor::updateTerminalO);
} }
} }

View File

@@ -26,6 +26,8 @@ class QComboBox;
/** /**
This class provides a widget to edit terminals within the element editor. 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 { class TerminalEditor : public ElementItemEditor {
Q_OBJECT Q_OBJECT
@@ -51,12 +53,13 @@ class TerminalEditor : public ElementItemEditor {
// methods // methods
public: public:
bool setPart(CustomElementPart *) override; bool setPart(CustomElementPart *) override;
bool setTerminals(QList<PartTerminal*> terminals); bool setParts(QList<CustomElementPart *> parts) override;
CustomElementPart *currentPart() const override; CustomElementPart *currentPart() const override;
public slots: public slots:
void updateTerminalO(); void updateTerminalO();
void updatePos(); void updateXPos();
void updateYPos();
void updateForm() override; void updateForm() override;
private: private: