mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-05-02 03:19:59 +02:00
@@ -225,6 +225,7 @@ namespace autonum
|
||||
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("%{description_auxiliary1}", dc.value("description_auxiliary1").toString());
|
||||
str.replace("%{designation_auxiliary1}", dc.value("designation_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;
|
||||
|
||||
@@ -762,10 +762,12 @@ QList < QSet <Conductor *> > 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<Element *>(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,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,
|
||||
@@ -1455,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;
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 <Conductor *> > 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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user