Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qcommandlineoption.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org>
3// Copyright (C) 2013 David Faure <faure@kde.org>
4// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
5
7
8#include "qset.h"
9
11
42
84
102
126 const QString &valueName,
127 const QString &defaultValue)
129{
132 setDefaultValue(defaultValue);
133}
134
161 const QString &valueName,
162 const QString &defaultValue)
164{
167 setDefaultValue(defaultValue);
168}
169
180
187
193{
194 d = other.d;
195 return *this;
196}
197
209{
210 return d->names;
211}
212
213namespace {
214 struct IsInvalidName
215 {
216 typedef bool result_type;
217 typedef QString argument_type;
218
220 result_type operator()(const QString &name) const noexcept
221 {
222 if (Q_UNLIKELY(name.isEmpty()))
223 return warn("be empty");
224
225 const QChar c = name.at(0);
226 if (Q_UNLIKELY(c == u'-'))
227 return warn("start with a '-'");
228 if (Q_UNLIKELY(c == u'/'))
229 return warn("start with a '/'");
230 if (Q_UNLIKELY(name.contains(u'=')))
231 return warn("contain a '='");
232
233 return false;
234 }
235
237 static bool warn(const char *what) noexcept
238 {
239 qWarning("QCommandLineOption: Option names cannot %s", what);
240 return true;
241 }
242 };
243} // unnamed namespace
244
245// static
247{
248 if (Q_UNLIKELY(nameList.isEmpty()))
249 qWarning("QCommandLineOption: Options must have at least one name");
250 else
251 nameList.removeIf(IsInvalidName());
252 return nameList;
253}
254
272{
273 d->valueName = valueName;
274}
275
284{
285 return d->valueName;
286}
287
298{
300}
301
308{
309 return d->description;
310}
311
323{
324 QStringList newDefaultValues;
325 if (!defaultValue.isEmpty()) {
326 newDefaultValues.reserve(1);
327 newDefaultValues << defaultValue;
328 }
329 // commit:
330 d->defaultValues.swap(newDefaultValues);
331}
332
345
355
362QCommandLineOption::Flags QCommandLineOption::flags() const
363{
364 return d->flags;
365}
366
377
\inmodule QtCore
QCommandLineOption::Flags flags
static QStringList removeInvalidNames(QStringList nameList)
Q_NEVER_INLINE QCommandLineOptionPrivate(const QString &name)
Q_NEVER_INLINE QCommandLineOptionPrivate(const QStringList &names)
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.
The QCommandLineOption class defines a possible command-line option. \inmodule QtCore.
void setDescription(const QString &description)
Sets the description used for this option to description.
Flags flags() const
Returns a set of flags that affect this command-line option.
void setDefaultValue(const QString &defaultValue)
Sets the default value used for this option to defaultValue.
~QCommandLineOption()
Destroys the command line option object.
QString valueName() const
Returns the name of the expected value.
QString description() const
Returns the description set for this option.
void setFlags(Flags aflags)
Set the set of flags that affect this command-line option to flags.
void setDefaultValues(const QStringList &defaultValues)
Sets the list of default values used for this option to defaultValues.
void setValueName(const QString &name)
Sets the name of the expected value, for the documentation, to valueName.
QStringList defaultValues() const
Returns the default values set for this option.
QCommandLineOption & operator=(const QCommandLineOption &other)
Move-assigns other to this QCommandLineOption instance.
QStringList names() const
Returns the names set for this option.
QCommandLineOption(const QString &name)
Constructs a command line option object with the name name.
\inmodule QtCore
Definition qshareddata.h:19
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
Combined button and popup list for selecting options.
#define Q_UNLIKELY(x)
#define Q_NEVER_INLINE
Flags
#define qWarning
Definition qlogging.h:166
GLbitfield flags
GLuint name
const GLubyte * c
GLuint GLuint * names
QSharedPointer< T > other(t)
[5]