Skip to content
Snippets Groups Projects
Commit 06dece18 authored by luyikei's avatar luyikei Committed by Hugo Beauzée-Luyssen
Browse files

EffectEngine: Have toVariant and loadFromVariant


Signed-off-by: default avatarHugo Beauzée-Luyssen <hugo@beauzee.fr>
parent 9355b3bf
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <QDomElement>
#include <QVariant>
#include <QReadWriteLock>
#include "EffectsEngine/EffectUser.h"
......@@ -173,54 +173,43 @@ EffectUser::getMixer( qint64 currentFrame )
return nullptr;
}
QVariant
EffectUser::toVariant() const
{
QVariantList l;
for ( const auto& filter : m_filters )
{
l << QVariantHash{
{ "name", filter->effectInstance()->effect()->name() },
{ "start", filter->begin() },
{ "end", filter->end() }
};
}
return QVariant( l );
}
void
EffectUser::loadEffects( const QDomElement &parent )
EffectUser::loadFromVariant( const QVariant& variant )
{
QDomElement effects = parent.firstChildElement( "effects" );
if ( effects.isNull() == true )
return ;
QDomElement effect = effects.firstChildElement( "effect" );
while ( effect.isNull() == false )
for ( const auto& var : variant.toList() )
{
if ( effect.hasAttribute( "name" ) == true &&
effect.hasAttribute( "start" ) == true &&
effect.hasAttribute( "end" ) == true )
QVariantMap m = var.toMap();
const QString& name = m["name"].toString();
qint64 start = m["start"].toLongLong();
qint64 end = m["end"].toLongLong();
if ( name.isEmpty() == false )
{
Effect *e = Core::instance()->effectsEngine()->effect( effect.attribute( "name" ) );
Effect *e = Core::instance()->effectsEngine()->effect( name );
if ( e != nullptr )
{
EffectHelper *helper = addEffect( e, effect.attribute( "start" ).toLongLong(),
effect.attribute( "end" ).toLongLong() );
EffectHelper *helper = addEffect( e, start, end );
if ( helper == nullptr )
vlmcCritical() << "Can't load effect" << effect.attribute( "name" );
vlmcCritical() << "Can't load effect" << name;
}
else
vlmcCritical() << "Can't load effect" << effect.attribute( "name" );
vlmcCritical() << "Can't load effect" << name;
}
effect = effect.nextSiblingElement();
}
}
void
EffectUser::saveFilters( QXmlStreamWriter &project ) const
{
QReadLocker lock( m_effectsLock );
if ( m_filters.size() <= 0 )
return ;
project.writeStartElement( "effects" );
EffectsEngine::EffectList::const_iterator it = m_filters.begin();
EffectsEngine::EffectList::const_iterator ite = m_filters.end();
while ( it != ite )
{
project.writeStartElement( "effect" );
project.writeAttribute( "name", (*it)->effectInstance()->effect()->name() );
project.writeAttribute( "start", QString::number( (*it)->begin() ) );
project.writeAttribute( "end", QString::number( (*it)->end() ) );
project.writeEndElement();
++it;
}
project.writeEndElement();
}
const EffectsEngine::EffectList&
......
......@@ -24,7 +24,6 @@
#define EFFECTUSER_H
#include <QObject>
#include <QXmlStreamWriter>
#include "EffectsEngine/EffectsEngine.h"
......@@ -58,8 +57,8 @@ class EffectUser : public QObject
void cleanEffects();
virtual qint64 length() const = 0;
virtual Type effectType() const = 0;
void loadEffects( const QDomElement &project );
void saveFilters( QXmlStreamWriter &project ) const;
virtual QVariant toVariant() const;
void loadFromVariant( const QVariant &var );
bool contains( Effect::Type, const QUuid &uuid ) const;
protected:
......
......@@ -294,7 +294,6 @@ ClipWorkflow::save( QXmlStreamWriter &project ) const
project.writeAttribute( "begin", QString::number( m_clipHelper->begin() ) );
project.writeAttribute( "end", QString::number( m_clipHelper->end() ) );
project.writeAttribute( "helper", m_clipHelper->uuid().toString() );
saveFilters( project );
}
qint64
......
......@@ -165,7 +165,6 @@ TrackHandler::save( QXmlStreamWriter& project ) const
project.writeAttribute( "type", QString::number( (int)m_trackType ) );
project.writeAttribute( "id", QString::number( i ) );
m_tracks[i]->save( project );
m_tracks[i]->saveFilters( project );
project.writeEndElement();
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment