diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 6e09f01ca..5222aa075 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -348,46 +348,46 @@ void Diagram::keyPressEvent(QKeyEvent *event) return; } } - else if(event->modifiers() == Qt::AltModifier) + else if(event->modifiers() == Qt::AltModifier) - { - switch(event->key()) - { - case Qt::Key_Left: - for (Element *item : dc.m_elements) - { - left_position = item->sceneBoundingRect().x(); - if(left_position <= 5) - return; - } - movement = QPointF(-xKeyGridFine, 0.0); - break; - case Qt::Key_Right: - movement = QPointF(+xKeyGridFine, 0.0); - break; - case Qt::Key_Up: - for(Element *item : dc.m_elements) - { - top_position = item->sceneBoundingRect().y(); - if(top_position <= 5) - return; - } - movement = QPointF(0.0, -yKeyGridFine); - break; - case Qt::Key_Down: - movement = QPointF(0.0, +yKeyGridFine); - break; - } + { + switch(event->key()) + { + case Qt::Key_Left: + for (Element *item : dc.m_elements) + { + left_position = item->sceneBoundingRect().x(); + if(left_position <= 5) + return; + } + movement = QPointF(-xKeyGridFine, 0.0); + break; + case Qt::Key_Right: + movement = QPointF(+xKeyGridFine, 0.0); + break; + case Qt::Key_Up: + for(Element *item : dc.m_elements) + { + top_position = item->sceneBoundingRect().y(); + if(top_position <= 5) + return; + } + movement = QPointF(0.0, -yKeyGridFine); + break; + case Qt::Key_Down: + movement = QPointF(0.0, +yKeyGridFine); + break; + } - if (!movement.isNull() && !focusItem()) - { - m_elements_mover.beginMovement(this); - m_elements_mover.continueMovement(movement); - event->accept(); - return; - } - } - else if(event->modifiers() == Qt::ControlModifier) + if (!movement.isNull() && !focusItem()) + { + m_elements_mover.beginMovement(this); + m_elements_mover.continueMovement(movement); + event->accept(); + return; + } + } + else if(event->modifiers() == Qt::ControlModifier) { //Adjust the alignment of a texts group if(selectedItems().size() == 1 && selectedItems().first()->type() == QGraphicsItemGroup::Type) @@ -873,41 +873,41 @@ bool Diagram::initFromXml(QDomElement &document, QPointF position, bool consider * \return */ Terminal* findTerminal(int conductor_index, QDomElement& f, QHash& table_adr_id, QList& added_elements) { - assert(conductor_index == 1 || conductor_index == 2); + assert(conductor_index == 1 || conductor_index == 2); - QString element_index = "element" + QString::number(conductor_index); - QString terminal_index = "terminal" + QString::number(conductor_index); + QString element_index = "element" + QString::number(conductor_index); + QString terminal_index = "terminal" + QString::number(conductor_index); - if (f.hasAttribute(element_index)) { - QUuid element_uuid = QUuid(f.attribute(element_index)); - // element1 did not exist in the conductor part of the xml until prior 0.7 - // It is used as an indicator that uuid's are used to identify terminals - bool element_found = false; - for (auto element: added_elements) { - if (element->uuid() != element_uuid) - continue; - element_found = true; - QUuid terminal_uuid = QUuid(f.attribute(terminal_index)); - for (auto terminal: element->terminals()) { - if (terminal->uuid() != terminal_uuid) - continue; + if (f.hasAttribute(element_index)) { + QUuid element_uuid = QUuid(f.attribute(element_index)); + // element1 did not exist in the conductor part of the xml until prior 0.7 + // It is used as an indicator that uuid's are used to identify terminals + bool element_found = false; + for (auto element: added_elements) { + if (element->uuid() != element_uuid) + continue; + element_found = true; + QUuid terminal_uuid = QUuid(f.attribute(terminal_index)); + for (auto terminal: element->terminals()) { + if (terminal->uuid() != terminal_uuid) + continue; - return terminal; - } - qDebug() << "Diagram::fromXml() : "<< terminal_index << ":" << terminal_uuid << "not found in " << element_index << ":" << element_uuid; - break; - } - if (!element_found) - qDebug() << "Diagram::fromXml() : " << element_index << ": " << element_uuid << "not found"; - } else { - // Backward compatibility. Until version 0.7 a generated id is used to link the terminal. - int id_p1 = f.attribute(terminal_index).toInt(); - if (!table_adr_id.contains(id_p1)) { - qDebug() << "Diagram::fromXml() : terminal id " << id_p1 << " not found"; - } else - return table_adr_id.value(id_p1); - } - return nullptr; + return terminal; + } + qDebug() << "Diagram::fromXml() : "<< terminal_index << ":" << terminal_uuid << "not found in " << element_index << ":" << element_uuid; + break; + } + if (!element_found) + qDebug() << "Diagram::fromXml() : " << element_index << ": " << element_uuid << "not found"; + } else { + // Backward compatibility. Until version 0.7 a generated id is used to link the terminal. + int id_p1 = f.attribute(terminal_index).toInt(); + if (!table_adr_id.contains(id_p1)) { + qDebug() << "Diagram::fromXml() : terminal id " << id_p1 << " not found"; + } else + return table_adr_id.value(id_p1); + } + return nullptr; } /** @@ -1079,21 +1079,21 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf //Check if terminal that conductor must be linked is know - Terminal* p1 = findTerminal(1, f, table_adr_id, added_elements); - Terminal* p2 = findTerminal(2, f, table_adr_id, added_elements); + Terminal* p1 = findTerminal(1, f, table_adr_id, added_elements); + Terminal* p2 = findTerminal(2, f, table_adr_id, added_elements); - if (p1 && p2 && p1 != p2) - { - Conductor *c = new Conductor(p1, p2); - if (c->isValid()) - { - addItem(c); - c -> fromXml(f); - added_conductors << c; - } - else - delete c; - } + if (p1 && p2 && p1 != p2) + { + Conductor *c = new Conductor(p1, p2); + if (c->isValid()) + { + addItem(c); + c -> fromXml(f); + added_conductors << c; + } + else + delete c; + } } //Load tables