# HG changeset patch # User Santeri Piippo # Date 1373072099 -10800 # Node ID 02e10ed4f8eb6d436fcba6140e7007190abdf6b8 # Parent ba2db5e22f8b64e05fec30f864180fe47f656e75 astyle history.cpp diff -r ba2db5e22f8b -r 02e10ed4f8eb src/history.cpp --- a/src/history.cpp Sat Jul 06 03:44:04 2013 +0300 +++ b/src/history.cpp Sat Jul 06 03:54:59 2013 +0300 @@ -1,17 +1,17 @@ /* * LDForge: LDraw parts authoring CAD * Copyright (C) 2013 Santeri Piippo - * + * * This program 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 3 of the License, or * (at your option) any later version. - * + * * This program 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 this program. If not, see . */ @@ -23,153 +23,172 @@ #include "gui.h" #include "gldraw.h" -EXTERN_ACTION (undo) -EXTERN_ACTION (redo) +EXTERN_ACTION( undo ) +EXTERN_ACTION( redo ) bool g_fullRefresh = false; -History::History () { - setPos (-1); +History::History() +{ + setPos( -1 ); } -void History::undo () { - if (m_changesets.size () == 0 || pos () == -1) +void History::undo() +{ + if( m_changesets.size() == 0 || pos() == -1 ) return; - const list& set = changeset (pos ()); + const list& set = changeset( pos() ); g_fullRefresh = false; // Iterate the list in reverse and undo all actions - for (const AbstractHistoryEntry* change : c_rev (set)) - change->undo (); + for( const AbstractHistoryEntry * change : c_rev ( set )) + change->undo(); - setPos (pos () - 1); + setPos( pos() - 1 ); - if (!g_fullRefresh) - g_win->refresh (); + if( !g_fullRefresh ) + g_win->refresh(); else - g_win->fullRefresh (); + g_win->fullRefresh(); - updateActions (); + updateActions(); } -void History::redo () { - if (pos () == (long) m_changesets.size ()) +void History::redo() +{ + if( pos() == (long) m_changesets.size() ) return; - const list& set = changeset (pos () + 1); + const list& set = changeset( pos() + 1 ); g_fullRefresh = false; // Redo things - in the order as they were done in the first place - for (const AbstractHistoryEntry* change : set) - change->redo (); + for( const AbstractHistoryEntry* change : set ) + change->redo(); - setPos (pos () + 1); + setPos( pos() + 1 ); - if (!g_fullRefresh) - g_win->refresh (); + if( !g_fullRefresh ) + g_win->refresh(); else - g_win->fullRefresh (); + g_win->fullRefresh(); - updateActions (); + updateActions(); } -void History::clear () { +void History::clear() +{ + for( vector set : m_changesets ) + for( AbstractHistoryEntry* change : set ) + delete change; + m_changesets.clear(); } -void History::updateActions () const { - ACTION (undo)->setEnabled (pos () != -1); - ACTION (redo)->setEnabled (pos () < (long) m_changesets.size () - 1); +void History::updateActions() const +{ + ACTION( undo )->setEnabled( pos() != -1 ); + ACTION( redo )->setEnabled( pos() < (long) m_changesets.size() - 1 ); } -void History::open () { - if (opened ()) +void History::open() +{ + if( opened() ) return; - setOpened (true); + setOpened( true ); } -void History::close () { - if (!opened ()) +void History::close() +{ + if( !opened() ) return; - setOpened (false); + setOpened( false ); - if (m_currentArchive.size () == 0) + if( m_currentArchive.size() == 0 ) return; - while (pos () < size () - 1) - m_changesets.erase (size () - 1); + while( pos() < size() - 1 ) + m_changesets.erase( size() - 1 ); m_changesets << m_currentArchive; - m_currentArchive.clear (); - setPos (pos () + 1); - updateActions (); + m_currentArchive.clear(); + setPos( pos() + 1 ); + updateActions(); } -void History::add (AbstractHistoryEntry* entry) { - if (!opened ()) { +void History::add( AbstractHistoryEntry* entry ) +{ + if( !opened() ) + { delete entry; return; } - - entry->setParent (this); + + entry->setParent( this ); m_currentArchive << entry; } // ============================================================================= -void AddHistory::undo () const { - LDOpenFile* f = parent ()->file (); - LDObject* obj = f->object (index ()); - f->forgetObject (obj); +void AddHistory::undo() const +{ + LDOpenFile* f = parent()->file(); + LDObject* obj = f->object( index() ); + f->forgetObject( obj ); delete obj; g_fullRefresh = true; } -void AddHistory::redo () const { - LDOpenFile* f = parent ()->file (); - LDObject* obj = parseLine (code ()); - f->insertObj (index (), obj); - g_win->R ()->compileObject (obj); +void AddHistory::redo() const +{ + LDOpenFile* f = parent()->file(); + LDObject* obj = parseLine( code() ); + f->insertObj( index(), obj ); + g_win->R()->compileObject( obj ); } -AddHistory::~AddHistory () {} +AddHistory::~AddHistory() {} // ============================================================================= // heh -void DelHistory::undo () const { - LDOpenFile* f = parent ()->file (); - LDObject* obj = parseLine (code ()); - f->insertObj (index (), obj); - g_win->R ()->compileObject (obj); +void DelHistory::undo() const +{ + LDOpenFile* f = parent()->file(); + LDObject* obj = parseLine( code() ); + f->insertObj( index(), obj ); + g_win->R()->compileObject( obj ); } -void DelHistory::redo () const { - LDOpenFile* f = parent ()->file (); - LDObject* obj = f->object (index ()); - f->forgetObject (obj); +void DelHistory::redo() const +{ + LDOpenFile* f = parent()->file(); + LDObject* obj = f->object( index() ); + f->forgetObject( obj ); delete obj; g_fullRefresh = true; } -DelHistory::~DelHistory () {} +DelHistory::~DelHistory() {} // ============================================================================= -void EditHistory::undo () const { - LDObject* obj = g_curfile->object (index ()); - LDObject* newobj = parseLine (oldCode ()); - obj->replace (newobj); - g_win->R ()->compileObject (newobj); +void EditHistory::undo() const +{ + LDObject* obj = g_curfile->object( index() ); + LDObject* newobj = parseLine( oldCode() ); + obj->replace( newobj ); + g_win->R()->compileObject( newobj ); } -void EditHistory::redo () const { - LDObject* obj = g_curfile->object (index ()); - LDObject* newobj = parseLine (newCode ()); - obj->replace (newobj); - g_win->R ()->compileObject (newobj); +void EditHistory::redo() const +{ + LDObject* obj = g_curfile->object( index() ); + LDObject* newobj = parseLine( newCode() ); + obj->replace( newobj ); + g_win->R()->compileObject( newobj ); } -EditHistory::~EditHistory () {} \ No newline at end of file +EditHistory::~EditHistory() {} \ No newline at end of file