diff --git a/sources/diagram.h b/sources/diagram.h
index f399b363a..cc988165f 100644
--- a/sources/diagram.h
+++ b/sources/diagram.h
@@ -142,10 +142,11 @@ 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:
+ void correctTextPos(Element* elmt);
+ void restoreText(Element* elmt);
QUuid uuid();
void setEventInterface (DiagramEventInterface *event_interface);
void clearEventInterface();
diff --git a/sources/elementspanelwidget.cpp b/sources/elementspanelwidget.cpp
index 57123465e..7c7484a4b 100644
--- a/sources/elementspanelwidget.cpp
+++ b/sources/elementspanelwidget.cpp
@@ -16,7 +16,6 @@
along with QElectroTech. If not, see .
*/
#include "elementspanelwidget.h"
-
#include "diagram.h"
#include "editor/ui/qetelementeditor.h"
#include "elementscategoryeditor.h"
@@ -26,6 +25,7 @@
#include "titleblock/templatedeleter.h"
#include
#include
+#include "element.h"
/*
When the ENABLE_PANEL_WIDGET_DND_CHECKS flag is set, the panel
@@ -611,6 +611,7 @@ void ElementsPanelWidget::duplicateDiagram()
if (!project || project->isReadOnly()) return;
for (Diagram *source_diagram : diagrams_to_duplicate) {
+
Diagram *new_diagram = project->addNewDiagram();
if (!new_diagram) continue;
@@ -623,9 +624,29 @@ void ElementsPanelWidget::duplicateDiagram()
BorderProperties bp = source_diagram->border_and_titleblock.exportBorder();
new_diagram->border_and_titleblock.importBorder(bp);
+ for (QGraphicsItem *item : source_diagram->items()) {
+ if (Element *elmt = dynamic_cast(item)) {
+ source_diagram->correctTextPos(elmt);
+ }
+ }
+
QDomDocument doc = source_diagram->toXml();
QDomElement diagram_elmt = doc.documentElement();
+
+ for (QGraphicsItem *item : source_diagram->items()) {
+ if (Element *elmt = dynamic_cast(item)) {
+ source_diagram->restoreText(elmt);
+ }
+ }
+
new_diagram->fromXml(diagram_elmt, QPointF(0, 0), false, nullptr);
+
+ for (QGraphicsItem *item : new_diagram->items()) {
+ if (Element *elmt = dynamic_cast(item)) {
+ new_diagram->restoreText(elmt);
+ }
+ }
}
+
elements_panel->reload();
}