[vlmc-devel] [PATCH] Fix QTimer running with its interval 0
Yikai Lu
luyikei.qmltu at gmail.com
Sun Mar 6 18:21:39 CET 2016
By enabling setLimits on the settingvalue, and making it Clamped.
also, delete the setProject functions, which is unneeded.
Sorry, the automaticBackup-related settings should be shared
---
src/Main/Core.cpp | 15 ++----------
src/Main/Core.h | 2 --
src/Project/Project.cpp | 55 +++++++++++++++++++++++++++++++++++++++---
src/Project/Project.h | 7 +++++-
src/Project/RecentProjects.cpp | 11 ---------
src/Project/RecentProjects.h | 2 --
6 files changed, 59 insertions(+), 33 deletions(-)
diff --git a/src/Main/Core.cpp b/src/Main/Core.cpp
index d1fac98..6ccd471 100644
--- a/src/Main/Core.cpp
+++ b/src/Main/Core.cpp
@@ -36,7 +36,6 @@
#include <Backend/IBackend.h>
#include <EffectsEngine/EffectsEngine.h>
#include "Library/Library.h"
-#include "Project/AutomaticBackup.h"
#include "Project/RecentProjects.h"
#include "Project/Workspace.h"
#include "Renderer/WorkflowRenderer.h"
@@ -53,7 +52,6 @@ Core::Core()
createSettings();
m_recentProjects = new RecentProjects( m_settings );
- m_automaticBackup = new AutomaticBackup( m_settings );
m_workspace = new Workspace( m_settings );
m_workflow = new MainWorkflow;
m_workflowRenderer = new WorkflowRenderer( Backend::getBackend(), m_workflow );
@@ -64,10 +62,8 @@ Core::Core()
connect( m_undoStack, SIGNAL( cleanChanged( bool ) ), m_currentProject, SLOT( cleanChanged( bool ) ) );
connect( m_currentProject, SIGNAL( projectSaved() ), m_undoStack, SLOT( setClean() ) );
connect( m_library, SIGNAL( cleanStateChanged( bool ) ), m_currentProject, SLOT( libraryCleanChanged( bool ) ) );
-
- //FIXME: Pass the project through the constructor since it doesn't change anymore
- m_automaticBackup->setProject( m_currentProject );
- m_recentProjects->setProject( m_currentProject );
+ connect( m_currentProject, SIGNAL( projectLoaded( QString, QString ) ),
+ m_recentProjects, SLOT( projectLoaded( QString, QString ) ) );
}
Core::~Core()
@@ -79,7 +75,6 @@ Core::~Core()
delete m_workflow;
delete m_currentProject;
delete m_workspace;
- delete m_automaticBackup;
delete m_settings;
delete m_logger;
delete m_effectsEngine;
@@ -128,12 +123,6 @@ Core::recentProjects()
return m_recentProjects;
}
-AutomaticBackup*
-Core::automaticBackup()
-{
- return m_automaticBackup;
-}
-
bool
Core::loadProject(const QString& fileName)
{
diff --git a/src/Main/Core.h b/src/Main/Core.h
index b4e26e0..52463a6 100644
--- a/src/Main/Core.h
+++ b/src/Main/Core.h
@@ -54,7 +54,6 @@ class Core : public QObject
Settings* settings();
VlmcLogger* logger();
RecentProjects* recentProjects();
- AutomaticBackup* automaticBackup();
Workspace* workspace();
Project* project();
WorkflowRenderer* workflowRenderer();
@@ -80,7 +79,6 @@ class Core : public QObject
Settings* m_settings;
VlmcLogger* m_logger;
RecentProjects* m_recentProjects;
- AutomaticBackup* m_automaticBackup;
Workspace* m_workspace;
Project* m_currentProject;
MainWorkflow* m_workflow;
diff --git a/src/Project/Project.cpp b/src/Project/Project.cpp
index af3eeaf..c37a0ae 100644
--- a/src/Project/Project.cpp
+++ b/src/Project/Project.cpp
@@ -25,8 +25,9 @@
#include <QFile>
#include <QFileInfo>
#include <QDomDocument>
+#include <QTimer>
+
-#include "AutomaticBackup.h"
#include "Backend/IBackend.h"
#include "Project.h"
#include "RecentProjects.h"
@@ -42,19 +43,42 @@
const QString Project::unNamedProject = Project::tr( "Untitled Project" );
const QString Project::backupSuffix = "~";
-Project::Project()
+Project::Project( Settings* settings )
: m_projectFile( nullptr )
, m_isClean( true )
, m_libraryCleanState( true )
+ , m_timer( new QTimer( this ) )
+ , m_settings( new Settings( QString() ) )
{
- m_settings = new Settings( QString() );
initSettings();
+
+ SettingValue *automaticBackup = settings->createVar( SettingValue::Bool, "vlmc/AutomaticBackup", false,
+ QT_TRANSLATE_NOOP( "PreferenceWidget", "Automatic save" ),
+ QT_TRANSLATE_NOOP( "PreferenceWidget", "When this option is activated,"
+ "VLMC will automatically save your project "
+ "at a specified interval" ), SettingValue::Nothing );
+ 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::Clamped );
+ automaticBackupInterval->setLimits(1, QVariant(QVariant::Invalid));
+
+ connect( m_timer, SIGNAL( timeout() ), this, SLOT(autoSaveRequired() ) );
+ connect( this, SIGNAL( destroyed() ), m_timer, SLOT( stop() ) );
+
+ connect( automaticBackup, SIGNAL( changed( QVariant ) ),
+ this, SLOT( autoSaveEnabledChanged( QVariant ) ) );
+ connect( automaticBackupInterval, SIGNAL( changed( QVariant ) ), this,
+ SLOT( autoSaveIntervalChanged( QVariant ) ) );
+
+ m_timer->start( automaticBackupInterval->get().toInt() * 1000 * 60 );
}
Project::~Project()
{
delete m_projectFile;
delete m_settings;
+ delete m_timer;
}
Settings*
@@ -193,7 +217,7 @@ Project::initSettings()
SettingValue* pName = m_settings->createVar( SettingValue::String, "vlmc/ProjectName", unNamedProject,
QT_TRANSLATE_NOOP( "PreferenceWidget", "Project name" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "The project name" ),
- SettingValue::NotEmpty );
+ SettingValue::NotEmpty );
connect( pName, SIGNAL( changed( QVariant ) ), this, SIGNAL( projectUpdated( QVariant ) ) );
}
@@ -299,3 +323,26 @@ Project::autoSaveRequired()
return ;
saveProject( m_projectFile->fileName() + Project::backupSuffix );
}
+
+
+void
+Project::autoSaveEnabledChanged(const QVariant &enabled)
+{
+ if ( enabled.toBool() == true )
+ {
+ int interval = Core::getInstance()->settings()->value( "vlmc/AutomaticBackupInterval" )->get().toInt();
+ m_timer->start( interval * 1000 * 60 );
+ }
+ else
+ m_timer->stop();
+}
+
+void
+Project::autoSaveIntervalChanged(const QVariant &interval)
+{
+ bool enabled = Core::getInstance()->settings()->value( "vlmc/AutomaticBackup" )->get().toBool();
+
+ if ( enabled == false )
+ return ;
+ m_timer->start( interval.toInt() * 1000 * 60 );
+}
diff --git a/src/Project/Project.h b/src/Project/Project.h
index 0c8b53a..3d53d05 100644
--- a/src/Project/Project.h
+++ b/src/Project/Project.h
@@ -33,6 +33,7 @@ class QDomDocument;
class QFile;
class QString;
class QXmlStreamWriter;
+class QTimer;
class AutomaticBackup;
class Library;
@@ -49,7 +50,7 @@ class Project : public QObject
public:
Q_DISABLE_COPY( Project );
- Project();
+ Project( Settings* settings );
virtual ~Project();
@@ -84,6 +85,9 @@ class Project : public QObject
void cleanChanged( bool val );
void libraryCleanChanged( bool val );
void autoSaveRequired();
+ void autoSaveEnabledChanged( const QVariant& enabled );
+ void autoSaveIntervalChanged( const QVariant& interval );
+
signals:
/**
@@ -120,6 +124,7 @@ private:
QFile* m_projectFile;
bool m_isClean;
bool m_libraryCleanState;
+ QTimer* m_timer;
///////////////////////////////////
// Dependent components part below:
diff --git a/src/Project/RecentProjects.cpp b/src/Project/RecentProjects.cpp
index 080950d..0b9bbbd 100644
--- a/src/Project/RecentProjects.cpp
+++ b/src/Project/RecentProjects.cpp
@@ -31,7 +31,6 @@
RecentProjects::RecentProjects( Settings* vlmcSettings, QObject *parent )
: QObject(parent)
, m_settings( vlmcSettings )
- , m_project( NULL )
{
SettingValue* recentProjects = vlmcSettings->createVar( SettingValue::String, "private/RecentsProjects", "",
"", "", SettingValue::Private );
@@ -40,16 +39,6 @@ RecentProjects::RecentProjects( Settings* vlmcSettings, QObject *parent )
}
void
-RecentProjects::setProject( Project* project )
-{
- if ( m_project != NULL )
- disconnect( m_project, SIGNAL( projectLoaded( QString, QString ) ) );
- m_project = project;
- connect( project, SIGNAL( projectLoaded( QString, QString ) ),
- this, SLOT( projectLoaded( QString, QString ) ) );
-}
-
-void
RecentProjects::projectLoaded(const QString& projectName, const QString& projectFile)
{
removeFromRecentProjects( projectName );
diff --git a/src/Project/RecentProjects.h b/src/Project/RecentProjects.h
index 4bdf3e2..aa864c3 100644
--- a/src/Project/RecentProjects.h
+++ b/src/Project/RecentProjects.h
@@ -42,7 +42,6 @@ class RecentProjects : public QObject
explicit RecentProjects(Settings* vlmcSettings, QObject *parent = 0 );
- void setProject(Project* projectManager );
void remove( const QString& projectFile );
const List& list() const;
@@ -59,7 +58,6 @@ class RecentProjects : public QObject
private:
Settings* m_settings;
- Project* m_project;
List m_recentsProjects;
};
--
1.9.1
More information about the Vlmc-devel
mailing list