mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-29 22:24:13 +02:00
2efce1752d
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
47 lines
1.3 KiB
C++
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
|