@@ -56,6 +56,16 @@ main(int argc, char *argv[])
56
56
" Autoconnect to monitor" );
57
57
parser.addOption (autoconnect_option);
58
58
59
+ QCommandLineOption file_option (QStringList () << " file" ,
60
+ " Load a file (only in editor mode)" ,
61
+ " tree.xml" );
62
+ parser.addOption (file_option);
63
+
64
+ QCommandLineOption output_svg_option (QStringList () << " output-svg" ,
65
+ " Save the input file to an svg" ,
66
+ " output.svg" );
67
+ parser.addOption (output_svg_option);
68
+
59
69
parser.process ( app );
60
70
61
71
QFile styleFile ( " :/stylesheet.qss" );
@@ -92,7 +102,7 @@ main(int argc, char *argv[])
92
102
else {
93
103
std::cout << " wrong mode passed to --mode. Use on of these: editor / monitor /replay"
94
104
<< std::endl;
95
- return 0 ;
105
+ return 1 ;
96
106
}
97
107
}
98
108
else {
@@ -114,6 +124,52 @@ main(int argc, char *argv[])
114
124
// Start the main application.
115
125
MainWindow win ( mode, monitor_address, monitor_pub_port,
116
126
monitor_srv_port, monitor_autoconnect );
127
+
128
+ if ( parser.isSet (file_option) )
129
+ {
130
+ if ( mode != GraphicMode::EDITOR )
131
+ {
132
+ std::cout << " --file can only be passed in editor mode" << std::endl;
133
+ return 1 ;
134
+ }
135
+
136
+ QString fileName = parser.value (file_option);
137
+ std::cout << " Loading file: " << fileName.toStdString () << std::endl;
138
+
139
+ // Open file
140
+ QFile file (fileName);
141
+ if (!file.open (QIODevice::ReadOnly))
142
+ {
143
+ std::cout << " Cannot open file" << std::endl;
144
+ return 1 ;
145
+ }
146
+
147
+ // Read file to xml
148
+ QString xml_text;
149
+ QTextStream in (&file);
150
+ while (!in.atEnd ()) {
151
+ xml_text += in.readLine ();
152
+ }
153
+
154
+ // Show xml
155
+ win.loadFromXML ( xml_text );
156
+ }
157
+
158
+
159
+ if ( parser.isSet (output_svg_option) )
160
+ {
161
+ if ( !parser.isSet (file_option))
162
+ {
163
+ std::cout << " --output-svg needs the --file" << std::endl;
164
+ return 1 ;
165
+ }
166
+ QString svgFile = parser.value (output_svg_option);
167
+
168
+ std::cout << " Writing to: " << svgFile.toStdString () << std::endl;
169
+ win.currentTabInfo ()->saveSvgFile (svgFile);
170
+ return 0 ;
171
+ }
172
+
117
173
win.show ();
118
174
return app.exec ();
119
175
}
0 commit comments