17 #include <QApplication>
18 #include <QMessageBox>
20 #include <QStringList>
21 #include <boost/program_options/config.hpp>
22 #include <boost/program_options/parsers.hpp>
28 const char* geometry =
"geometry";
29 const char* nohighdpi =
"nohighdpi";
32 QSize windowSize(
const QString& size_string)
34 QStringList list = size_string.split(
"x");
39 return QSize(list[0].toInt(), list[1].toInt());
43 bool isValid(
const QSize& win_size)
45 return win_size.width() > 640 && win_size.height() > 480;
48 void exitWithGuiMessage(
const QString msg)
51 QApplication a(argc,
nullptr);
62 m_options.add_options()(
"help,h",
"print help message and exit");
63 m_options.add_options()(
"version,v",
"print version and exit");
64 m_options.add_options()(
"with-debug",
"run application with debug printout");
65 m_options.add_options()(geometry, bpo::value<std::string>(),
66 "Main window geometry, e.g. 1600x1000");
67 m_options.add_options()(nohighdpi,
"Run without high-dpi support");
95 bpo::store(bpo::command_line_parser(argc, argv)
105 }
catch (std::exception& e) {
107 s <<
"BornAgain was launched with invalid command line option.\n"
108 <<
"Parser error message: " << e.what() <<
".\n"
109 <<
"Available options:\n"
111 exitWithGuiMessage(QString::fromStdString(s.str()));
128 std::cout <<
"BornAgain Graphical User Interface" << std::endl;
141 exitWithGuiMessage(
"Wrong window size, try --geometry=1600x900\n");
147 QString size_str = QString::fromStdString(
m_variables_map[geometry].as<std::string>());
148 return windowSize(size_str);
153 return find(nohighdpi);
Collection of utilities to parse command line options.
Defines class Helpers functions.
bool find(std::string name) const
Returns true if option with given name has been set.
bpo::variables_map & getVariables()
Returns reference to the variables container.
void parseCommandLine(int argc, char **argv)
Parses command line arguments.
bpo::options_description & getOptions()
Returns reference to the options description.
bpo::options_description m_options
options description, to be filled with add() from different program modules
ApplicationOptions(int argc=0, char **argv=0)
bool disableHighDPISupport() const
bpo::variables_map m_variables_map
QSize mainWindowSize() const
bpo::positional_options_description m_positional_options
positional options description, to be filled with addPositional() from main module
const bpo::variable_value & operator[](const std::string &s) const
access to variable with given name defined in variables container
QString const & name(EShape k)
QString getBornAgainVersionString()