ProjectJournal.h 2.9 KB

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