[vlmc-devel] [PATCH 2/3] Fix QTimer running with its interval of 0

Yikai Lu luyikei.qmltu at gmail.com
Mon Mar 7 16:37:37 CET 2016


By letting SettingValue "setLimits" and making it Clamped, we avoid it being 0.

Also, have QTimer run with the interval saved as SettingValue, not just start()

Make SettingsValue emit change(val) when it is initially loaded.
---
 src/Project/Project.cpp       | 5 ++---
 src/Settings/SettingValue.cpp | 5 +++++
 src/Settings/SettingValue.h   | 1 +
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/Project/Project.cpp b/src/Project/Project.cpp
index 3800e51..6c36d83 100644
--- a/src/Project/Project.cpp
+++ b/src/Project/Project.cpp
@@ -60,7 +60,8 @@ Project::Project( Settings* settings )
     SettingValue    *automaticBackupInterval = settings->createVar( SettingValue::Int, "vlmc/AutomaticBackupInterval", 5,
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Automatic save interval" ),
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "This is the interval that VLMC will wait "
-                                                       "between two automatic save" ), SettingValue::Nothing );
+                                                       "between two automatic save" ), SettingValue::Clamped );
+    automaticBackupInterval->setLimits(1, QVariant(QVariant::Invalid));
 
     connect( m_timer, SIGNAL( timeout() ), this, SLOT(autoSaveRequired() ) );
     connect( this, SIGNAL( destroyed() ), m_timer, SLOT( stop() ) );
@@ -69,8 +70,6 @@ Project::Project( Settings* settings )
              this, SLOT( autoSaveEnabledChanged( QVariant ) ) );
     connect( automaticBackupInterval, SIGNAL( changed( QVariant ) ), this,
              SLOT( autoSaveIntervalChanged( QVariant ) ) );
-
-    m_timer->start();
 }
 
 Project::~Project()
diff --git a/src/Settings/SettingValue.cpp b/src/Settings/SettingValue.cpp
index 7f35926..22655a3 100644
--- a/src/Settings/SettingValue.cpp
+++ b/src/Settings/SettingValue.cpp
@@ -52,6 +52,11 @@ SettingValue::set( const QVariant& _val )
         m_val = val;
         emit changed( m_val );
     }
+    else if ( m_initLoad )
+    {
+        emit changed( m_val );
+        m_initLoad = false;
+    }
 }
 
 const QVariant&
diff --git a/src/Settings/SettingValue.h b/src/Settings/SettingValue.h
index 60f1bea..309c369 100644
--- a/src/Settings/SettingValue.h
+++ b/src/Settings/SettingValue.h
@@ -130,6 +130,7 @@ class   SettingValue : public QObject
         Flags           m_flags;
         QVariant        m_min;
         QVariant        m_max;
+        bool            m_initLoad  = true;
     signals:
         /**
          * \brief This signal is emmited while the m_val
-- 
1.9.1



More information about the Vlmc-devel mailing list