Remove Song's dependency to MainWindow
Finally remove Song's dependency to MainWindow by moving the window title update which is triggered due to a changed project file name from the class Song into MainWindow. Implementation details: Add a new signal projectFileNameChanged to Song and connect the new slot method MainWindow::onProjectFileNameChanged to it. Update the window title whenever the slot is triggered. Add a new private method Song::setProjectFileName which sets the project file name and emits the signal (only if the file name really changes). Call setProjectFileName everywhere where m_fileName was manipulated directly. This is done to ensure that the signal can be potentially emitted in all relevant situations. Remove the calls to gui->mainWindow from Song::createNewProjectFromTemplate. These changes finally remove the include to "MainWindow.h". The include for "ConfigManager.h" was previously done implicitly through the include of "MainWindow.h" and therefore had to be added explicitly after the latter is removed.
This commit is contained in:
@@ -254,6 +254,7 @@ private slots:
|
||||
void onImportProject();
|
||||
void onSongStopped();
|
||||
void onSongModified();
|
||||
void onProjectFileNameChanged();
|
||||
|
||||
signals:
|
||||
void periodicUpdate();
|
||||
|
||||
@@ -372,6 +372,8 @@ private:
|
||||
|
||||
void setModified(bool value);
|
||||
|
||||
void setProjectFileName(QString const & projectFileName);
|
||||
|
||||
AutomationTrack * m_globalAutomationTrack;
|
||||
|
||||
IntModel m_tempoModel;
|
||||
@@ -432,6 +434,7 @@ signals:
|
||||
void updateSampleTracks();
|
||||
void stopped();
|
||||
void modified();
|
||||
void projectFileNameChanged();
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "BBEditor.h"
|
||||
#include "BBTrack.h"
|
||||
#include "BBTrackContainer.h"
|
||||
#include "ConfigManager.h"
|
||||
#include "ControllerRackView.h"
|
||||
#include "ControllerConnection.h"
|
||||
#include "embed.h"
|
||||
@@ -45,7 +46,6 @@
|
||||
#include "FxMixerView.h"
|
||||
#include "GuiApplication.h"
|
||||
#include "ExportFilter.h"
|
||||
#include "MainWindow.h"
|
||||
#include "Pattern.h"
|
||||
#include "PianoRoll.h"
|
||||
#include "ProjectJournal.h"
|
||||
@@ -916,7 +916,8 @@ void Song::createNewProject()
|
||||
|
||||
Engine::projectJournal()->setJournalling( false );
|
||||
|
||||
m_fileName = m_oldFileName = "";
|
||||
m_oldFileName = "";
|
||||
setProjectFileName("");
|
||||
|
||||
Track * t;
|
||||
t = Track::create( Track::InstrumentTrack, this );
|
||||
@@ -957,13 +958,10 @@ void Song::createNewProjectFromTemplate( const QString & templ )
|
||||
loadProject( templ );
|
||||
// clear file-name so that user doesn't overwrite template when
|
||||
// saving...
|
||||
m_fileName = m_oldFileName = "";
|
||||
m_oldFileName = "";
|
||||
setProjectFileName("");
|
||||
// update window title
|
||||
m_loadOnLaunch = false;
|
||||
if( gui->mainWindow() )
|
||||
{
|
||||
gui->mainWindow()->resetWindowTitle();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -979,7 +977,7 @@ void Song::loadProject( const QString & fileName )
|
||||
Engine::projectJournal()->setJournalling( false );
|
||||
|
||||
m_oldFileName = m_fileName;
|
||||
m_fileName = fileName;
|
||||
setProjectFileName(fileName);
|
||||
|
||||
DataFile dataFile( m_fileName );
|
||||
// if file could not be opened, head-node is null and we create
|
||||
@@ -990,7 +988,7 @@ void Song::loadProject( const QString & fileName )
|
||||
{
|
||||
createNewProject();
|
||||
}
|
||||
m_fileName = m_oldFileName;
|
||||
setProjectFileName(m_oldFileName);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1180,7 +1178,8 @@ bool Song::saveProjectFile( const QString & filename )
|
||||
bool Song::guiSaveProject()
|
||||
{
|
||||
DataFile dataFile( DataFile::SongProject );
|
||||
m_fileName = dataFile.nameWithExtension( m_fileName );
|
||||
QString fileNameWithExtension = dataFile.nameWithExtension( m_fileName );
|
||||
setProjectFileName(fileNameWithExtension);
|
||||
|
||||
bool const saveResult = saveProjectFile( m_fileName );
|
||||
|
||||
@@ -1200,12 +1199,12 @@ bool Song::guiSaveProjectAs( const QString & _file_name )
|
||||
{
|
||||
QString o = m_oldFileName;
|
||||
m_oldFileName = m_fileName;
|
||||
m_fileName = _file_name;
|
||||
setProjectFileName(_file_name);
|
||||
|
||||
if(!guiSaveProject())
|
||||
{
|
||||
// Saving failed. Restore old filenames.
|
||||
m_fileName = m_oldFileName;
|
||||
setProjectFileName(m_oldFileName);
|
||||
m_oldFileName = o;
|
||||
|
||||
return false;
|
||||
@@ -1294,6 +1293,15 @@ void Song::setModified()
|
||||
setModified(true);
|
||||
}
|
||||
|
||||
void Song::setProjectFileName(QString const & projectFileName)
|
||||
{
|
||||
if (m_fileName != projectFileName)
|
||||
{
|
||||
m_fileName = projectFileName;
|
||||
emit projectFileNameChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -238,6 +238,7 @@ MainWindow::MainWindow() :
|
||||
connect(Engine::getSong(), SIGNAL(stopped()), SLOT(onSongStopped()));
|
||||
|
||||
connect(Engine::getSong(), SIGNAL(modified()), SLOT(onSongModified()));
|
||||
connect(Engine::getSong(), SIGNAL(projectFileNameChanged()), SLOT(onProjectFileNameChanged()));
|
||||
}
|
||||
|
||||
|
||||
@@ -1817,3 +1818,8 @@ void MainWindow::onSongModified()
|
||||
this->resetWindowTitle();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onProjectFileNameChanged()
|
||||
{
|
||||
this->resetWindowTitle();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user