From 9acff89ad315406bac95d0109e97a15355e5d961 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sun, 10 Dec 2017 11:40:44 +0100 Subject: [PATCH] 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. --- include/MainWindow.h | 1 + include/Song.h | 3 +++ src/core/Song.cpp | 32 ++++++++++++++++++++------------ src/gui/MainWindow.cpp | 6 ++++++ 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/include/MainWindow.h b/include/MainWindow.h index ee0804b22..6f243bfab 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -254,6 +254,7 @@ private slots: void onImportProject(); void onSongStopped(); void onSongModified(); + void onProjectFileNameChanged(); signals: void periodicUpdate(); diff --git a/include/Song.h b/include/Song.h index c1ca62688..8b2c21316 100644 --- a/include/Song.h +++ b/include/Song.h @@ -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(); } ; diff --git a/src/core/Song.cpp b/src/core/Song.cpp index a7f81bf46..3fc16da4a 100644 --- a/src/core/Song.cpp +++ b/src/core/Song.cpp @@ -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(); + } +} + diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 651de1177..5153b1951 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -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(); +}