Commit 90241ff2 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Refactored StackedAction into a Action namespace, and multiple class

This is way more logical than an Action suffit for class names
parent a2687506
......@@ -28,13 +28,13 @@ Stack::~Stack()
{
while ( empty() == false )
{
StackedAction* act = top();
Action::Generic* act = top();
delete act;
pop();
}
}
void Stack::addAction( StackedAction* act )
void Stack::addAction( Action::Generic* act )
{
iterator it = begin();
iterator ite = end();
......
......@@ -29,11 +29,11 @@
namespace Action
{
class Stack : public QStack<StackedAction*>
class Stack : public QStack<Action::Generic*>
{
public:
~Stack();
void addAction( StackedAction* act );
void addAction( Action::Generic* act );
};
}
......
......@@ -27,132 +27,134 @@
#include "MainWorkflow.h"
class StackedAction
namespace Action
{
public:
enum Type
{
Pause,
Unpause,
Resize,
Remove,
Add,
};
StackedAction( Type type ) : m_type( type ) {}
virtual ~StackedAction(){}
virtual void execute() = 0;
virtual bool isOpposite( const StackedAction* ) const
{
return false;
}
Type getType() const
{
return m_type;
}
private:
Type m_type;
};
class Generic
{
public:
enum Type
{
Pause,
Unpause,
Resize,
Remove,
Add,
};
Generic( Type type ) : m_type( type ) {}
virtual ~Generic(){}
virtual void execute() = 0;
virtual bool isOpposite( const Generic* ) const
{
return false;
}
Type getType() const
{
return m_type;
}
private:
Type m_type;
};
class WorkflowAction : public StackedAction
{
public:
WorkflowAction( MainWorkflow* mainWorkflow, Type type ) : StackedAction( type ), m_mainWorkflow( mainWorkflow ) {}
protected:
MainWorkflow* m_mainWorkflow;
};
class TrackAction : public WorkflowAction
{
public:
TrackAction( MainWorkflow* mainWorkflow, uint32_t trackId, MainWorkflow::TrackType trackType, Type type ) :
WorkflowAction( mainWorkflow, type ), m_trackId( trackId ), m_trackType( trackType )
{
}
protected:
uint32_t m_trackId;
MainWorkflow::TrackType m_trackType;
};
class Workflow : public Generic
{
public:
Workflow( MainWorkflow* mainWorkflow, Type type ) : Generic( type ), m_mainWorkflow( mainWorkflow ) {}
protected:
MainWorkflow* m_mainWorkflow;
};
class AddClipAction : public TrackAction
{
public:
AddClipAction( MainWorkflow* mainWorkflow, uint32_t trackId, MainWorkflow::TrackType trackType,
Clip* clip, qint64 startingPos ) : TrackAction( mainWorkflow, trackId, trackType, Add ),
m_clip( clip ), m_startingPos( startingPos )
{
}
void execute()
{
m_mainWorkflow->addClip( m_clip, m_trackId, m_startingPos, m_trackType );
}
protected:
Clip* m_clip;
qint64 m_startingPos;
};
class Track : public Workflow
{
public:
Track( MainWorkflow* mainWorkflow, uint32_t trackId, MainWorkflow::TrackType trackType, Type type ) :
Workflow( mainWorkflow, type ), m_trackId( trackId ), m_trackType( trackType )
{
}
protected:
uint32_t m_trackId;
MainWorkflow::TrackType m_trackType;
};
class RemoveClipAction : public TrackAction
{
public:
RemoveClipAction( MainWorkflow* mainWorkflow, uint32_t trackId, MainWorkflow::TrackType trackType,
const QUuid& uuid ) : TrackAction( mainWorkflow, trackId, trackType, Remove ),
m_uuid( uuid )
{
}
void execute()
{
m_mainWorkflow->removeClip( m_uuid, m_trackId, m_trackType );
}
protected:
QUuid m_uuid;
};
class AddClip : public Track
{
public:
AddClip( MainWorkflow* mainWorkflow, uint32_t trackId, MainWorkflow::TrackType trackType,
Clip* clip, qint64 startingPos ) : Track( mainWorkflow, trackId, trackType, Add ),
m_clip( clip ), m_startingPos( startingPos )
{
}
void execute()
{
m_mainWorkflow->addClip( m_clip, m_trackId, m_startingPos, m_trackType );
}
protected:
Clip* m_clip;
qint64 m_startingPos;
};
class ResizeClipAction : public StackedAction
{
public:
ResizeClipAction( Clip* clip, qint64 newBegin, qint64 newEnd ) : StackedAction( Resize ),
m_clip( clip ), m_newBegin( newBegin ), m_newEnd( newEnd )
{
}
void execute()
{
m_clip->setBoundaries( m_newBegin, m_newEnd );
}
protected:
Clip* m_clip;
qint64 m_newBegin;
qint64 m_newEnd;
};
class RemoveClip : public Track
{
public:
RemoveClip( MainWorkflow* mainWorkflow, uint32_t trackId, MainWorkflow::TrackType trackType,
const QUuid& uuid ) : Track( mainWorkflow, trackId, trackType, Remove ),
m_uuid( uuid )
{
}
void execute()
{
m_mainWorkflow->removeClip( m_uuid, m_trackId, m_trackType );
}
protected:
QUuid m_uuid;
};
class PauseAction : public WorkflowAction
{
public:
PauseAction( MainWorkflow* mainWorkflow ) : WorkflowAction( mainWorkflow, Pause )
{
}
void execute()
{
m_mainWorkflow->pause();
}
bool isOpposite( const StackedAction* act ) const
{
return ( act->getType() == Unpause );
}
};
class ResizeClip : public Generic
{
public:
ResizeClip( Clip* clip, qint64 newBegin, qint64 newEnd ) : Generic( Resize ),
m_clip( clip ), m_newBegin( newBegin ), m_newEnd( newEnd )
{
}
void execute()
{
m_clip->setBoundaries( m_newBegin, m_newEnd );
}
protected:
Clip* m_clip;
qint64 m_newBegin;
qint64 m_newEnd;
};
class UnpauseAction : public WorkflowAction
{
public:
UnpauseAction( MainWorkflow* mainWorkflow ) : WorkflowAction( mainWorkflow, Unpause )
{
}
void execute()
{
m_mainWorkflow->unpause();
}
bool isOpposite( const StackedAction* act ) const
{
return ( act->getType() == Pause );
}
};
class Pause : public Workflow
{
public:
Pause( MainWorkflow* mainWorkflow ) : Workflow( mainWorkflow, Generic::Pause )
{
}
void execute()
{
m_mainWorkflow->pause();
}
bool isOpposite( const Generic* act ) const
{
return ( act->getType() == Unpause );
}
};
class Unpause : public Workflow
{
public:
Unpause( MainWorkflow* mainWorkflow ) : Workflow( mainWorkflow, Generic::Unpause )
{
}
void execute()
{
m_mainWorkflow->unpause();
}
bool isOpposite( const Generic* act ) const
{
return ( act->getType() == Generic::Pause );
}
};
}
#endif // STACKEDACTION_H
......@@ -118,7 +118,7 @@ void WorkflowRenderer::checkActions()
return ;
while ( m_actions.empty() == false )
{
StackedAction* act = m_actions.top();
Action::Generic* act = m_actions.top();
m_actions.pop();
act->execute();
delete act;
......@@ -185,7 +185,7 @@ void WorkflowRenderer::internalPlayPause( bool forcePause )
{
if ( m_paused == true && forcePause == false )
{
StackedAction* act = new UnpauseAction( m_mainWorkflow );
Action::Generic* act = new Action::Unpause( m_mainWorkflow );
QMutexLocker lock( m_actionsMutex );
m_actions.addAction( act );
}
......@@ -193,7 +193,7 @@ void WorkflowRenderer::internalPlayPause( bool forcePause )
{
if ( m_paused == false )
{
StackedAction* act = new PauseAction( m_mainWorkflow );
Action::Generic* act = new Action::Unpause( m_mainWorkflow );
QMutexLocker lock( m_actionsMutex );
m_actions.addAction( act );
}
......@@ -230,8 +230,8 @@ void WorkflowRenderer::removeClip( const QUuid& uuid, uint32_t trackId, M
{
if ( m_isRendering == true )
{
StackedAction* act = new RemoveClipAction( m_mainWorkflow, trackId, trackType, uuid );
QMutexLocker lock( m_actionsMutex );
Action::Generic* act = new Action::RemoveClip( m_mainWorkflow, trackId, trackType, uuid );
QMutexLocker lock( m_actionsMutex );
m_actions.addAction( act );
}
else
......@@ -242,8 +242,8 @@ void WorkflowRenderer::addClip( Clip* clip, uint32_t trackId, qint64 star
{
if ( m_isRendering == true )
{
StackedAction* act = new AddClipAction( m_mainWorkflow, trackId, trackType, clip, startingPos );
QMutexLocker lock( m_actionsMutex );
Action::Generic* act = new Action::AddClip( m_mainWorkflow, trackId, trackType, clip, startingPos );
QMutexLocker lock( m_actionsMutex );
m_actions.addAction( act );
}
else
......@@ -274,9 +274,9 @@ Clip* WorkflowRenderer::split( Clip* toSplit, uint32_t trackId, qint64 new
//adding clip
//We can NOT call addClip, as it would lock the action lock and then release it,
//thus potentially breaking the synchrone way of doing this
StackedAction* act = new AddClipAction( m_mainWorkflow, trackId, trackType, newClip, newClipPos );
Action::Generic* act = new Action::AddClip( m_mainWorkflow, trackId, trackType, newClip, newClipPos );
//resizing it
StackedAction* act2 = new ResizeClipAction( toSplit, toSplit->getBegin(), newClipBegin );
Action::Generic* act2 = new Action::ResizeClip( toSplit, toSplit->getBegin(), newClipBegin );
//Push the actions onto the action stack
QMutexLocker lock( m_actionsMutex );
......@@ -296,11 +296,11 @@ void WorkflowRenderer::unsplit( Clip* origin, Clip* splitted, uint32_t trackI
if ( m_isRendering == true )
{
//removing clip
StackedAction* act = new RemoveClipAction( m_mainWorkflow, trackId, trackType, splitted->getUuid() );
Action::Generic* act = new Action::RemoveClip( m_mainWorkflow, trackId, trackType, splitted->getUuid() );
//resizing it
StackedAction* act2 = new ResizeClipAction( origin, splitted->getBegin(), oldEnd );
Action::Generic* act2 = new Action::ResizeClip( origin, splitted->getBegin(), oldEnd );
//Push the actions onto the action stack
QMutexLocker lock( m_actionsMutex );
QMutexLocker lock( m_actionsMutex );
m_actions.addAction( act );
m_actions.addAction( act2 );
}
......@@ -315,8 +315,8 @@ void WorkflowRenderer::resizeClip( Clip* clip, qint64 newBegin, qint64 newEnd
{
if ( m_isRendering == true )
{
StackedAction* act = new ResizeClipAction( clip, newBegin, newEnd );
QMutexLocker lock( m_actionsMutex );
Action::Generic* act = new Action::ResizeClip( clip, newBegin, newEnd );
QMutexLocker lock( m_actionsMutex );
m_actions.addAction( act );
}
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment