diff --git a/sources/autoNum/assignvariables.cpp b/sources/autoNum/assignvariables.cpp index 8c97625eb..e69ead7f7 100644 --- a/sources/autoNum/assignvariables.cpp +++ b/sources/autoNum/assignvariables.cpp @@ -221,11 +221,12 @@ namespace autonum str.replace("%{designation}", dc.value("designation").toString()); str.replace("%{manufacturer}", dc.value("manufacturer").toString()); str.replace("%{manufacturer_reference}", - dc.value("manufacturer_reference").toString()); + dc.value("manufacturer_reference").toString()); str.replace("%{supplier}", dc.value("supplier").toString()); str.replace("%{quantity}", dc.value("quantity").toString()); str.replace("%{unity}", dc.value("unity").toString()); - str.replace("%{auxiliary1}", dc.value("auxiliary1").toString()); + + str.replace("%{auxiliary1}", dc.value("auxiliary1").toString()); str.replace("%{description_auxiliary1}", dc.value("description_auxiliary1").toString()); str.replace("%{designation_auxiliary1}", dc.value("designation_auxiliary1").toString()); str.replace("%{manufacturer_auxiliary1}", dc.value("manufacturer_auxiliary1").toString()); @@ -264,10 +265,14 @@ namespace autonum str.replace("%{unity_auxiliary4}", dc.value("unity_auxiliary4").toString()); - str.replace("%{machine_manufacturer_reference}", - dc.value("machine_manufacturer_reference").toString()); + str.replace("%{machine_manufacturer_reference}", dc.value("machine_manufacturer_reference").toString()); + str.replace("%{location}", dc.value("location").toString()); str.replace("%{function}", dc.value("function").toString()); + str.replace("%{tension_protocol}", dc.value("tension_protocol").toString()); + str.replace("%{conductor_section}", dc.value("conductor_section").toString()); + str.replace("%{conductor_color}", dc.value("conductor_color").toString()); + str.replace("%{void}", QString()); return str; diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 79a945a8e..41996cf06 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -762,10 +762,12 @@ QList < QSet > Diagram::potentials() represent the entire schema or only the selected content \~French Booleen (a vrai par defaut) indiquant si le XML genere doit representer l'integralite du schema ou seulement le contenu selectionne + \~ @param is_copy_command: + Boolean (false by default) indicating if function is called by an copy command \~ @return An XML Document (QDomDocument) \~French Un Document XML (QDomDocument) */ -QDomDocument Diagram::toXml(bool whole_content) { +QDomDocument Diagram::toXml(bool whole_content, bool is_copy_command) { // document QDomDocument document; @@ -912,8 +914,13 @@ QDomDocument Diagram::toXml(bool whole_content) { { case Element::Type: { auto elmt = static_cast(qgi); - if (whole_content || elmt->isSelected()) + if (whole_content || elmt->isSelected()){ + // For a copy/paste command, the text positions must be recalculated for + // correct text alignment, before it is saved to the clipboard + if(is_copy_command && (elmt->linkType() == Element::Slave || elmt->linkType()&Element::AllReport)) + correctTextPos(elmt); list_elements << elmt; + } break; } case Conductor::Type: { @@ -973,6 +980,9 @@ QDomDocument Diagram::toXml(bool whole_content) { for (auto elmt : list_elements) { dom_elements.appendChild(elmt->toXml(document, table_adr_id)); + // If copy is active we have to undo the changes we have made during creating(filling) 'list_elements' + if(is_copy_command && (elmt->linkType() == Element::Slave || elmt->linkType()&Element::AllReport)) + restoreText(elmt); } dom_root.appendChild(dom_elements); } @@ -1428,33 +1438,6 @@ bool Diagram::fromXml(QDomElement &document, added_shapes << dii; } - // Load conductor - QList added_conductors; - for (auto f : QET::findInDomElement(root, - QStringLiteral("conductors"), - QStringLiteral("conductor"))) - { - if (!Conductor::valideXml(f)) continue; - - //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); - - 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 QVector added_tables; for (const auto &dom_table : QETXML::subChild(root, @@ -1475,7 +1458,6 @@ bool Diagram::fromXml(QDomElement &document, { QVector 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; @@ -1500,6 +1482,33 @@ bool Diagram::fromXml(QDomElement &document, qgi->setPos(qgi->pos() += pos_); } + // Load conductor + QList added_conductors; + for (auto f : QET::findInDomElement(root, + QStringLiteral("conductors"), + QStringLiteral("conductor"))) + { + if (!Conductor::valideXml(f)) continue; + + //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); + + 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; + } + } + //Filling of falculatory lists if (content_ptr) { content_ptr -> m_elements = added_elements; @@ -2472,3 +2481,80 @@ bool Diagram::canRotateSelection() const return false; } +/* + * To copy elements with right-aligned or centered elementtext, the text position + of dynamicElementTextItems in report- and slave elements must be reset + to the original insert position bevor writing to clipboard. + It is only necessary for right-aligned and centered texts, + but we do it for all, because it has no influence on other texts. +*/ +/** + @brief Diagram::correctTextPos + set insertion position to the original insertion position of the element texts before copying + @param Element +*/ +void Diagram::correctTextPos(Element* elmt) +{ + for (auto deti : elmt->dynamicTextItems()){ + if( deti->textFrom() == DynamicElementTextItem::ElementInfo || + deti->textFrom() == DynamicElementTextItem::CompositeText) { + + if (deti->text().isEmpty()){ + deti->setText(deti->toPlainText()); + } + // block alignment calculation + deti->m_block_alignment = true; + deti->setPlainText(deti->text()); + // release the alignment calculation + deti->m_block_alignment = false; + // writing an empty string sets the insertion point + // to the original insertion point + deti->setPlainText(""); + } + } + // same for textgroups + for (auto group : elmt->textGroups()){ + for(DynamicElementTextItem *deti : group->texts()){ + if( deti->textFrom() == DynamicElementTextItem::ElementInfo || + deti->textFrom() == DynamicElementTextItem::CompositeText) { + if (deti->text().isEmpty()){ + deti->setText(deti->toPlainText()); + } + deti->m_block_alignment = true; + deti->setPlainText(deti->text()); + deti->m_block_alignment = false; + deti->setPlainText(""); + } + } + } +} + +/* + * After changing the element texts for copying, the element texts has to be restored. + */ +/** + @brief Diagram::restoreText + After correcting the elementtext position during copying + the Text has to be restored + @param Element +*/ +void Diagram::restoreText(Element* elmt) +{ + for (auto deti : elmt->dynamicTextItems()){ + if( deti->textFrom() == DynamicElementTextItem::ElementInfo || + deti->textFrom() == DynamicElementTextItem::CompositeText) + { + deti->setPlainText(deti->text()); + } + } + + for (auto group : elmt->textGroups()){ + for(DynamicElementTextItem *deti : group->texts()){ + if( deti->textFrom() == DynamicElementTextItem::ElementInfo || + deti->textFrom() == DynamicElementTextItem::CompositeText) + { + deti->setPlainText(deti->text()); + } + } + } +} diff --git a/sources/diagram.h b/sources/diagram.h index 452c52a24..3c421e36f 100644 --- a/sources/diagram.h +++ b/sources/diagram.h @@ -142,6 +142,8 @@ class Diagram : public QGraphicsScene void wheelEvent (QGraphicsSceneWheelEvent *event) override; void keyPressEvent (QKeyEvent *event) override; void keyReleaseEvent (QKeyEvent *) override; + void correctTextPos(Element* elmt); + void restoreText(Element* elmt); public: QUuid uuid(); @@ -167,7 +169,7 @@ class Diagram : public QGraphicsScene QList < QSet > potentials(); // methods related to XML import/export - QDomDocument toXml(bool = true); + QDomDocument toXml(bool wholeContent = true, bool is_copy_command = false); bool initFromXml(QDomElement &, QPointF = QPointF(), bool = true, diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 73dcb018a..cacefcd1d 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -391,7 +391,7 @@ void DiagramView::cut() void DiagramView::copy() { QClipboard *presse_papier = QApplication::clipboard(); - QString contenu_presse_papier = m_diagram -> toXml(false).toString(4); + QString contenu_presse_papier = m_diagram -> toXml(false, true).toString(4); if (presse_papier -> supportsSelection()) presse_papier -> setText(contenu_presse_papier, QClipboard::Selection); presse_papier -> setText(contenu_presse_papier); } diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.cpp b/sources/qetgraphicsitem/dynamicelementtextitem.cpp index 41a2474bd..63dee4fea 100644 --- a/sources/qetgraphicsitem/dynamicelementtextitem.cpp +++ b/sources/qetgraphicsitem/dynamicelementtextitem.cpp @@ -1212,6 +1212,12 @@ QString DynamicElementTextItem::reportReplacedCompositeText() const label = autonum::AssignVariables::formulaToLabel(label, elmt->rSequenceStruct(), elmt->diagram(), elmt); string.replace("%{label}", label); } + // if element is not linked, replace an empty string + else + { + string.replace("%{label}", ""); + } + if (m_watched_conductor) { if(string.contains("%{function}")) @@ -1223,6 +1229,18 @@ QString DynamicElementTextItem::reportReplacedCompositeText() const if(string.contains("%{conductor_section}")) string.replace("%{conductor_section}", m_watched_conductor.data()->properties().m_wire_section); } + // if no conductor is connected, replace an empty String + else + { + if(string.contains("%{function}")) + string.replace("%{function}", ""); + if(string.contains("%{tension_protocol}")) + string.replace("%{tension_protocol}", ""); + if(string.contains("%{conductor_color}")) + string.replace("%{conductor_color}", ""); + if(string.contains("%{conductor_section}")) + string.replace("%{conductor_section}", ""); + } } return string;