Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
a04f4f38
Commit
a04f4f38
authored
3 years ago
by
Wuttke, Joachim
Committed by
Wuttke, Joachim
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Upon invalid command-line option, show Qt message box
parent
ff9c308e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!705
GUI/App/main, file paths: various improvements
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
App/AppOptions.cpp
+20
-15
20 additions, 15 deletions
App/AppOptions.cpp
App/AppOptions.h
+0
-3
0 additions, 3 deletions
App/AppOptions.h
App/main.cpp
+0
-2
0 additions, 2 deletions
App/main.cpp
with
20 additions
and
20 deletions
App/AppOptions.cpp
+
20
−
15
View file @
a04f4f38
...
...
@@ -14,7 +14,9 @@
#include
"App/AppOptions.h"
#include
"GUI/Util/Path.h"
#include
<QApplication>
#include
<QSize>
#include
<QMessageBox>
#include
<QStringList>
#include
<boost/program_options/config.hpp>
#include
<boost/program_options/parsers.hpp>
...
...
@@ -43,10 +45,19 @@ bool isValid(const QSize& win_size)
return
win_size
.
width
()
>
640
&&
win_size
.
height
()
>
480
;
}
void
exitWithGuiMessage
(
const
QString
msg
)
{
int
argc
=
0
;
QApplication
a
(
argc
,
nullptr
);
QMessageBox
msgBox
;
msgBox
.
setText
(
msg
);
msgBox
.
exec
();
exit
(
-
1
);
}
}
// namespace
ApplicationOptions
::
ApplicationOptions
(
int
argc
,
char
**
argv
)
:
m_options_is_consistent
(
false
)
{
m_options
.
add_options
()(
"help,h"
,
"print help message and exit"
);
m_options
.
add_options
()(
"version,v"
,
"print version and exit"
);
...
...
@@ -72,16 +83,10 @@ bool ApplicationOptions::find(std::string name) const
return
m_variables_map
.
count
(
name
);
}
bool
ApplicationOptions
::
isConsistent
()
const
{
return
m_options_is_consistent
;
}
//! parse command line arguments
void
ApplicationOptions
::
parseCommandLine
(
int
argc
,
char
**
argv
)
{
m_options_is_consistent
=
false
;
// parsing command line arguments
try
{
// if positional option description is empty, no command line arguments
...
...
@@ -97,11 +102,13 @@ void ApplicationOptions::parseCommandLine(int argc, char** argv)
// 'notify' raises any errors encountered
bpo
::
notify
(
m_variables_map
);
m_options_is_consistent
=
true
;
}
catch
(
std
::
exception
&
e
)
{
// we get here if there is unrecognized options
std
::
cout
<<
"main() -> "
<<
e
.
what
()
<<
std
::
endl
;
std
::
cout
<<
m_options
<<
std
::
endl
;
std
::
stringstream
s
;
s
<<
"BornAgain was launched with invalid command line option.
\n
"
<<
"Parser error message: "
<<
e
.
what
()
<<
".
\n
"
<<
"Available options:
\n
"
<<
m_options
<<
"
\n
"
;
exitWithGuiMessage
(
QString
::
fromStdString
(
s
.
str
()));
}
}
...
...
@@ -130,10 +137,8 @@ void ApplicationOptions::processOptions()
}
else
if
(
m_variables_map
.
count
(
geometry
))
{
if
(
!
isValid
(
mainWindowSize
()))
{
std
::
cout
<<
"Wrong window size, try --geometry=1600x900
\n
"
;
m_options_is_consistent
=
false
;
}
if
(
!
isValid
(
mainWindowSize
()))
exitWithGuiMessage
(
"Wrong window size, try --geometry=1600x900
\n
"
);
}
}
...
...
This diff is collapsed.
Click to expand it.
App/AppOptions.h
+
0
−
3
View file @
a04f4f38
...
...
@@ -35,9 +35,6 @@ public:
//! access to variable with given name defined in variables container
const
bpo
::
variable_value
&
operator
[](
const
std
::
string
&
s
)
const
;
//! Returns true if options are consistent (no conflicts, no --help request)
bool
isConsistent
()
const
;
QSize
mainWindowSize
()
const
;
bool
disableHighDPISupport
()
const
;
...
...
This diff is collapsed.
Click to expand it.
App/main.cpp
+
0
−
2
View file @
a04f4f38
...
...
@@ -32,8 +32,6 @@ void messageHandler(QtMsgType, const QMessageLogContext&, const QString&) {}
int
main
(
int
argc
,
char
*
argv
[])
{
ApplicationOptions
options
(
argc
,
argv
);
if
(
!
options
.
isConsistent
())
return
0
;
QLocale
::
setDefault
(
QLocale
(
QLocale
::
English
,
QLocale
::
UnitedStates
));
qRegisterMetaType
<
QVector
<
double
>>
(
"QVector<double>"
);
...
...
This diff is collapsed.
Click to expand it.
Wuttke, Joachim
@j.wuttke
mentioned in issue
#194 (closed)
·
3 years ago
mentioned in issue
#194 (closed)
mentioned in issue #194
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment