7 #include "ColorFilterMode.h" 8 #include "FittingCurveCoefficients.h" 11 #include "MainWindow.h" 12 #include <QApplication> 13 #include <QCoreApplication> 18 #include <QProcessEnvironment> 19 #include <QStyleFactory> 20 #include "TranslatorContainer.h" 21 #include "ZoomFactor.h" 25 const QString CMD_DEBUG (
"debug");
26 const QString CMD_ERROR_REPORT (
"errorreport");
27 const QString CMD_FILE_CMD_SCRIPT (
"filecmdscript");
28 const QString CMD_GNUPLOT (
"gnuplot");
29 const QString CMD_HELP (
"help");
30 const QString CMD_REGRESSION (
"regression");
31 const QString CMD_RESET (
"reset");
32 const QString CMD_STYLES (
"styles");
33 const QString DASH (
"-");
34 const QString DASH_DEBUG (
"-" + CMD_DEBUG);
35 const QString DASH_ERROR_REPORT (
"-" + CMD_ERROR_REPORT);
36 const QString DASH_FILE_CMD_SCRIPT (
"-" + CMD_FILE_CMD_SCRIPT);
37 const QString DASH_GNUPLOT (
"-" + CMD_GNUPLOT);
38 const QString DASH_HELP (
"-" + CMD_HELP);
39 const QString DASH_REGRESSION (
"-" + CMD_REGRESSION);
40 const QString DASH_RESET (
"-" + CMD_RESET);
41 const QString DASH_STYLES (
"-" + CMD_STYLES);
42 const QString ENGAUGE_LOG_FILE (
"engauge.log");
45 bool checkFileExists (
const QString &file);
46 QString engaugeLogFilename ();
47 bool engaugeLogFilenameAttempt (
const QString &path,
48 QString &pathAndFile);
49 void parseCmdLine (
int argc,
53 QString &errorReportFile,
54 QString &fileCmdScriptFile,
55 bool &isErrorReportRegressionTest,
57 QStringList &loadStartupFiles);
58 void showStylesAndExit ();
61 bool checkFileExists (
const QString &file)
63 QFileInfo check (file);
64 return check.exists() && check.isFile();
67 QString engaugeLogFilename()
71 #if !defined(OSX_RELEASE) && !defined(WIN_RELEASE) && !defined(APPIMAGE_RELEASE) 72 QProcessEnvironment env;
75 if (!engaugeLogFilenameAttempt (QCoreApplication::applicationDirPath(), pathAndFile)) {
76 if (!engaugeLogFilenameAttempt (env.value (
"HOME"), pathAndFile)) {
77 if (!engaugeLogFilenameAttempt (env.value (
"TEMP"), pathAndFile)) {
78 pathAndFile = ENGAUGE_LOG_FILE;
87 bool engaugeLogFilenameAttempt (
const QString &path,
93 pathAndFile = QString (
"%1%2%3")
95 .arg (QDir::separator())
96 .arg (ENGAUGE_LOG_FILE);
97 QFile file (pathAndFile);
98 if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
107 int main(
int argc,
char *argv[])
109 qRegisterMetaType<ColorFilterMode> (
"ColorFilterMode");
110 qRegisterMetaType<FittingCurveCoefficients> (
"FilterCurveCoefficients");
111 qRegisterMetaType<ZoomFactor> (
"ZoomFactor");
113 QApplication app(argc, argv);
119 bool isDebug, isReset, isGnuplot, isErrorReportRegressionTest;
120 QString errorReportFile, fileCmdScriptFile;
121 QStringList loadStartupFiles;
128 isErrorReportRegressionTest,
133 initializeLogging (
"engauge",
134 engaugeLogFilename(),
136 LOG4CPP_INFO_S ((*mainCat)) <<
"main args=" << QApplication::arguments().join (
" ").toLatin1().data();
141 isErrorReportRegressionTest,
151 void parseCmdLine (
int argc,
155 QString &errorReportFile,
156 QString &fileCmdScriptFile,
157 bool &isErrorReportRegressionTest,
159 QStringList &loadStartupFiles)
161 const int COLUMN_WIDTH = 20;
162 bool showUsage =
false;
165 bool nextIsErrorReportFile =
false;
166 bool nextIsFileCmdScript =
false;
171 errorReportFile =
"";
172 fileCmdScriptFile =
"";
173 isErrorReportRegressionTest =
false;
176 for (
int i = 1; i < argc; i++) {
178 if (nextIsErrorReportFile) {
179 errorReportFile = argv [i];
180 showUsage |= !checkFileExists (errorReportFile);
181 nextIsErrorReportFile =
false;
182 }
else if (nextIsFileCmdScript) {
183 fileCmdScriptFile = argv [i];
184 showUsage |= !checkFileExists (fileCmdScriptFile);
185 nextIsFileCmdScript =
false;
186 }
else if (strcmp (argv [i], DASH_DEBUG.toLatin1().data()) == 0) {
188 }
else if (strcmp (argv [i], DASH_ERROR_REPORT.toLatin1().data()) == 0) {
189 nextIsErrorReportFile =
true;
190 }
else if (strcmp (argv [i], DASH_FILE_CMD_SCRIPT.toLatin1().data()) == 0) {
191 nextIsFileCmdScript =
true;
192 }
else if (strcmp (argv [i], DASH_GNUPLOT.toLatin1().data()) == 0) {
194 }
else if (strcmp (argv [i], DASH_HELP.toLatin1().data()) == 0) {
196 }
else if (strcmp (argv [i], DASH_REGRESSION.toLatin1().data()) == 0) {
197 isErrorReportRegressionTest =
true;
198 }
else if (strcmp (argv [i], DASH_RESET.toLatin1().data()) == 0) {
200 }
else if (strcmp (argv [i], DASH_STYLES.toLatin1().data()) == 0) {
201 showStylesAndExit ();
202 }
else if (strncmp (argv [i], DASH.toLatin1().data(), 1) == 0) {
207 QString fileName = argv [i];
208 QFileInfo fInfo (fileName);
209 if (fInfo.isRelative()) {
210 fileName = fInfo.absoluteFilePath();
212 loadStartupFiles << fileName;
216 if (showUsage || nextIsErrorReportFile) {
218 cerr <<
"Usage: engauge " 219 <<
"[" << DASH_DEBUG.toLatin1().data() <<
"] " 220 <<
"[" << DASH_ERROR_REPORT.toLatin1().data() <<
" <file>] " 221 <<
"[" << DASH_FILE_CMD_SCRIPT.toLatin1().data() <<
" <file> " 222 <<
"[" << DASH_GNUPLOT.toLatin1().data() <<
"] " 223 <<
"[" << DASH_HELP.toLatin1().data() <<
"] " 224 <<
"[" << DASH_REGRESSION.toLatin1().data() <<
"] " 225 <<
"[" << DASH_RESET.toLatin1().data () <<
"] " 226 <<
"[" << DASH_STYLES.toLatin1().data () <<
"] " 227 <<
"[<load_file1>] [<load_file2>] ..." << endl
228 <<
" " << DASH_DEBUG.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
229 << QObject::tr (
"Enables extra debug information. Used for debugging").toLatin1().data() << endl
230 <<
" " << DASH_ERROR_REPORT.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
231 << QObject::tr (
"Specifies an error report file as input. Used for debugging and testing").toLatin1().data() << endl
232 <<
" " << DASH_FILE_CMD_SCRIPT.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
233 << QObject::tr (
"Specifies a file command script file as input. Used for debugging and testing").toLatin1().data() << endl
234 <<
" " << DASH_GNUPLOT.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
235 << QObject::tr (
"Output diagnostic gnuplot input files. Used for debugging").toLatin1().data() << endl
236 <<
" " << DASH_HELP.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
237 << QObject::tr (
"Show this help information").toLatin1().data() << endl
238 <<
" " << DASH_REGRESSION.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
239 << QObject::tr (
"Executes the error report file or file command script. Used for regression testing").toLatin1().data() << endl
240 <<
" " << DASH_RESET.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
241 << QObject::tr (
"Removes all stored settings, including window positions. Used when windows start up offscreen").toLatin1().data() << endl
242 <<
" " << DASH_STYLES.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
243 << QObject::tr (
"Show a list of available styles that can be used with the -style command").toLatin1().data() << endl
244 <<
" " << QString (
"<load file> ").leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
245 << QObject::tr (
"File(s) to be imported or opened at startup").toLatin1().data() << endl;
251 void showStylesAndExit ()
253 cout <<
"Available styles: " << QStyleFactory::keys ().join (
", ").toLatin1().data() << endl;
Class that stores QTranslator objects for the duration of application execution.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...