From e5ef064c0e4e2ec9356ab2a66bc44f4e1add8f78 Mon Sep 17 00:00:00 2001 From: Illya Yalovoy Date: Sat, 19 Dec 2009 13:40:22 +0000 Subject: [PATCH] refs #889 --- src/gui/FWCmdBasic.cpp | 28 +++++++++++++++++++++++++++- src/gui/FWCmdBasic.h | 19 ++++++++++++++++--- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/gui/FWCmdBasic.cpp b/src/gui/FWCmdBasic.cpp index 8ce7a6576..ef870b771 100644 --- a/src/gui/FWCmdBasic.cpp +++ b/src/gui/FWCmdBasic.cpp @@ -24,6 +24,7 @@ */ #include "FWCmdBasic.h" +#include using namespace libfwbuilder; @@ -34,10 +35,35 @@ FWCmdBasic::FWCmdBasic(ProjectPanel *project) FWObject* FWCmdBasic::getObject() { - return getObject(id); + return getObject(obj_id); } FWObject* FWCmdBasic::getObject(int id) { return project->db()->findInIndex(id); } + +bool FWCmdBasic::mergeWith(const QUndoCommand *other) +{ + qDebug() << "FWCmdBasic::mergeWith(const QUndoCommand *other)"; + qDebug() << "cmd:" << other->text(); + + const FWCmdTerm* term = dynamic_cast (other); + + return term != 0; +} + + + +void undoAndRemoveLastCommand(QUndoStack* undoStack) +{ + qDebug() << "undoAndRemoveLastCommand(QUndoStack undoStack)"; + undoStack->undo(); + qDebug() << "count:" << undoStack->count(); + if (undoStack->count() == 1) { + undoStack->clear(); + } else { + FWCmdTerm* cmd = new FWCmdTerm(); + undoStack->push(cmd); + } +} diff --git a/src/gui/FWCmdBasic.h b/src/gui/FWCmdBasic.h index 44de36c99..cbcc646ce 100644 --- a/src/gui/FWCmdBasic.h +++ b/src/gui/FWCmdBasic.h @@ -27,6 +27,8 @@ #define FWCMDBASIC_H #include +#include +#include #include "ProjectPanel.h" @@ -34,18 +36,29 @@ class FWCmdBasic : public QUndoCommand { - int id; + int obj_id; protected: ProjectPanel *project; public: FWCmdBasic(ProjectPanel *project); - int objectId() {return id;} - void setObject(libfwbuilder::FWObject *object) {id = object->getId();} + int objectId() {return obj_id;} + void setObject(libfwbuilder::FWObject *object) {obj_id = object->getId();} libfwbuilder::FWObject* getObject(); libfwbuilder::FWObject* getObject(int id); + int id() const {return 1;} + bool mergeWith(const QUndoCommand *other); }; +class FWCmdTerm : public QUndoCommand +{ +public: + FWCmdTerm() : QUndoCommand() {setText("Terminator");} + int id() const {return 1;} +}; + +void undoAndRemoveLastCommand(QUndoStack* undoStack); + #endif // FWCMDBASIC_H