qelectrotech-source-mirror/sources/undocommand/movegraphicsitemcommand.h
achim 29c362fe4c Better handling of conductors when moving
For conductors, the setPos() function can result in negative
coordinates.
For unknown reasons, this can lead to an offset in the scene coordinate
system, resulting in a free space above and to the left of the drawing
frame. This free space could not be removed.

It is better to set the conductors using the conductor::updatePath()
function. If the conductor text has been moved by the user, the new
position of the text must be calculated.
It is important to position the elements first and then 'connect' the
conductors.
Setting the conductor position via setPos() was done in elemntsmover.cpp
(corrected here) and in Diagram::fromXML (corrected in the commit
'Better handling of conductors when creating from XML').
2025-08-14 22:03:05 +02:00

67 lines
1.8 KiB
C++

/*
Copyright 2006-2022 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MOVEGRAPHICSITEMCOMMAND_H
#define MOVEGRAPHICSITEMCOMMAND_H
#include <QUndoCommand>
#include <QParallelAnimationGroup>
#include <QPointer>
#include "../diagramcontent.h"
class Diagram;
/**
* @brief The MoveGraphicsItemCommand class
* An undo command used for move item(s) in a diagram
*/
class MoveGraphicsItemCommand : public QUndoCommand
{
public:
MoveGraphicsItemCommand(Diagram *diagram,
const DiagramContent &content,
const QPointF &movement,
QUndoCommand *parent = nullptr);
~MoveGraphicsItemCommand() {}
private:
MoveGraphicsItemCommand(const MoveGraphicsItemCommand &);
public:
void undo() override;
void redo() override;
private:
void move(const QPointF &movement);
void updateConductors(bool is_redo = false);
void setupAnimation(QObject *target,
const QByteArray &property_name,
const QVariant &start,
const QVariant &end);
private:
QPointer<Diagram> m_diagram;
DiagramContent m_content;
const QPointF m_movement;
QParallelAnimationGroup m_anim_group;
bool m_first_redo{true};
};
#endif // MOVEGRAPHICSITEMCOMMAND_H