Merge pull request #853 from Kellermorph/fix-template-placing

Fix macro drag-and-drop placement and preview for Qt6
This commit is contained in:
Laurent Trinques
2026-09-13 12:27:51 +02:00
committed by GitHub
2 changed files with 12 additions and 11 deletions
@@ -17,6 +17,7 @@
#include <QGraphicsSceneMouseEvent>
#include <QStatusBar>
#include <QPainter>
#include <QSettings>
DiagramEventAddMacro::DiagramEventAddMacro(const ElementsLocation &location, Diagram *diagram, QPointF pos) :
DiagramEventInterface(diagram),
@@ -63,6 +64,7 @@ m_preview_item(nullptr)
QDomElement diagram_node = root.firstChildElement("diagram_content").firstChildElement("diagram");
if (!diagram_node.isNull()) {
dummy_diagram->setDisplayGrid(false);
dummy_diagram->fromXml(diagram_node, QPointF(0, 0), false, nullptr);
QRectF scene_rect = dummy_diagram->itemsBoundingRect();
@@ -237,13 +239,16 @@ void DiagramEventAddMacro::addMacro(QPointF final_pos)
if (!diagram_node.isNull()) {
QDomElement cloned_node = diagram_node.cloneNode(true).toElement();
QPointF target_pos = final_pos;
DiagramContent pasted_content;
m_diagram->fromXml(cloned_node, target_pos, false, &pasted_content);
m_diagram->fromXml(cloned_node, final_pos, false, &pasted_content);
m_diagram->refreshContents();
// Prevent PasteDiagramCommand from erasing labels (BMK)
QSettings settings;
bool saved_erase = settings.value("diagramcommands/erase-label-on-copy", true).toBool();
settings.setValue("diagramcommands/erase-label-on-copy", false);
m_diagram->undoStack().push(new PasteDiagramCommand(m_diagram, pasted_content));
settings.setValue("diagramcommands/erase-label-on-copy", saved_erase);
}
}
+4 -8
View File
@@ -211,10 +211,10 @@ void DiagramView::handleElementDrop(QDropEvent *event)
}
QPointF drop_pos;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
drop_pos = mapToScene(event->pos());
#else
drop_pos = event->position();
drop_pos = mapToScene(event->position().toPoint());
#endif
if (location.path().endsWith(".qetmak")) {
@@ -290,16 +290,12 @@ void DiagramView::handleTextDrop(QDropEvent *e) {
iti -> setHtml (e -> mimeData() -> text());
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
m_diagram->undoStack().push(new AddGraphicsObjectCommand(
iti, m_diagram, mapToScene(e->pos())));
#else
#if TODO_LIST
#pragma message("@TODO remove code for QT 6 or later")
#endif
m_diagram->undoStack().push(new AddGraphicsObjectCommand(
iti, m_diagram, e->position()));
iti, m_diagram, mapToScene(e->position().toPoint())));
#endif
}