JournallingObject, ProjectJournal: global checkpoint management
There's no need for having each JournallingObject maintain it's own checkpoints and build a complex (and buggy) logic in ProjectJournal in order to manage all the JournallingObject with their checkpoints. Instead do it the simple way: in ProjectJournal maintain a stack for undo checkpoints and a stack for redo checkpoints. On each undo or redo operation simply push and pop to/from the according stacks and save and load states of the concerned JournallingObject. This basically strips most functionality from JournallingObject. All what's left is the management of its ID which unluckily is still required in order to properly implement undo/redo of additions and removals of JournallingObject.
This commit is contained in:
@@ -27,7 +27,6 @@
|
||||
|
||||
#include "lmms_basics.h"
|
||||
#include "export.h"
|
||||
#include "mmp.h"
|
||||
#include "SerializingObject.h"
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
@@ -35,39 +34,6 @@
|
||||
#include <QtCore/QStack>
|
||||
|
||||
|
||||
class JournalCheckPoint
|
||||
{
|
||||
public:
|
||||
JournalCheckPoint( const multimediaProject &data =
|
||||
multimediaProject( multimediaProject::JournalData ) ) :
|
||||
m_data( data )
|
||||
{
|
||||
}
|
||||
|
||||
~JournalCheckPoint()
|
||||
{
|
||||
}
|
||||
|
||||
const multimediaProject &data() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
multimediaProject &data()
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
multimediaProject m_data;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
typedef QVector<JournalCheckPoint> JournalCheckPointVector;
|
||||
|
||||
|
||||
class EXPORT JournallingObject : public SerializingObject
|
||||
{
|
||||
public:
|
||||
@@ -79,27 +45,10 @@ public:
|
||||
return m_id;
|
||||
}
|
||||
|
||||
void undo();
|
||||
void redo();
|
||||
|
||||
void clear()
|
||||
{
|
||||
m_journalCheckPoints.clear();
|
||||
m_currentJournalCheckPoint = m_journalCheckPoints.end();
|
||||
}
|
||||
|
||||
void clearRedoSteps()
|
||||
{
|
||||
m_journalCheckPoints.erase( m_currentJournalCheckPoint,
|
||||
m_journalCheckPoints.end() );
|
||||
m_currentJournalCheckPoint = m_journalCheckPoints.end();
|
||||
|
||||
}
|
||||
|
||||
void saveJournallingState( const bool _new_state )
|
||||
void saveJournallingState( const bool newState )
|
||||
{
|
||||
m_journallingStateStack.push( m_journalling );
|
||||
m_journalling = _new_state;
|
||||
m_journalling = newState;
|
||||
}
|
||||
|
||||
void restoreJournallingState()
|
||||
@@ -110,11 +59,10 @@ public:
|
||||
void addJournalCheckPoint();
|
||||
|
||||
virtual QDomElement saveState( QDomDocument & _doc,
|
||||
QDomElement & _parent );
|
||||
QDomElement & _parent );
|
||||
|
||||
virtual void restoreState( const QDomElement & _this );
|
||||
|
||||
|
||||
inline bool isJournalling() const
|
||||
{
|
||||
return m_journalling;
|
||||
@@ -125,10 +73,10 @@ public:
|
||||
m_journalling = _sr;
|
||||
}
|
||||
|
||||
inline bool testAndSetJournalling( const bool _sr )
|
||||
inline bool testAndSetJournalling( const bool newState )
|
||||
{
|
||||
const bool oldJournalling = m_journalling;
|
||||
m_journalling = _sr;
|
||||
m_journalling = newState;
|
||||
return oldJournalling;
|
||||
}
|
||||
|
||||
@@ -138,15 +86,8 @@ protected:
|
||||
|
||||
|
||||
private:
|
||||
void saveJournal( QDomDocument & _doc, QDomElement & _parent );
|
||||
void loadJournal( const QDomElement & _this );
|
||||
|
||||
|
||||
jo_id_t m_id;
|
||||
|
||||
JournalCheckPointVector m_journalCheckPoints;
|
||||
JournalCheckPointVector::Iterator m_currentJournalCheckPoint;
|
||||
|
||||
bool m_journalling;
|
||||
|
||||
QStack<bool> m_journallingStateStack;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* ProjectJournal.h - declaration of class ProjectJournal
|
||||
*
|
||||
* Copyright (c) 2006-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
* Copyright (c) 2006-2010 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
@@ -26,10 +26,10 @@
|
||||
#define _PROJECT_JOURNAL_H
|
||||
|
||||
#include <QtCore/QHash>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QVector>
|
||||
#include <QtCore/QStack>
|
||||
|
||||
#include "lmms_basics.h"
|
||||
#include "mmp.h"
|
||||
|
||||
class JournallingObject;
|
||||
|
||||
@@ -43,8 +43,7 @@ public:
|
||||
void undo();
|
||||
void redo();
|
||||
|
||||
// tell history that a new journal entry was added to object with ID _id
|
||||
void journalEntryAdded( const jo_id_t _id );
|
||||
void addJournalCheckPoint( JournallingObject *jo );
|
||||
|
||||
bool isJournalling() const
|
||||
{
|
||||
@@ -72,10 +71,6 @@ public:
|
||||
reallocID( _id, NULL );
|
||||
}
|
||||
|
||||
// completely remove everything linked with ID _id - all global
|
||||
// journalling information about the ID get's lost
|
||||
void forgetAboutID( const jo_id_t _id );
|
||||
|
||||
void clearJournal();
|
||||
|
||||
JournallingObject * journallingObject( const jo_id_t _id )
|
||||
@@ -90,12 +85,25 @@ public:
|
||||
|
||||
private:
|
||||
typedef QHash<jo_id_t, JournallingObject *> JoIdMap;
|
||||
typedef QVector<jo_id_t> JournalEntryVector;
|
||||
|
||||
struct CheckPoint
|
||||
{
|
||||
CheckPoint( jo_id_t initID = 0,
|
||||
const multimediaProject &initData =
|
||||
multimediaProject( multimediaProject::JournalData ) ) :
|
||||
joID( initID ),
|
||||
data( initData )
|
||||
{
|
||||
}
|
||||
jo_id_t joID;
|
||||
multimediaProject data;
|
||||
} ;
|
||||
typedef QStack<CheckPoint> CheckPointStack;
|
||||
|
||||
JoIdMap m_joIDs;
|
||||
|
||||
JournalEntryVector m_journalEntries;
|
||||
JournalEntryVector::Iterator m_currentJournalEntry;
|
||||
CheckPointStack m_undoCheckPoints;
|
||||
CheckPointStack m_redoCheckPoints;
|
||||
|
||||
bool m_journalling;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user