1 /* 2 * ProjectJournal.h - declaration of class ProjectJournal 3 * 4 * Copyright (c) 2006-2010 Tobias Doerffel <tobydox/at/users.sourceforge.net> 5 * 6 * This file is part of LMMS - https://lmms.io 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public 19 * License along with this program (see COPYING); if not, write to the 20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 * Boston, MA 02110-1301 USA. 22 * 23 */ 24 25 #ifndef PROJECT_JOURNAL_H 26 #define PROJECT_JOURNAL_H 27 28 #include <QtCore/QHash> 29 #include <QtCore/QStack> 30 31 #include "lmms_basics.h" 32 #include "DataFile.h" 33 34 class JournallingObject; 35 36 37 //! @warning many parts of this class may be rewritten soon 38 class ProjectJournal 39 { 40 public: 41 static const int MAX_UNDO_STATES; 42 43 ProjectJournal(); 44 virtual ~ProjectJournal(); 45 46 void undo(); 47 void redo(); 48 49 bool canUndo() const; 50 bool canRedo() const; 51 52 void addJournalCheckPoint( JournallingObject *jo ); 53 isJournalling()54 bool isJournalling() const 55 { 56 return m_journalling; 57 } 58 setJournalling(const bool _on)59 void setJournalling( const bool _on ) 60 { 61 m_journalling = _on; 62 } 63 64 // alloc new ID and register object _obj to it 65 jo_id_t allocID( JournallingObject * _obj ); 66 67 // if there's already something known about ID _id, but it is currently 68 // unused (e.g. after jouralling object was deleted), register object 69 // _obj to this id 70 void reallocID( const jo_id_t _id, JournallingObject * _obj ); 71 72 // make ID _id unused, but keep all global journalling information 73 // (order of journalling entries etc.) referring to _id - needed for 74 // restoring a journalling object later freeID(const jo_id_t _id)75 void freeID( const jo_id_t _id ) 76 { 77 reallocID( _id, NULL ); 78 } 79 80 //! hack, not used when saving a file 81 static jo_id_t idToSave( jo_id_t id ); 82 //! hack, not used when loading a savefile 83 static jo_id_t idFromSave( jo_id_t id ); 84 85 void clearJournal(); 86 void stopAllJournalling(); journallingObject(const jo_id_t _id)87 JournallingObject * journallingObject( const jo_id_t _id ) 88 { 89 if( m_joIDs.contains( _id ) ) 90 { 91 return m_joIDs[_id]; 92 } 93 return NULL; 94 } 95 96 97 private: 98 typedef QHash<jo_id_t, JournallingObject *> JoIdMap; 99 100 struct CheckPoint 101 { 102 CheckPoint( jo_id_t initID = 0, const DataFile& initData = DataFile( DataFile::JournalData ) ) : joIDCheckPoint103 joID( initID ), 104 data( initData ) 105 { 106 } 107 jo_id_t joID; 108 DataFile data; 109 } ; 110 typedef QStack<CheckPoint> CheckPointStack; 111 112 JoIdMap m_joIDs; 113 114 CheckPointStack m_undoCheckPoints; 115 CheckPointStack m_redoCheckPoints; 116 117 bool m_journalling; 118 119 } ; 120 121 122 #endif 123 124