mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Better handling of conductors when creating from XML
The position of a conductor is determined by the two terminals the conductor connects. Therefore, it makes no sense to set the position with 'setPos()'. It is better to first load all elements (but not the conductors), position them if necessary, and only then load the conductors and assign them to the elements (terminals).
This commit is contained in:
@@ -1438,6 +1438,50 @@ bool Diagram::fromXml(QDomElement &document,
|
||||
added_shapes << dii;
|
||||
}
|
||||
|
||||
//Load tables
|
||||
QVector<QetGraphicsTableItem *> added_tables;
|
||||
for (const auto &dom_table : QETXML::subChild(root,
|
||||
QStringLiteral("tables"),
|
||||
QetGraphicsTableItem::xmlTagName()))
|
||||
{
|
||||
auto table = new QetGraphicsTableItem();
|
||||
addItem(table);
|
||||
table->fromXml(dom_table);
|
||||
added_tables << table;
|
||||
}
|
||||
|
||||
//Load terminal strip item
|
||||
QVector<TerminalStripItem *> added_strips { TerminalStripItemXml::fromXml(this, root) };
|
||||
|
||||
//Translate items if a new position was given in parameter
|
||||
if (position != QPointF())
|
||||
{
|
||||
QVector <QGraphicsItem *> added_items;
|
||||
for (auto element : qAsConst(added_elements )) added_items << element;
|
||||
for (auto shape : qAsConst(added_shapes )) added_items << shape;
|
||||
for (auto text : qAsConst(added_texts )) added_items << text;
|
||||
for (auto image : qAsConst(added_images )) added_items << image;
|
||||
for (auto table : qAsConst(added_tables )) added_items << table;
|
||||
for (const auto &strip : qAsConst(added_strips)) added_items << strip;
|
||||
|
||||
//Get the top left corner of the rectangle that contain all added items
|
||||
QRectF items_rect;
|
||||
for (auto item : added_items) {
|
||||
items_rect = items_rect.united(
|
||||
item->mapToScene(
|
||||
item->boundingRect()
|
||||
).boundingRect());
|
||||
}
|
||||
|
||||
QPointF point_ = items_rect.topLeft();
|
||||
QPointF pos_ = Diagram::snapToGrid(QPointF (position.x() - point_.x(),
|
||||
position.y() - point_.y()));
|
||||
|
||||
//Translate all added items
|
||||
for (auto qgi : added_items)
|
||||
qgi->setPos(qgi->pos() += pos_);
|
||||
}
|
||||
|
||||
// Load conductor
|
||||
QList<Conductor *> added_conductors;
|
||||
for (auto f : QET::findInDomElement(root,
|
||||
@@ -1465,51 +1509,6 @@ bool Diagram::fromXml(QDomElement &document,
|
||||
}
|
||||
}
|
||||
|
||||
//Load tables
|
||||
QVector<QetGraphicsTableItem *> added_tables;
|
||||
for (const auto &dom_table : QETXML::subChild(root,
|
||||
QStringLiteral("tables"),
|
||||
QetGraphicsTableItem::xmlTagName()))
|
||||
{
|
||||
auto table = new QetGraphicsTableItem();
|
||||
addItem(table);
|
||||
table->fromXml(dom_table);
|
||||
added_tables << table;
|
||||
}
|
||||
|
||||
//Load terminal strip item
|
||||
QVector<TerminalStripItem *> added_strips { TerminalStripItemXml::fromXml(this, root) };
|
||||
|
||||
//Translate items if a new position was given in parameter
|
||||
if (position != QPointF())
|
||||
{
|
||||
QVector <QGraphicsItem *> added_items;
|
||||
for (auto element : qAsConst(added_elements )) added_items << element;
|
||||
for (auto cond : qAsConst(added_conductors )) added_items << cond;
|
||||
for (auto shape : qAsConst(added_shapes )) added_items << shape;
|
||||
for (auto text : qAsConst(added_texts )) added_items << text;
|
||||
for (auto image : qAsConst(added_images )) added_items << image;
|
||||
for (auto table : qAsConst(added_tables )) added_items << table;
|
||||
for (const auto &strip : qAsConst(added_strips)) added_items << strip;
|
||||
|
||||
//Get the top left corner of the rectangle that contain all added items
|
||||
QRectF items_rect;
|
||||
for (auto item : added_items) {
|
||||
items_rect = items_rect.united(
|
||||
item->mapToScene(
|
||||
item->boundingRect()
|
||||
).boundingRect());
|
||||
}
|
||||
|
||||
QPointF point_ = items_rect.topLeft();
|
||||
QPointF pos_ = Diagram::snapToGrid(QPointF (position.x() - point_.x(),
|
||||
position.y() - point_.y()));
|
||||
|
||||
//Translate all added items
|
||||
for (auto qgi : added_items)
|
||||
qgi->setPos(qgi->pos() += pos_);
|
||||
}
|
||||
|
||||
//Filling of falculatory lists
|
||||
if (content_ptr) {
|
||||
content_ptr -> m_elements = added_elements;
|
||||
|
||||
Reference in New Issue
Block a user