Commit c34d8b9c authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Project can now be loaded once, and overwritten afterward.

parent 3a1bccaa
...@@ -138,39 +138,12 @@ void MainWindow::setupLibrary() ...@@ -138,39 +138,12 @@ void MainWindow::setupLibrary()
void MainWindow::on_actionSave_triggered() void MainWindow::on_actionSave_triggered()
{ {
QString outputFileName = ProjectManager::getInstance()->saveProject();
QFileDialog::getSaveFileName( NULL, "Enter the output file name",
QString(), "VLMC project file(*.vlmc)" );
if ( outputFileName.length() == 0 )
return ;
else
{
//Project manager will destroy itself.
QStringList list = outputFileName.split( "." );
if ( list.at( list.size() - 1 ) != "vlmc" )
{
list.append( "vlmc" );
outputFileName = list.join(".");
}
ProjectManager* pm = new ProjectManager( outputFileName );
pm->saveProject();
}
} }
void MainWindow::on_actionLoad_Project_triggered() void MainWindow::on_actionLoad_Project_triggered()
{ {
QString outputFileName = ProjectManager::getInstance()->loadProject();
QFileDialog::getOpenFileName( NULL, "Enter the output file name",
QString(), "VLMC project file(*.vlmc)" );
if ( outputFileName.length() == 0 )
return ;
else
{
//Project manager will destroy itself.
ProjectManager* pm = new ProjectManager( outputFileName );
pm->loadProject();
}
} }
void MainWindow::createStatusBar() void MainWindow::createStatusBar()
......
...@@ -28,6 +28,7 @@ UndoStack::UndoStack( QWidget* parent ) : QUndoView( parent ) ...@@ -28,6 +28,7 @@ UndoStack::UndoStack( QWidget* parent ) : QUndoView( parent )
m_undoStack = new QUndoStack( this ); m_undoStack = new QUndoStack( this );
setStack( m_undoStack ); setStack( m_undoStack );
connect( m_undoStack, SIGNAL( cleanChanged(bool) ), this, SIGNAL( cleanChanged() ) );
m_undoShortcut = new QShortcut( QKeySequence( tr( "Ctrl+z", "Undo" ) ), this ); m_undoShortcut = new QShortcut( QKeySequence( tr( "Ctrl+z", "Undo" ) ), this );
m_redoShortcut = new QShortcut( QKeySequence( tr( "Ctrl+Shift+z", "Redo" ) ), this ); m_redoShortcut = new QShortcut( QKeySequence( tr( "Ctrl+Shift+z", "Redo" ) ), this );
......
...@@ -43,6 +43,10 @@ class UndoStack : public QUndoView, public QSingleton<UndoStack> ...@@ -43,6 +43,10 @@ class UndoStack : public QUndoView, public QSingleton<UndoStack>
QUndoStack* m_undoStack; QUndoStack* m_undoStack;
QShortcut* m_undoShortcut; QShortcut* m_undoShortcut;
QShortcut* m_redoShortcut; QShortcut* m_redoShortcut;
signals:
void cleanChanged();
friend class QSingleton<UndoStack>; friend class QSingleton<UndoStack>;
}; };
......
...@@ -69,16 +69,7 @@ void ProjectWizard::reject() ...@@ -69,16 +69,7 @@ void ProjectWizard::reject()
void ProjectWizard::loadProject() void ProjectWizard::loadProject()
{ {
QString outputFileName = QFileDialog::getOpenFileName( NULL, ProjectManager::getInstance()->loadProject();
"Enter the output file name",
QString(), "VLMC project file(*.vlmc)" );
if ( outputFileName.length() == 0 )
return ;
else
{
ProjectManager* pm = new ProjectManager( outputFileName );
pm->loadProject();
}
restart(); restart();
QDialog::accept(); QDialog::accept();
} }
...@@ -20,29 +20,33 @@ ...@@ -20,29 +20,33 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#include <QFileDialog>
#include "ProjectManager.h" #include "ProjectManager.h"
#include "Library.h" #include "Library.h"
#include "MainWorkflow.h" #include "MainWorkflow.h"
#include "SettingsManager.h" #include "SettingsManager.h"
ProjectManager::ProjectManager( const QString& filePath ) ProjectManager::ProjectManager() : m_projectFile( NULL )
{ {
m_projectFile = new QFile( filePath, this );
} }
ProjectManager::~ProjectManager() ProjectManager::~ProjectManager()
{ {
if ( m_projectFile != NULL )
delete m_projectFile;
} }
void ProjectManager::loadTimeline() void ProjectManager::loadTimeline()
{ {
QDomElement root = m_domDocument->documentElement(); QDomElement root = m_domDocument->documentElement();
MainWorkflow::getInstance()->loadProject( root.firstChildElement( "timeline" ) ); MainWorkflow::getInstance()->loadProject( root.firstChildElement( "timeline" ) );
deleteLater();
} }
void ProjectManager::loadProject() void ProjectManager::loadProject()
{ {
if ( loadProjectFile() == false )
return ;
m_domDocument = new QDomDocument; m_domDocument = new QDomDocument;
m_projectFile->open( QFile::ReadOnly ); m_projectFile->open( QFile::ReadOnly );
m_domDocument->setContent( m_projectFile ); m_domDocument->setContent( m_projectFile );
...@@ -55,8 +59,39 @@ void ProjectManager::loadProject() ...@@ -55,8 +59,39 @@ void ProjectManager::loadProject()
SettingsManager::getInstance()->loadSettings( "project", root.firstChildElement( "project" ) ); SettingsManager::getInstance()->loadSettings( "project", root.firstChildElement( "project" ) );
} }
bool ProjectManager::loadProjectFile()
{
QString fileName =
QFileDialog::getOpenFileName( NULL, "Enter the output file name",
QString(), "VLMC project file(*.vlmc)" );
if ( fileName.length() == 0 )
return false;
if ( m_projectFile != NULL )
delete m_projectFile;
m_projectFile = new QFile( fileName );
return true;
}
bool ProjectManager::checkProjectOpen()
{
if ( m_projectFile == NULL )
{
QString outputFileName =
QFileDialog::getSaveFileName( NULL, "Enter the output file name",
QString(), "VLMC project file(*.vlmc)" );
if ( outputFileName.length() == 0 )
return false;
if ( m_projectFile != NULL )
delete m_projectFile;
m_projectFile = new QFile( outputFileName );
}
return true;
}
void ProjectManager::saveProject() void ProjectManager::saveProject()
{ {
if ( checkProjectOpen() == false )
return ;
QDomImplementation implem = QDomDocument().implementation(); QDomImplementation implem = QDomDocument().implementation();
//FIXME: Think about naming the project... //FIXME: Think about naming the project...
QString name = "VLMCProject"; QString name = "VLMCProject";
...@@ -75,5 +110,4 @@ void ProjectManager::saveProject() ...@@ -75,5 +110,4 @@ void ProjectManager::saveProject()
m_projectFile->open( QFile::WriteOnly ); m_projectFile->open( QFile::WriteOnly );
m_projectFile->write( doc.toString().toAscii() ); m_projectFile->write( doc.toString().toAscii() );
m_projectFile->close(); m_projectFile->close();
deleteLater();
} }
...@@ -27,21 +27,28 @@ ...@@ -27,21 +27,28 @@
#include <QObject> #include <QObject>
#include <QDomDocument> #include <QDomDocument>
class ProjectManager : public QObject #include "Singleton.hpp"
class ProjectManager : public QObject, public Singleton<ProjectManager>
{ {
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY( ProjectManager ); Q_DISABLE_COPY( ProjectManager );
public: public:
ProjectManager( const QString& filePath );
~ProjectManager();
void loadProject(); void loadProject();
void saveProject(); void saveProject();
private:
ProjectManager();
~ProjectManager();
bool checkProjectOpen();
bool loadProjectFile();
private: private:
QFile* m_projectFile; QFile* m_projectFile;
QDomDocument* m_domDocument; QDomDocument* m_domDocument;
friend class Singleton<ProjectManager>;
private slots: private slots:
void loadTimeline(); void loadTimeline();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment