diff options
author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-03-24 16:10:15 +0100 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-03-24 16:10:15 +0100 |
commit | 3b5c0bc0780f1749fed7c07bd8b691400a0282b7 (patch) | |
tree | 1022f5553ad5a0aca9b5f3b49ca38a01c2329d20 /src/corelib/tools | |
parent | c79918733a194ebbe5a2fe1617c884659f3e4b9f (diff) | |
parent | 21f1738a94fc8544ece04b3b1ee03a11986fe59b (diff) |
Merge remote-tracking branch 'origin/stable' into dev
Conflicts:
src/gui/image/qjpeghandler.cpp
Change-Id: I9db3acea7d5c82f5da679c8eaeb29431136665f0
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qcommandlineparser.cpp | 72 | ||||
-rw-r--r-- | src/corelib/tools/qhash.h | 24 | ||||
-rw-r--r-- | src/corelib/tools/qlist.h | 9 | ||||
-rw-r--r-- | src/corelib/tools/qmap.h | 9 | ||||
-rw-r--r-- | src/corelib/tools/qmargins.cpp | 12 | ||||
-rw-r--r-- | src/corelib/tools/qrect.cpp | 4 | ||||
-rw-r--r-- | src/corelib/tools/qregexp.cpp | 4 | ||||
-rw-r--r-- | src/corelib/tools/qsharedpointer.cpp | 8 | ||||
-rw-r--r-- | src/corelib/tools/qsharedpointer.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qstring.h | 11 | ||||
-rw-r--r-- | src/corelib/tools/qstringbuilder.h | 8 | ||||
-rw-r--r-- | src/corelib/tools/qtimezoneprivate_mac.mm | 1 | ||||
-rw-r--r-- | src/corelib/tools/qvector.h | 9 |
13 files changed, 154 insertions, 19 deletions
diff --git a/src/corelib/tools/qcommandlineparser.cpp b/src/corelib/tools/qcommandlineparser.cpp index 0f5d9a6827..168701d13c 100644 --- a/src/corelib/tools/qcommandlineparser.cpp +++ b/src/corelib/tools/qcommandlineparser.cpp @@ -187,6 +187,78 @@ QStringList QCommandLineParserPrivate::aliases(const QString &optionName) const QCoreApplication::arguments() before QCommandLineParser defines the \c{profile} option and parses the command line. + \section2 How to Use QCommandLineParser in Complex Applications + + In practice, additional error checking needs to be performed on the positional + arguments and option values. For example, ranges of numbers should be checked. + + It is then advisable to introduce a function to do the command line parsing + which takes a struct or class receiving the option values returning an + enumeration representing the result. The dnslookup example of the QtNetwork + module illustrates this: + + \snippet dnslookup.h 0 + + \snippet dnslookup.cpp 0 + + In the main function, help should be printed to the standard output if the help option + was passed and the application should return the exit code 0. + + If an error was detected, the error message should be printed to the standard + error output and the application should return an exit code other than 0. + + \snippet dnslookup.cpp 1 + + A special case to consider here are GUI applications on Windows and mobile + platforms. These applications may not use the standard output or error channels + since the output is either discarded or not accessible. + + For such GUI applications, it is recommended to display help texts and error messages + using a QMessageBox. To preserve the formatting of the help text, rich text + with \c <pre> elements should be used: + + \code + + switch (parseCommandLine(parser, &query, &errorMessage)) { + case CommandLineOk: + break; + case CommandLineError: +#ifdef Q_OS_WIN + QMessageBox::warning(0, QGuiApplication::applicationDisplayName(), + "<html><head/><body><h2>" + errorMessage + "</h2><pre>" + + parser.helpText() + "</pre></body></html>"); +#else + fputs(qPrintable(errorMessage), stderr); + fputs("\n\n", stderr); + fputs(qPrintable(parser.helpText()), stderr); +#endif + return 1; + case CommandLineVersionRequested: +#ifdef Q_OS_WIN + QMessageBox::information(0, QGuiApplication::applicationDisplayName(), + QGuiApplication::applicationDisplayName() + ' ' + + QCoreApplication::applicationVersion()); +#else + printf("%s %s\n", QGuiApplication::applicationDisplayName(), + qPrintable(QCoreApplication::applicationVersion())); +#endif + return 0; + case CommandLineHelpRequested: +#ifdef Q_OS_WIN + QMessageBox::warning(0, QGuiApplication::applicationDisplayName(), + "<html><head/><body><pre>" + + parser.helpText() + "</pre></body></html>"); + return 0; +#else + parser.showHelp(); + Q_UNREACHABLE(); +#endif + } + \endcode + + However, this does not apply to the dnslookup example, because it is a + console application. + \sa QCommandLineOption, QCoreApplication */ diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 7a421a4586..67924c0888 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -52,6 +52,12 @@ #include <initializer_list> #endif +#if defined(Q_CC_MSVC) +#pragma warning( push ) +#pragma warning( disable : 4311 ) // disable pointer truncation warning +#pragma warning( disable : 4127 ) // conditional expression is constant +#endif + QT_BEGIN_NAMESPACE class QBitArray; @@ -95,18 +101,10 @@ Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(QLatin1String key, uint seed = 0) Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qt_hash(const QString &key) Q_DECL_NOTHROW; Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qt_hash(const QStringRef &key) Q_DECL_NOTHROW; -#if defined(Q_CC_MSVC) -#pragma warning( push ) -#pragma warning( disable : 4311 ) // disable pointer truncation warning -#endif template <class T> inline uint qHash(const T *key, uint seed = 0) Q_DECL_NOTHROW { return qHash(reinterpret_cast<quintptr>(key), seed); } -#if defined(Q_CC_MSVC) -#pragma warning( pop ) -#endif - template<typename T> inline uint qHash(const T &t, uint seed) Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(t))) { return (qHash(t) ^ seed); } @@ -214,6 +212,9 @@ struct QHashNode inline QHashNode(const Key &key0, const T &value0, uint hash, QHashNode *n) : next(n), h(hash), key(key0), value(value0) {} inline bool same_key(uint h0, const Key &key0) const { return h0 == h && key0 == key; } + +private: + Q_DISABLE_COPY(QHashNode) }; template <class Key, class T> @@ -224,6 +225,9 @@ struct QHashDummyNode const Key key; inline QHashDummyNode(const Key &key0, uint hash, QHashNode<Key, T> *n) : next(n), h(hash), key(key0) {} + +private: + Q_DISABLE_COPY(QHashDummyNode) }; @@ -1087,4 +1091,8 @@ Q_DECLARE_MUTABLE_ASSOCIATIVE_ITERATOR(Hash) QT_END_NAMESPACE +#if defined(Q_CC_MSVC) +#pragma warning( pop ) +#endif + #endif // QHASH_H diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 16f058b001..3a0d01aa8d 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -58,6 +58,11 @@ #include <limits.h> #include <string.h> +#ifdef Q_CC_MSVC +#pragma warning( push ) +#pragma warning( disable : 4127 ) // "conditional expression is constant" +#endif + QT_BEGIN_NAMESPACE @@ -937,4 +942,8 @@ Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(List) QT_END_NAMESPACE +#ifdef Q_CC_MSVC +#pragma warning( pop ) +#endif + #endif // QLIST_H diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index db0cd6a2d6..487039ccfb 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -260,6 +260,11 @@ QMapNode<Key, T> *QMapNode<Key, T>::copy(QMapData<Key, T> *d) const return n; } +#if defined(Q_CC_MSVC) +#pragma warning( push ) +#pragma warning( disable : 4127 ) // conditional expression is constant +#endif + template <class Key, class T> void QMapNode<Key, T>::destroySubTree() { @@ -275,6 +280,10 @@ void QMapNode<Key, T>::destroySubTree() } } +#if defined(Q_CC_MSVC) +#pragma warning( pop ) +#endif + template <class Key, class T> void QMapData<Key, T>::deleteNode(QMapNode<Key, T> *z) { diff --git a/src/corelib/tools/qmargins.cpp b/src/corelib/tools/qmargins.cpp index 088f0dc083..03993f05a9 100644 --- a/src/corelib/tools/qmargins.cpp +++ b/src/corelib/tools/qmargins.cpp @@ -312,7 +312,7 @@ QT_BEGIN_NAMESPACE */ /*! - \fn QMargins &operator+=(const QMargins &margins) + \fn QMargins &QMargins::operator+=(const QMargins &margins) Add each component of \a margins to the respective component of this object and returns a reference to it. @@ -323,7 +323,7 @@ QT_BEGIN_NAMESPACE */ /*! - \fn QMargins &operator-=(const QMargins &margins) + \fn QMargins &QMargins::operator-=(const QMargins &margins) Subtract each component of \a margins from the respective component of this object and returns a reference to it. @@ -334,7 +334,7 @@ QT_BEGIN_NAMESPACE */ /*! - \fn QMargins &operator*=(int factor) + \fn QMargins &QMargins::operator*=(int factor) Multiplies each component of this object by \a factor and returns a reference to it. @@ -345,7 +345,7 @@ QT_BEGIN_NAMESPACE */ /*! - \fn QMargins &operator*=(qreal factor) + \fn QMargins &QMargins::operator*=(qreal factor) \overload Multiplies each component of this object by \a factor @@ -357,7 +357,7 @@ QT_BEGIN_NAMESPACE */ /*! - \fn QMargins &operator/=(int divisor) + \fn QMargins &QMargins::operator/=(int divisor) Divides each component of this object by \a divisor and returns a reference to it. @@ -368,7 +368,7 @@ QT_BEGIN_NAMESPACE */ /*! - \fn QMargins &operator/=(qreal divisor) + \fn QMargins &QMargins::operator/=(qreal divisor) \overload diff --git a/src/corelib/tools/qrect.cpp b/src/corelib/tools/qrect.cpp index 1b3a28839c..35c7d1cd3c 100644 --- a/src/corelib/tools/qrect.cpp +++ b/src/corelib/tools/qrect.cpp @@ -1201,7 +1201,7 @@ bool QRect::intersects(const QRect &r) const */ /*! - \fn QRect QRect::operator+=(const QMargins &margins) const + \fn QRect QRect::operator+=(const QMargins &margins) Adds the \a margins to the rectangle, growing it. @@ -1221,7 +1221,7 @@ bool QRect::intersects(const QRect &r) const */ /*! - \fn QRect QRect::operator -=(const QMargins &margins) const + \fn QRect QRect::operator -=(const QMargins &margins) Returns a rectangle shrunk by the \a margins. diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp index d2b5adc974..cadf2da019 100644 --- a/src/corelib/tools/qregexp.cpp +++ b/src/corelib/tools/qregexp.cpp @@ -133,8 +133,8 @@ int qFindString(const QChar *haystack, int haystackLen, int from, or \b{5}. An expression can also be a set of characters enclosed in square brackets. \b{[ABCD]} will match an \b{A} or a \b{B} or a \b{C} or a \b{D}. We can write this same - expression as \b{[A-D]}, and an experession to match any - captital letter in the English alphabet is written as + expression as \b{[A-D]}, and an expression to match any + capital letter in the English alphabet is written as \b{[A-Z]}. A quantifier specifies the number of occurrences of an expression diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index 77409f5c71..a610fc46e5 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -478,6 +478,14 @@ */ /*! + \fn void QSharedPointer::swap(QSharedPointer<T> &other); + \since 5.3 + + Swaps this shared pointer instance with \a other. This function is + very fast and never fails. +*/ + +/*! \fn T *QSharedPointer::data() const Returns the value of the pointer referenced by this object. diff --git a/src/corelib/tools/qsharedpointer.h b/src/corelib/tools/qsharedpointer.h index 7d1f00814d..34b4bfbb12 100644 --- a/src/corelib/tools/qsharedpointer.h +++ b/src/corelib/tools/qsharedpointer.h @@ -79,6 +79,8 @@ public: QSharedPointer<T> &operator=(const QSharedPointer<T> &other); QSharedPointer<T> &operator=(const QWeakPointer<T> &other); + void swap(QSharedPointer<T> &other); + QWeakPointer<T> toWeakRef() const; void clear(); diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 9063f59171..cf0726d831 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -870,6 +870,12 @@ inline QString QString::arg(const QString &a1, const QString &a2, const QString inline QString QString::section(QChar asep, int astart, int aend, SectionFlags aflags) const { return section(QString(asep), astart, aend, aflags); } +#ifdef Q_CC_MSVC +// "conditional expression is constant" +#pragma warning(push) +#pragma warning(disable : 4127) +#endif + inline int QString::toWCharArray(wchar_t *array) const { if (sizeof(wchar_t) == sizeof(QChar)) { @@ -878,6 +884,11 @@ inline int QString::toWCharArray(wchar_t *array) const } return toUcs4_helper(d->data(), size(), reinterpret_cast<uint *>(array)); } + +#ifdef Q_CC_MSVC +#pragma warning(pop) +#endif + inline QString QString::fromWCharArray(const wchar_t *string, int size) { return sizeof(wchar_t) == sizeof(QChar) ? fromUtf16(reinterpret_cast<const ushort *>(string), size) diff --git a/src/corelib/tools/qstringbuilder.h b/src/corelib/tools/qstringbuilder.h index f0670999d7..befa40081c 100644 --- a/src/corelib/tools/qstringbuilder.h +++ b/src/corelib/tools/qstringbuilder.h @@ -143,12 +143,16 @@ class QStringBuilder <QString, QString> : public QStringBuilderBase<QStringBuild { public: QStringBuilder(const QString &a_, const QString &b_) : a(a_), b(b_) {} + QStringBuilder(const QStringBuilder &other) : a(other.a), b(other.b) {} operator QString() const { QString r(a); r += b; return r; } const QString &a; const QString &b; + + private: + QStringBuilder &operator=(const QStringBuilder &) Q_DECL_EQ_DELETE; }; template <> @@ -156,12 +160,16 @@ class QStringBuilder <QByteArray, QByteArray> : public QStringBuilderBase<QStrin { public: QStringBuilder(const QByteArray &a_, const QByteArray &b_) : a(a_), b(b_) {} + QStringBuilder(const QStringBuilder &other) : a(other.a), b(other.b) {} operator QByteArray() const { QByteArray r(a); r += b; return r; } const QByteArray &a; const QByteArray &b; + + private: + QStringBuilder &operator=(const QStringBuilder &) Q_DECL_EQ_DELETE; }; diff --git a/src/corelib/tools/qtimezoneprivate_mac.mm b/src/corelib/tools/qtimezoneprivate_mac.mm index 3d95377850..49930490ff 100644 --- a/src/corelib/tools/qtimezoneprivate_mac.mm +++ b/src/corelib/tools/qtimezoneprivate_mac.mm @@ -272,7 +272,6 @@ QSet<QByteArray> QMacTimeZonePrivate::availableTimeZoneIds() const tzid = QCFString::toQString([enumerator nextObject]).toUtf8(); } - [enumerator release]; return set; } diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 075e8e83e8..b0be98c296 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -287,6 +287,11 @@ void QVector<T>::copyConstruct(const T *srcFrom, const T *srcTo, T *dstFrom) } } +#if defined(Q_CC_MSVC) +#pragma warning( push ) +#pragma warning( disable : 4127 ) // conditional expression is constant +#endif + template <typename T> void QVector<T>::destruct(T *from, T *to) { @@ -297,6 +302,10 @@ void QVector<T>::destruct(T *from, T *to) } } +#if defined(Q_CC_MSVC) +#pragma warning( pop ) +#endif + template <typename T> inline QVector<T>::QVector(const QVector<T> &v) { |