lmms
Cross-platform music production software
Loading...
Searching...
No Matches
ProjectJournal.h
Go to the documentation of this file.
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 LMMS_PROJECT_JOURNAL_H
26#define LMMS_PROJECT_JOURNAL_H
27
28#include <QHash>
29#include <QStack>
30#include <set>
31
32#include "LmmsTypes.h"
33#include "DataFile.h"
34
35
36namespace lmms
37{
38
39
41
42
45{
46public:
47 static const int MAX_UNDO_STATES;
48
50 virtual ~ProjectJournal() = default;
51
52 void undo();
53 void redo();
54
55 bool canUndo() const;
56 bool canRedo() const;
57
59
60 bool isJournalling() const
61 {
62 return m_journalling;
63 }
64
65 void setJournalling( const bool _on )
66 {
67 m_journalling = _on;
68 }
69
70 // alloc new ID and register object _obj to it
72
73 //Create a new id without registering any object
75
76 // if there's already something known about ID _id, but it is currently
77 // unused (e.g. after jouralling object was deleted), register object
78 // _obj to this id
79 void reallocID( const jo_id_t _id, JournallingObject * _obj );
80
81 // make ID _id unused, but keep all global journalling information
82 // (order of journalling entries etc.) referring to _id - needed for
83 // restoring a journalling object later
84 void freeID( const jo_id_t _id )
85 {
86 reallocID( _id, nullptr );
87 }
88
90 static jo_id_t idToSave( jo_id_t id );
92 static jo_id_t idFromSave( jo_id_t id );
93
94 void clearJournal();
95 void stopAllJournalling();
97 {
98 if( m_joIDs.contains( _id ) )
99 {
100 return m_joIDs[_id];
101 }
102 return nullptr;
103 }
104
105
106private:
107 using JoIdMap = QHash<jo_id_t, JournallingObject*>;
108
110 {
111 CheckPoint( jo_id_t initID = 0, const DataFile& initData = DataFile( DataFile::Type::JournalData ) ) :
112 joID( initID ),
113 data( initData )
114 {
115 }
118 } ;
119 using CheckPointStack = QStack<CheckPoint>;
120
122 std::set<jo_id_t> m_unregisteredIds;
123
126
128
129} ;
130
131
132} // namespace lmms
133
134#endif // LMMS_PROJECT_JOURNAL_H
Definition DataFile.h:44
DataFile(const QString &fileName)
Definition DataFile.cpp:156
@ JournalData
Definition DataFile.h:57
Definition JournallingObject.h:37
std::set< jo_id_t > m_unregisteredIds
Definition ProjectJournal.h:122
void freeID(const jo_id_t _id)
Definition ProjectJournal.h:84
jo_id_t generateId()
Definition ProjectJournal.cpp:147
QHash< jo_id_t, JournallingObject * > JoIdMap
Definition ProjectJournal.h:107
JournallingObject * journallingObject(const jo_id_t _id)
Definition ProjectJournal.h:96
void addJournalCheckPoint(JournallingObject *jo)
Definition ProjectJournal.cpp:121
QStack< CheckPoint > CheckPointStack
Definition ProjectJournal.h:119
void undo()
Definition ProjectJournal.cpp:55
void stopAllJournalling()
Definition ProjectJournal.cpp:201
static jo_id_t idFromSave(jo_id_t id)
hack, not used when loading a savefile
Definition ProjectJournal.cpp:175
void reallocID(const jo_id_t _id, JournallingObject *_obj)
Definition ProjectJournal.cpp:157
CheckPointStack m_redoCheckPoints
Definition ProjectJournal.h:125
void setJournalling(const bool _on)
Definition ProjectJournal.h:65
bool isJournalling() const
Definition ProjectJournal.h:60
JoIdMap m_joIDs
Definition ProjectJournal.h:121
void redo()
Definition ProjectJournal.cpp:86
static jo_id_t idToSave(jo_id_t id)
hack, not used when saving a file
Definition ProjectJournal.cpp:170
bool canUndo() const
Definition ProjectJournal.cpp:109
ProjectJournal()
Definition ProjectJournal.cpp:44
virtual ~ProjectJournal()=default
void clearJournal()
Definition ProjectJournal.cpp:183
CheckPointStack m_undoCheckPoints
Definition ProjectJournal.h:124
bool canRedo() const
Definition ProjectJournal.cpp:114
bool m_journalling
Definition ProjectJournal.h:127
jo_id_t allocID(JournallingObject *_obj)
Definition ProjectJournal.cpp:139
static const int MAX_UNDO_STATES
Definition ProjectJournal.h:47
Definition RemotePluginBase.cpp:34
std::uint32_t jo_id_t
Definition LmmsTypes.h:50
DataFile data
Definition ProjectJournal.h:117
jo_id_t joID
Definition ProjectJournal.h:116
CheckPoint(jo_id_t initID=0, const DataFile &initData=DataFile(DataFile::Type::JournalData))
Definition ProjectJournal.h:111