7 #include "ColorFilterMode.h"
8 #include "FittingCurveCoefficients.h"
11 #include "MainWindow.h"
12 #include <QApplication>
13 #include <QCoreApplication>
17 #include <QMessageBox>
19 #include <QProcessEnvironment>
20 #include <QStyleFactory>
21 #include "TranslatorContainer.h"
22 #include "ZoomFactor.h"
26 const QString CMD_DEBUG (
"debug");
27 const QString CMD_ERROR_REPORT (
"errorreport");
28 const QString CMD_EXPORT_ONLY (
"exportonly");
29 const QString CMD_FILE_CMD_SCRIPT (
"filecmdscript");
30 const QString CMD_GNUPLOT (
"gnuplot");
31 const QString CMD_HELP (
"help");
32 const QString CMD_REGRESSION (
"regression");
33 const QString CMD_RESET (
"reset");
34 const QString CMD_STYLES (
"styles");
35 const QString DASH (
"-");
36 const QString DASH_DEBUG (
"-" + CMD_DEBUG);
37 const QString DASH_ERROR_REPORT (
"-" + CMD_ERROR_REPORT);
38 const QString DASH_EXPORT_ONLY (
"-" + CMD_EXPORT_ONLY);
39 const QString DASH_FILE_CMD_SCRIPT (
"-" + CMD_FILE_CMD_SCRIPT);
40 const QString DASH_GNUPLOT (
"-" + CMD_GNUPLOT);
41 const QString DASH_HELP (
"-" + CMD_HELP);
42 const QString DASH_REGRESSION (
"-" + CMD_REGRESSION);
43 const QString DASH_RESET (
"-" + CMD_RESET);
44 const QString DASH_STYLES (
"-" + CMD_STYLES);
45 const QString ENGAUGE_LOG_FILE (
".engauge.log");
48 bool checkFileExists (
const QString &file);
49 QString engaugeLogFilename ();
50 bool engaugeLogFilenameAttempt (
const QString &path,
51 QString &pathAndFile);
52 void parseCmdLine (
int argc,
56 QString &errorReportFile,
57 QString &fileCmdScriptFile,
58 bool &isErrorReportRegressionTest,
61 QStringList &loadStartupFiles);
62 void showStylesAndExit ();
65 bool checkFileExists (
const QString &file)
67 QFileInfo check (file);
68 return check.exists() && check.isFile();
71 QString engaugeLogFilename()
75 #if !defined(OSX_RELEASE) && !defined(WIN_RELEASE) && !defined(APPIMAGE_RELEASE)
76 QProcessEnvironment env;
79 if (!engaugeLogFilenameAttempt (QCoreApplication::applicationDirPath(), pathAndFile)) {
80 if (!engaugeLogFilenameAttempt (env.value (
"HOME"), pathAndFile)) {
81 if (!engaugeLogFilenameAttempt (env.value (
"TEMP"), pathAndFile)) {
82 pathAndFile = ENGAUGE_LOG_FILE;
91 bool engaugeLogFilenameAttempt (
const QString &path,
97 pathAndFile = QString (
"%1%2%3")
99 .arg (QDir::separator())
100 .arg (ENGAUGE_LOG_FILE);
101 QFile file (pathAndFile);
102 if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
112 int main(
int argc,
char *argv[])
114 qRegisterMetaType<ColorFilterMode> (
"ColorFilterMode");
115 qRegisterMetaType<FittingCurveCoefficients> (
"FilterCurveCoefficients");
116 qRegisterMetaType<ZoomFactor> (
"ZoomFactor");
118 QApplication app(argc, argv);
124 bool isDebug, isReset, isGnuplot, isErrorReportRegressionTest, isExportOnly;
125 QString errorReportFile, fileCmdScriptFile;
126 QStringList loadStartupFiles;
133 isErrorReportRegressionTest,
139 initializeLogging (
"engauge",
140 engaugeLogFilename(),
142 LOG4CPP_INFO_S ((*mainCat)) <<
"main args=" << QApplication::arguments().join (
" ").toLatin1().data();
147 isErrorReportRegressionTest,
158 void parseCmdLine (
int argc,
162 QString &errorReportFile,
163 QString &fileCmdScriptFile,
164 bool &isErrorReportRegressionTest,
167 QStringList &loadStartupFiles)
169 bool showUsage =
false;
172 bool nextIsErrorReportFile =
false;
173 bool nextIsFileCmdScript =
false;
178 errorReportFile =
"";
179 fileCmdScriptFile =
"";
180 isErrorReportRegressionTest =
false;
182 isExportOnly =
false;
184 for (
int i = 1; i < argc; i++) {
186 if (nextIsErrorReportFile) {
187 errorReportFile = argv [i];
188 showUsage |= !checkFileExists (errorReportFile);
189 nextIsErrorReportFile =
false;
190 }
else if (nextIsFileCmdScript) {
191 fileCmdScriptFile = argv [i];
192 showUsage |= !checkFileExists (fileCmdScriptFile);
193 nextIsFileCmdScript =
false;
194 }
else if (strcmp (argv [i], DASH_DEBUG.toLatin1().data()) == 0) {
196 }
else if (strcmp (argv [i], DASH_ERROR_REPORT.toLatin1().data()) == 0) {
197 nextIsErrorReportFile =
true;
198 }
else if (strcmp (argv [i], DASH_EXPORT_ONLY.toLatin1().data()) == 0) {
200 }
else if (strcmp (argv [i], DASH_FILE_CMD_SCRIPT.toLatin1().data()) == 0) {
201 nextIsFileCmdScript =
true;
202 }
else if (strcmp (argv [i], DASH_GNUPLOT.toLatin1().data()) == 0) {
204 }
else if (strcmp (argv [i], DASH_HELP.toLatin1().data()) == 0) {
206 }
else if (strcmp (argv [i], DASH_REGRESSION.toLatin1().data()) == 0) {
207 isErrorReportRegressionTest =
true;
208 }
else if (strcmp (argv [i], DASH_RESET.toLatin1().data()) == 0) {
210 }
else if (strcmp (argv [i], DASH_STYLES.toLatin1().data()) == 0) {
211 showStylesAndExit ();
212 }
else if (strncmp (argv [i], DASH.toLatin1().data(), 1) == 0) {
217 QString fileName = argv [i];
218 QFileInfo fInfo (fileName);
219 if (fInfo.isRelative()) {
220 fileName = fInfo.absoluteFilePath();
222 loadStartupFiles << fileName;
227 if (isExportOnly && (!errorReportFile.isEmpty() ||
228 !fileCmdScriptFile.isEmpty() ||
229 loadStartupFiles.size() != 1)) {
231 QTextStream str (&msg);
232 str << DASH_EXPORT_ONLY.toLatin1().data() <<
" " << QObject::tr (
" is used only with one document file specified");
233 QMessageBox::critical (0,
234 QObject::tr (
"Engauge Digitizer"),
240 if (showUsage || nextIsErrorReportFile) {
243 QTextStream str (&msg);
244 str <<
"<html>Usage: engauge "
245 <<
"[" << DASH_DEBUG.toLatin1().data() <<
"] "
246 <<
"[" << DASH_ERROR_REPORT.toLatin1().data() <<
" <file>] "
247 <<
"[" << DASH_EXPORT_ONLY.toLatin1().data() <<
"] "
248 <<
"[" << DASH_FILE_CMD_SCRIPT.toLatin1().data() <<
" <file> "
249 <<
"[" << DASH_GNUPLOT.toLatin1().data() <<
"] "
250 <<
"[" << DASH_HELP.toLatin1().data() <<
"] "
251 <<
"[" << DASH_REGRESSION.toLatin1().data() <<
"] "
252 <<
"[" << DASH_RESET.toLatin1().data () <<
"] "
253 <<
"[" << DASH_STYLES.toLatin1().data () <<
"] "
254 <<
"[<load_file1>] [<load_file2>] ..." << endl
257 <<
"<td>" << DASH_DEBUG.toLatin1().data() <<
"</td>"
258 <<
"<td>" << QObject::tr (
"Enables extra debug information. Used for debugging").toLatin1().data() <<
"</td>"
261 <<
"<td>" << DASH_ERROR_REPORT.toLatin1().data() <<
"</td>"
262 <<
"<td>" << QObject::tr (
"Specifies an error report file as input. Used for debugging and testing").toLatin1().data() <<
"</td>"
265 <<
"<td>" << DASH_EXPORT_ONLY.toLatin1().data() <<
"</td>"
266 <<
"<td>" << QObject::tr (
"Export the loaded startup file, which must have all axis points defined, then stop").toLatin1().data() <<
"</td>"
269 <<
"<td>" << DASH_FILE_CMD_SCRIPT.toLatin1().data() <<
"</td>"
270 <<
"<td>" << QObject::tr (
"Specifies a file command script file as input. Used for debugging and testing").toLatin1().data() <<
"</td>"
273 <<
"<td>" << DASH_GNUPLOT.toLatin1().data() <<
"</td>"
274 <<
"<td>" << QObject::tr (
"Output diagnostic gnuplot input files. Used for debugging").toLatin1().data() <<
"</td>"
277 <<
"<td>" << DASH_HELP.toLatin1().data() <<
"</td>"
278 <<
"<td>" << QObject::tr (
"Show this help information").toLatin1().data() <<
"</td>"
281 <<
"<td>" << DASH_REGRESSION.toLatin1().data() <<
"</td>"
282 <<
"<td>" << QObject::tr (
"Executes the error report file or file command script. Used for regression testing").toLatin1().data() <<
"</td>"
285 <<
"<td>" << DASH_RESET.toLatin1().data() <<
"</td>"
286 <<
"<td>" << QObject::tr (
"Removes all stored settings, including window positions. Used when windows start up offscreen").toLatin1().data() <<
"</td>"
289 <<
"<td>" << DASH_STYLES.toLatin1().data() <<
"</td>"
290 <<
"<td>" << QObject::tr (
"Show a list of available styles that can be used with the -style command").toLatin1().data() <<
"</td>"
293 <<
"<td>" << QString (
"<load file> ").toLatin1().data() <<
"</td>"
294 <<
"<td>" << QObject::tr (
"File(s) to be imported or opened at startup").toLatin1().data() <<
"</td>"
296 <<
"</table></html>";
299 QMessageBox::critical (0,
300 QObject::tr (
"Engauge Digitizer"),
306 void showStylesAndExit ()
308 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...