Wed, 10 Apr 2013 03:30:58 +0300
Added history handling for set contents
gui_editactions.cpp | file | annotate | diff | comparison | revisions | |
history.cpp | file | annotate | diff | comparison | revisions | |
history.h | file | annotate | diff | comparison | revisions | |
ldtypes.cpp | file | annotate | diff | comparison | revisions | |
zz_setContentsDialog.cpp | file | annotate | diff | comparison | revisions | |
zz_setContentsDialog.h | file | annotate | diff | comparison | revisions |
--- a/gui_editactions.cpp Wed Apr 10 02:40:52 2013 +0300 +++ b/gui_editactions.cpp Wed Apr 10 03:30:58 2013 +0300 @@ -187,7 +187,7 @@ return; LDObject* obj = g_ForgeWindow->getSelectedObjects ()[0]; - SetContentsDialog::staticDialog (obj, g_ForgeWindow); + SetContentsDialog::staticDialog (obj); } // =============================================================================
--- a/history.cpp Wed Apr 10 02:40:52 2013 +0300 +++ b/history.cpp Wed Apr 10 03:30:58 2013 +0300 @@ -71,6 +71,28 @@ g_ForgeWindow->refresh (); } +SetColorHistory::~SetColorHistory () {} + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +void SetContentsHistory::undo () { + LDObject* obj = g_CurrentFile->objects[ulIndex]; + obj->replace (oldObj->clone ()); + g_ForgeWindow->refresh (); +} + +void SetContentsHistory::redo () { + LDObject* obj = g_CurrentFile->objects[ulIndex]; + obj->replace (newObj->clone ()); + g_ForgeWindow->refresh (); +} + +SetContentsHistory::~SetContentsHistory () { + delete oldObj; + delete newObj; +} + // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // =============================================================================
--- a/history.h Wed Apr 10 02:40:52 2013 +0300 +++ b/history.h Wed Apr 10 03:30:58 2013 +0300 @@ -25,10 +25,14 @@ virtual HistoryType_e getType () const { \ return HISTORY_##N; \ } \ + virtual ~N##History (); \ + virtual void undo (); \ + virtual void redo (); enum HistoryType_e { HISTORY_Delete, HISTORY_SetColor, + HISTORY_SetContents, }; // ============================================================================= @@ -57,9 +61,6 @@ DeleteHistory (vector<ulong> indices, vector<LDObject*> cache) : indices (indices), cache (cache) {} - virtual ~DeleteHistory (); - virtual void undo (); - virtual void redo (); }; // ============================================================================= @@ -75,9 +76,17 @@ SetColorHistory (vector<ulong> ulaIndices, vector<short> daColors, short dNewColor) : ulaIndices (ulaIndices), daColors (daColors), dNewColor (dNewColor) {} - virtual ~SetColorHistory () {} - virtual void undo (); - virtual void redo (); +}; + +class SetContentsHistory : public HistoryEntry { +public: + IMPLEMENT_HISTORY_TYPE (SetContents) + + ulong ulIndex; + LDObject* oldObj, *newObj; + + SetContentsHistory (ulong ulIndex, LDObject* oldObj, LDObject* newObj) : + ulIndex (ulIndex), oldObj (oldObj), newObj (newObj) {} }; // =============================================================================
--- a/ldtypes.cpp Wed Apr 10 02:40:52 2013 +0300 +++ b/ldtypes.cpp Wed Apr 10 03:30:58 2013 +0300 @@ -226,7 +226,7 @@ // ============================================================================= void LDObject::replace (LDObject* replacement) { // Replace all instances of the old object with the new object - for (LDObject* obj : g_CurrentFile->objects) + for (LDObject*& obj : g_CurrentFile->objects) if (obj == this) obj = replacement;
--- a/zz_setContentsDialog.cpp Wed Apr 10 02:40:52 2013 +0300 +++ b/zz_setContentsDialog.cpp Wed Apr 10 03:30:58 2013 +0300 @@ -21,6 +21,7 @@ #include "zz_setContentsDialog.h" #include "file.h" #include "gui.h" +#include "history.h" // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @@ -81,19 +82,26 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void SetContentsDialog::staticDialog (LDObject* obj, ForgeWindow* parent) { +void SetContentsDialog::staticDialog (LDObject* obj) { if (!obj) return; - SetContentsDialog dlg (obj, parent); - if (dlg.exec ()) { - LDObject* oldobj = obj; - - // Reinterpret it from the text of the input field - obj = parseLine (dlg.qContents->text ().toStdString ().c_str ()); - oldobj->replace (obj); - - // Rebuild stuff after this - parent->refresh (); - } + SetContentsDialog dlg (obj, g_ForgeWindow); + if (dlg.exec () == false) + return; + + LDObject* oldobj = obj; + + // Reinterpret it from the text of the input field + obj = parseLine (dlg.qContents->text ().toStdString ().c_str ()); + + // Mark down the history now before we perform the replacement (which + // destroys the old object) + History::addEntry (new SetContentsHistory (oldobj->getIndex (g_CurrentFile), + oldobj->clone (), obj->clone ())); + + oldobj->replace (obj); + + // Rebuild stuff after this + g_ForgeWindow->refresh (); } \ No newline at end of file
--- a/zz_setContentsDialog.h Wed Apr 10 02:40:52 2013 +0300 +++ b/zz_setContentsDialog.h Wed Apr 10 03:30:58 2013 +0300 @@ -36,7 +36,7 @@ QDialogButtonBox* qButtons; SetContentsDialog (LDObject* obj, QWidget* parent = nullptr); - static void staticDialog (LDObject* obj, ForgeWindow* parent); + static void staticDialog (LDObject* obj); private slots: void slot_handleButtons (QAbstractButton* qButton);