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()
void MainWindow::on_actionSave_triggered()
{
QString outputFileName =
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();
}
ProjectManager::getInstance()->saveProject();
}
void MainWindow::on_actionLoad_Project_triggered()
{
QString outputFileName =
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();
}
ProjectManager::getInstance()->loadProject();
}
void MainWindow::createStatusBar()
......
......@@ -28,6 +28,7 @@ UndoStack::UndoStack( QWidget* parent ) : QUndoView( parent )
m_undoStack = new QUndoStack( this );
setStack( m_undoStack );
connect( m_undoStack, SIGNAL( cleanChanged(bool) ), this, SIGNAL( cleanChanged() ) );
m_undoShortcut = new QShortcut( QKeySequence( tr( "Ctrl+z", "Undo" ) ), this );
m_redoShortcut = new QShortcut( QKeySequence( tr( "Ctrl+Shift+z", "Redo" ) ), this );
......
......@@ -43,6 +43,10 @@ class UndoStack : public QUndoView, public QSingleton<UndoStack>
QUndoStack* m_undoStack;
QShortcut* m_undoShortcut;
QShortcut* m_redoShortcut;
signals:
void cleanChanged();
friend class QSingleton<UndoStack>;
};
......
......@@ -69,16 +69,7 @@ void ProjectWizard::reject()
void ProjectWizard::loadProject()
{
QString outputFileName = QFileDialog::getOpenFileName( NULL,
"Enter the output file name",
QString(), "VLMC project file(*.vlmc)" );
if ( outputFileName.length() == 0 )
return ;
else
{
ProjectManager* pm = new ProjectManager( outputFileName );
pm->loadProject();
}
ProjectManager::getInstance()->loadProject();
restart();
QDialog::accept();
}
......@@ -20,29 +20,33 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <QFileDialog>
#include "ProjectManager.h"
#include "Library.h"
#include "MainWorkflow.h"
#include "SettingsManager.h"
ProjectManager::ProjectManager( const QString& filePath )
ProjectManager::ProjectManager() : m_projectFile( NULL )
{
m_projectFile = new QFile( filePath, this );
}
ProjectManager::~ProjectManager()
{
if ( m_projectFile != NULL )
delete m_projectFile;
}
void ProjectManager::loadTimeline()
{
QDomElement root = m_domDocument->documentElement();
MainWorkflow::getInstance()->loadProject( root.firstChildElement( "timeline" ) );
deleteLater();
}
void ProjectManager::loadProject()
{
if ( loadProjectFile() == false )
return ;
m_domDocument = new QDomDocument;
m_projectFile->open( QFile::ReadOnly );
m_domDocument->setContent( m_projectFile );
......@@ -55,8 +59,39 @@ void ProjectManager::loadProject()
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()
{
if ( checkProjectOpen() == false )
return ;
QDomImplementation implem = QDomDocument().implementation();
//FIXME: Think about naming the project...
QString name = "VLMCProject";
......@@ -75,5 +110,4 @@ void ProjectManager::saveProject()
m_projectFile->open( QFile::WriteOnly );
m_projectFile->write( doc.toString().toAscii() );
m_projectFile->close();
deleteLater();
}
......@@ -27,21 +27,28 @@
#include <QObject>
#include <QDomDocument>
class ProjectManager : public QObject
#include "Singleton.hpp"
class ProjectManager : public QObject, public Singleton<ProjectManager>
{
Q_OBJECT
Q_DISABLE_COPY( ProjectManager );
public:
ProjectManager( const QString& filePath );
~ProjectManager();
void loadProject();
void saveProject();
private:
ProjectManager();
~ProjectManager();
bool checkProjectOpen();
bool loadProjectFile();
private:
QFile* m_projectFile;
QDomDocument* m_domDocument;
friend class Singleton<ProjectManager>;
private slots:
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