-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e42435a
commit fd7e3ce
Showing
5 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "commands.h" | ||
|
||
namespace Logicsim | ||
{ | ||
|
||
MoveCommand::MoveCommand(Component *Mcomponent, const QPointF &MOldPos,QUndoCommand *parent) : QUndoCommand(parent) | ||
{ | ||
draggedComponent = Mcomponent; | ||
newPos = Mcomponent->pos(); | ||
oldPos = MOldPos; | ||
} | ||
|
||
void MoveCommand::undo() | ||
{ | ||
draggedComponent->setPos(oldPos); | ||
setText(QObject::tr("Move %1").arg(createCommandString(draggedComponent, newPos))); | ||
} | ||
|
||
void MoveCommand::redo() | ||
{ | ||
draggedComponent->setPos(newPos); | ||
setText(QObject::tr("Move %1").arg(createCommandString(draggedComponent, newPos))); | ||
} | ||
|
||
AddCommand::AddCommand(Component *Acomponent, Canvas *Acanvas,QUndoCommand *parent) : QUndoCommand(parent) | ||
{ | ||
static int itemCount = 0; | ||
|
||
canvas = Acanvas; | ||
addedComponent = Acomponent; | ||
pos = Acomponent->pos(); | ||
|
||
Acanvas->update(); | ||
++itemCount; | ||
setText(QObject::tr("Add %1").arg(createCommandString(addedComponent, pos))); | ||
} | ||
|
||
AddCommand::~AddCommand() | ||
{ | ||
if (!addedComponent->scene()) | ||
delete addedComponent; | ||
} | ||
|
||
void AddCommand::undo() | ||
{ | ||
canvas->removeItem(addedComponent); | ||
canvas->update(); | ||
} | ||
|
||
void AddCommand::redo() | ||
{ | ||
canvas->addItem(addedComponent); | ||
addedComponent->setPos(pos); | ||
canvas->clearSelection(); | ||
canvas->update(); | ||
} | ||
|
||
QString createCommandString(Component *item, const QPointF &pos) | ||
{ | ||
return QObject::tr("%2, %3").arg(pos.x()).arg(pos.y()); | ||
} | ||
|
||
} //LogicSim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef COMMANDS_H | ||
#define COMMANDS_H | ||
|
||
#include <QUndoCommand> | ||
|
||
#include "component.h" | ||
#include "canvas.h" | ||
|
||
namespace Logicsim | ||
{ | ||
|
||
class MoveCommand : public QUndoCommand | ||
{ | ||
public: | ||
MoveCommand(Component *Mcomponent, const QPointF &MOldPos,QUndoCommand *parent = 0); | ||
void undo() Q_DECL_OVERRIDE; | ||
void redo() Q_DECL_OVERRIDE; | ||
|
||
private: | ||
Component *draggedComponent; | ||
QPointF oldPos; | ||
QPointF newPos; | ||
}; | ||
|
||
class AddCommand : public QUndoCommand | ||
{ | ||
public: | ||
AddCommand(Component *Acomponent, Canvas *Acanvas,QUndoCommand *parent = 0); | ||
~AddCommand(); | ||
void undo() Q_DECL_OVERRIDE; | ||
void redo() Q_DECL_OVERRIDE; | ||
|
||
private: | ||
Component *addedComponent; | ||
Canvas *canvas; | ||
QPointF pos; | ||
}; | ||
|
||
QString createCommandString(Component *item, const QPointF &point); | ||
|
||
} | ||
#endif // COMMANDS_H |