[vlmc-devel] [PATCH] Avoid using setProject functions
Yikai Lu
luyikei.qmltu at gmail.com
Sat Mar 5 18:26:45 CET 2016
Instead, these functions are merged into constructors.
---
src/Main/Core.cpp | 8 ++------
src/Project/AutomaticBackup.cpp | 18 +++++++-----------
src/Project/AutomaticBackup.h | 3 +--
src/Project/RecentProjects.cpp | 13 ++++---------
src/Project/RecentProjects.h | 3 +--
5 files changed, 15 insertions(+), 30 deletions(-)
diff --git a/src/Main/Core.cpp b/src/Main/Core.cpp
index d1fac98..ea7698a 100644
--- a/src/Main/Core.cpp
+++ b/src/Main/Core.cpp
@@ -52,22 +52,18 @@ Core::Core()
m_logger = new VlmcLogger;
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 );
m_undoStack = new QUndoStack;
m_library = new Library( m_workspace );
m_currentProject = new Project;
+ m_recentProjects = new RecentProjects( m_settings, m_currentProject );
+ m_automaticBackup = new AutomaticBackup( m_settings, m_currentProject );
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 );
}
Core::~Core()
diff --git a/src/Project/AutomaticBackup.cpp b/src/Project/AutomaticBackup.cpp
index 5018a91..9552a3e 100644
--- a/src/Project/AutomaticBackup.cpp
+++ b/src/Project/AutomaticBackup.cpp
@@ -26,7 +26,7 @@
#include "Project.h"
#include "Settings/Settings.h"
-AutomaticBackup::AutomaticBackup( Settings* vlmcSettings, QObject *parent )
+AutomaticBackup::AutomaticBackup( Settings* vlmcSettings, Project* project, QObject *parent )
: QObject(parent)
, m_vlmcSettings( vlmcSettings )
{
@@ -42,7 +42,12 @@ AutomaticBackup::AutomaticBackup( Settings* vlmcSettings, QObject *parent )
"between two automatic save" ), SettingValue::Nothing );
connect( autoBackup, SIGNAL( changed( QVariant ) ), this, SLOT( automaticSaveEnabledChanged( QVariant ) ) );
- connect( interval, SIGNAL( changed( QVariant ) ), this, SLOT( automaticSaveIntervalChanged( QVariant ) ) );
+ connect( interval, SIGNAL( changed( QVariant ) ), this, SLOT( automaticSaveIntervalChanged( QVariant ) ) );
+
+ connect( m_timer, SIGNAL( timeout() ), project, SLOT(autoSaveRequired() ) );
+ connect( project, SIGNAL( destroyed() ), m_timer, SLOT( stop() ) );
+ m_timer->setInterval( 5 * 1000 * 60 );
+ m_timer->start();
}
AutomaticBackup::~AutomaticBackup()
@@ -51,15 +56,6 @@ AutomaticBackup::~AutomaticBackup()
}
void
-AutomaticBackup::setProject( Project* projectManager )
-{
- m_timer->disconnect();
- connect( m_timer, SIGNAL( timeout() ), projectManager, SLOT(autoSaveRequired() ) );
- connect( projectManager, SIGNAL( destroyed() ), m_timer, SLOT( stop() ) );
- m_timer->start();
-}
-
-void
AutomaticBackup::automaticSaveEnabledChanged( const QVariant& val )
{
bool enabled = val.toBool();
diff --git a/src/Project/AutomaticBackup.h b/src/Project/AutomaticBackup.h
index bbfdc5b..be451df 100644
--- a/src/Project/AutomaticBackup.h
+++ b/src/Project/AutomaticBackup.h
@@ -35,9 +35,8 @@ class AutomaticBackup : public QObject
Q_OBJECT
public:
- explicit AutomaticBackup( Settings* vlmcSettings, QObject *parent = 0 );
+ explicit AutomaticBackup( Settings* vlmcSettings, Project *project, QObject *parent = 0 );
virtual ~AutomaticBackup();
- void setProject( Project* projectManager );
private:
Settings* m_vlmcSettings;
diff --git a/src/Project/RecentProjects.cpp b/src/Project/RecentProjects.cpp
index 080950d..6e25377 100644
--- a/src/Project/RecentProjects.cpp
+++ b/src/Project/RecentProjects.cpp
@@ -28,24 +28,19 @@
#include "Settings/Settings.h"
#include "Tools/VlmcDebug.h"
-RecentProjects::RecentProjects( Settings* vlmcSettings, QObject *parent )
+RecentProjects::RecentProjects( Settings* vlmcSettings, Project* project, QObject *parent )
: QObject(parent)
, m_settings( vlmcSettings )
- , m_project( NULL )
+ , m_project( project )
{
SettingValue* recentProjects = vlmcSettings->createVar( SettingValue::String, "private/RecentsProjects", "",
"", "", SettingValue::Private );
- connect( recentProjects, SIGNAL( changed( QVariant ) ), this, SLOT( loadRecentProjects( QVariant ) ) );
-}
+ connect( recentProjects, SIGNAL( changed( QVariant ) ), this, SLOT( loadRecentProjects( QVariant ) ) );
-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 ) ),
+ connect( m_project, SIGNAL( projectLoaded( QString, QString ) ),
this, SLOT( projectLoaded( QString, QString ) ) );
}
diff --git a/src/Project/RecentProjects.h b/src/Project/RecentProjects.h
index 4bdf3e2..f7aa377 100644
--- a/src/Project/RecentProjects.h
+++ b/src/Project/RecentProjects.h
@@ -40,9 +40,8 @@ class RecentProjects : public QObject
};
typedef QList<RecentProject> List;
- explicit RecentProjects(Settings* vlmcSettings, QObject *parent = 0 );
+ explicit RecentProjects(Settings* vlmcSettings, Project *project, QObject *parent = 0 );
- void setProject(Project* projectManager );
void remove( const QString& projectFile );
const List& list() const;
--
1.9.1
More information about the Vlmc-devel
mailing list