44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
63
64
65
66
67
68
71
72
73
74
75
76
77
78
79
80QCommandLineOption::QCommandLineOption(
const QString &name)
81 : d(
new QCommandLineOptionPrivate(name))
86
87
88
89
90
91
92
93
94
95
96
97
98QCommandLineOption::QCommandLineOption(
const QStringList &names)
99 : d(
new QCommandLineOptionPrivate(names))
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125QCommandLineOption::QCommandLineOption(
const QString &name,
const QString &description,
126 const QString &valueName,
127 const QString &defaultValue)
128 : d(
new QCommandLineOptionPrivate(name))
130 setValueName(valueName);
131 setDescription(description);
132 setDefaultValue(defaultValue);
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160QCommandLineOption::QCommandLineOption(
const QStringList &names,
const QString &description,
161 const QString &valueName,
162 const QString &defaultValue)
163 : d(
new QCommandLineOptionPrivate(names))
165 setValueName(valueName);
166 setDescription(description);
167 setDefaultValue(defaultValue);
171
172
173
174
175
176QCommandLineOption::QCommandLineOption(
const QCommandLineOption &other)
182
183
184QCommandLineOption::~QCommandLineOption()
189
190
191
192QCommandLineOption &QCommandLineOption::operator=(
const QCommandLineOption &other)
199
200
201
204
205
206QStringList QCommandLineOption::names()
const
214 typedef bool result_type;
215 typedef QString argument_type;
218 result_type operator()(
const QString &name)
const noexcept
220 if (Q_UNLIKELY(name.isEmpty()))
221 return warn(
"be empty");
223 const QChar c = name.at(0);
224 if (Q_UNLIKELY(c == u'-'))
225 return warn(
"start with a '-'");
226 if (Q_UNLIKELY(c == u'/'))
227 return warn(
"start with a '/'");
228 if (Q_UNLIKELY(name.contains(u'=')))
229 return warn(
"contain a '='");
235 static bool warn(
const char *what)
noexcept
237 qWarning(
"QCommandLineOption: Option names cannot %s", what);
246 if (Q_UNLIKELY(nameList.isEmpty()))
247 qWarning(
"QCommandLineOption: Options must have at least one name");
249 nameList.removeIf(IsInvalidName());
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269void QCommandLineOption::setValueName(
const QString &valueName)
271 d->valueName = valueName;
275
276
277
278
279
280
281QString QCommandLineOption::valueName()
const
287
288
289
290
291
292
293
294
295void QCommandLineOption::setDescription(
const QString &description)
297 d->description = description;
301
302
303
304
305QString QCommandLineOption::description()
const
307 return d->description;
311
312
313
314
315
316
317
318
319
320void QCommandLineOption::setDefaultValue(
const QString &defaultValue)
322 QStringList newDefaultValues;
323 if (!defaultValue.isEmpty()) {
324 newDefaultValues.reserve(1);
325 newDefaultValues << defaultValue;
328 d->defaultValues.swap(newDefaultValues);
332
333
334
335
336
337
338
339void QCommandLineOption::setDefaultValues(
const QStringList &defaultValues)
341 d->defaultValues = defaultValues;
345
346
347
348
349QStringList QCommandLineOption::defaultValues()
const
351 return d->defaultValues;
355
356
357
358
359
360QCommandLineOption::Flags QCommandLineOption::flags()
const
366
367
368
369
370
371void QCommandLineOption::setFlags(Flags flags)
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
static QStringList removeInvalidNames(QStringList nameList)
QStringList names
The list of names used for this option.
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.