diff --git a/App/main.cpp b/App/main.cpp index 9c0c5d93b3b82ef265751be8184be689b901f978..b19d25779b70e767bc135ff59aae832053dde948 100644 --- a/App/main.cpp +++ b/App/main.cpp @@ -18,6 +18,7 @@ #include "GUI/Model/State/SessionData.h" #include "GUI/Util/OSInfo.h" #include "GUI/Util/Path.h" +#include "GUI/View/Global/Globals.h" #include "GUI/View/Loaders/DataLoaderUtil.h" #include "GUI/View/Main/MainWindow.h" #include "config_build.h" @@ -70,6 +71,7 @@ int main(int argc, char* argv[]) GSession.instrumentLibrary.load(); MainWindow win; + GUI::Global::mainWindow = &win; if (options.find("geometry")) win.resize(options.mainWindowSize()); diff --git a/GUI/Model/From/SampleListModel.cpp b/GUI/Model/From/SampleListModel.cpp index 8ebab50dc1b5c9ebe33555344b1bd398fccda254..3e33ad7a948d8ce8dbc1e01a3199f991afe14215 100644 --- a/GUI/Model/From/SampleListModel.cpp +++ b/GUI/Model/From/SampleListModel.cpp @@ -18,7 +18,7 @@ #include "GUI/Model/Sample/MultiLayerItem.h" #include "GUI/Model/Sample/SampleModel.h" #include "GUI/Util/String.h" -#include "GUI/View/Main/PyImportAssistant.h" +#include "GUI/View/Project/PyImportAssistant.h" #include "Sample/Multilayer/MultiLayer.h" #include <QFontMetrics> #include <QIcon> diff --git a/GUI/Model/Sample/MesoCrystalItem.cpp b/GUI/Model/Sample/MesoCrystalItem.cpp index 0e3255fa1c35f2c22148d9f029a04d298c926638..b96e2b9d12c2b4419e972b47de7f24f5b1c42bb3 100644 --- a/GUI/Model/Sample/MesoCrystalItem.cpp +++ b/GUI/Model/Sample/MesoCrystalItem.cpp @@ -20,10 +20,10 @@ #include "GUI/Model/Sample/ParticleItem.h" #include "GUI/Util/Error.h" #include "Sample/Particle/Crystal.h" +#include "Sample/Particle/IBornFF.h" #include "Sample/Particle/MesoCrystal.h" #include "Sample/Particle/Particle.h" #include "Sample/Particle/ParticleCoreShell.h" -#include "Sample/Particle/IBornFF.h" namespace { diff --git a/GUI/View/Global/Globals.h b/GUI/View/Global/Globals.h new file mode 100644 index 0000000000000000000000000000000000000000..4ac1cbd2e6258d3f52a72ca83bc69acbbdeb7a7b --- /dev/null +++ b/GUI/View/Global/Globals.h @@ -0,0 +1,26 @@ +// ************************************************************************************************ +// +// BornAgain: simulate and fit reflection and scattering +// +//! @file GUI/View/Global/Globals.h +//! @brief Defines global pointers +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2018 +//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) +// +// ************************************************************************************************ + +#ifndef BORNAGAIN_GUI_VIEW_GLOBAL_GLOBALS_H +#define BORNAGAIN_GUI_VIEW_GLOBAL_GLOBALS_H + +#include <QMainWindow> + +namespace GUI::Global { + +static QMainWindow* mainWindow; + +} // namespace GUI::Global + +#endif // BORNAGAIN_GUI_VIEW_GLOBAL_GLOBALS_H diff --git a/GUI/View/Import/RealDataPropertiesWidget.cpp b/GUI/View/Import/RealDataPropertiesWidget.cpp index a87d393ba377505a220f276443022012f472cc98..832a6c2d53dc98ad5dd7ece9214a82d57cd25425 100644 --- a/GUI/View/Import/RealDataPropertiesWidget.cpp +++ b/GUI/View/Import/RealDataPropertiesWidget.cpp @@ -18,7 +18,7 @@ #include "GUI/Model/Instrument/InstrumentModel.h" #include "GUI/Model/Instrument/LinkInstrumentManager.h" #include "GUI/Model/Project/ProjectDocument.h" -#include "GUI/View/Main/MainWindow.h" +#include "GUI/View/Global/Globals.h" #include <QComboBox> #include <QLabel> #include <QVBoxLayout> @@ -99,7 +99,7 @@ void RealDataPropertiesWidget::onInstrumentComboIndexChanged(int /*index*/) return; if (m_document->linkInstrumentManager()->canLinkDataToInstrument( - m_currentDataItem, newSelectedInstrumentId, baWin)) { + m_currentDataItem, newSelectedInstrumentId, GUI::Global::mainWindow)) { m_currentDataItem->setInstrumentId(newSelectedInstrumentId); InstrumentItem* newSelectedInstrument = m_document->instrumentModel()->findInstrumentById(newSelectedInstrumentId); diff --git a/GUI/View/Import/RealDataSelectorWidget.cpp b/GUI/View/Import/RealDataSelectorWidget.cpp index c4deca65d2935c508c7b06c4b273a323dbb51900..c0b528faf8cad61572f66571179cd78e57f8e5c7 100644 --- a/GUI/View/Import/RealDataSelectorWidget.cpp +++ b/GUI/View/Import/RealDataSelectorWidget.cpp @@ -26,7 +26,7 @@ #include "GUI/View/Import/RealDataPropertiesWidget.h" #include "GUI/View/Import/RealDataTreeModel.h" #include "GUI/View/Info/MessageBox.h" -#include "GUI/View/Main/ProjectManager.h" +#include "GUI/View/Project/ProjectManager.h" #include <QFileDialog> #include <QItemSelectionModel> #include <QLineEdit> diff --git a/GUI/View/Import/SpecularDataImportWidget.cpp b/GUI/View/Import/SpecularDataImportWidget.cpp index 5c6b79637ecefb1fe1cd8b37e1ad9abab3e94303..0aceaa9e568898bd20e351a6b2ac704a6dfb7a3a 100644 --- a/GUI/View/Import/SpecularDataImportWidget.cpp +++ b/GUI/View/Import/SpecularDataImportWidget.cpp @@ -19,8 +19,8 @@ #include "GUI/Model/IO/AbstractDataLoaderResultModel.h" #include "GUI/Model/IO/DataLoaders1D.h" #include "GUI/Model/Instrument/InstrumentItems.h" +#include "GUI/View/Global/Globals.h" #include "GUI/View/Loaders/DataLoaderUtil.h" -#include "GUI/View/Main/MainWindow.h" #include "ui_SpecularDataImportWidget.h" #include <QAction> #include <QBoxLayout> @@ -194,7 +194,7 @@ void SpecularDataImportWidget::onFormatSelectionChanged() QSignalBlocker b(m_ui->formatSelectionComboBox); m_ui->formatSelectionComboBox->setCurrentText(m_loader->name()); - QMessageBox::information(baWin, "Information", + QMessageBox::information(GUI::Global::mainWindow, "Information", "Changing the loader is not possible because the original file " "contents are not available any more."); diff --git a/GUI/View/Instrument/InstrumentListView.cpp b/GUI/View/Instrument/InstrumentListView.cpp index 3746f77d89ef6099a5b0eddd3d4092f553cf1bfe..85eaa1ce3fb4785e1189e9596748af65935c588d 100644 --- a/GUI/View/Instrument/InstrumentListView.cpp +++ b/GUI/View/Instrument/InstrumentListView.cpp @@ -17,9 +17,9 @@ #include "GUI/Model/Instrument/InstrumentModel.h" #include "GUI/Model/Project/ProjectDocument.h" #include "GUI/Model/State/SessionData.h" +#include "GUI/View/Global/Globals.h" #include "GUI/View/Instrument/InstrumentLibraryEditor.h" #include "GUI/View/Instrument/InstrumentListModel.h" -#include "GUI/View/Main/MainWindow.h" #include <QAction> #include <QListView> #include <QMessageBox> @@ -210,7 +210,7 @@ void InstrumentListView::onStoreInLibrary() QModelIndex idx = m_listView->selectionModel()->selectedIndexes().front(); InstrumentItem* instrument = m_model->instrumentForIndex(idx); - InstrumentLibraryEditor dlg(baWin); + InstrumentLibraryEditor dlg(GUI::Global::mainWindow); dlg.setGisasEnabled(m_document->functionalities().testFlag(ProjectDocument::Gisas)); dlg.setOffSpecEnabled(m_document->functionalities().testFlag(ProjectDocument::OffSpecular)); dlg.setSpecularEnabled(m_document->functionalities().testFlag(ProjectDocument::Specular)); @@ -221,12 +221,12 @@ void InstrumentListView::onStoreInLibrary() void InstrumentListView::onLoadFromLibrary() { if (gSessionData->instrumentLibrary.isEmpty()) { - QMessageBox::information(baWin, "Select from library", + QMessageBox::information(GUI::Global::mainWindow, "Select from library", "The library does not contain instruments so far."); return; } - InstrumentLibraryEditor dlg(baWin); + InstrumentLibraryEditor dlg(GUI::Global::mainWindow); dlg.setGisasEnabled(m_document->functionalities().testFlag(ProjectDocument::Gisas)); dlg.setOffSpecEnabled(m_document->functionalities().testFlag(ProjectDocument::OffSpecular)); dlg.setSpecularEnabled(m_document->functionalities().testFlag(ProjectDocument::Specular)); diff --git a/GUI/View/Intensity/IntensityDataCanvas.cpp b/GUI/View/Intensity/IntensityDataCanvas.cpp index 4ee5288dfbf2fdcbc992de37ccebe0ce62a6497c..2a32a8cedccd22ca7212aa48546339950fa51677 100644 --- a/GUI/View/Intensity/IntensityDataCanvas.cpp +++ b/GUI/View/Intensity/IntensityDataCanvas.cpp @@ -17,11 +17,11 @@ #include "GUI/Model/Data/RealDataItem.h" #include "GUI/Model/State/SessionData.h" #include "GUI/Util/ComboProperty.h" +#include "GUI/View/Global/Globals.h" #include "GUI/View/Info/MessageBox.h" #include "GUI/View/Intensity/ColorMap.h" #include "GUI/View/Intensity/ColorMapCanvas.h" #include "GUI/View/Intensity/SavePlotAssistant.h" -#include "GUI/View/Main/MainWindow.h" #include <QAction> #include <QMouseEvent> #include <QSettings> @@ -118,8 +118,9 @@ void IntensityDataCanvas::rotateData() const QString title("Rotate data"); const QString message("Rotation will break the link between the data and the instrument. " "Detector masks or projections, if they exist, will be removed."); - if (!GUI::View::Helpers::question(baWin, title, message, "Do you wish to rotate the data?", - "Yes, please rotate", "No, cancel data rotation")) + if (!GUI::View::Helpers::question(GUI::Global::mainWindow, title, message, + "Do you wish to rotate the data?", "Yes, please rotate", + "No, cancel data rotation")) return; } diff --git a/GUI/View/Job/JobView.cpp b/GUI/View/Job/JobView.cpp index 3e5a9bf476f550470883b07bd7dea5ef439057b4..9947e170c5ab14e5a4664f848d7fedf98f5cf4e6 100644 --- a/GUI/View/Job/JobView.cpp +++ b/GUI/View/Job/JobView.cpp @@ -24,7 +24,7 @@ #include "GUI/View/Job/JobSelectorWidget.h" #include "GUI/View/Job/JobViewActivities.h" #include "GUI/View/Main/MainWindow.h" -#include "GUI/View/Main/ProjectManager.h" +#include "GUI/View/Project/ProjectManager.h" #include <QMenu> JobView::JobView(MainWindow* mainWindow, ProjectDocument* document) diff --git a/GUI/View/Main/ActionManager.cpp b/GUI/View/Main/ActionManager.cpp index 6abb36c394251892f04d4bca5ddacdc4bf11a86e..c1fe2fce0129d9995a01a3491fc530bc98ddf12a 100644 --- a/GUI/View/Main/ActionManager.cpp +++ b/GUI/View/Main/ActionManager.cpp @@ -22,8 +22,7 @@ #include "GUI/View/Job/JobView.h" #include "GUI/View/Main/AboutDialog.h" #include "GUI/View/Main/MainWindow.h" -#include "GUI/View/Main/ProjectManager.h" -#include "GUI/View/Main/PyImportAssistant.h" +#include "GUI/View/Project/ProjectManager.h" #include "GUI/View/SampleDesigner/SampleView.h" #include "GUI/View/Tool/mainwindow_constants.h" #include <QDesktopServices> diff --git a/GUI/View/Main/MainWindow.cpp b/GUI/View/Main/MainWindow.cpp index d720a1b53d2b2c658c071331d965ce271e310b27..df5a164df05279772e920adc4609c2dbb7169923 100644 --- a/GUI/View/Main/MainWindow.cpp +++ b/GUI/View/Main/MainWindow.cpp @@ -22,7 +22,7 @@ #include "GUI/View/Instrument/InstrumentView.h" #include "GUI/View/Job/JobView.h" #include "GUI/View/Main/ActionManager.h" -#include "GUI/View/Main/ProjectManager.h" +#include "GUI/View/Project/ProjectManager.h" #include "GUI/View/SampleDesigner/SampleView.h" #include "GUI/View/Tool/mainwindow_constants.h" #include "GUI/View/Toplevel/ProjectSettingsView.h" @@ -42,15 +42,13 @@ #include <QStatusBar> #include <QToolButton> -MainWindow* MainWindow::s_instance = nullptr; - MainWindow::MainWindow() : QMainWindow(nullptr) , m_progressBar(new QProgressBar) , m_viewSelectionButtons(new QButtonGroup(this)) , m_viewsStack(new QStackedLayout) , m_viewSelectionButtonsLayout(new QVBoxLayout) - , m_projectManager(new ProjectManager(this)) + , m_projectManager(new ProjectManager()) , m_actionManager(new ActionManager(this)) , m_welcomeView(nullptr) , m_instrumentView(nullptr) @@ -61,8 +59,6 @@ MainWindow::MainWindow() , m_jobView(nullptr) , m_sessionModelView(nullptr) { - s_instance = this; - auto* centralWidget = new QWidget(this); auto* mainLayout = new QHBoxLayout(centralWidget); mainLayout->setMargin(0); @@ -102,6 +98,9 @@ MainWindow::MainWindow() connect(m_projectManager, &ProjectManager::documentOpenedOrClosed, this, &MainWindow::onDocumentOpenedOrClosed); + connect(m_projectManager, &ProjectManager::documentModified, this, + &MainWindow::onDocumentModified); + connect(m_projectManager, &ProjectManager::aboutToCloseDocument, this, &MainWindow::onAboutToCloseDocument); @@ -114,15 +113,7 @@ MainWindow::MainWindow() m_projectManager->newProject(); } -MainWindow::~MainWindow() -{ - s_instance = nullptr; -} - -MainWindow* MainWindow::instance() -{ - return s_instance; -} +MainWindow::~MainWindow() = default; QProgressBar* MainWindow::progressBar() { @@ -363,10 +354,17 @@ void MainWindow::updateViewSelectionButtonsGeometry() const m_progressBar->setFixedWidth(buttonExtent); } -void MainWindow::onDocumentOpenedOrClosed() +void MainWindow::onDocumentOpenedOrClosed(bool open) { initViews(); updateTitle(); + if (open) + setCurrentView(MainWindow::PROJECT); +} + +void MainWindow::onDocumentModified() +{ + updateTitle(); } void MainWindow::onAboutToCloseDocument() diff --git a/GUI/View/Main/MainWindow.h b/GUI/View/Main/MainWindow.h index c3c4f958cadc2a2d123fc4513e9eab24b0d56192..a82e6560feb8be08e89a89a0acecabf72bd807a4 100644 --- a/GUI/View/Main/MainWindow.h +++ b/GUI/View/Main/MainWindow.h @@ -45,9 +45,6 @@ public: explicit MainWindow(); ~MainWindow() override; - //! Returns the one and only instance of this class - static MainWindow* instance(); - QProgressBar* progressBar(); ProjectManager* projectManager(); @@ -83,7 +80,8 @@ private: //! Recalculate the size of the view selection buttons to show complete button text void updateViewSelectionButtonsGeometry() const; - void onDocumentOpenedOrClosed(); + void onDocumentOpenedOrClosed(bool open); + void onDocumentModified(); void onAboutToCloseDocument(); void raiseView(int viewId); @@ -105,11 +103,6 @@ private: ProjectSettingsView* m_projectSettingsView; JobView* m_jobView; SessionModelView* m_sessionModelView; - - //! Holds the one and only instance of this class - static MainWindow* s_instance; }; -#define baWin (MainWindow::instance()) - #endif // BORNAGAIN_GUI_VIEW_MAIN_MAINWINDOW_H diff --git a/GUI/View/Main/AutosaveController.cpp b/GUI/View/Project/AutosaveController.cpp similarity index 97% rename from GUI/View/Main/AutosaveController.cpp rename to GUI/View/Project/AutosaveController.cpp index 6b15d8d300f812e30f68cbf7930f1900af34dbd4..40eb8dea19ef9462fb30e8c50cb41b4b5909309c 100644 --- a/GUI/View/Main/AutosaveController.cpp +++ b/GUI/View/Project/AutosaveController.cpp @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit reflection and scattering // -//! @file GUI/View/Main/AutosaveController.cpp +//! @file GUI/View/Project/AutosaveController.cpp //! @brief Implements class AutosaveController //! //! @homepage http://www.bornagainproject.org @@ -12,7 +12,7 @@ // // ************************************************************************************************ -#include "GUI/View/Main/AutosaveController.h" +#include "GUI/View/Project/AutosaveController.h" #include "GUI/Model/IO/ProjectUtils.h" #include "GUI/Model/Project/ProjectDocument.h" #include "GUI/View/Tool/UpdateTimer.h" diff --git a/GUI/View/Main/AutosaveController.h b/GUI/View/Project/AutosaveController.h similarity index 88% rename from GUI/View/Main/AutosaveController.h rename to GUI/View/Project/AutosaveController.h index 06020058140343e1f1ea055f73f2ca738f5c8b18..c49ffbc7c1abe28bb758b099439810fe68c2e2f6 100644 --- a/GUI/View/Main/AutosaveController.h +++ b/GUI/View/Project/AutosaveController.h @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit reflection and scattering // -//! @file GUI/View/Main/AutosaveController.h +//! @file GUI/View/Project/AutosaveController.h //! @brief Defines class AutosaveController //! //! @homepage http://www.bornagainproject.org @@ -12,8 +12,8 @@ // // ************************************************************************************************ -#ifndef BORNAGAIN_GUI_VIEW_MAIN_AUTOSAVECONTROLLER_H -#define BORNAGAIN_GUI_VIEW_MAIN_AUTOSAVECONTROLLER_H +#ifndef BORNAGAIN_GUI_VIEW_PROJECT_AUTOSAVECONTROLLER_H +#define BORNAGAIN_GUI_VIEW_PROJECT_AUTOSAVECONTROLLER_H #include <QObject> @@ -59,4 +59,4 @@ private: UpdateTimer* m_timer; }; -#endif // BORNAGAIN_GUI_VIEW_MAIN_AUTOSAVECONTROLLER_H +#endif // BORNAGAIN_GUI_VIEW_PROJECT_AUTOSAVECONTROLLER_H diff --git a/GUI/View/Main/NewProjectDialog.cpp b/GUI/View/Project/NewProjectDialog.cpp similarity index 98% rename from GUI/View/Main/NewProjectDialog.cpp rename to GUI/View/Project/NewProjectDialog.cpp index 07a5d9109ac8e10d587088cf41e33108fe348ce5..f78a185dbfbc5d0956cab55ad512cf829286f46a 100644 --- a/GUI/View/Main/NewProjectDialog.cpp +++ b/GUI/View/Project/NewProjectDialog.cpp @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit reflection and scattering // -//! @file GUI/View/Main/NewProjectDialog.cpp +//! @file GUI/View/Project/NewProjectDialog.cpp //! @brief Implements class NewProjectDialog //! //! @homepage http://www.bornagainproject.org @@ -12,7 +12,7 @@ // // ************************************************************************************************ -#include "GUI/View/Main/NewProjectDialog.h" +#include "GUI/View/Project/NewProjectDialog.h" #include "GUI/Application/ApplicationSettings.h" #include "GUI/Model/IO/ProjectUtils.h" #include "GUI/Model/Project/ProjectDocument.h" diff --git a/GUI/View/Main/NewProjectDialog.h b/GUI/View/Project/NewProjectDialog.h similarity index 88% rename from GUI/View/Main/NewProjectDialog.h rename to GUI/View/Project/NewProjectDialog.h index ebab71526228fc2a4bf0c2981b8ee5d6fc99cead..e4c83eb7032b2cda02ad6a5a82e3c814557fd928 100644 --- a/GUI/View/Main/NewProjectDialog.h +++ b/GUI/View/Project/NewProjectDialog.h @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit reflection and scattering // -//! @file GUI/View/Main/NewProjectDialog.h +//! @file GUI/View/Project/NewProjectDialog.h //! @brief Defines class NewProjectDialog //! //! @homepage http://www.bornagainproject.org @@ -12,8 +12,8 @@ // // ************************************************************************************************ -#ifndef BORNAGAIN_GUI_VIEW_MAIN_NEWPROJECTDIALOG_H -#define BORNAGAIN_GUI_VIEW_MAIN_NEWPROJECTDIALOG_H +#ifndef BORNAGAIN_GUI_VIEW_PROJECT_NEWPROJECTDIALOG_H +#define BORNAGAIN_GUI_VIEW_PROJECT_NEWPROJECTDIALOG_H #include <QDialog> #include <QLineEdit> @@ -56,4 +56,4 @@ private: bool m_valid_projectPath; }; -#endif // BORNAGAIN_GUI_VIEW_MAIN_NEWPROJECTDIALOG_H +#endif // BORNAGAIN_GUI_VIEW_PROJECT_NEWPROJECTDIALOG_H diff --git a/GUI/View/Main/ProjectManager.cpp b/GUI/View/Project/ProjectManager.cpp similarity index 91% rename from GUI/View/Main/ProjectManager.cpp rename to GUI/View/Project/ProjectManager.cpp index b3f2008bac619a2eae5b1d7a502ce615f968e3f9..0f526e29355df6fecd5bb4d5f478af359a77ac20 100644 --- a/GUI/View/Main/ProjectManager.cpp +++ b/GUI/View/Project/ProjectManager.cpp @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit reflection and scattering // -//! @file GUI/View/Main/ProjectManager.cpp +//! @file GUI/View/Project/ProjectManager.cpp //! @brief Implements class ProjectManager //! //! @homepage http://www.bornagainproject.org @@ -12,7 +12,7 @@ // // ************************************************************************************************ -#include "GUI/View/Main/ProjectManager.h" +#include "GUI/View/Project/ProjectManager.h" #include "Base/Util/Assert.h" #include "GUI/Application/ApplicationSettings.h" #include "GUI/Model/IO/ProjectUtils.h" @@ -21,9 +21,9 @@ #include "GUI/Util/MessageService.h" #include "GUI/View/Info/MessageBox.h" #include "GUI/View/Info/ProjectLoadProblemDialog.h" -#include "GUI/View/Main/MainWindow.h" -#include "GUI/View/Main/NewProjectDialog.h" -#include "GUI/View/Main/SaveService.h" +#include "GUI/View/Global/Globals.h" +#include "GUI/View/Project/NewProjectDialog.h" +#include "GUI/View/Project/SaveService.h" #include "GUI/View/Tool/mainwindow_constants.h" #include <QApplication> #include <QDateTime> @@ -46,8 +46,8 @@ const QString S_LASTUSEDIMPORFILTER2D = "LastUsedImportFilter2D"; ProjectManager* ProjectManager::s_instance = nullptr; -ProjectManager::ProjectManager(MainWindow* parent) - : m_mainWindow(parent), m_saveService(new SaveService(this)) +ProjectManager::ProjectManager() + : m_saveService(new SaveService(this)) { if (s_instance != nullptr) @@ -195,13 +195,6 @@ void ProjectManager::setAutosaveEnabled(bool value) settings.setValue(S_PROJECTMANAGER + "/" + S_AUTOSAVE, value); } -//! Updates title of main window when the project was modified. - -void ProjectManager::onDocumentModified() -{ - m_mainWindow->updateTitle(); -} - //! Clears list of recent projects. void ProjectManager::clearRecentProjects() @@ -216,10 +209,8 @@ void ProjectManager::newProject() { if (!closeCurrentProject()) return; - createNewProject(); - emit documentOpenedOrClosed(); - m_mainWindow->setCurrentView(MainWindow::PROJECT); + emit documentOpenedOrClosed(true); } //! Processes close current project request. Call save/discard/cancel dialog, if necessary. @@ -252,7 +243,7 @@ bool ProjectManager::closeCurrentProject() } deleteCurrentProject(); - emit documentOpenedOrClosed(); + emit documentOpenedOrClosed(false); return true; } @@ -277,7 +268,7 @@ bool ProjectManager::saveProject(QString projectFileName) message.append("Exception was thrown.\n\n"); message.append(ex.what()); - QMessageBox::warning(m_mainWindow, "Error while saving project", message); + QMessageBox::warning(GUI::Global::mainWindow, "Error while saving project", message); return false; } @@ -307,7 +298,7 @@ void ProjectManager::openProject(QString fileName) if (fileName.isEmpty()) { fileName = QFileDialog::getOpenFileName( - m_mainWindow, "Open project file", workingDirectory(), + GUI::Global::mainWindow, "Open project file", workingDirectory(), "BornAgain project Files (*.pro)", nullptr, appSettings->useNativeFileDialog() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog); @@ -329,10 +320,8 @@ void ProjectManager::openProject(QString fileName) riseProjectLoadProblemDialog(messageService); addToRecentProjects(); } - if (gSessionData->projectDocument != nullptr) { - emit documentOpenedOrClosed(); - m_mainWindow->setCurrentView(MainWindow::PROJECT); - } + if (gSessionData->projectDocument != nullptr) + emit documentOpenedOrClosed(true); } //! Calls dialog window to define project path and name. @@ -356,8 +345,8 @@ void ProjectManager::createNewProject() m_saveService->setDocument(gSessionData->projectDocument); - connect(gSessionData->projectDocument, &ProjectDocument::modified, this, - &ProjectManager::onDocumentModified); + connect(gSessionData->projectDocument, &ProjectDocument::modified, + [this]() { emit documentModified(); }); } void ProjectManager::deleteCurrentProject() @@ -397,7 +386,7 @@ ProjectDocument::ReadResult ProjectManager::loadProject(const QString& projectFi QString ProjectManager::acquireProjectFileName() { - NewProjectDialog dialog(m_mainWindow, workingDirectory(), untitledProjectName()); + NewProjectDialog dialog(GUI::Global::mainWindow, workingDirectory(), untitledProjectName()); if (dialog.exec() != QDialog::Accepted) return ""; @@ -457,14 +446,14 @@ void ProjectManager::riseProjectLoadFailedDialog(const MessageService& messageSe for (const auto& details : messageService.errors()) message.append(details + "\n"); - QMessageBox::warning(m_mainWindow, "Error while opening project file", message); + QMessageBox::warning(GUI::Global::mainWindow, "Error while opening project file", message); } void ProjectManager::riseProjectLoadProblemDialog(const MessageService& messageService) { ASSERT(gSessionData->projectDocument); auto* problemDialog = - new ProjectLoadProblemDialog(m_mainWindow, messageService.warnings(true), + new ProjectLoadProblemDialog(GUI::Global::mainWindow, messageService.warnings(true), gSessionData->projectDocument->documentVersion()); problemDialog->show(); @@ -488,7 +477,7 @@ bool ProjectManager::restoreProjectDialog(const QString& projectFileName, .arg(lmProject) .arg(lmAutoSave); - return GUI::View::Helpers::question(m_mainWindow, title, message, + return GUI::View::Helpers::question(GUI::Global::mainWindow, title, message, "\nDo you want to restore from autosave?\n", "Yes, please restore.", "No, keep loading original"); } diff --git a/GUI/View/Main/ProjectManager.h b/GUI/View/Project/ProjectManager.h similarity index 89% rename from GUI/View/Main/ProjectManager.h rename to GUI/View/Project/ProjectManager.h index 1ec66f7e3f342df674584fadabaf510a58eaf8e0..d4a2ab110142efac42422371c13a284f25758e11 100644 --- a/GUI/View/Main/ProjectManager.h +++ b/GUI/View/Project/ProjectManager.h @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit reflection and scattering // -//! @file GUI/View/Main/ProjectManager.h +//! @file GUI/View/Project/ProjectManager.h //! @brief Defines class ProjectManager //! //! @homepage http://www.bornagainproject.org @@ -12,8 +12,8 @@ // // ************************************************************************************************ -#ifndef BORNAGAIN_GUI_VIEW_MAIN_PROJECTMANAGER_H -#define BORNAGAIN_GUI_VIEW_MAIN_PROJECTMANAGER_H +#ifndef BORNAGAIN_GUI_VIEW_PROJECT_PROJECTMANAGER_H +#define BORNAGAIN_GUI_VIEW_PROJECT_PROJECTMANAGER_H #include "GUI/Model/Project/ProjectDocument.h" #include <QObject> @@ -28,7 +28,7 @@ class SaveService; class ProjectManager : public QObject { Q_OBJECT public: - ProjectManager(MainWindow* parent); + ProjectManager(); ~ProjectManager() override; static ProjectManager* instance(); @@ -50,12 +50,12 @@ public: signals: void aboutToCloseDocument(); - void documentOpenedOrClosed(); + void documentOpenedOrClosed(bool); + void documentModified(); void recentListModified(); public slots: void setAutosaveEnabled(bool value); - void onDocumentModified(); void clearRecentProjects(); void newProject(); bool closeCurrentProject(); @@ -78,8 +78,6 @@ private: void riseProjectLoadProblemDialog(const MessageService& messageService); bool restoreProjectDialog(const QString& projectFileName, QString autosaveName); - MainWindow* m_mainWindow; - //!< Name of directory where project directory was created. QString m_workingDirectory; @@ -98,4 +96,4 @@ private: static ProjectManager* s_instance; }; -#endif // BORNAGAIN_GUI_VIEW_MAIN_PROJECTMANAGER_H +#endif // BORNAGAIN_GUI_VIEW_PROJECT_PROJECTMANAGER_H diff --git a/GUI/View/Main/PyImportAssistant.cpp b/GUI/View/Project/PyImportAssistant.cpp similarity index 88% rename from GUI/View/Main/PyImportAssistant.cpp rename to GUI/View/Project/PyImportAssistant.cpp index 337a28478acde92710f0ff1edc72be1fe69cd57d..c6ad7abf8dc12305343d09c65af085f3bb267090 100644 --- a/GUI/View/Main/PyImportAssistant.cpp +++ b/GUI/View/Project/PyImportAssistant.cpp @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit reflection and scattering // -//! @file GUI/View/Main/PyImportAssistant.cpp +//! @file GUI/View/Project/PyImportAssistant.cpp //! @brief Implements class PyImportAssistant //! //! @homepage http://www.bornagainproject.org @@ -14,7 +14,7 @@ #ifdef BORNAGAIN_PYTHON -#include "GUI/View/Main/PyImportAssistant.h" +#include "GUI/View/Project/PyImportAssistant.h" #include "BABuild.h" #include "Base/Util/Assert.h" #include "Base/Util/SysUtils.h" @@ -23,11 +23,11 @@ #include "GUI/Model/IO/ProjectUtils.h" #include "GUI/Util/Path.h" #include "GUI/Util/String.h" +#include "GUI/View/Global/Globals.h" #include "GUI/View/Info/ComboSelectorDialog.h" #include "GUI/View/Info/DetailedMessageBox.h" #include "GUI/View/Info/MessageBox.h" -#include "GUI/View/Main/MainWindow.h" -#include "GUI/View/Main/ProjectManager.h" +#include "GUI/View/Project/ProjectManager.h" #include "Sample/Multilayer/MultiLayer.h" #include "Sample/Multilayer/PyImport.h" #include <QApplication> @@ -69,7 +69,7 @@ QString fileNameToOpen() QString dirname = ProjectManager::instance()->userImportDir(); QString result = QFileDialog::getOpenFileName( - baWin, "Open python script", dirname, "Python scripts (*.py)", nullptr, + GUI::Global::mainWindow, "Open python script", dirname, "Python scripts (*.py)", nullptr, appSettings->useNativeFileDialog() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog); @@ -91,7 +91,7 @@ QString readFile(const QString& fileName) const QString message = "Can't read the file. \n\nPyImportAssistant::readFile -> Error: Can' t open the file '" + fileName + "' for reading."; - GUI::View::Helpers::warning(baWin, "File read failure.", message); + GUI::View::Helpers::warning(GUI::Global::mainWindow, "File read failure.", message); return {}; } @@ -110,7 +110,7 @@ std::unique_ptr<MultiLayer> createMultiLayer(const QString& snippet, const QStri QApplication::restoreOverrideCursor(); QString message("Exception thrown while executing Python code to create multilayer.\n\n"); QString details = QString::fromStdString(std::string(ex.what())); - DetailedMessageBox(baWin, "Python failure", message, details).exec(); + DetailedMessageBox(GUI::Global::mainWindow, "Python failure", message, details).exec(); } QApplication::restoreOverrideCursor(); @@ -125,7 +125,7 @@ QString selectPySampleFunction(const QStringList& funcNames) if (funcNames.empty()) { QString message("Python code doesn't contain any functions.\n\n"); - GUI::View::Helpers::warning(baWin, "Python failure", message); + GUI::View::Helpers::warning(GUI::Global::mainWindow, "Python failure", message); } else if (funcNames.size() == 1) return funcNames.front(); else { @@ -157,7 +157,7 @@ QString getPySampleFunctionName(const QString& snippet) QApplication::restoreOverrideCursor(); QString message("Exception thrown while acquiring functions from Python code.\n\n"); QString details = QString::fromStdString(std::string(ex.what())); - DetailedMessageBox(baWin, "Python failure", message, details).exec(); + DetailedMessageBox(GUI::Global::mainWindow, "Python failure", message, details).exec(); return ""; } @@ -206,13 +206,15 @@ MultiLayerItem* PyImportAssistant::populateModels(SampleModel* sampleModel, QString message("Seems that import was successful.\n\n" "Check SampleView for new sample and material editor for new materials."); - GUI::View::Helpers::information(baWin, "Python import", message); + GUI::View::Helpers::information(GUI::Global::mainWindow, "Python import", message); return newItem; } catch (const std::exception& ex) { QString message("Exception thrown while trying to build GUI models.\n" "GUI models might be in inconsistent state.\n\n"); QString details = QString::fromStdString(std::string(ex.what())); - DetailedMessageBox(baWin, "GUI::Model::ObjectBuilder failure", message, details).exec(); + DetailedMessageBox(GUI::Global::mainWindow, "GUI::Model::ObjectBuilder failure", message, + details) + .exec(); return nullptr; } } diff --git a/GUI/View/Main/PyImportAssistant.h b/GUI/View/Project/PyImportAssistant.h similarity index 84% rename from GUI/View/Main/PyImportAssistant.h rename to GUI/View/Project/PyImportAssistant.h index 03aef4efa759430e9e75ed47cdf3fe74857389d0..84f456a42b51ec3ad483d166bc6d0949a779e609 100644 --- a/GUI/View/Main/PyImportAssistant.h +++ b/GUI/View/Project/PyImportAssistant.h @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit reflection and scattering // -//! @file GUI/View/Main/PyImportAssistant.h +//! @file GUI/View/Project/PyImportAssistant.h //! @brief Implements class PyImportAssistant //! //! @homepage http://www.bornagainproject.org @@ -12,8 +12,8 @@ // // ************************************************************************************************ -#ifndef BORNAGAIN_GUI_VIEW_MAIN_PYIMPORTASSISTANT_H -#define BORNAGAIN_GUI_VIEW_MAIN_PYIMPORTASSISTANT_H +#ifndef BORNAGAIN_GUI_VIEW_PROJECT_PYIMPORTASSISTANT_H +#define BORNAGAIN_GUI_VIEW_PROJECT_PYIMPORTASSISTANT_H #ifdef BORNAGAIN_PYTHON @@ -40,4 +40,4 @@ MultiLayerItem* populateModels(SampleModel* sampleModel, MaterialModel* material #endif // BORNAGAIN_PYTHON -#endif // BORNAGAIN_GUI_VIEW_MAIN_PYIMPORTASSISTANT_H +#endif // BORNAGAIN_GUI_VIEW_PROJECT_PYIMPORTASSISTANT_H diff --git a/GUI/View/Main/SaveService.cpp b/GUI/View/Project/SaveService.cpp similarity index 95% rename from GUI/View/Main/SaveService.cpp rename to GUI/View/Project/SaveService.cpp index f63724d007ea8924d3808348c85d6613b1c1f5d8..85d777a72726f14153cba3a873484818ab4e3e66 100644 --- a/GUI/View/Main/SaveService.cpp +++ b/GUI/View/Project/SaveService.cpp @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit reflection and scattering // -//! @file GUI/View/Main/SaveService.cpp +//! @file GUI/View/Project/SaveService.cpp //! @brief Implements class SaveService //! //! @homepage http://www.bornagainproject.org @@ -12,13 +12,13 @@ // // ************************************************************************************************ -#include "GUI/View/Main/SaveService.h" +#include "GUI/View/Project/SaveService.h" #include "Base/Util/Assert.h" #include "GUI/Model/IO/ProjectUtils.h" #include "GUI/Model/Project/ProjectDocument.h" #include "GUI/Util/Error.h" -#include "GUI/View/Main/AutosaveController.h" -#include "GUI/View/Main/SaveThread.h" +#include "GUI/View/Project/AutosaveController.h" +#include "GUI/View/Project/SaveThread.h" #include <QApplication> #include <QCoreApplication> #include <QTime> diff --git a/GUI/View/Main/SaveService.h b/GUI/View/Project/SaveService.h similarity index 87% rename from GUI/View/Main/SaveService.h rename to GUI/View/Project/SaveService.h index 01729f5f145ef142b34ff393e93d9a40f5995714..4e1648ecb563497de6eb5ba69ab0af18899a90d2 100644 --- a/GUI/View/Main/SaveService.h +++ b/GUI/View/Project/SaveService.h @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit reflection and scattering // -//! @file GUI/View/Main/SaveService.h +//! @file GUI/View/Project/SaveService.h //! @brief Defines class SaveService //! //! @homepage http://www.bornagainproject.org @@ -12,8 +12,8 @@ // // ************************************************************************************************ -#ifndef BORNAGAIN_GUI_VIEW_MAIN_SAVESERVICE_H -#define BORNAGAIN_GUI_VIEW_MAIN_SAVESERVICE_H +#ifndef BORNAGAIN_GUI_VIEW_PROJECT_SAVESERVICE_H +#define BORNAGAIN_GUI_VIEW_PROJECT_SAVESERVICE_H #include <QObject> #include <QQueue> @@ -61,4 +61,4 @@ private: ProjectDocument* m_document; }; -#endif // BORNAGAIN_GUI_VIEW_MAIN_SAVESERVICE_H +#endif // BORNAGAIN_GUI_VIEW_PROJECT_SAVESERVICE_H diff --git a/GUI/View/Main/SaveThread.cpp b/GUI/View/Project/SaveThread.cpp similarity index 92% rename from GUI/View/Main/SaveThread.cpp rename to GUI/View/Project/SaveThread.cpp index 863634697f862bc5dfbeef12a8757d1ba0e1d69a..5c291360db800fc36e85e3923b2dd21d9d173941 100644 --- a/GUI/View/Main/SaveThread.cpp +++ b/GUI/View/Project/SaveThread.cpp @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit reflection and scattering // -//! @file GUI/View/Main/SaveThread.cpp +//! @file GUI/View/Project/SaveThread.cpp //! @brief Defines SaveThread classes //! //! @homepage http://www.bornagainproject.org @@ -12,7 +12,7 @@ // // ************************************************************************************************ -#include "GUI/View/Main/SaveThread.h" +#include "GUI/View/Project/SaveThread.h" #include "Base/Util/Assert.h" #include "GUI/Model/Project/ProjectDocument.h" diff --git a/GUI/View/Main/SaveThread.h b/GUI/View/Project/SaveThread.h similarity index 84% rename from GUI/View/Main/SaveThread.h rename to GUI/View/Project/SaveThread.h index afa5f99881d8ba476bb04bf748833462f69a0cfe..a3c0995bb8e3d8fa9992957c350512647863f3e7 100644 --- a/GUI/View/Main/SaveThread.h +++ b/GUI/View/Project/SaveThread.h @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit reflection and scattering // -//! @file GUI/View/Main/SaveThread.h +//! @file GUI/View/Project/SaveThread.h //! @brief Defines SaveThread classes //! //! @homepage http://www.bornagainproject.org @@ -12,8 +12,8 @@ // // ************************************************************************************************ -#ifndef BORNAGAIN_GUI_VIEW_MAIN_SAVETHREAD_H -#define BORNAGAIN_GUI_VIEW_MAIN_SAVETHREAD_H +#ifndef BORNAGAIN_GUI_VIEW_PROJECT_SAVETHREAD_H +#define BORNAGAIN_GUI_VIEW_PROJECT_SAVETHREAD_H #include <QObject> #include <QThread> @@ -40,4 +40,4 @@ private: QString m_projectFile; }; -#endif // BORNAGAIN_GUI_VIEW_MAIN_SAVETHREAD_H +#endif // BORNAGAIN_GUI_VIEW_PROJECT_SAVETHREAD_H diff --git a/GUI/View/SampleDesigner/MaterialInplaceForm.cpp b/GUI/View/SampleDesigner/MaterialInplaceForm.cpp index 7a123f8a54c847645211b4f0e3f6a284c5077ab9..b69235986e13e316e0cd19f217b2d77c57016054 100644 --- a/GUI/View/SampleDesigner/MaterialInplaceForm.cpp +++ b/GUI/View/SampleDesigner/MaterialInplaceForm.cpp @@ -21,7 +21,7 @@ #include "GUI/Model/Types/VectorDescriptor.h" #include "GUI/View/Edit/DoubleLineEdit.h" #include "GUI/View/Edit/DoubleSpinBox.h" -#include "GUI/View/Main/MainWindow.h" +#include "GUI/View/Global/Globals.h" #include "GUI/View/MaterialEditor/MaterialEditorDialog.h" #include "GUI/View/SampleDesigner/LayerEditorUtils.h" #include "GUI/View/SampleDesigner/SampleEditorController.h" @@ -63,7 +63,7 @@ void MaterialInplaceForm::updateValues() void MaterialInplaceForm::selectMaterial() { const QString newMaterialIdentifier = MaterialEditorDialog::chooseMaterial( - baWin, m_ec->projectDocument(), m_item->materialIdentifier()); + GUI::Global::mainWindow, m_ec->projectDocument(), m_item->materialIdentifier()); if (!newMaterialIdentifier.isEmpty() && newMaterialIdentifier != m_item->materialIdentifier()) { itemWithMaterial()->materialItem()->disconnect(this); diff --git a/GUI/View/Toplevel/SessionModelView.cpp b/GUI/View/Toplevel/SessionModelView.cpp index 767c0600b5f262a1739b81e0bfce06c12e681d40..9c9f20a0a859c37c24a5ccd2bbc80a98506570e9 100644 --- a/GUI/View/Toplevel/SessionModelView.cpp +++ b/GUI/View/Toplevel/SessionModelView.cpp @@ -21,7 +21,7 @@ #include "GUI/Model/Sample/SampleModel.h" #include "GUI/Model/Session/SessionDecorationModel.h" #include "GUI/Util/ComboProperty.h" -#include "GUI/View/Main/ProjectManager.h" +#include "GUI/View/Project/ProjectManager.h" #include "GUI/View/Tool/StyleUtils.h" #include <QApplication> #include <QStyledItemDelegate> diff --git a/GUI/View/Toplevel/SimulationView.cpp b/GUI/View/Toplevel/SimulationView.cpp index a1626b83bcae0470e85a41aadd24b817504dfec1..65800b4c50b98624730b84d039ccb5614ccaeb6e 100644 --- a/GUI/View/Toplevel/SimulationView.cpp +++ b/GUI/View/Toplevel/SimulationView.cpp @@ -24,8 +24,8 @@ #include "GUI/Model/Sample/SampleModel.h" #include "GUI/Model/Sample/SampleValidator.h" #include "GUI/Model/Session/SimulationOptionsItem.h" -#include "GUI/View/Main/MainWindow.h" -#include "GUI/View/Main/ProjectManager.h" +#include "GUI/View/Global/Globals.h" +#include "GUI/View/Project/ProjectManager.h" #include "GUI/View/Script/PythonScriptWidget.h" #include "GUI/View/Tool/GroupBoxCollapser.h" #include "ui_SimulationView.h" @@ -157,7 +157,7 @@ void SimulationView::exportPythonScript() "Can't export to Python with current settings\n\n" + msg); return; } - auto* pythonWidget = new PythonScriptWidget(baWin); + auto* pythonWidget = new PythonScriptWidget(GUI::Global::mainWindow); pythonWidget->show(); pythonWidget->raise(); pythonWidget->generatePythonScript(selectedSample(), selectedInstrument(), *optionsItem(), diff --git a/GUI/View/Toplevel/WelcomeView.cpp b/GUI/View/Toplevel/WelcomeView.cpp index f894683468f29e287d8a0ac9fe20e3305190ea4a..e950888396f661a56c44f4d36f9d6e682013c0f1 100644 --- a/GUI/View/Toplevel/WelcomeView.cpp +++ b/GUI/View/Toplevel/WelcomeView.cpp @@ -14,7 +14,7 @@ #include "GUI/View/Toplevel/WelcomeView.h" #include "GUI/Util/Path.h" -#include "GUI/View/Main/ProjectManager.h" +#include "GUI/View/Project/ProjectManager.h" #include "GUI/View/Tool/GroupBoxCollapser.h" #include "GUI/View/Tool/LayoutUtils.h" #include "ui_WelcomeView.h" diff --git a/Sample/Particle/Particle.h b/Sample/Particle/Particle.h index 474ccd9775415257eddb1f0f9ec05df97f33a96d..74d6d9ff36e409cabee3cad7de091285732f8f77 100644 --- a/Sample/Particle/Particle.h +++ b/Sample/Particle/Particle.h @@ -16,8 +16,8 @@ #define BORNAGAIN_SAMPLE_PARTICLE_PARTICLE_H #include "Sample/Material/Material.h" -#include "Sample/Particle/IParticle.h" #include "Sample/Particle/IBornFF.h" +#include "Sample/Particle/IParticle.h" //! A particle with a form factor and refractive index. //! @ingroup samples diff --git a/Tests/Unit/GUI/TestSaveService.cpp b/Tests/Unit/GUI/TestSaveService.cpp index e46c32dc8b3690560080e4df4f5620ab2531c3dc..172b8fc9ee815385ca4bbc53dcac617d56f7bf59 100644 --- a/Tests/Unit/GUI/TestSaveService.cpp +++ b/Tests/Unit/GUI/TestSaveService.cpp @@ -8,8 +8,8 @@ #include "GUI/Model/Project/ProjectDocument.h" #include "GUI/Util/Error.h" #include "GUI/Util/Path.h" -#include "GUI/View/Main/AutosaveController.h" -#include "GUI/View/Main/SaveService.h" +#include "GUI/View/Project/AutosaveController.h" +#include "GUI/View/Project/SaveService.h" #include "Tests/GTestWrapper/google_test.h" #include "Tests/Unit/GUI/Utils.h" #include <QSignalSpy>