-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
106 lines (85 loc) · 4 KB
/
Copy pathmain.cpp
File metadata and controls
106 lines (85 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <QApplication>
#include <QSplashScreen>
#include <QString>
#include <QStyle>
#include <QTimer>
#include <QCommandLineParser>
#include "mainwindow.h"
#include "version.h"
#include "darkstyletheme.h"
#ifdef _WIN32
#include <iostream>
#include <Windows.h>
#endif
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setQuitOnLastWindowClosed(true);
//Style program with our dark style
a.setStyle(new DarkStyleTheme);
QString version = QString("%1.%2.%3").arg(MAJORVERSION).arg(MINORVERSION).arg(PATCHVERSION);
QCoreApplication::setApplicationVersion(version);
// Start GUI version...
if (argc < 2)
{
#if defined( _WIN32 )
// hide console window
::ShowWindow( ::GetConsoleWindow(), SW_HIDE );
#endif
QPixmap splashPixmap(":/palaeoware_logo_square.png");
QSplashScreen *splash = new QSplashScreen(splashPixmap, Qt::WindowStaysOnTopHint);
splash->setAttribute(Qt::WA_DeleteOnClose, true);
splash->show();
splash->showMessage("<font><b>" + QString(PRODUCTNAME) + " - " + QString(PRODUCTTAG) + "</b></font>", Qt::AlignHCenter, Qt::white);
QApplication::processEvents();
QTimer::singleShot(5000, splash, SLOT(close()));
MainWindow *w = new MainWindow;
w->show();
int e = a.exec();
delete w; //needed to execute deconstructor
exit(e); //needed to exit the hidden console
return e;
}
// Start from a console...
else
{
//Sort out command line option
QCommandLineParser *parser = new QCommandLineParser();
QString message("TREvoSim is an individual-based evolutionary model. You are using the command line option. See documentation and associated publications for description of software. This is ");
QString version = QString(PRODUCTNAME) + " v" + QString("%1.%2.%3").arg(MAJORVERSION).arg(MINORVERSION).arg(PATCHVERSION);
message.append(version);
message.append(QString(", compiled on ") + __DATE__ + QString("."));
parser->setApplicationDescription(message);
parser->addHelpOption();
parser->addVersionOption();
parser->setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
QCommandLineOption opt_o(QStringList() << "o" << "open",
QCoreApplication::translate("main", "Settings file to load on start."),
QCoreApplication::translate("main", "Path to file (string)."));
parser->addOption(opt_o);
QCommandLineOption opt_b(QStringList() << "b" << "batch",
QCoreApplication::translate("main", "Run in batch mode."),
QCoreApplication::translate("main", "An integer representing the required number of replicates."));
parser->addOption(opt_b);
QCommandLineOption opt_s(QStringList() << "s" << "skipInput",
QCoreApplication::translate("main", "Skip requests for user input."),
QCoreApplication::translate("main", " An integer of value between 1 and 1000000 that dictates the number of attempts to reach requested replicate number in batch mode."));
parser->addOption(opt_s);
parser->process(a);
MainWindow *w = new MainWindow;
QHash<QString, QString> parsedOptions;
if (parser->isSet(opt_b)) parsedOptions.insert("batchReplicates", parser->value(opt_b));
if (parser->isSet(opt_s)) parsedOptions.insert("skipInput", parser->value(opt_s));
if (parser->isSet(opt_o))
{
QString fileFromCommandLine = QString();
fileFromCommandLine = parser->value(opt_o);
if (!fileFromCommandLine.isNull()) parsedOptions.insert("fileFromCommandLine", parser->value(opt_o));
}
w->runFromCommandLine(parsedOptions);
int e = a.exec();
delete w; //needed to execute deconstructor
exit(e); //needed to exit the hidden console
return e;
}
}