LMMS
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
31#include "LmmsTypes.h"
32#include "DataFile.h"
33
34
35namespace lmms
36{
37
38
40
41
44{
45public:
46 static const int MAX_UNDO_STATES;
47
49 virtual ~ProjectJournal() = default;
50
51 void undo();
52 void redo();
53
54 bool canUndo() const;
55 bool canRedo() const;
56
58
59 bool isJournalling() const
60 {
61 return m_journalling;
62 }
63
64 void setJournalling( const bool _on )
65 {
66 m_journalling = _on;
67 }
68
69 // alloc new ID and register object _obj to it
71
72 // if there's already something known about ID _id, but it is currently
73 // unused (e.g. after jouralling object was deleted), register object
74 // _obj to this id
75 void reallocID( const jo_id_t _id, JournallingObject * _obj );
76
77 // make ID _id unused, but keep all global journalling information
78 // (order of journalling entries etc.) referring to _id - needed for
79 // restoring a journalling object later
80 void freeID( const jo_id_t _id )
81 {
82 reallocID( _id, nullptr );
83 }
84
86 static jo_id_t idToSave( jo_id_t id );
88 static jo_id_t idFromSave( jo_id_t id );
89
90 void clearJournal();
91 void stopAllJournalling();
93 {
94 if( m_joIDs.contains( _id ) )
95 {
96 return m_joIDs[_id];
97 }
98 return nullptr;
99 }
100
101
102private:
103 using JoIdMap = QHash<jo_id_t, JournallingObject*>;
104
106 {
107 CheckPoint( jo_id_t initID = 0, const DataFile& initData = DataFile( DataFile::Type::JournalData ) ) :
108 joID( initID ),
109 data( initData )
110 {
111 }
114 } ;
115 using CheckPointStack = QStack<CheckPoint>;
116
118
121
123
124} ;
125
126
127} // namespace lmms
128
129#endif // LMMS_PROJECT_JOURNAL_H
Definition DataFile.h:44
@ JournalData
Definition DataFile.h:57
Definition JournallingObject.h:37
void freeID(const jo_id_t _id)
Definition ProjectJournal.h:80
QHash< jo_id_t, JournallingObject * > JoIdMap
Definition ProjectJournal.h:103
JournallingObject * journallingObject(const jo_id_t _id)
Definition ProjectJournal.h:92
void addJournalCheckPoint(JournallingObject *jo)
Definition ProjectJournal.cpp:121
QStack< CheckPoint > CheckPointStack
Definition ProjectJournal.h:115
void undo()
Definition ProjectJournal.cpp:55
void stopAllJournalling()
Definition ProjectJournal.cpp:191
static jo_id_t idFromSave(jo_id_t id)
hack, not used when loading a savefile
Definition ProjectJournal.cpp:165
void reallocID(const jo_id_t _id, JournallingObject *_obj)
Definition ProjectJournal.cpp:148
CheckPointStack m_redoCheckPoints
Definition ProjectJournal.h:120
void setJournalling(const bool _on)
Definition ProjectJournal.h:64
bool isJournalling() const
Definition ProjectJournal.h:59
JoIdMap m_joIDs
Definition ProjectJournal.h:117
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:160
bool canUndo() const
Definition ProjectJournal.cpp:109
ProjectJournal()
Definition ProjectJournal.cpp:44
virtual ~ProjectJournal()=default
void clearJournal()
Definition ProjectJournal.cpp:173
CheckPointStack m_undoCheckPoints
Definition ProjectJournal.h:119
bool canRedo() const
Definition ProjectJournal.cpp:114
bool m_journalling
Definition ProjectJournal.h:122
jo_id_t allocID(JournallingObject *_obj)
Definition ProjectJournal.cpp:139
static const int MAX_UNDO_STATES
Definition ProjectJournal.h:46
Definition AudioAlsa.cpp:35
std::uint32_t jo_id_t
Definition LmmsTypes.h:50
DataFile data
Definition ProjectJournal.h:113
jo_id_t joID
Definition ProjectJournal.h:112
CheckPoint(jo_id_t initID=0, const DataFile &initData=DataFile(DataFile::Type::JournalData))
Definition ProjectJournal.h:107