mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-05 18:54:14 +02:00
Merge pull request #1122 from ispyisail/feat/editor-derived-terminal-uuids
Give old symbols' terminals their lasting uuid in the symbol editor
This commit is contained in:
@@ -28,12 +28,12 @@ namespace {
|
||||
@return the <terminal> of the definition held by the embedded
|
||||
collection element @p collection_element
|
||||
*/
|
||||
QList<QDomElement> terminalsOf(const QDomElement &collection_element)
|
||||
//The <terminal> of the <definition> @p definition
|
||||
QList<QDomElement> definitionTerminals(const QDomElement &definition)
|
||||
{
|
||||
QList<QDomElement> terminals;
|
||||
const QDomElement description = collection_element
|
||||
.firstChildElement(QStringLiteral("definition"))
|
||||
.firstChildElement(QStringLiteral("description"));
|
||||
const QDomElement description =
|
||||
definition.firstChildElement(QStringLiteral("description"));
|
||||
for (QDomElement t = description.firstChildElement(QStringLiteral("terminal"));
|
||||
!t.isNull();
|
||||
t = t.nextSiblingElement(QStringLiteral("terminal"))) {
|
||||
@@ -42,6 +42,12 @@ QList<QDomElement> terminalsOf(const QDomElement &collection_element)
|
||||
return terminals;
|
||||
}
|
||||
|
||||
QList<QDomElement> terminalsOf(const QDomElement &collection_element)
|
||||
{
|
||||
return definitionTerminals(
|
||||
collection_element.firstChildElement(QStringLiteral("definition")));
|
||||
}
|
||||
|
||||
//Place and orientation, "10" and "10.0" being the same place
|
||||
QString terminalPlace(const QDomElement &terminal)
|
||||
{
|
||||
@@ -61,10 +67,10 @@ int orientationOf(const QDomElement &terminal)
|
||||
return 0;
|
||||
}
|
||||
|
||||
//The <terminal> of one element definition get a uuid where missing
|
||||
int fillDefinition(const QDomElement &collection_element)
|
||||
//The <terminal> of one <definition> get a uuid where missing
|
||||
int fillDefinition(const QDomElement &definition)
|
||||
{
|
||||
const QList<QDomElement> terminals = terminalsOf(collection_element);
|
||||
const QList<QDomElement> terminals = definitionTerminals(definition);
|
||||
QSet<QUuid> taken;
|
||||
for (const QDomElement &t : terminals) {
|
||||
const QUuid uuid(t.attribute(QStringLiteral("uuid")));
|
||||
@@ -105,7 +111,8 @@ int fillDirectory(const QDomElement &directory)
|
||||
if (child.tagName() == QLatin1String("category")) {
|
||||
filled += fillDirectory(child);
|
||||
} else if (child.tagName() == QLatin1String("element")) {
|
||||
filled += fillDefinition(child);
|
||||
filled += fillDefinition(
|
||||
child.firstChildElement(QStringLiteral("definition")));
|
||||
}
|
||||
}
|
||||
return filled;
|
||||
@@ -252,3 +259,16 @@ int TerminalUuids::fillMissing(const QDomElement &collection_root)
|
||||
{
|
||||
return fillDirectory(collection_root);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief TerminalUuids::fillMissingInDefinition
|
||||
fillMissing() for a single element definition (@p definition is its
|
||||
<definition>), as the element editor reads it from a file: an old
|
||||
symbol opened and saved there gets the uuids a project gives the same
|
||||
terminals, not random ones that would make every copy of it differ.
|
||||
@return the number of terminals given a uuid
|
||||
*/
|
||||
int TerminalUuids::fillMissingInDefinition(const QDomElement &definition)
|
||||
{
|
||||
return fillDefinition(definition);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace TerminalUuids
|
||||
{
|
||||
QUuid derived(qreal x, qreal y, int orientation, int occurrence = 0);
|
||||
int fillMissing(const QDomElement &collection_root);
|
||||
int fillMissingInDefinition(const QDomElement &definition);
|
||||
void keep(const QDomElement &old_element, QDomElement &new_element);
|
||||
void keepInDirectory(const QDomElement &old_directory,
|
||||
QDomElement &new_directory);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
#include "openelmtcommand.h"
|
||||
#include "../elementscene.h"
|
||||
#include "../graphicspart/partterminal.h"
|
||||
|
||||
#include <QDomDocument>
|
||||
#include <QObject>
|
||||
@@ -52,6 +53,15 @@ void OpenElmtCommand::redo()
|
||||
if (m_first_redo)
|
||||
{
|
||||
m_scene->fromXml(m_document, QPointF(), true, &m_graphics_item);
|
||||
//The terminals are added to an element that may already hold
|
||||
//the same ones -- importing the same symbol twice, or two old
|
||||
//symbols whose terminals get the same derived uuid -- so they
|
||||
//get new uuids, as a paste gives them (PastePartsCommand).
|
||||
for (QGraphicsItem *qgi : std::as_const(m_graphics_item)) {
|
||||
if (qgi->type() == PartTerminal::Type) {
|
||||
static_cast<PartTerminal *>(qgi)->setNewUuid();
|
||||
}
|
||||
}
|
||||
m_scene->qgiManager().manage(m_graphics_item);
|
||||
m_first_redo = false;
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
#include "elementscene.h"
|
||||
|
||||
#include "../ElementsCollection/terminaluuids.h"
|
||||
#include "../NameList/ui/namelistdialog.h"
|
||||
#include "../NameList/ui/namelistwidget.h"
|
||||
#include "../QPropertyUndoCommand/qpropertyundocommand.h"
|
||||
@@ -1196,6 +1197,13 @@ ElementContent ElementScene::loadContent(const QDomDocument &xml_document)
|
||||
if (root.tagName() != "definition" || root.attribute("type") != "element")
|
||||
return(loaded_parts);
|
||||
|
||||
//Terminals saved without a uuid get the one a project gives them
|
||||
//(see TerminalUuids::fillMissing()), not a random one: the same old
|
||||
//symbol then has the same terminal uuids wherever it is copied.
|
||||
//On a copy, the document is the caller's. A paste renews them all.
|
||||
root = root.cloneNode(true).toElement();
|
||||
TerminalUuids::fillMissingInDefinition(root);
|
||||
|
||||
//Load the graphic description of the element
|
||||
for (QDomNode node = root.firstChild() ; !node.isNull() ; node = node.nextSibling())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user