Element editor : improve code

Better use of signal partsAdded and partsRemoved
This commit is contained in:
joshua
2022-07-26 17:03:18 +02:00
parent 5a497cd6b5
commit 57695bbbea
7 changed files with 139 additions and 81 deletions

View File

@@ -90,54 +90,6 @@ void ElementEditionCommand::setElementView(ElementView *view) {
m_view = view;
}
/*** DeletePartsCommand ***/
/**
Constructeur
@param scene ElementScene concernee
@param parts Liste des parties supprimees
@param parent QUndoCommand parent
*/
DeletePartsCommand::DeletePartsCommand(
ElementScene *scene,
const QList<QGraphicsItem *>& parts,
QUndoCommand *parent
) :
ElementEditionCommand(QObject::tr("suppression", "undo caption"), scene, nullptr, parent),
deleted_parts(parts)
{
foreach(QGraphicsItem *qgi, deleted_parts) {
m_scene -> qgiManager().manage(qgi);
}
}
/// Destructeur : detruit egalement les parties supprimees
DeletePartsCommand::~DeletePartsCommand()
{
foreach(QGraphicsItem *qgi, deleted_parts) {
m_scene -> qgiManager().release(qgi);
}
}
/// Restaure les parties supprimees
void DeletePartsCommand::undo()
{
m_scene -> blockSignals(true);
foreach(QGraphicsItem *qgi, deleted_parts) {
m_scene -> addItem(qgi);
}
m_scene -> blockSignals(false);
}
/// Supprime les parties
void DeletePartsCommand::redo()
{
m_scene -> blockSignals(true);
foreach(QGraphicsItem *qgi, deleted_parts) {
m_scene -> removeItem(qgi);
}
m_scene -> blockSignals(false);
}
/*** CutPartsCommand ***/
/**
Constructeur
@@ -150,7 +102,7 @@ CutPartsCommand::CutPartsCommand(
const QList<QGraphicsItem *>& parts,
QUndoCommand *parent
) :
DeletePartsCommand(scene, parts, parent)
DeletePartsCommand(scene, parts.toVector(), parent)
{
setText(QString(QObject::tr("couper des parties", "undo caption")));
}