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()
{
QList<QGraphicsItem *> selected_qgis = m_elmt_scene -> selectedItems();
QList<CustomElementPart *> cep_list;
bool style_editable = false;
if (selected_qgis.isEmpty()) {
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());
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) {
QString selection_xml_name = part->xmlName();
bool same_xml_name = true;
bool style_editable = true;
for (QGraphicsItem *qgi: selected_qgis) {
if (CustomElementPart *cep = dynamic_cast<CustomElementPart *>(qgi)) {
cep_list << cep;
if (cep->xmlName() != selection_xml_name)
same_xml_name = false;
break;
}
}
} else
same_xml_name = false;
} else
style_editable = false;
}
if (style_editable)
style_editable = StyleEditor::isStyleEditable(cep_list);
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") {
clearToolsDock();
//We add the editor widget
TerminalEditor *editor = static_cast<TerminalEditor*>(m_editors[selection_xml_name]);
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);
}
else
@@ -645,59 +661,13 @@ void QETElementEditor::slot_updateInformations()
qDebug() << "Editor refused part.";
}
}
return;
}
}
//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;
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.
else if (style_editable)
//There's several parts selecteds and all can be edited by style editor.
if (style_editable)
{
clearToolsDock();
ElementItemEditor *selection_editor = m_editors["style"];

View File

@@ -119,9 +119,9 @@ bool TerminalEditor::setPart(CustomElementPart* new_part)
return(false);
}
bool TerminalEditor::setTerminals(QList<PartTerminal *> terminals)
bool TerminalEditor::setParts(QList<CustomElementPart *> parts)
{
if (terminals.isEmpty())
if (parts.isEmpty())
{
m_terminals.clear();
if (m_part)
@@ -130,13 +130,15 @@ bool TerminalEditor::setTerminals(QList<PartTerminal *> terminals)
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)
disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
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();
connect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
return(true);
@@ -169,13 +171,14 @@ void TerminalEditor::updateTerminalO()
m_locked = false;
}
void TerminalEditor::updatePos()
{
if (m_locked) return;
m_locked = true;
QPointF new_pos(qle_x->value(), qle_y->value());
void TerminalEditor::updateXPos() {
if (m_locked) return;
m_locked = true;
QPointF new_pos(qle_x->value(), 0);
for (auto term: m_terminals) {
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"));
@@ -183,7 +186,24 @@ void TerminalEditor::updatePos()
undoStack().push(undo);
}
}
m_locked=false;
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) {
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;
}
/// update Number and name, create cancel object
@@ -207,14 +227,14 @@ void TerminalEditor::activeConnections(bool active)
{
if (active)
{
connect(qle_x, SIGNAL(editingFinished()), this, SLOT(updatePos()));
connect(qle_y, SIGNAL(editingFinished()), this, SLOT(updatePos()));
connect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO()));
connect(qle_x, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateXPos);
connect(qle_y, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateYPos);
connect(orientation, QOverload<int>::of(&QComboBox::activated), this, &TerminalEditor::updateTerminalO);
}
else
{
disconnect(qle_x, SIGNAL(editingFinished()), this, SLOT(updatePos()));
disconnect(qle_y, SIGNAL(editingFinished()), this, SLOT(updatePos()));
disconnect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO()));
disconnect(qle_x, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateXPos);
disconnect(qle_y, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateYPos);
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.
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
@@ -51,12 +53,13 @@ class TerminalEditor : public ElementItemEditor {
// methods
public:
bool setPart(CustomElementPart *) override;
bool setTerminals(QList<PartTerminal*> terminals);
bool setParts(QList<CustomElementPart *> parts) override;
CustomElementPart *currentPart() const override;
public slots:
void updateTerminalO();
void updatePos();
void updateXPos();
void updateYPos();
void updateForm() override;
private: