ProjectJournal.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #ifndef PROJECT_JOURNAL_H
  25. #define PROJECT_JOURNAL_H
  26. #include <QtCore/QHash>
  27. #include <QtCore/QStack>
  28. #include "lmms_basics.h"
  29. #include "DataFile.h"
  30. class JournallingObject;
  31. class ProjectJournal
  32. {
  33. public:
  34. static const int MAX_UNDO_STATES;
  35. ProjectJournal();
  36. virtual ~ProjectJournal();
  37. void undo();
  38. void redo();
  39. bool canUndo() const;
  40. bool canRedo() const;
  41. void addJournalCheckPoint( JournallingObject *jo );
  42. bool isJournalling() const
  43. {
  44. return m_journalling;
  45. }
  46. void setJournalling( const bool _on )
  47. {
  48. m_journalling = _on;
  49. }
  50. // alloc new ID and register object _obj to it
  51. jo_id_t allocID( JournallingObject * _obj );
  52. // if there's already something known about ID _id, but it is currently
  53. // unused (e.g. after jouralling object was deleted), register object
  54. // _obj to this id
  55. void reallocID( const jo_id_t _id, JournallingObject * _obj );
  56. // make ID _id unused, but keep all global journalling information
  57. // (order of journalling entries etc.) referring to _id - needed for
  58. // restoring a journalling object later
  59. void freeID( const jo_id_t _id )
  60. {
  61. reallocID( _id, NULL );
  62. }
  63. static jo_id_t idToSave( jo_id_t id );
  64. void clearJournal();
  65. void stopAllJournalling();
  66. JournallingObject * journallingObject( const jo_id_t _id )
  67. {
  68. if( m_joIDs.contains( _id ) )
  69. {
  70. return m_joIDs[_id];
  71. }
  72. return NULL;
  73. }
  74. private:
  75. typedef QHash<jo_id_t, JournallingObject *> JoIdMap;
  76. struct CheckPoint
  77. {
  78. CheckPoint( jo_id_t initID = 0, const DataFile& initData = DataFile( DataFile::JournalData ) ) :
  79. joID( initID ),
  80. data( initData )
  81. {
  82. }
  83. jo_id_t joID;
  84. DataFile data;
  85. } ;
  86. typedef QStack<CheckPoint> CheckPointStack;
  87. JoIdMap m_joIDs;
  88. CheckPointStack m_undoCheckPoints;
  89. CheckPointStack m_redoCheckPoints;
  90. bool m_journalling;
  91. } ;
  92. #endif