Fix-indentation-code

This commit is contained in:
Laurent Trinques
2020-07-15 19:57:37 +02:00
parent a718cfa16d
commit 6313319f80

View File

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