Files
qelectrotech-source-mirror/sources/diagramevent/diagrameventaddmacro.h
T
Kellermorph 2efce1752d fix: correct macro placement position mismatch
Fix macro elements jumping to upper-left corner instead of being placed
at the correct drop position.

Root cause: The preview offset used itemsBoundingRect() (all items
including children), while Diagram::fromXml() computed its translation
offset from top-level items only. This mismatch caused fromXml to
translate elements to the wrong position.

Changes:
- Compute top-level-only bounding rect in dummy diagram constructor
  to get the correct m_items_top_left reference point
- Pass final_pos + m_items_top_left to fromXml() so the internal
  translation yields the intended final position
- Add braces around single-statement for-loop in fromXml
- Remove empty else block leftovers from debug cleanup
2026-09-20 21:24:38 +02:00

47 lines
1.3 KiB
C++

/*
C opyright 2006-2026 The QEle*ctroTech Team
This file is part of QElectroTech.
*/
#ifndef DIAGRAMEVENTADDMACRO_H
#define DIAGRAMEVENTADDMACRO_H
#include "../ElementsCollection/elementslocation.h"
#include "diagrameventinterface.h"
#include <QDomDocument>
#include <QGraphicsPixmapItem>
class QStatusBar;
/**
* @brief The DiagramEventAddMacro class
*/
class DiagramEventAddMacro : public DiagramEventInterface
{
Q_OBJECT
public:
DiagramEventAddMacro(const ElementsLocation &location, Diagram *diagram, QPointF pos = QPointF(0,0));
~DiagramEventAddMacro() override;
void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override;
void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override;
void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override;
void keyPressEvent (QKeyEvent *event) override;
void init() override;
private:
bool loadMacro();
void addMacro(QPointF final_pos);
private:
ElementsLocation m_location;
QDomDocument m_macro_doc;
QGraphicsPixmapItem *m_preview_item;
QPointer<QStatusBar> m_status_bar;
QPointF m_items_top_left; // top-left of bounding rect of top-level items in the macro (for correct placement offset)
};
#endif // DIAGRAMEVENTADDMACRO_H