diff --git a/App/main.cpp b/App/main.cpp index f017b48da80c0e31982c0028fd27568d99f28948..4445f715426838b003128efd0859ad0bf91ba956 100644 --- a/App/main.cpp +++ b/App/main.cpp @@ -18,7 +18,6 @@ #include "GUI/Support/Util/Path.h" #include "GUI/View/Layout/AppConfig.h" #include "GUI/View/Main/MainWindow.h" -#include "GUI/View/Tool/Globals.h" #include "config_build.h" #include <QApplication> #include <QDir> @@ -73,7 +72,7 @@ int main(int argc, char* argv[]) gDoc = std::make_unique<ProjectDocument>(); MainWindow win; - GUI::Global::mainWindow = &win; + gApp->mainWindow = &win; if (options.find("geometry")) win.resize(options.mainWindowSize()); diff --git a/GUI/View/Layout/AppConfig.h b/GUI/View/Layout/AppConfig.h index a5a930ea6e106b95cab08db4c7041413845ae665..4afcf3ff3d78f8fc7e20f38fd8e2f89dea4dfa37 100644 --- a/GUI/View/Layout/AppConfig.h +++ b/GUI/View/Layout/AppConfig.h @@ -26,6 +26,8 @@ public: bool useNativeFileDialog() const; + class QWidget* mainWindow; //!< Pointer to _the_ MainWindow + QString import_filter_1D; //!< Last used import filter for 1D files QString import_filter_2D; //!< Last used import filter for 2D files diff --git a/GUI/View/Manager/ProjectManager.cpp b/GUI/View/Manager/ProjectManager.cpp index 418f92f95ff6065746fdcbbb8d13ff414f815380..7f2ca3e6b9dac46bee4ef59836cca740be6cad7f 100644 --- a/GUI/View/Manager/ProjectManager.cpp +++ b/GUI/View/Manager/ProjectManager.cpp @@ -20,7 +20,6 @@ #include "GUI/View/Info/MessageBox.h" #include "GUI/View/Layout/AppConfig.h" #include "GUI/View/Manager/NewProjectDialog.h" -#include "GUI/View/Tool/Globals.h" #include <QApplication> #include <QDateTime> #include <QFileDialog> @@ -174,7 +173,7 @@ bool ProjectManager::saveProject(QString projectPullPath) message.append("Exception was thrown.\n\n"); message.append(ex.what()); - QMessageBox::warning(GUI::Global::mainWindow, "Error while saving project", message); + QMessageBox::warning(gApp->mainWindow, "Error while saving project", message); return false; } addToRecentProjects(); @@ -200,7 +199,7 @@ void ProjectManager::openProject(QString projectPullPath) if (projectPullPath.isEmpty()) { const QString ext = QString(GUI::Util::Project::projectFileExtension); projectPullPath = QFileDialog::getOpenFileName( - GUI::Global::mainWindow, "Open project file", m_working_directory, + gApp->mainWindow, "Open project file", m_working_directory, "BornAgain project Files (*" + ext + ")", nullptr, gApp->useNativeFileDialog() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog); @@ -247,7 +246,7 @@ void ProjectManager::loadProject(const QString& fullPathAndName) QString ProjectManager::acquireProjectPullPath() { - NewProjectDialog dialog(GUI::Global::mainWindow, m_working_directory, untitledProjectName()); + NewProjectDialog dialog(gApp->mainWindow, m_working_directory, untitledProjectName()); if (dialog.exec() != QDialog::Accepted) return ""; @@ -306,7 +305,7 @@ bool ProjectManager::restoreProjectDialog(const QString& projectFileName, .arg(lmProject) .arg(lmAutoSave); - return GUI::Message::question(GUI::Global::mainWindow, title, message, + return GUI::Message::question(gApp->mainWindow, title, message, "\nDo you want to restore from autosave?\n", "Yes, please restore.", "No, keep loading original"); } diff --git a/GUI/View/Manager/PyImportAssistant.cpp b/GUI/View/Manager/PyImportAssistant.cpp index 2143a44edd0c7b6a39b10aba703209363058ab0e..4576c0683edd02f6f5718f710d2e29898dfab5c9 100644 --- a/GUI/View/Manager/PyImportAssistant.cpp +++ b/GUI/View/Manager/PyImportAssistant.cpp @@ -27,7 +27,6 @@ #include "GUI/View/Info/DetailedMessageBox.h" #include "GUI/View/Info/MessageBox.h" #include "GUI/View/Layout/AppConfig.h" -#include "GUI/View/Tool/Globals.h" #include "PyCore/Embed/PyInterpreter.h" // listOfFunctions #include "PyCore/Sample/ImportMultiLayer.h" // createMultiLayerFromPython #include "Sample/Multilayer/MultiLayer.h" @@ -69,8 +68,8 @@ QString getCandidate(const QStringList& funcNames) QString fnameToOpen() { QString result = QFileDialog::getOpenFileName( - GUI::Global::mainWindow, "Open python script", gApp->script_import_dir, - "Python scripts (*.py)", nullptr, + gApp->mainWindow, "Open python script", gApp->script_import_dir, "Python scripts (*.py)", + nullptr, gApp->useNativeFileDialog() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog); return result; @@ -88,7 +87,7 @@ QString readFile(const QString& fname) const QString message = "Cannot read the file. \n\nPyImportAssistant::readFile -> Error: Can' t open the file '" + fname + "' for reading."; - GUI::Message::warning(GUI::Global::mainWindow, "File read failure.", message); + GUI::Message::warning(gApp->mainWindow, "File read failure.", message); return {}; } @@ -115,7 +114,7 @@ QString selectPySampleFunction(const QStringList& funcNames) if (funcNames.empty()) { QString message("Python code doesn't contain any functions.\n\n"); - GUI::Message::warning(GUI::Global::mainWindow, "Python failure", message); + GUI::Message::warning(gApp->mainWindow, "Python failure", message); } else { ComboSelectorDialog dialog; dialog.addItems(funcNames, getCandidate(funcNames)); @@ -144,7 +143,7 @@ QString getPySampleFunctionName(const QString& snippet) if (funcs_res.empty()) { QString message("Exception thrown while acquiring functions from Python code.\n\n"); - DetailedMessageBox(GUI::Global::mainWindow, "Python failure", message, "").exec(); + DetailedMessageBox(gApp->mainWindow, "Python failure", message, "").exec(); return ""; } @@ -159,14 +158,13 @@ SampleItem* itemizeSample(const MultiLayer& sample) QString message("Seems that import was successful.\n\n" "Check SampleView for new sample and material editor for new materials."); - GUI::Message::information(GUI::Global::mainWindow, "Python import", message); + GUI::Message::information(gApp->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(GUI::Global::mainWindow, "GUI::ObjectBuilder failure", message, details) - .exec(); + DetailedMessageBox(gApp->mainWindow, "GUI::ObjectBuilder failure", message, details).exec(); return nullptr; } } diff --git a/GUI/View/Tool/Globals.h b/GUI/View/Tool/Globals.h deleted file mode 100644 index ce87ddd23b2eeb8701b9518679a931c42c52ab68..0000000000000000000000000000000000000000 --- a/GUI/View/Tool/Globals.h +++ /dev/null @@ -1,26 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/Tool/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_TOOL_GLOBALS_H -#define BORNAGAIN_GUI_VIEW_TOOL_GLOBALS_H - -class QWidget; - -namespace GUI::Global { - -inline class QWidget* mainWindow; - -} // namespace GUI::Global - -#endif // BORNAGAIN_GUI_VIEW_TOOL_GLOBALS_H diff --git a/GUI/View/Views/SimulationView.cpp b/GUI/View/Views/SimulationView.cpp index 8b47b8246eb5677080a782dafaf92f737620017f..a77dcd8ad8b78b963007d07b46d381b8ac1a7537 100644 --- a/GUI/View/Views/SimulationView.cpp +++ b/GUI/View/Views/SimulationView.cpp @@ -22,8 +22,8 @@ #include "GUI/Model/Sample/SampleValidator.h" #include "GUI/Model/Sample/SamplesSet.h" #include "GUI/Support/Data/SimulationOptionsItem.h" +#include "GUI/View/Layout/AppConfig.h" #include "GUI/View/Loader/PythonScriptWidget.h" -#include "GUI/View/Tool/Globals.h" #include "GUI/View/Widget/GroupBoxes.h" #include <QButtonGroup> #include <QFormLayout> @@ -259,7 +259,7 @@ void SimulationView::simulate() void SimulationView::exportPythonScript() { readOptionsFromUI(); - auto* pythonWidget = new PythonScriptWidget(GUI::Global::mainWindow); + auto* pythonWidget = new PythonScriptWidget(gApp->mainWindow); pythonWidget->show(); pythonWidget->raise(); pythonWidget->generatePythonScript(gDoc->samples()->currentItem(),