45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
64
65
66
67
68
69
72
73
74
75
76
77
78
79
80
81QCommandLineOption::QCommandLineOption(
const QString &name)
82 : d(
new QCommandLineOptionPrivate(name))
87
88
89
90
91
92
93
94
95
96
97
98
99QCommandLineOption::QCommandLineOption(
const QStringList &names)
100 : d(
new QCommandLineOptionPrivate(names))
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126QCommandLineOption::QCommandLineOption(
const QString &name,
const QString &description,
127 const QString &valueName,
128 const QString &defaultValue)
129 : d(
new QCommandLineOptionPrivate(name))
131 setValueName(valueName);
132 setDescription(description);
133 setDefaultValue(defaultValue);
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161QCommandLineOption::QCommandLineOption(
const QStringList &names,
const QString &description,
162 const QString &valueName,
163 const QString &defaultValue)
164 : d(
new QCommandLineOptionPrivate(names))
166 setValueName(valueName);
167 setDescription(description);
168 setDefaultValue(defaultValue);
172
173
174
175
176
177QCommandLineOption::QCommandLineOption(
const QCommandLineOption &other)
183
184
185QCommandLineOption::~QCommandLineOption()
190
191
192
193QCommandLineOption &QCommandLineOption::operator=(
const QCommandLineOption &other)
200
201
202
205
206
207QStringList QCommandLineOption::names()
const
215 typedef bool result_type;
216 typedef QString argument_type;
219 result_type operator()(
const QString &name)
const noexcept
221 if (Q_UNLIKELY(name.isEmpty()))
222 return warn(
"be empty");
224 const QChar c = name.at(0);
225 if (Q_UNLIKELY(c == u'-'))
226 return warn(
"start with a '-'");
227 if (Q_UNLIKELY(c == u'/'))
228 return warn(
"start with a '/'");
229 if (Q_UNLIKELY(name.contains(u'=')))
230 return warn(
"contain a '='");
236 static bool warn(
const char *what)
noexcept
238 qWarning(
"QCommandLineOption: Option names cannot %s", what);
247 if (Q_UNLIKELY(nameList.isEmpty()))
248 qWarning(
"QCommandLineOption: Options must have at least one name");
250 nameList.removeIf(IsInvalidName());
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270void QCommandLineOption::setValueName(
const QString &valueName)
272 d->valueName = valueName;
276
277
278
279
280
281
282QString QCommandLineOption::valueName()
const
288
289
290
291
292
293
294
295
296void QCommandLineOption::setDescription(
const QString &description)
298 d->description = description;
302
303
304
305
306QString QCommandLineOption::description()
const
308 return d->description;
312
313
314
315
316
317
318
319
320
321void QCommandLineOption::setDefaultValue(
const QString &defaultValue)
323 QStringList newDefaultValues;
324 if (!defaultValue.isEmpty()) {
325 newDefaultValues.reserve(1);
326 newDefaultValues << defaultValue;
329 d->defaultValues.swap(newDefaultValues);
333
334
335
336
337
338
339
340void QCommandLineOption::setDefaultValues(
const QStringList &defaultValues)
342 d->defaultValues = defaultValues;
346
347
348
349
350QStringList QCommandLineOption::defaultValues()
const
352 return d->defaultValues;
356
357
358
359
360
361QCommandLineOption::Flags QCommandLineOption::flags()
const
367
368
369
370
371
372void QCommandLineOption::setFlags(Flags flags)
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
static QStringList removeInvalidNames(QStringList nameList)
QStringList names
The list of names used for this option.
QString valueName
The documentation name for the value, if one is expected Example: "-o <file>" means valueName == "fil...
QStringList defaultValues
The list of default values used for this option.
QString description
The description used for this option.
Combined button and popup list for selecting options.