From 63274c95a3d78fbed8f511690cf7b248a6231273 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 17 Mar 2016 12:48:38 +0100 Subject: Add QCommandLineOption::Flags containing HiddenFromHelp and ShortOptionStyle This patch adds a new option, QCommandLineOption::ShortOptionStyle, which helps applications (such as compilers, so moc and now qdoc) which need to mix long-style and short flags. [ChangeLog][QtCore][QCommandLineOption] Added flags() and setFlags() methods. Added ShortOptionStyle and HiddenFromHelp flags. Change-Id: I944ce56aff2b28ecd6bb9d2d23c4e726e9d06647 Reviewed-by: Marc Mutz --- src/corelib/tools/qcommandlineoption.cpp | 58 +++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 9 deletions(-) (limited to 'src/corelib/tools/qcommandlineoption.cpp') diff --git a/src/corelib/tools/qcommandlineoption.cpp b/src/corelib/tools/qcommandlineoption.cpp index 64cabcc304..1f7f9cc33b 100644 --- a/src/corelib/tools/qcommandlineoption.cpp +++ b/src/corelib/tools/qcommandlineoption.cpp @@ -49,14 +49,12 @@ class QCommandLineOptionPrivate : public QSharedData public: Q_NEVER_INLINE explicit QCommandLineOptionPrivate(const QString &name) - : names(removeInvalidNames(QStringList(name))), - hidden(false) + : names(removeInvalidNames(QStringList(name))) { } Q_NEVER_INLINE explicit QCommandLineOptionPrivate(const QStringList &names) - : names(removeInvalidNames(names)), - hidden(false) + : names(removeInvalidNames(names)) { } static QStringList removeInvalidNames(QStringList nameList); @@ -74,8 +72,7 @@ public: //! The list of default values used for this option. QStringList defaultValues; - //! Show or hide in --help - bool hidden; + QCommandLineOption::Flags flags; }; /*! @@ -394,6 +391,7 @@ QStringList QCommandLineOption::defaultValues() const return d->defaultValues; } +#if QT_DEPRECATED_SINCE(5, 8) /*! Sets whether to hide this option in the user-visible help output. @@ -401,11 +399,12 @@ QStringList QCommandLineOption::defaultValues() const a particular option makes it internal, i.e. not listed in the help output. \since 5.6 + \obsolete Use setFlags(QCommandLineOption::HiddenFromHelp), QCommandLineOption::HiddenFromHelp \sa isHidden */ void QCommandLineOption::setHidden(bool hide) { - d->hidden = hide; + d->flags.setFlag(HiddenFromHelp, hide); } /*! @@ -413,11 +412,52 @@ void QCommandLineOption::setHidden(bool hide) false if the option is listed. \since 5.6 - \sa setHidden() + \obsolete Use flags() & QCommandLineOption::HiddenFromHelp + \sa setHidden(), QCommandLineOption::HiddenFromHelp */ bool QCommandLineOption::isHidden() const { - return d->hidden; + return d->flags & HiddenFromHelp; } +#endif + +/*! + Returns a set of flags that affect this command-line option. + + \since 5.8 + \sa setFlags(), QCommandLineOption::Flags + */ +QCommandLineOption::Flags QCommandLineOption::flags() const +{ + return d->flags; +} + +/*! + Set the set of flags that affect this command-line option. + + \since 5.8 + \sa flags(), QCommandLineOption::Flags + */ +void QCommandLineOption::setFlags(Flags flags) +{ + d->flags = flags; +} + +/*! + \enum QCommandLineOption::Flag + + \value HiddenFromHelp Hide this option in the user-visible help output. All + options are visible by default. Setting this flag for a particular + option makes it internal, i.e. not listed in the help output. + + \value ShortOptionStyle The option will always be understood as a short + option, regardless of what was set by + QCommandLineParser::setSingleDashWordOptionMode. + This allows flags such as \c{-DDEFINE=VALUE} or \c{-I/include/path} to be + interpreted as short flags even when the parser is in + QCommandLineParser::ParseAsLongOptions mode. + + \sa QCommandLineOption::setFlags(), QCommandLineOption::flags() +*/ QT_END_NAMESPACE -- cgit v1.2.3