BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
main.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file App/main.cpp
6 //! @brief Main function of the whole GUI
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #include "App/AppOptions.h"
16 #include "App/MessageHandler.h"
19 #include "GUI/Util/Path.h"
23 #include "config_build.h"
24 #include <QDir>
25 #include <QIcon>
26 #include <QLocale>
27 #include <QMessageBox>
28 #include <QMetaType>
29 
30 void messageHandler(QtMsgType, const QMessageLogContext&, const QString&) {}
31 
32 int main(int argc, char* argv[])
33 {
34  ApplicationOptions options(argc, argv);
35 
36  QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
37  qRegisterMetaType<QVector<double>>("QVector<double>");
38 
39  if (!options.disableHighDPISupport())
40  QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
41 
42  QApplication app(argc, argv);
43  QApplication::setApplicationName("BornAgain");
44  QApplication::setApplicationVersion(GUI::Util::Path::getBornAgainVersionString());
45  QApplication::setOrganizationName("BornAgain");
46 #ifndef Q_OS_MAC
47  QApplication::setWindowIcon(QIcon(":/images/BornAgain.ico"));
48 #endif
49 
50  ApplicationSettings applicationSettings;
51  SessionData GSession;
52 
53  qInstallMessageHandler(MessageHandler);
54 
56 
57  auto style = applicationSettings.styleToUse();
58  applicationSettings.loadStyle(style);
59 
60  QString dir = GUI::Util::Path::appDataFolder();
61  if (!QDir().exists(dir))
62  QDir().mkpath(dir);
63 
64  GSession.instrumentLibrary.load();
65 
66  MainWindow win;
68  if (options.find("geometry"))
69  win.resize(options.mainWindowSize());
70 
71  win.show();
72 
73  int result = QApplication::exec();
74 
76 
77  return result;
78 }
Collection of utilities to parse command line options.
Defines class ApplicationSettings.
void register1DDataLoaders()
register the concrete data loaders with the registration facility
Utility functions for data loaders.
Defines global pointers.
Defines class MainWindow.
void MessageHandler(QtMsgType type, const QMessageLogContext &, const QString &msg)
This is set by main to be the message handler of our GUI.
Declares function MessageHandler.
Defines class Helpers functions.
Defines struct SessionData.
Handles command line and config file program options.
Definition: AppOptions.h:31
bool find(std::string name) const
Returns true if option with given name has been set.
Definition: AppOptions.cpp:81
bool disableHighDPISupport() const
Definition: AppOptions.cpp:151
QSize mainWindowSize() const
Definition: AppOptions.cpp:145
Application wide settings.
void loadStyle(ApplicationSettings::Style style)
int main(int argc, char *argv[])
Definition: main.cpp:32
void messageHandler(QtMsgType, const QMessageLogContext &, const QString &)
Definition: main.cpp:30
static QMainWindow * mainWindow
Definition: Globals.h:22
QString appDataFolder()
The folder where persistent application data shall be stored. Under Windows this is the AppData/Roami...
Definition: Path.cpp:139
QString getBornAgainVersionString()
Definition: Path.cpp:60
InstrumentLibrary instrumentLibrary
Definition: SessionData.h:26