[vlmc-devel] Implement postLoad/preSave

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


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

Implement postLoad/preSave

I find out that if I use connect(Qt::DirectConnection), which its slot is executed in the emitter's thread, I can handle postLoad and preSave functions in each classes gracefully. It is because we can ensure ordering of loading and saving!

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

> https://code.videolan.org/videolan/vlmc/commit/b78df552a0e6d54cc4ec67dc18cd89589784f809
---

 src/Settings/Settings.cpp | 2 ++
 src/Settings/Settings.h   | 6 +++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/Settings/Settings.cpp b/src/Settings/Settings.cpp
index 7717bee..cbe5bd7 100644
--- a/src/Settings/Settings.cpp
+++ b/src/Settings/Settings.cpp
@@ -162,11 +162,13 @@ Settings::loadJsonFrom( const QJsonObject &object )
         if ( setValue( it.key(), (*it).toVariant() ) == false )
             vlmcWarning() << "Loaded invalid project setting:" << it.key();
     }
+    emit postLoad();
 }
 
 void
 Settings::saveJsonTo( QJsonObject &object )
 {
+    emit preSave();
     for ( const auto& val : m_settings )
     {
         if ( ( val->flags() & SettingValue::Runtime ) != 0 )
diff --git a/src/Settings/Settings.h b/src/Settings/Settings.h
index ff4461f..f3af1a2 100644
--- a/src/Settings/Settings.h
+++ b/src/Settings/Settings.h
@@ -102,8 +102,9 @@ class QJsonDocument;
         VLMC_CREATE_PROJECT_VAR( SettingValue::String, key, defaultValue, "", "", SettingValue::Private )
 
 
-class   Settings
+class   Settings: public QObject
 {
+    Q_OBJECT
     public:
         typedef QList<SettingValue*>                SettingList;
         typedef QMap<QString, SettingValue*>        SettingMap;
@@ -132,6 +133,9 @@ class   Settings
         QJsonDocument               readSettingsFromFile();
         void                        loadJsonFrom( const QJsonObject& object );
         void                        saveJsonTo( QJsonObject& object );
+    signals:
+        void                        postLoad();
+        void                        preSave();
 };
 
 #endif



More information about the Vlmc-devel mailing list