[vlmc-devel] EffectEngine: Have toVariant and loadFromVariant

Yikai Lu git at videolan.org
Sat Apr 9 22:18:12 CEST 2016


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Sat Apr  9 11:44:10 2016 +0900| [06dece184eef989c7877c7dc3d0031e81568ccbf] | committer: Hugo Beauzée-Luyssen

EffectEngine: Have toVariant and loadFromVariant

Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>

> https://code.videolan.org/videolan/vlmc/commit/06dece184eef989c7877c7dc3d0031e81568ccbf
---

 src/EffectsEngine/EffectUser.cpp | 65 +++++++++++++++++-----------------------
 src/EffectsEngine/EffectUser.h   |  5 ++--
 src/Workflow/ClipWorkflow.cpp    |  1 -
 src/Workflow/TrackHandler.cpp    |  1 -
 4 files changed, 29 insertions(+), 43 deletions(-)

diff --git a/src/EffectsEngine/EffectUser.cpp b/src/EffectsEngine/EffectUser.cpp
index fe368c7..e9ebb75 100644
--- a/src/EffectsEngine/EffectUser.cpp
+++ b/src/EffectsEngine/EffectUser.cpp
@@ -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&
diff --git a/src/EffectsEngine/EffectUser.h b/src/EffectsEngine/EffectUser.h
index 432cd83..7bdb95a 100644
--- a/src/EffectsEngine/EffectUser.h
+++ b/src/EffectsEngine/EffectUser.h
@@ -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:
diff --git a/src/Workflow/ClipWorkflow.cpp b/src/Workflow/ClipWorkflow.cpp
index 305069b..b06f441 100644
--- a/src/Workflow/ClipWorkflow.cpp
+++ b/src/Workflow/ClipWorkflow.cpp
@@ -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
diff --git a/src/Workflow/TrackHandler.cpp b/src/Workflow/TrackHandler.cpp
index ab1eb64..bb3b027 100644
--- a/src/Workflow/TrackHandler.cpp
+++ b/src/Workflow/TrackHandler.cpp
@@ -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();
         }
     }



More information about the Vlmc-devel mailing list