summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/animation/qabstractanimation.h2
-rw-r--r--src/corelib/animation/qabstractanimation_p.h10
-rw-r--r--src/corelib/animation/qanimationgroup.h2
-rw-r--r--src/corelib/animation/qparallelanimationgroup.h10
-rw-r--r--src/corelib/animation/qparallelanimationgroup_p.h2
-rw-r--r--src/corelib/animation/qpauseanimation.h6
-rw-r--r--src/corelib/animation/qpropertyanimation.h6
-rw-r--r--src/corelib/animation/qsequentialanimationgroup.h10
-rw-r--r--src/corelib/animation/qsequentialanimationgroup_p.h4
-rw-r--r--src/corelib/animation/qvariantanimation.h8
-rw-r--r--src/corelib/codecs/qicucodec_p.h10
-rw-r--r--src/corelib/codecs/qisciicodec_p.h8
-rw-r--r--src/corelib/codecs/qlatincodec_p.h20
-rw-r--r--src/corelib/codecs/qtsciicodec_p.h8
-rw-r--r--src/corelib/codecs/qutfcodec_p.h52
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qmimedata.cpp6
-rw-r--r--src/corelib/doc/snippets/qstring/main.cpp14
-rw-r--r--src/corelib/global/qcompilerdetection.h104
-rw-r--r--src/corelib/global/qflags.h14
-rw-r--r--src/corelib/global/qglobal.cpp116
-rw-r--r--src/corelib/global/qglobal.h37
-rw-r--r--src/corelib/global/qlibraryinfo.cpp2
-rw-r--r--src/corelib/global/qlogging.cpp19
-rw-r--r--src/corelib/global/qsysinfo.h18
-rw-r--r--src/corelib/io/qbuffer.cpp4
-rw-r--r--src/corelib/io/qbuffer.h22
-rw-r--r--src/corelib/io/qdatastream.cpp1
-rw-r--r--src/corelib/io/qdatastream.h5
-rw-r--r--src/corelib/io/qdebug.cpp22
-rw-r--r--src/corelib/io/qdebug.h11
-rw-r--r--src/corelib/io/qdir.cpp29
-rw-r--r--src/corelib/io/qfile.h12
-rw-r--r--src/corelib/io/qfiledevice.h18
-rw-r--r--src/corelib/io/qfiledevice_p.h2
-rw-r--r--src/corelib/io/qfileselector.cpp2
-rw-r--r--src/corelib/io/qfilesystemengine_unix.cpp37
-rw-r--r--src/corelib/io/qfilesystemwatcher_inotify_p.h4
-rw-r--r--src/corelib/io/qfilesystemwatcher_polling_p.h4
-rw-r--r--src/corelib/io/qfsfileengine_iterator_p.h8
-rw-r--r--src/corelib/io/qfsfileengine_p.h68
-rw-r--r--src/corelib/io/qiodevice.cpp167
-rw-r--r--src/corelib/io/qipaddress.cpp3
-rw-r--r--src/corelib/io/qnoncontiguousbytedevice_p.h52
-rw-r--r--src/corelib/io/qprocess.h20
-rw-r--r--src/corelib/io/qprocess_unix.cpp2
-rw-r--r--src/corelib/io/qresource.cpp22
-rw-r--r--src/corelib/io/qresource_iterator_p.h6
-rw-r--r--src/corelib/io/qresource_p.h60
-rw-r--r--src/corelib/io/qsettings.h2
-rw-r--r--src/corelib/io/qsettings_p.h18
-rw-r--r--src/corelib/io/qstorageinfo_p.h6
-rw-r--r--src/corelib/io/qstorageinfo_unix.cpp4
-rw-r--r--src/corelib/io/qstorageinfo_win.cpp8
-rw-r--r--src/corelib/io/qtemporaryfile.cpp1
-rw-r--r--src/corelib/io/qtemporaryfile.h4
-rw-r--r--src/corelib/io/qtextstream.cpp85
-rw-r--r--src/corelib/io/qtextstream_p.h8
-rw-r--r--src/corelib/io/qurlrecode.cpp4
-rw-r--r--src/corelib/itemmodels/qabstractitemmodel.cpp17
-rw-r--r--src/corelib/itemmodels/qabstractitemmodel.h34
-rw-r--r--src/corelib/itemmodels/qabstractproxymodel.h48
-rw-r--r--src/corelib/itemmodels/qidentityproxymodel.cpp3
-rw-r--r--src/corelib/itemmodels/qidentityproxymodel.h38
-rw-r--r--src/corelib/itemmodels/qsortfilterproxymodel.cpp23
-rw-r--r--src/corelib/itemmodels/qsortfilterproxymodel.h66
-rw-r--r--src/corelib/itemmodels/qstringlistmodel.h18
-rw-r--r--src/corelib/json/qjsonobject.cpp43
-rw-r--r--src/corelib/json/qjsonobject.h4
-rw-r--r--src/corelib/json/qjsonvalue.cpp3
-rw-r--r--src/corelib/kernel/kernel.pri24
-rw-r--r--src/corelib/kernel/qcore_mac_objc.mm67
-rw-r--r--src/corelib/kernel/qcore_mac_p.h8
-rw-r--r--src/corelib/kernel/qcoreapplication.h2
-rw-r--r--src/corelib/kernel/qcoreevent.cpp1
-rw-r--r--src/corelib/kernel/qcoreevent.h2
-rw-r--r--src/corelib/kernel/qeventdispatcher_glib_p.h4
-rw-r--r--src/corelib/kernel/qeventdispatcher_unix_p.h6
-rw-r--r--src/corelib/kernel/qeventloop.h2
-rw-r--r--src/corelib/kernel/qfunctions_wince.h2
-rw-r--r--src/corelib/kernel/qmetaobject.cpp208
-rw-r--r--src/corelib/kernel/qmetaobject.h35
-rw-r--r--src/corelib/kernel/qmetaobject_p.h4
-rw-r--r--src/corelib/kernel/qmetatype.cpp256
-rw-r--r--src/corelib/kernel/qmetatype.h70
-rw-r--r--src/corelib/kernel/qmetatype_p.h6
-rw-r--r--src/corelib/kernel/qmimedata.cpp5
-rw-r--r--src/corelib/kernel/qobject.cpp10
-rw-r--r--src/corelib/kernel/qobject_p.h4
-rw-r--r--src/corelib/kernel/qobjectdefs.h15
-rw-r--r--src/corelib/kernel/qsocketnotifier.h2
-rw-r--r--src/corelib/kernel/qtimer.cpp2
-rw-r--r--src/corelib/kernel/qtimer.h2
-rw-r--r--src/corelib/kernel/qtranslator.cpp1
-rw-r--r--src/corelib/kernel/qvariant.cpp211
-rw-r--r--src/corelib/mimetypes/qmimedatabase_p.h1
-rw-r--r--src/corelib/mimetypes/qmimeprovider_p.h38
-rw-r--r--src/corelib/plugin/qlibrary.cpp10
-rw-r--r--src/corelib/plugin/qlibrary.h3
-rw-r--r--src/corelib/plugin/qlibrary_unix.cpp4
-rw-r--r--src/corelib/plugin/quuid.cpp21
-rw-r--r--src/corelib/plugin/quuid.h15
-rw-r--r--src/corelib/statemachine/qabstractstate.h2
-rw-r--r--src/corelib/statemachine/qabstracttransition.h2
-rw-r--r--src/corelib/statemachine/qeventtransition.h6
-rw-r--r--src/corelib/statemachine/qfinalstate.h6
-rw-r--r--src/corelib/statemachine/qhistorystate.h6
-rw-r--r--src/corelib/statemachine/qsignaltransition.h6
-rw-r--r--src/corelib/statemachine/qsignaltransition_p.h2
-rw-r--r--src/corelib/statemachine/qstate.cpp15
-rw-r--r--src/corelib/statemachine/qstate.h20
-rw-r--r--src/corelib/statemachine/qstatemachine.cpp8
-rw-r--r--src/corelib/statemachine/qstatemachine.h8
-rw-r--r--src/corelib/thread/qatomic.h11
-rw-r--r--src/corelib/thread/qexception.h4
-rw-r--r--src/corelib/thread/qfutureinterface.cpp4
-rw-r--r--src/corelib/thread/qfuturewatcher.h14
-rw-r--r--src/corelib/thread/qfuturewatcher_p.h4
-rw-r--r--src/corelib/thread/qthread.h2
-rw-r--r--src/corelib/thread/qthread_p.h2
-rw-r--r--src/corelib/thread/qthreadpool.cpp46
-rw-r--r--src/corelib/thread/qthreadpool.h1
-rw-r--r--src/corelib/thread/qthreadpool_p.h3
-rw-r--r--src/corelib/tools/qarraydata.cpp19
-rw-r--r--src/corelib/tools/qarraydatapointer.h6
-rw-r--r--src/corelib/tools/qbytearray.cpp237
-rw-r--r--src/corelib/tools/qbytearray.h40
-rw-r--r--src/corelib/tools/qchar.h125
-rw-r--r--src/corelib/tools/qcommandlineparser.cpp68
-rw-r--r--src/corelib/tools/qdatetime.cpp101
-rw-r--r--src/corelib/tools/qdatetime.h16
-rw-r--r--src/corelib/tools/qdatetime_mac.mm76
-rw-r--r--src/corelib/tools/qdatetime_p.h3
-rw-r--r--src/corelib/tools/qeasingcurve.cpp105
-rw-r--r--src/corelib/tools/qelapsedtimer_generic.cpp4
-rw-r--r--src/corelib/tools/qelapsedtimer_unix.cpp14
-rw-r--r--src/corelib/tools/qhash.cpp46
-rw-r--r--src/corelib/tools/qhash.h2
-rw-r--r--src/corelib/tools/qlist.cpp2
-rw-r--r--src/corelib/tools/qlist.h25
-rw-r--r--src/corelib/tools/qmap.cpp43
-rw-r--r--src/corelib/tools/qmap.h2
-rw-r--r--src/corelib/tools/qmargins.h90
-rw-r--r--src/corelib/tools/qpair.h4
-rw-r--r--src/corelib/tools/qpoint.h72
-rw-r--r--src/corelib/tools/qrect.h264
-rw-r--r--src/corelib/tools/qregularexpression.cpp131
-rw-r--r--src/corelib/tools/qregularexpression.h10
-rw-r--r--src/corelib/tools/qringbuffer_p.h46
-rw-r--r--src/corelib/tools/qsize.h56
-rw-r--r--src/corelib/tools/qstring.cpp514
-rw-r--r--src/corelib/tools/qstring.h88
-rw-r--r--src/corelib/tools/qstring_compat.cpp49
-rw-r--r--src/corelib/tools/qstringalgorithms_p.h156
-rw-r--r--src/corelib/tools/qstringiterator_p.h5
-rw-r--r--src/corelib/tools/qstringlist.cpp45
-rw-r--r--src/corelib/tools/qstringlist.h18
-rw-r--r--src/corelib/tools/qtimeline.h2
-rw-r--r--src/corelib/tools/qtimezone.cpp4
-rw-r--r--src/corelib/tools/qtimezoneprivate_android.cpp287
-rw-r--r--src/corelib/tools/qtimezoneprivate_p.h50
-rw-r--r--src/corelib/tools/qtools_p.h31
-rw-r--r--src/corelib/tools/qvector.cpp12
-rw-r--r--src/corelib/tools/qvector.h26
-rw-r--r--src/corelib/tools/tools.pri11
-rw-r--r--src/corelib/xml/qxmlstream.cpp9
-rw-r--r--src/corelib/xml/qxmlstream.h5
166 files changed, 3537 insertions, 2101 deletions
diff --git a/src/corelib/animation/qabstractanimation.h b/src/corelib/animation/qabstractanimation.h
index 2c325e7c02..43190cc9e2 100644
--- a/src/corelib/animation/qabstractanimation.h
+++ b/src/corelib/animation/qabstractanimation.h
@@ -111,7 +111,7 @@ public Q_SLOTS:
protected:
QAbstractAnimation(QAbstractAnimationPrivate &dd, QObject *parent = 0);
- bool event(QEvent *event);
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
virtual void updateCurrentTime(int currentTime) = 0;
virtual void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h
index 827d6aeb54..6365b45cbe 100644
--- a/src/corelib/animation/qabstractanimation_p.h
+++ b/src/corelib/animation/qabstractanimation_p.h
@@ -110,7 +110,7 @@ class QDefaultAnimationDriver : public QAnimationDriver
Q_OBJECT
public:
QDefaultAnimationDriver(QUnifiedTimer *timer);
- void timerEvent(QTimerEvent *e);
+ void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE;
private Q_SLOTS:
void startTimer();
@@ -190,7 +190,7 @@ public:
qint64 elapsed() const;
protected:
- void timerEvent(QTimerEvent *);
+ void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE;
private Q_SLOTS:
void startTimers();
@@ -259,11 +259,11 @@ public:
*/
static void updateAnimationTimer();
- void restartAnimationTimer();
- void updateAnimationsTime(qint64 delta);
+ void restartAnimationTimer() Q_DECL_OVERRIDE;
+ void updateAnimationsTime(qint64 delta) Q_DECL_OVERRIDE;
//useful for profiling/debugging
- int runningAnimationCount() { return animations.count(); }
+ int runningAnimationCount() Q_DECL_OVERRIDE { return animations.count(); }
private Q_SLOTS:
void startAnimations();
diff --git a/src/corelib/animation/qanimationgroup.h b/src/corelib/animation/qanimationgroup.h
index 5a027e75ca..59478b07fb 100644
--- a/src/corelib/animation/qanimationgroup.h
+++ b/src/corelib/animation/qanimationgroup.h
@@ -61,7 +61,7 @@ public:
protected:
QAnimationGroup(QAnimationGroupPrivate &dd, QObject *parent);
- bool event(QEvent *event);
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(QAnimationGroup)
diff --git a/src/corelib/animation/qparallelanimationgroup.h b/src/corelib/animation/qparallelanimationgroup.h
index 7183823987..7ae3d638a7 100644
--- a/src/corelib/animation/qparallelanimationgroup.h
+++ b/src/corelib/animation/qparallelanimationgroup.h
@@ -50,15 +50,15 @@ public:
QParallelAnimationGroup(QObject *parent = 0);
~QParallelAnimationGroup();
- int duration() const;
+ int duration() const Q_DECL_OVERRIDE;
protected:
QParallelAnimationGroup(QParallelAnimationGroupPrivate &dd, QObject *parent);
- bool event(QEvent *event);
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
- void updateCurrentTime(int currentTime);
- void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
- void updateDirection(QAbstractAnimation::Direction direction);
+ void updateCurrentTime(int currentTime) Q_DECL_OVERRIDE;
+ void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) Q_DECL_OVERRIDE;
+ void updateDirection(QAbstractAnimation::Direction direction) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(QParallelAnimationGroup)
diff --git a/src/corelib/animation/qparallelanimationgroup_p.h b/src/corelib/animation/qparallelanimationgroup_p.h
index cfaa851b06..68f26312d7 100644
--- a/src/corelib/animation/qparallelanimationgroup_p.h
+++ b/src/corelib/animation/qparallelanimationgroup_p.h
@@ -72,7 +72,7 @@ public:
void connectUncontrolledAnimations();
void disconnectUncontrolledAnimations();
- void animationRemoved(int index, QAbstractAnimation *);
+ void animationRemoved(int index, QAbstractAnimation *) Q_DECL_OVERRIDE;
// private slot
void _q_uncontrolledAnimationFinished();
diff --git a/src/corelib/animation/qpauseanimation.h b/src/corelib/animation/qpauseanimation.h
index 2d53e6da52..aa11936294 100644
--- a/src/corelib/animation/qpauseanimation.h
+++ b/src/corelib/animation/qpauseanimation.h
@@ -52,12 +52,12 @@ public:
QPauseAnimation(int msecs, QObject *parent = 0);
~QPauseAnimation();
- int duration() const;
+ int duration() const Q_DECL_OVERRIDE;
void setDuration(int msecs);
protected:
- bool event(QEvent *e);
- void updateCurrentTime(int);
+ bool event(QEvent *e) Q_DECL_OVERRIDE;
+ void updateCurrentTime(int) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(QPauseAnimation)
diff --git a/src/corelib/animation/qpropertyanimation.h b/src/corelib/animation/qpropertyanimation.h
index 437438dd57..ef946416f0 100644
--- a/src/corelib/animation/qpropertyanimation.h
+++ b/src/corelib/animation/qpropertyanimation.h
@@ -60,9 +60,9 @@ public:
void setPropertyName(const QByteArray &propertyName);
protected:
- bool event(QEvent *event);
- void updateCurrentValue(const QVariant &value);
- void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
+ void updateCurrentValue(const QVariant &value) Q_DECL_OVERRIDE;
+ void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(QPropertyAnimation)
diff --git a/src/corelib/animation/qsequentialanimationgroup.h b/src/corelib/animation/qsequentialanimationgroup.h
index 9346d12e26..b1b5670f39 100644
--- a/src/corelib/animation/qsequentialanimationgroup.h
+++ b/src/corelib/animation/qsequentialanimationgroup.h
@@ -57,18 +57,18 @@ public:
QPauseAnimation *insertPause(int index, int msecs);
QAbstractAnimation *currentAnimation() const;
- int duration() const;
+ int duration() const Q_DECL_OVERRIDE;
Q_SIGNALS:
void currentAnimationChanged(QAbstractAnimation *current);
protected:
QSequentialAnimationGroup(QSequentialAnimationGroupPrivate &dd, QObject *parent);
- bool event(QEvent *event);
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
- void updateCurrentTime(int);
- void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
- void updateDirection(QAbstractAnimation::Direction direction);
+ void updateCurrentTime(int) Q_DECL_OVERRIDE;
+ void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) Q_DECL_OVERRIDE;
+ void updateDirection(QAbstractAnimation::Direction direction) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(QSequentialAnimationGroup)
diff --git a/src/corelib/animation/qsequentialanimationgroup_p.h b/src/corelib/animation/qsequentialanimationgroup_p.h
index caa32faaf8..2b8ac576bb 100644
--- a/src/corelib/animation/qsequentialanimationgroup_p.h
+++ b/src/corelib/animation/qsequentialanimationgroup_p.h
@@ -76,8 +76,8 @@ public:
void setCurrentAnimation(int index, bool intermediate = false);
void activateCurrentAnimation(bool intermediate = false);
- void animationInsertedAt(int index);
- void animationRemoved(int index, QAbstractAnimation *anim);
+ void animationInsertedAt(int index) Q_DECL_OVERRIDE;
+ void animationRemoved(int index, QAbstractAnimation *anim) Q_DECL_OVERRIDE;
bool atEnd() const;
diff --git a/src/corelib/animation/qvariantanimation.h b/src/corelib/animation/qvariantanimation.h
index f2d8c0cfd3..17e8c2a871 100644
--- a/src/corelib/animation/qvariantanimation.h
+++ b/src/corelib/animation/qvariantanimation.h
@@ -76,7 +76,7 @@ public:
QVariant currentValue() const;
- int duration() const;
+ int duration() const Q_DECL_OVERRIDE;
void setDuration(int msecs);
QEasingCurve easingCurve() const;
@@ -89,10 +89,10 @@ Q_SIGNALS:
protected:
QVariantAnimation(QVariantAnimationPrivate &dd, QObject *parent = 0);
- bool event(QEvent *event);
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
- void updateCurrentTime(int);
- void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
+ void updateCurrentTime(int) Q_DECL_OVERRIDE;
+ void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) Q_DECL_OVERRIDE;
virtual void updateCurrentValue(const QVariant &value);
virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const;
diff --git a/src/corelib/codecs/qicucodec_p.h b/src/corelib/codecs/qicucodec_p.h
index 9786b4398a..900debeb7b 100644
--- a/src/corelib/codecs/qicucodec_p.h
+++ b/src/corelib/codecs/qicucodec_p.h
@@ -66,12 +66,12 @@ public:
static QTextCodec *codecForNameUnlocked(const char *name);
static QTextCodec *codecForMibUnlocked(int mib);
- QString convertToUnicode(const char *, int, ConverterState *) const;
- QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;
+ QString convertToUnicode(const char *, int, ConverterState *) const Q_DECL_OVERRIDE;
+ QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const Q_DECL_OVERRIDE;
- QByteArray name() const;
- QList<QByteArray> aliases() const;
- int mibEnum() const;
+ QByteArray name() const Q_DECL_OVERRIDE;
+ QList<QByteArray> aliases() const Q_DECL_OVERRIDE;
+ int mibEnum() const Q_DECL_OVERRIDE;
private:
QIcuCodec(const char *name);
diff --git a/src/corelib/codecs/qisciicodec_p.h b/src/corelib/codecs/qisciicodec_p.h
index ce49975445..4bf89ccd5e 100644
--- a/src/corelib/codecs/qisciicodec_p.h
+++ b/src/corelib/codecs/qisciicodec_p.h
@@ -58,11 +58,11 @@ public:
static QTextCodec *create(const char *name);
- QByteArray name() const;
- int mibEnum() const;
+ QByteArray name() const Q_DECL_OVERRIDE;
+ int mibEnum() const Q_DECL_OVERRIDE;
- QString convertToUnicode(const char *, int, ConverterState *) const;
- QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;
+ QString convertToUnicode(const char *, int, ConverterState *) const Q_DECL_OVERRIDE;
+ QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const Q_DECL_OVERRIDE;
private:
int idx;
diff --git a/src/corelib/codecs/qlatincodec_p.h b/src/corelib/codecs/qlatincodec_p.h
index c4c9b11ef7..b51cfb856e 100644
--- a/src/corelib/codecs/qlatincodec_p.h
+++ b/src/corelib/codecs/qlatincodec_p.h
@@ -56,12 +56,12 @@ class QLatin1Codec : public QTextCodec
public:
~QLatin1Codec();
- QString convertToUnicode(const char *, int, ConverterState *) const;
- QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;
+ QString convertToUnicode(const char *, int, ConverterState *) const Q_DECL_OVERRIDE;
+ QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const Q_DECL_OVERRIDE;
- QByteArray name() const;
- QList<QByteArray> aliases() const;
- int mibEnum() const;
+ QByteArray name() const Q_DECL_OVERRIDE;
+ QList<QByteArray> aliases() const Q_DECL_OVERRIDE;
+ int mibEnum() const Q_DECL_OVERRIDE;
};
@@ -71,12 +71,12 @@ class QLatin15Codec: public QTextCodec
public:
~QLatin15Codec();
- QString convertToUnicode(const char *, int, ConverterState *) const;
- QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;
+ QString convertToUnicode(const char *, int, ConverterState *) const Q_DECL_OVERRIDE;
+ QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const Q_DECL_OVERRIDE;
- QByteArray name() const;
- QList<QByteArray> aliases() const;
- int mibEnum() const;
+ QByteArray name() const Q_DECL_OVERRIDE;
+ QList<QByteArray> aliases() const Q_DECL_OVERRIDE;
+ int mibEnum() const Q_DECL_OVERRIDE;
};
#endif // QT_NO_TEXTCODEC
diff --git a/src/corelib/codecs/qtsciicodec_p.h b/src/corelib/codecs/qtsciicodec_p.h
index 62a62b718c..030e9a5ed0 100644
--- a/src/corelib/codecs/qtsciicodec_p.h
+++ b/src/corelib/codecs/qtsciicodec_p.h
@@ -84,11 +84,11 @@ class QTsciiCodec : public QTextCodec {
public:
~QTsciiCodec();
- QByteArray name() const;
- int mibEnum() const;
+ QByteArray name() const Q_DECL_OVERRIDE;
+ int mibEnum() const Q_DECL_OVERRIDE;
- QString convertToUnicode(const char *, int, ConverterState *) const;
- QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;
+ QString convertToUnicode(const char *, int, ConverterState *) const Q_DECL_OVERRIDE;
+ QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const Q_DECL_OVERRIDE;
};
#endif // QT_NO_CODECS
diff --git a/src/corelib/codecs/qutfcodec_p.h b/src/corelib/codecs/qutfcodec_p.h
index eb222bb2d5..16fc9945d3 100644
--- a/src/corelib/codecs/qutfcodec_p.h
+++ b/src/corelib/codecs/qutfcodec_p.h
@@ -305,11 +305,11 @@ class QUtf8Codec : public QTextCodec {
public:
~QUtf8Codec();
- QByteArray name() const;
- int mibEnum() const;
+ QByteArray name() const Q_DECL_OVERRIDE;
+ int mibEnum() const Q_DECL_OVERRIDE;
- QString convertToUnicode(const char *, int, ConverterState *) const;
- QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;
+ QString convertToUnicode(const char *, int, ConverterState *) const Q_DECL_OVERRIDE;
+ QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const Q_DECL_OVERRIDE;
void convertToUnicode(QString *target, const char *, int, ConverterState *) const;
};
@@ -319,12 +319,12 @@ public:
QUtf16Codec() { e = DetectEndianness; }
~QUtf16Codec();
- QByteArray name() const;
- QList<QByteArray> aliases() const;
- int mibEnum() const;
+ QByteArray name() const Q_DECL_OVERRIDE;
+ QList<QByteArray> aliases() const Q_DECL_OVERRIDE;
+ int mibEnum() const Q_DECL_OVERRIDE;
- QString convertToUnicode(const char *, int, ConverterState *) const;
- QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;
+ QString convertToUnicode(const char *, int, ConverterState *) const Q_DECL_OVERRIDE;
+ QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const Q_DECL_OVERRIDE;
protected:
DataEndianness e;
@@ -333,17 +333,17 @@ protected:
class QUtf16BECodec : public QUtf16Codec {
public:
QUtf16BECodec() : QUtf16Codec() { e = BigEndianness; }
- QByteArray name() const;
- QList<QByteArray> aliases() const;
- int mibEnum() const;
+ QByteArray name() const Q_DECL_OVERRIDE;
+ QList<QByteArray> aliases() const Q_DECL_OVERRIDE;
+ int mibEnum() const Q_DECL_OVERRIDE;
};
class QUtf16LECodec : public QUtf16Codec {
public:
QUtf16LECodec() : QUtf16Codec() { e = LittleEndianness; }
- QByteArray name() const;
- QList<QByteArray> aliases() const;
- int mibEnum() const;
+ QByteArray name() const Q_DECL_OVERRIDE;
+ QList<QByteArray> aliases() const Q_DECL_OVERRIDE;
+ int mibEnum() const Q_DECL_OVERRIDE;
};
class QUtf32Codec : public QTextCodec {
@@ -351,12 +351,12 @@ public:
QUtf32Codec() { e = DetectEndianness; }
~QUtf32Codec();
- QByteArray name() const;
- QList<QByteArray> aliases() const;
- int mibEnum() const;
+ QByteArray name() const Q_DECL_OVERRIDE;
+ QList<QByteArray> aliases() const Q_DECL_OVERRIDE;
+ int mibEnum() const Q_DECL_OVERRIDE;
- QString convertToUnicode(const char *, int, ConverterState *) const;
- QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;
+ QString convertToUnicode(const char *, int, ConverterState *) const Q_DECL_OVERRIDE;
+ QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const Q_DECL_OVERRIDE;
protected:
DataEndianness e;
@@ -365,17 +365,17 @@ protected:
class QUtf32BECodec : public QUtf32Codec {
public:
QUtf32BECodec() : QUtf32Codec() { e = BigEndianness; }
- QByteArray name() const;
- QList<QByteArray> aliases() const;
- int mibEnum() const;
+ QByteArray name() const Q_DECL_OVERRIDE;
+ QList<QByteArray> aliases() const Q_DECL_OVERRIDE;
+ int mibEnum() const Q_DECL_OVERRIDE;
};
class QUtf32LECodec : public QUtf32Codec {
public:
QUtf32LECodec() : QUtf32Codec() { e = LittleEndianness; }
- QByteArray name() const;
- QList<QByteArray> aliases() const;
- int mibEnum() const;
+ QByteArray name() const Q_DECL_OVERRIDE;
+ QList<QByteArray> aliases() const Q_DECL_OVERRIDE;
+ int mibEnum() const Q_DECL_OVERRIDE;
};
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qmimedata.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qmimedata.cpp
index 7f42cd8def..278a00fdfd 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qmimedata.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qmimedata.cpp
@@ -106,3 +106,9 @@ if (event->mimeData()->hasColor()) {
...
}
//! [7]
+
+
+//! [8]
+application/x-qt-windows-mime;value="FileContents";index=0
+application/x-qt-windows-mime;value="FileContents";index=1
+//! [8]
diff --git a/src/corelib/doc/snippets/qstring/main.cpp b/src/corelib/doc/snippets/qstring/main.cpp
index f49c4dd359..17d0adf097 100644
--- a/src/corelib/doc/snippets/qstring/main.cpp
+++ b/src/corelib/doc/snippets/qstring/main.cpp
@@ -394,6 +394,13 @@ void Widget::firstIndexOfFunction()
QString str = "the minimum";
str.indexOf(QRegularExpression("m[aeiou]"), 0); // returns 4
//! [93]
+
+ //! [97]
+ QString str = "the minimum";
+ QRegularExpressionMatch match;
+ str.indexOf(QRegularExpression("m[aeiou]"), 0, &match); // returns 4
+ // match.captured() == mi
+ //! [97]
}
void Widget::insertFunction()
@@ -444,6 +451,13 @@ void Widget::lastIndexOfFunction()
QString str = "the minimum";
str.lastIndexOf(QRegularExpression("m[aeiou]")); // returns 8
//! [94]
+
+ //! [98]
+ QString str = "the minimum";
+ QRegularExpressionMatch match;
+ str.lastIndexOf(QRegularExpression("m[aeiou]"), -1, &match); // returns 8
+ // match.captured() == mu
+ //! [98]
}
void Widget::leftFunction()
diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h
index 5f8ca5c7cc..db5f6f3bb1 100644
--- a/src/corelib/global/qcompilerdetection.h
+++ b/src/corelib/global/qcompilerdetection.h
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Copyright (C) 2012 Intel Corporation
+** Copyright (C) 2014 Intel Corporation
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -75,7 +75,6 @@
# if defined(__SC__) && __SC__ < 0x750
# error "Compiler not supported"
# endif
-# define Q_NO_USING_KEYWORD
#elif defined(_MSC_VER)
# define Q_CC_MSVC (_MSC_VER)
@@ -113,7 +112,6 @@
# if __BORLANDC__ < 0x502
# error "Compiler not supported"
# endif
-# define Q_NO_USING_KEYWORD
#elif defined(__WATCOMC__)
# define Q_CC_WAT
@@ -278,7 +276,6 @@
# error "Compiler not supported"
# endif
/* Spurious (?) error messages observed on Compaq C++ V6.5-014. */
-# define Q_NO_USING_KEYWORD
/* Apply to all versions prior to Compaq C++ V6.0-000 - observed on
DEC C++ V5.5-004. */
# if __DECCXX_VER < 60060000
@@ -323,7 +320,6 @@
compiler is using its own set of rules. Forget it. */
# elif defined(__KCC)
# define Q_CC_KAI
-# define Q_NO_USING_KEYWORD
/* Using the `using' keyword avoids Intel C++ for Linux warnings */
# elif defined(__INTEL_COMPILER)
@@ -346,23 +342,19 @@
# if !defined(__SCO_VERSION__) || (__SCO_VERSION__ < 302200010)
# define Q_OUTOFLINE_TEMPLATE inline
# endif
-# define Q_NO_USING_KEYWORD /* ### check "using" status */
/* Never tested! */
# elif defined(CENTERLINE_CLPP) || defined(OBJECTCENTER)
# define Q_CC_OC
-# define Q_NO_USING_KEYWORD
/* CDS++ defines __EDG__ although this is not documented in the Reliant
documentation. It also follows conventions like _BOOL and this documented */
# elif defined(sinix)
# define Q_CC_CDS
-# define Q_NO_USING_KEYWORD
/* The MIPSpro compiler defines __EDG */
# elif defined(__sgi)
# define Q_CC_MIPS
-# define Q_NO_USING_KEYWORD /* ### check "using" status */
# define Q_NO_TEMPLATE_FRIENDS
# if defined(_COMPILER_VERSION) && (_COMPILER_VERSION >= 740)
# define Q_OUTOFLINE_TEMPLATE inline
@@ -404,9 +396,6 @@
# if !defined(_BOOL)
# error "Compiler not supported"
# endif
-# if defined(__SUNPRO_CC_COMPAT) && (__SUNPRO_CC_COMPAT <= 4)
-# define Q_NO_USING_KEYWORD
-# endif
# define Q_C_CALLBACKS
/* 4.2 compiler or older */
# else
@@ -445,7 +434,6 @@
# else
# error "Compiler not supported"
# endif
-# define Q_NO_USING_KEYWORD /* ### check "using" status */
#else
# error "Qt has not been tested with this compiler - see http://www.qt-project.org/"
@@ -511,7 +499,7 @@
// at least since 13.1, but I can't test further back
# define Q_COMPILER_BINARY_LITERALS
# endif
-# if __cplusplus >= 201103L
+# if __cplusplus >= 201103L || defined(__INTEL_CXX11_MODE__)
# if __INTEL_COMPILER >= 1200
# define Q_COMPILER_AUTO_TYPE
# define Q_COMPILER_CLASS_ENUM
@@ -529,7 +517,9 @@
# define Q_COMPILER_AUTO_FUNCTION
# define Q_COMPILER_NULLPTR
# define Q_COMPILER_TEMPLATE_ALIAS
-# define Q_COMPILER_UNICODE_STRINGS
+# ifndef _CHAR16T // MSVC headers
+# define Q_COMPILER_UNICODE_STRINGS
+# endif
# define Q_COMPILER_VARIADIC_TEMPLATES
# endif
# if __INTEL_COMPILER >= 1300
@@ -874,7 +864,24 @@
# if _MSC_FULL_VER >= 180030324 // VC 12 SP 2 RC
# define Q_COMPILER_INITIALIZER_LISTS
# endif /* VC 12 SP 2 RC */
-
+# if _MSC_VER >= 1900
+ /* C++11 features in VC14 = VC2015 */
+# define Q_COMPILER_ALIGNAS
+# define Q_COMPILER_ALIGNOF
+// Partial support, insufficient for Qt
+//# define Q_COMPILER_CONSTEXPR
+# define Q_COMPILER_INHERITING_CONSTRUCTORS
+# define Q_COMPILER_NOEXCEPT
+# define Q_COMPILER_RANGE_FOR
+# define Q_COMPILER_REF_QUALIFIERS
+# define Q_COMPILER_THREAD_LOCAL
+# define Q_COMPILER_THREADSAFE_STATICS
+# define Q_COMPILER_UDL
+# define Q_COMPILER_UNICODE_STRINGS
+// Uniform initialization is not working yet -- build errors with QUuid
+//# define Q_COMPILER_UNIFORM_INIT
+# define Q_COMPILER_UNRESTRICTED_UNIONS
+# endif
# endif /* __cplusplus */
#endif /* Q_CC_MSVC */
@@ -944,12 +951,21 @@
# define Q_COMPILER_DEFAULT_DELETE_MEMBERS
#endif
-#ifdef Q_COMPILER_CONSTEXPR
+#if defined(__cpp_constexpr) && __cpp_constexpr-0 >= 201304
+# define Q_DECL_CONSTEXPR constexpr
+# define Q_DECL_RELAXED_CONSTEXPR constexpr
+# define Q_CONSTEXPR constexpr
+# define Q_RELAXED_CONSTEXPR constexpr
+#elif defined Q_COMPILER_CONSTEXPR
# define Q_DECL_CONSTEXPR constexpr
+# define Q_DECL_RELAXED_CONSTEXPR
# define Q_CONSTEXPR constexpr
+# define Q_RELAXED_CONSTEXPR const
#else
# define Q_DECL_CONSTEXPR
+# define Q_DECL_RELAXED_CONSTEXPR
# define Q_CONSTEXPR const
+# define Q_RELAXED_CONSTEXPR const
#endif
#ifdef Q_COMPILER_EXPLICIT_OVERRIDES
@@ -1052,6 +1068,60 @@
#endif
/*
+ * Warning/diagnostic handling
+ */
+
+#define QT_DO_PRAGMA(text) _Pragma(#text)
+#if defined(Q_CC_INTEL) && defined(Q_CC_MSVC)
+/* icl.exe: Intel compiler on Windows */
+# undef QT_DO_PRAGMA /* not needed */
+# define QT_WARNING_PUSH __pragma(warning(push))
+# define QT_WARNING_POP __pragma(warning(pop))
+# define QT_WARNING_DISABLE_MSVC(number)
+# define QT_WARNING_DISABLE_INTEL(number) __pragma(warning(disable: number))
+# define QT_WARNING_DISABLE_CLANG(text)
+# define QT_WARNING_DISABLE_GCC(text)
+#elif defined(Q_CC_INTEL)
+/* icc: Intel compiler on Linux or OS X */
+# define QT_WARNING_PUSH QT_DO_PRAGMA(warning(push))
+# define QT_WARNING_POP QT_DO_PRAGMA(warning(pop))
+# define QT_WARNING_DISABLE_INTEL(number) QT_DO_PRAGMA(warning(disable: number))
+# define QT_WARNING_DISABLE_MSVC(number)
+# define QT_WARNING_DISABLE_CLANG(text)
+# define QT_WARNING_DISABLE_GCC(text)
+#elif defined(Q_CC_MSVC) && _MSC_VER >= 1500
+# undef QT_DO_PRAGMA /* not needed */
+# define QT_WARNING_PUSH __pragma(warning(push))
+# define QT_WARNING_POP __pragma(warning(pop))
+# define QT_WARNING_DISABLE_MSVC(number) __pragma(warning(disable: number))
+# define QT_WARNING_DISABLE_INTEL(number)
+# define QT_WARNING_DISABLE_CLANG(text)
+# define QT_WARNING_DISABLE_GCC(text)
+#elif defined(Q_CC_CLANG)
+# define QT_WARNING_PUSH QT_DO_PRAGMA(clang diagnostic push)
+# define QT_WARNING_POP QT_DO_PRAGMA(clang diagnostic pop)
+# define QT_WARNING_DISABLE_CLANG(text) QT_DO_PRAGMA(clang diagnostic ignored text)
+# define QT_WARNING_DISABLE_GCC(text) QT_DO_PRAGMA(GCC diagnostic ignored text) // GCC directives work in Clang too
+# define QT_WARNING_DISABLE_INTEL(number)
+# define QT_WARNING_DISABLE_MSVC(number)
+#elif defined(Q_CC_GNU) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 405)
+# define QT_WARNING_PUSH QT_DO_PRAGMA(GCC diagnostic push)
+# define QT_WARNING_POP QT_DO_PRAGMA(GCC diagnostic pop)
+# define QT_WARNING_DISABLE_GCC(text) QT_DO_PRAGMA(GCC diagnostic ignored text)
+# define QT_WARNING_DISABLE_CLANG(text)
+# define QT_WARNING_DISABLE_INTEL(number)
+# define QT_WARNING_DISABLE_MSVC(number)
+#else // All other compilers, GCC < 4.6 and MSVC < 2008
+# define QT_WARNING_DISABLE_GCC(text)
+# define QT_WARNING_PUSH
+# define QT_WARNING_POP
+# define QT_WARNING_DISABLE_INTEL(number)
+# define QT_WARNING_DISABLE_MSVC(number)
+# define QT_WARNING_DISABLE_CLANG(text)
+# define QT_WARNING_DISABLE_GCC(text)
+#endif
+
+/*
Proper for-scoping in MIPSpro CC
*/
#ifndef QT_NO_KEYWORDS
diff --git a/src/corelib/global/qflags.h b/src/corelib/global/qflags.h
index 275ab12800..cfe75c4eea 100644
--- a/src/corelib/global/qflags.h
+++ b/src/corelib/global/qflags.h
@@ -117,13 +117,13 @@ public:
: i(initializer_list_helper(flags.begin(), flags.end())) {}
#endif
- inline QFlags &operator&=(int mask) { i &= mask; return *this; }
- inline QFlags &operator&=(uint mask) { i &= mask; return *this; }
- inline QFlags &operator&=(Enum mask) { i &= Int(mask); return *this; }
- inline QFlags &operator|=(QFlags f) { i |= f.i; return *this; }
- inline QFlags &operator|=(Enum f) { i |= Int(f); return *this; }
- inline QFlags &operator^=(QFlags f) { i ^= f.i; return *this; }
- inline QFlags &operator^=(Enum f) { i ^= Int(f); return *this; }
+ Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator&=(int mask) { i &= mask; return *this; }
+ Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator&=(uint mask) { i &= mask; return *this; }
+ Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator&=(Enum mask) { i &= Int(mask); return *this; }
+ Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator|=(QFlags f) { i |= f.i; return *this; }
+ Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator|=(Enum f) { i |= Int(f); return *this; }
+ Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator^=(QFlags f) { i ^= f.i; return *this; }
+ Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator^=(Enum f) { i ^= Int(f); return *this; }
Q_DECL_CONSTEXPR inline operator Int() const { return i; }
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index ae3e86629e..2d4edb48d1 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -39,6 +39,7 @@
#include "qthreadstorage.h"
#include "qdir.h"
#include "qdatetime.h"
+#include <private/qlocale_tools_p.h>
#ifndef QT_NO_QOBJECT
#include <private/qthread_p.h>
@@ -984,9 +985,9 @@ bool qSharedBuild() Q_DECL_NOTHROW
\li \l ByteOrder specifies whether the platform is big-endian or
little-endian.
\li \l WindowsVersion specifies the version of the Windows operating
- system on which the application is run (Windows only)
+ system on which the application is run.
\li \l MacintoshVersion specifies the version of the Macintosh
- operating system on which the application is run (Mac only).
+ operating system on which the application is run.
\endlist
Some constants are defined only on certain platforms. You can use
@@ -1009,7 +1010,7 @@ bool qSharedBuild() Q_DECL_NOTHROW
/*!
\variable QSysInfo::WindowsVersion
\brief the version of the Windows operating system on which the
- application is run (Windows only)
+ application is run.
*/
/*!
@@ -1017,19 +1018,22 @@ bool qSharedBuild() Q_DECL_NOTHROW
\since 4.4
Returns the version of the Windows operating system on which the
- application is run (Windows only).
+ application is run, or WV_None if the operating system is not
+ Windows.
*/
/*!
\variable QSysInfo::MacintoshVersion
\brief the version of the Macintosh operating system on which
- the application is run (Mac only).
+ the application is run.
*/
/*!
\fn QSysInfo::MacVersion QSysInfo::macVersion()
- Returns the version of Darwin (OS X or iOS) on which the application is run.
+ Returns the version of Darwin (OS X or iOS) on which the
+ application is run, or MV_None if the operating system
+ is not a version of Darwin.
*/
/*!
@@ -1092,6 +1096,8 @@ bool qSharedBuild() Q_DECL_NOTHROW
\value WV_NT_based NT-based version of Windows
\value WV_CE_based CE-based version of Windows
+ \value WV_None Operating system other than Windows.
+
\sa MacVersion
*/
@@ -1139,6 +1145,8 @@ bool qSharedBuild() Q_DECL_NOTHROW
\value MV_IOS_7_1 iOS 7.1
\value MV_IOS_8_0 iOS 8.0
+ \value MV_None Not a Darwin operating system
+
\sa WinVersion
*/
@@ -1845,16 +1853,14 @@ Q_CORE_EXPORT QString qt_mac_from_pascal_string(const Str255 pstr) {
QSysInfo::MacVersion QSysInfo::macVersion()
{
+ const QAppleOperatingSystemVersion version = qt_apple_os_version(); // qtcore_mac_objc.mm
#if defined(Q_OS_OSX)
- SInt32 gestalt_version;
- if (Gestalt(gestaltSystemVersionMinor, &gestalt_version) == noErr) {
- // add 2 because OS X 10.0 is 0x02 in the enum
- return QSysInfo::MacVersion(gestalt_version + 2);
- }
+ return QSysInfo::MacVersion(Q_MV_OSX(version.major, version.minor));
#elif defined(Q_OS_IOS)
- return qt_ios_version(); // qtcore_mac_objc.mm
-#endif
+ return QSysInfo::MacVersion(Q_MV_IOS(version.major, version.minor));
+#else
return QSysInfo::MV_Unknown;
+#endif
}
const QSysInfo::MacVersion QSysInfo::MacintoshVersion = QSysInfo::macVersion();
@@ -2493,25 +2499,9 @@ QString QSysInfo::productType()
*/
QString QSysInfo::productVersion()
{
-#if defined(Q_OS_IOS)
- int major = (int(MacintoshVersion) >> 4) & 0xf;
- int minor = int(MacintoshVersion) & 0xf;
- if (Q_LIKELY(major < 10 && minor < 10)) {
- char buf[4] = { char(major + '0'), '.', char(minor + '0'), '\0' };
- return QString::fromLatin1(buf, 3);
- }
- return QString::number(major) + QLatin1Char('.') + QString::number(minor);
-#elif defined(Q_OS_OSX)
- int minor = int(MacintoshVersion) - 2; // we're not running on Mac OS 9
- Q_ASSERT(minor < 100);
- char buf[] = "10.0\0";
- if (Q_LIKELY(minor < 10)) {
- buf[3] += minor;
- } else {
- buf[3] += minor / 10;
- buf[4] = '0' + minor % 10;
- }
- return QString::fromLatin1(buf);
+#if defined(Q_OS_MAC)
+ const QAppleOperatingSystemVersion version = qt_apple_os_version();
+ return QString::number(version.major) + QLatin1Char('.') + QString::number(version.minor);
#elif defined(Q_OS_WIN)
const char *version = winVer_helper();
if (version)
@@ -3007,6 +2997,53 @@ bool qEnvironmentVariableIsEmpty(const char *varName) Q_DECL_NOEXCEPT
/*!
\relates <QtGlobal>
+ \since 5.5
+
+ Returns the numerical value of the environment variable \a varName.
+ If \a ok is not null, sets \c{*ok} to \c true or \c false depending
+ on the success of the conversion.
+
+ Equivalent to
+ \code
+ qgetenv(varName).toInt()
+ \endcode
+ except that it's much faster, and can't throw exceptions.
+
+ \sa qgetenv(), qEnvironmentVariableIsSet()
+*/
+int qEnvironmentVariableIntValue(const char *varName, bool *ok) Q_DECL_NOEXCEPT
+{
+#if defined(_MSC_VER) && _MSC_VER >= 1400
+ // we provide a buffer that can hold any int value:
+ static const int NumBinaryDigitsPerOctalDigit = 3;
+ static const int MaxDigitsForOctalInt =
+ (std::numeric_limits<uint>::digits + NumBinaryDigitsPerOctalDigit - 1) / NumBinaryDigitsPerOctalDigit;
+ char buffer[MaxDigitsForOctalInt + 2]; // +1 for NUL +1 for optional '-'
+ size_t dummy;
+ if (getenv_s(&dummy, buffer, sizeof buffer, varName) != 0) {
+ if (ok)
+ *ok = false;
+ return 0;
+ }
+#else
+ const char * const buffer = ::getenv(varName);
+ if (!buffer || !*buffer) {
+ if (ok)
+ *ok = false;
+ return 0;
+ }
+#endif
+ const qlonglong value = qstrtoll(buffer, Q_NULLPTR, 0, ok);
+ if (int(value) != value) { // this is the check in QByteArray::toInt(), keep it in sync
+ if (ok)
+ *ok = false;
+ return 0;
+ }
+ return int(value);
+}
+
+/*!
+ \relates <QtGlobal>
\since 5.1
Returns whether the environment variable \a varName is set.
@@ -3910,6 +3947,21 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
It expands to "constexpr" if your compiler supports that C++11 keyword, or to nothing
otherwise.
+
+ \sa Q_DECL_RELAXED_CONSTEXPR
+*/
+
+/*!
+ \macro Q_DECL_RELAXED_CONSTEXPR
+ \relates <QtGlobal>
+
+ This macro can be used to declare an inline function that can be computed
+ at compile-time according to the relaxed rules from C++14.
+
+ It expands to "constexpr" if your compiler supports C++14 relaxed constant
+ expressions, or to nothing otherwise.
+
+ \sa Q_DECL_CONSTEXPR
*/
/*!
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index cb8bd15d8d..e93bfbcc4a 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -35,13 +35,17 @@
#ifndef QGLOBAL_H
#define QGLOBAL_H
-#include <stddef.h>
+#ifdef __cplusplus
+# include <cstddef>
+#else
+# include <stddef.h>
+#endif
-#define QT_VERSION_STR "5.4.1"
+#define QT_VERSION_STR "5.5.0"
/*
QT_VERSION is (major << 16) + (minor << 8) + patch.
*/
-#define QT_VERSION 0x050401
+#define QT_VERSION 0x050500
/*
can be used like #if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0))
*/
@@ -655,7 +659,7 @@ Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int line)
#if !defined(Q_ASSERT)
# if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
-# define Q_ASSERT(cond) qt_noop()
+# define Q_ASSERT(cond) do { } while (false && (cond))
# else
# define Q_ASSERT(cond) ((!(cond)) ? qt_assert(#cond,__FILE__,__LINE__) : qt_noop())
# endif
@@ -834,22 +838,22 @@ Q_CORE_EXPORT void qFreeAligned(void *ptr);
#endif
#if defined(QT_NO_WARNINGS)
# if defined(Q_CC_MSVC)
-# pragma warning(disable: 4251) /* class 'type' needs to have dll-interface to be used by clients of class 'type2' */
-# pragma warning(disable: 4244) /* conversion from 'type1' to 'type2', possible loss of data */
-# pragma warning(disable: 4275) /* non - DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier' */
-# pragma warning(disable: 4514) /* unreferenced inline function has been removed */
-# pragma warning(disable: 4800) /* 'type' : forcing value to bool 'true' or 'false' (performance warning) */
-# pragma warning(disable: 4097) /* typedef-name 'identifier1' used as synonym for class-name 'identifier2' */
-# pragma warning(disable: 4706) /* assignment within conditional expression */
+QT_WARNING_DISABLE_MSVC(4251) /* class 'type' needs to have dll-interface to be used by clients of class 'type2' */
+QT_WARNING_DISABLE_MSVC(4244) /* conversion from 'type1' to 'type2', possible loss of data */
+QT_WARNING_DISABLE_MSVC(4275) /* non - DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier' */
+QT_WARNING_DISABLE_MSVC(4514) /* unreferenced inline function has been removed */
+QT_WARNING_DISABLE_MSVC(4800) /* 'type' : forcing value to bool 'true' or 'false' (performance warning) */
+QT_WARNING_DISABLE_MSVC(4097) /* typedef-name 'identifier1' used as synonym for class-name 'identifier2' */
+QT_WARNING_DISABLE_MSVC(4706) /* assignment within conditional expression */
# if _MSC_VER <= 1310 // MSVC 2003
-# pragma warning(disable: 4786) /* 'identifier' : identifier was truncated to 'number' characters in the debug information */
+QT_WARNING_DISABLE_MSVC(4786) /* 'identifier' : identifier was truncated to 'number' characters in the debug information */
# endif
-# pragma warning(disable: 4355) /* 'this' : used in base member initializer list */
+QT_WARNING_DISABLE_MSVC(4355) /* 'this' : used in base member initializer list */
# if _MSC_VER < 1800 // MSVC 2013
-# pragma warning(disable: 4231) /* nonstandard extension used : 'identifier' before template explicit instantiation */
+QT_WARNING_DISABLE_MSVC(4231) /* nonstandard extension used : 'identifier' before template explicit instantiation */
# endif
-# pragma warning(disable: 4710) /* function not inlined */
-# pragma warning(disable: 4530) /* C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc */
+QT_WARNING_DISABLE_MSVC(4710) /* function not inlined */
+QT_WARNING_DISABLE_MSVC(4530) /* C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc */
# elif defined(Q_CC_BOR)
# pragma option -w-inl
# pragma option -w-aus
@@ -1027,6 +1031,7 @@ Q_CORE_EXPORT bool qunsetenv(const char *varName);
Q_CORE_EXPORT bool qEnvironmentVariableIsEmpty(const char *varName) Q_DECL_NOEXCEPT;
Q_CORE_EXPORT bool qEnvironmentVariableIsSet(const char *varName) Q_DECL_NOEXCEPT;
+Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=0) Q_DECL_NOEXCEPT;
inline int qIntCast(double f) { return int(f); }
inline int qIntCast(float f) { return int(f); }
diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp
index 7ca0aa7f0b..c60ca7e9b0 100644
--- a/src/corelib/global/qlibraryinfo.cpp
+++ b/src/corelib/global/qlibraryinfo.cpp
@@ -288,6 +288,8 @@ QLibraryInfo::buildDate()
# define COMPILER_STRING "MSVC 2012"
# elif _MSC_VER < 1900
# define COMPILER_STRING "MSVC 2013"
+# elif _MSC_VER < 2000
+# define COMPILER_STRING "MSVC 2015"
# else
# define COMPILER_STRING "MSVC _MSC_VER " QT_STRINGIFY(_MSC_VER)
# endif
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index 50d35a6d84..c4dacd3411 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -825,6 +825,9 @@ struct QMessagePattern {
const char **literals;
const char **tokens;
QString timeFormat;
+#ifndef QT_BOOTSTRAPPED
+ QElapsedTimer timer;
+#endif
#ifdef QLOGGING_HAVE_BACKTRACE
int backtraceDepth;
QString backtraceSeparator;
@@ -832,10 +835,6 @@ struct QMessagePattern {
bool fromEnvironment;
static QBasicMutex mutex;
-#ifndef QT_BOOTSTRAPPED
- QElapsedTimer timer;
- QDateTime startTime;
-#endif
};
QBasicMutex QMessagePattern::mutex;
@@ -848,9 +847,6 @@ QMessagePattern::QMessagePattern()
, backtraceSeparator(QLatin1Char('|'))
#endif
, fromEnvironment(false)
-#ifndef QT_BOOTSTRAPPED
- , startTime(QDateTime::currentDateTime())
-#endif
{
#ifndef QT_BOOTSTRAPPED
timer.start();
@@ -1201,6 +1197,12 @@ QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context, con
if (pattern->timeFormat == QLatin1String("process")) {
quint64 ms = pattern->timer.elapsed();
message.append(QString().sprintf("%6d.%03d", uint(ms / 1000), uint(ms % 1000)));
+ } else if (pattern->timeFormat == QLatin1String("boot")) {
+ // just print the milliseconds since the elapsed timer reference
+ // like the Linux kernel does
+ pattern->timer.elapsed();
+ uint ms = pattern->timer.msecsSinceReference();
+ message.append(QString().sprintf("%6d.%03d", uint(ms / 1000), uint(ms % 1000)));
} else if (pattern->timeFormat.isEmpty()) {
message.append(QDateTime::currentDateTime().toString(Qt::ISODate));
} else {
@@ -1551,6 +1553,9 @@ void qErrnoWarning(int code, const char *msg, ...)
\row \li \c %{threadid} \li ID of current thread
\row \li \c %{type} \li "debug", "warning", "critical" or "fatal"
\row \li \c %{time process} \li time of the message, in seconds since the process started (the token "process" is literal)
+ \row \li \c %{time boot} \li the time of the message, in seconds since the system boot if that
+ can be determined (the token "boot" is literal). If the time since boot could not be obtained,
+ the output is indeterminate (see QElapsedTimer::msecsSinceReference()).
\row \li \c %{time [format]} \li system time when the message occurred, formatted by
passing the \c format to \l QDateTime::toString(). If the format is
not specified, the format of Qt::ISODate is used.
diff --git a/src/corelib/global/qsysinfo.h b/src/corelib/global/qsysinfo.h
index 277caa8db6..35672479e0 100644
--- a/src/corelib/global/qsysinfo.h
+++ b/src/corelib/global/qsysinfo.h
@@ -72,8 +72,9 @@ public:
# endif
};
#endif
-#if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
enum WinVersion {
+ WV_None = 0x0000,
+
WV_32s = 0x0001,
WV_95 = 0x0002,
WV_98 = 0x0003,
@@ -107,13 +108,18 @@ public:
WV_CE_6 = 0x0400,
WV_CE_based = 0x0f00
};
+#if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
static const WinVersion WindowsVersion;
static WinVersion windowsVersion();
-
+#else
+ static const WinVersion WindowsVersion = WV_None;
+ static WinVersion windowsVersion() { return WV_None; }
#endif
-#ifdef Q_OS_MAC
-# define Q_MV_IOS(major, minor) (QSysInfo::MV_IOS | major << 4 | minor)
+
+#define Q_MV_OSX(major, minor) (major == 10 ? minor + 2 : (major == 9 ? 1 : 0))
+#define Q_MV_IOS(major, minor) (QSysInfo::MV_IOS | major << 4 | minor)
enum MacVersion {
+ MV_None = 0xffff,
MV_Unknown = 0x0000,
/* version */
@@ -154,8 +160,12 @@ public:
MV_IOS_7_1 = Q_MV_IOS(7, 1),
MV_IOS_8_0 = Q_MV_IOS(8, 0)
};
+#if defined(Q_OS_MAC)
static const MacVersion MacintoshVersion;
static MacVersion macVersion();
+#else
+ static const MacVersion MacintoshVersion = MV_None;
+ static MacVersion macVersion() { return MV_None; }
#endif
static QString buildCpuArchitecture();
diff --git a/src/corelib/io/qbuffer.cpp b/src/corelib/io/qbuffer.cpp
index 5377eb21e3..200d6a0c0c 100644
--- a/src/corelib/io/qbuffer.cpp
+++ b/src/corelib/io/qbuffer.cpp
@@ -54,8 +54,8 @@ public:
QByteArray *buf;
QByteArray defaultBuf;
- virtual qint64 peek(char *data, qint64 maxSize);
- virtual QByteArray peek(qint64 maxSize);
+ virtual qint64 peek(char *data, qint64 maxSize) Q_DECL_OVERRIDE;
+ virtual QByteArray peek(qint64 maxSize) Q_DECL_OVERRIDE;
#ifndef QT_NO_QOBJECT
// private slots
diff --git a/src/corelib/io/qbuffer.h b/src/corelib/io/qbuffer.h
index 24b05aad13..56c80f8a7d 100644
--- a/src/corelib/io/qbuffer.h
+++ b/src/corelib/io/qbuffer.h
@@ -67,22 +67,22 @@ public:
inline void setData(const char *data, int len);
const QByteArray &data() const;
- bool open(OpenMode openMode);
+ bool open(OpenMode openMode) Q_DECL_OVERRIDE;
- void close();
- qint64 size() const;
- qint64 pos() const;
- bool seek(qint64 off);
- bool atEnd() const;
- bool canReadLine() const;
+ void close() Q_DECL_OVERRIDE;
+ qint64 size() const Q_DECL_OVERRIDE;
+ qint64 pos() const Q_DECL_OVERRIDE;
+ bool seek(qint64 off) Q_DECL_OVERRIDE;
+ bool atEnd() const Q_DECL_OVERRIDE;
+ bool canReadLine() const Q_DECL_OVERRIDE;
protected:
#ifndef QT_NO_QOBJECT
- void connectNotify(const QMetaMethod &);
- void disconnectNotify(const QMetaMethod &);
+ void connectNotify(const QMetaMethod &) Q_DECL_OVERRIDE;
+ void disconnectNotify(const QMetaMethod &) Q_DECL_OVERRIDE;
#endif
- qint64 readData(char *data, qint64 maxlen);
- qint64 writeData(const char *data, qint64 len);
+ qint64 readData(char *data, qint64 maxlen) Q_DECL_OVERRIDE;
+ qint64 writeData(const char *data, qint64 len) Q_DECL_OVERRIDE;
private:
Q_DECLARE_PRIVATE(QBuffer)
diff --git a/src/corelib/io/qdatastream.cpp b/src/corelib/io/qdatastream.cpp
index beaafe4762..60f04ce4f1 100644
--- a/src/corelib/io/qdatastream.cpp
+++ b/src/corelib/io/qdatastream.cpp
@@ -525,6 +525,7 @@ void QDataStream::setByteOrder(ByteOrder bo)
\value Qt_5_2 Version 15 (Qt 5.2)
\value Qt_5_3 Same as Qt_5_2
\value Qt_5_4 Version 16 (Qt 5.4)
+ \value Qt_5_5 Same as Qt_5_4
\omitvalue Qt_DefaultCompiledVersion
\sa setVersion(), version()
diff --git a/src/corelib/io/qdatastream.h b/src/corelib/io/qdatastream.h
index 75ffa11543..8e1d777011 100644
--- a/src/corelib/io/qdatastream.h
+++ b/src/corelib/io/qdatastream.h
@@ -82,10 +82,11 @@ public:
Qt_5_2 = 15,
Qt_5_3 = Qt_5_2,
Qt_5_4 = 16,
-#if QT_VERSION >= 0x050500
+ Qt_5_5 = Qt_5_4,
+#if QT_VERSION >= 0x050600
#error Add the datastream version for this Qt version and update Qt_DefaultCompiledVersion
#endif
- Qt_DefaultCompiledVersion = Qt_5_4
+ Qt_DefaultCompiledVersion = Qt_5_5
};
enum ByteOrder {
diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp
index 5c77ccdcbf..050a48bd65 100644
--- a/src/corelib/io/qdebug.cpp
+++ b/src/corelib/io/qdebug.cpp
@@ -148,6 +148,28 @@ QDebug::~QDebug()
}
/*!
+ \internal
+*/
+void QDebug::putUcs4(uint ucs4)
+{
+ maybeQuote('\'');
+ if (ucs4 < 0x20) {
+ stream->ts << hex << "\\x" << ucs4 << reset;
+ } else if (ucs4 < 0x80) {
+ stream->ts << char(ucs4);
+ } else {
+ stream->ts << hex << qSetPadChar(QLatin1Char('0'));
+ if (ucs4 < 0x10000)
+ stream->ts << qSetFieldWidth(4) << "\\u";
+ else
+ stream->ts << qSetFieldWidth(8) << "\\U";
+ stream->ts << ucs4 << reset;
+ }
+ maybeQuote('\'');
+}
+
+
+/*!
\fn QDebug::swap(QDebug &other)
\since 5.0
diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h
index 4edb3057fb..4295800f1a 100644
--- a/src/corelib/io/qdebug.h
+++ b/src/corelib/io/qdebug.h
@@ -76,6 +76,8 @@ class Q_CORE_EXPORT QDebug
// added in 5.4
int flags;
} *stream;
+
+ void putUcs4(uint ucs4);
public:
inline QDebug(QIODevice *device) : stream(new Stream(device)) {}
inline QDebug(QString *string) : stream(new Stream(string)) {}
@@ -98,11 +100,15 @@ public:
inline QDebug &noquote() { stream->setFlag(Stream::NoQuotes); return *this; }
inline QDebug &maybeQuote(char c = '"') { if (!(stream->testFlag(Stream::NoQuotes))) stream->ts << c; return *this; }
- inline QDebug &operator<<(QChar t) { maybeQuote('\''); stream->ts << t; maybeQuote('\''); return maybeSpace(); }
+ inline QDebug &operator<<(QChar t) { putUcs4(t.unicode()); return maybeSpace(); }
inline QDebug &operator<<(bool t) { stream->ts << (t ? "true" : "false"); return maybeSpace(); }
inline QDebug &operator<<(char t) { stream->ts << t; return maybeSpace(); }
inline QDebug &operator<<(signed short t) { stream->ts << t; return maybeSpace(); }
inline QDebug &operator<<(unsigned short t) { stream->ts << t; return maybeSpace(); }
+#ifdef Q_COMPILER_UNICODE_STRINGS
+ inline QDebug &operator<<(char16_t t) { return *this << QChar(t); }
+ inline QDebug &operator<<(char32_t t) { putUcs4(t); return maybeSpace(); }
+#endif
inline QDebug &operator<<(signed int t) { stream->ts << t; return maybeSpace(); }
inline QDebug &operator<<(unsigned int t) { stream->ts << t; return maybeSpace(); }
inline QDebug &operator<<(signed long t) { stream->ts << t; return maybeSpace(); }
@@ -117,6 +123,9 @@ public:
inline QDebug &operator<<(QLatin1String t) { maybeQuote(); stream->ts << t; maybeQuote(); return maybeSpace(); }
inline QDebug &operator<<(const QByteArray & t) { maybeQuote(); stream->ts << t; maybeQuote(); return maybeSpace(); }
inline QDebug &operator<<(const void * t) { stream->ts << t; return maybeSpace(); }
+#ifdef Q_COMPILER_NULLPTR
+ inline QDebug &operator<<(std::nullptr_t) { stream->ts << "(nullptr)"; return maybeSpace(); }
+#endif
inline QDebug &operator<<(QTextStreamFunction f) {
stream->ts << f;
return *this;
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
index a5e189a825..92f2fc0815 100644
--- a/src/corelib/io/qdir.cpp
+++ b/src/corelib/io/qdir.cpp
@@ -2271,6 +2271,8 @@ QStringList QDir::nameFiltersFromString(const QString &nameFilter)
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug debug, QDir::Filters filters)
{
+ QDebugStateSaver save(debug);
+ debug.resetFormat();
QStringList flags;
if (filters == QDir::NoFilter) {
flags << QLatin1String("NoFilter");
@@ -2291,12 +2293,14 @@ QDebug operator<<(QDebug debug, QDir::Filters filters)
if (filters & QDir::System) flags << QLatin1String("System");
if (filters & QDir::CaseSensitive) flags << QLatin1String("CaseSensitive");
}
- debug << "QDir::Filters(" << qPrintable(flags.join(QLatin1Char('|'))) << ')';
+ debug.noquote() << "QDir::Filters(" << flags.join(QLatin1Char('|')) << ')';
return debug;
}
static QDebug operator<<(QDebug debug, QDir::SortFlags sorting)
{
+ QDebugStateSaver save(debug);
+ debug.resetFormat();
if (sorting == QDir::NoSort) {
debug << "QDir::SortFlags(NoSort)";
} else {
@@ -2312,24 +2316,23 @@ static QDebug operator<<(QDebug debug, QDir::SortFlags sorting)
if (sorting & QDir::IgnoreCase) flags << QLatin1String("IgnoreCase");
if (sorting & QDir::LocaleAware) flags << QLatin1String("LocaleAware");
if (sorting & QDir::Type) flags << QLatin1String("Type");
- debug << "QDir::SortFlags(" << qPrintable(type)
- << '|'
- << qPrintable(flags.join(QLatin1Char('|'))) << ')';
+ debug.noquote() << "QDir::SortFlags(" << type << '|' << flags.join(QLatin1Char('|')) << ')';
}
return debug;
}
QDebug operator<<(QDebug debug, const QDir &dir)
{
- debug.maybeSpace() << "QDir(" << dir.path()
- << ", nameFilters = {"
- << qPrintable(dir.nameFilters().join(QLatin1Char(',')))
- << "}, "
- << dir.sorting()
- << ','
- << dir.filter()
- << ')';
- return debug.space();
+ QDebugStateSaver save(debug);
+ debug.resetFormat();
+ debug << "QDir(" << dir.path() << ", nameFilters = {"
+ << dir.nameFilters().join(QLatin1Char(','))
+ << "}, "
+ << dir.sorting()
+ << ','
+ << dir.filter()
+ << ')';
+ return debug;
}
#endif // QT_NO_DEBUG_STREAM
diff --git a/src/corelib/io/qfile.h b/src/corelib/io/qfile.h
index 75f246da96..3c44ee3397 100644
--- a/src/corelib/io/qfile.h
+++ b/src/corelib/io/qfile.h
@@ -63,7 +63,7 @@ public:
#endif
~QFile();
- QString fileName() const;
+ QString fileName() const Q_DECL_OVERRIDE;
void setFileName(const QString &name);
#if defined(Q_OS_DARWIN)
@@ -116,18 +116,18 @@ public:
bool copy(const QString &newName);
static bool copy(const QString &fileName, const QString &newName);
- bool open(OpenMode flags);
+ bool open(OpenMode flags) Q_DECL_OVERRIDE;
bool open(FILE *f, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle);
bool open(int fd, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle);
- qint64 size() const;
+ qint64 size() const Q_DECL_OVERRIDE;
- bool resize(qint64 sz);
+ bool resize(qint64 sz) Q_DECL_OVERRIDE;
static bool resize(const QString &filename, qint64 sz);
- Permissions permissions() const;
+ Permissions permissions() const Q_DECL_OVERRIDE;
static Permissions permissions(const QString &filename);
- bool setPermissions(Permissions permissionSpec);
+ bool setPermissions(Permissions permissionSpec) Q_DECL_OVERRIDE;
static bool setPermissions(const QString &filename, Permissions permissionSpec);
protected:
diff --git a/src/corelib/io/qfiledevice.h b/src/corelib/io/qfiledevice.h
index b79b0055fa..ca12bb0411 100644
--- a/src/corelib/io/qfiledevice.h
+++ b/src/corelib/io/qfiledevice.h
@@ -86,19 +86,19 @@ public:
FileError error() const;
void unsetError();
- virtual void close();
+ virtual void close() Q_DECL_OVERRIDE;
- bool isSequential() const;
+ bool isSequential() const Q_DECL_OVERRIDE;
int handle() const;
virtual QString fileName() const;
- qint64 pos() const;
- bool seek(qint64 offset);
- bool atEnd() const;
+ qint64 pos() const Q_DECL_OVERRIDE;
+ bool seek(qint64 offset) Q_DECL_OVERRIDE;
+ bool atEnd() const Q_DECL_OVERRIDE;
bool flush();
- qint64 size() const;
+ qint64 size() const Q_DECL_OVERRIDE;
virtual bool resize(qint64 sz);
virtual Permissions permissions() const;
@@ -122,9 +122,9 @@ protected:
QFileDevice(QFileDevicePrivate &dd, QObject *parent = 0);
#endif
- qint64 readData(char *data, qint64 maxlen);
- qint64 writeData(const char *data, qint64 len);
- qint64 readLineData(char *data, qint64 maxlen);
+ qint64 readData(char *data, qint64 maxlen) Q_DECL_OVERRIDE;
+ qint64 writeData(const char *data, qint64 len) Q_DECL_OVERRIDE;
+ qint64 readLineData(char *data, qint64 maxlen) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(QFileDevice)
diff --git a/src/corelib/io/qfiledevice_p.h b/src/corelib/io/qfiledevice_p.h
index 891a5e4be4..da29c51468 100644
--- a/src/corelib/io/qfiledevice_p.h
+++ b/src/corelib/io/qfiledevice_p.h
@@ -64,7 +64,7 @@ protected:
inline bool ensureFlushed() const;
- bool putCharHelper(char c);
+ bool putCharHelper(char c) Q_DECL_OVERRIDE;
void setError(QFileDevice::FileError err);
void setError(QFileDevice::FileError err, const QString &errorString);
diff --git a/src/corelib/io/qfileselector.cpp b/src/corelib/io/qfileselector.cpp
index 5d1d5dfe23..95fa970b2d 100644
--- a/src/corelib/io/qfileselector.cpp
+++ b/src/corelib/io/qfileselector.cpp
@@ -335,7 +335,7 @@ void QFileSelectorPrivate::updateSelectors()
if (envSelectors.count())
sharedData->staticSelectors << envSelectors;
- if (!qgetenv(env_override).isEmpty())
+ if (!qEnvironmentVariableIsEmpty(env_override))
return;
sharedData->staticSelectors << sharedData->preloadedStatics; //Potential for static selectors from other modules
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp
index cd42aff35c..11d421591a 100644
--- a/src/corelib/io/qfilesystemengine_unix.cpp
+++ b/src/corelib/io/qfilesystemengine_unix.cpp
@@ -723,36 +723,29 @@ bool QFileSystemEngine::setCurrentPath(const QFileSystemEntry &path)
QFileSystemEntry QFileSystemEngine::currentPath()
{
QFileSystemEntry result;
- QT_STATBUF st;
- if (QT_STAT(".", &st) == 0) {
#if defined(__GLIBC__) && !defined(PATH_MAX)
- char *currentName = ::get_current_dir_name();
- if (currentName) {
- result = QFileSystemEntry(QByteArray(currentName), QFileSystemEntry::FromNativePath());
- ::free(currentName);
- }
+ char *currentName = ::get_current_dir_name();
+ if (currentName) {
+ result = QFileSystemEntry(QByteArray(currentName), QFileSystemEntry::FromNativePath());
+ ::free(currentName);
+ }
#else
- char currentName[PATH_MAX+1];
- if (::getcwd(currentName, PATH_MAX)) {
+ char currentName[PATH_MAX+1];
+ if (::getcwd(currentName, PATH_MAX)) {
#if defined(Q_OS_VXWORKS) && defined(VXWORKS_VXSIM)
- QByteArray dir(currentName);
- if (dir.indexOf(':') < dir.indexOf('/'))
- dir.remove(0, dir.indexOf(':')+1);
+ QByteArray dir(currentName);
+ if (dir.indexOf(':') < dir.indexOf('/'))
+ dir.remove(0, dir.indexOf(':')+1);
- qstrncpy(currentName, dir.constData(), PATH_MAX);
+ qstrncpy(currentName, dir.constData(), PATH_MAX);
#endif
- result = QFileSystemEntry(QByteArray(currentName), QFileSystemEntry::FromNativePath());
- }
+ result = QFileSystemEntry(QByteArray(currentName), QFileSystemEntry::FromNativePath());
+ }
# if defined(QT_DEBUG)
- if (result.isEmpty())
- qWarning("QFileSystemEngine::currentPath: getcwd() failed");
+ if (result.isEmpty())
+ qWarning("QFileSystemEngine::currentPath: getcwd() failed");
# endif
#endif
- } else {
-# if defined(QT_DEBUG)
- qWarning("QFileSystemEngine::currentPath: stat(\".\") failed");
-# endif
- }
return result;
}
QT_END_NAMESPACE
diff --git a/src/corelib/io/qfilesystemwatcher_inotify_p.h b/src/corelib/io/qfilesystemwatcher_inotify_p.h
index a9bc8486dc..506f571e2b 100644
--- a/src/corelib/io/qfilesystemwatcher_inotify_p.h
+++ b/src/corelib/io/qfilesystemwatcher_inotify_p.h
@@ -64,8 +64,8 @@ public:
static QInotifyFileSystemWatcherEngine *create(QObject *parent);
- QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories);
- QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories);
+ QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories) Q_DECL_OVERRIDE;
+ QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories) Q_DECL_OVERRIDE;
private Q_SLOTS:
void readFromInotify();
diff --git a/src/corelib/io/qfilesystemwatcher_polling_p.h b/src/corelib/io/qfilesystemwatcher_polling_p.h
index f39d72d5d8..3833869806 100644
--- a/src/corelib/io/qfilesystemwatcher_polling_p.h
+++ b/src/corelib/io/qfilesystemwatcher_polling_p.h
@@ -104,8 +104,8 @@ class QPollingFileSystemWatcherEngine : public QFileSystemWatcherEngine
public:
QPollingFileSystemWatcherEngine(QObject *parent);
- QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories);
- QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories);
+ QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories) Q_DECL_OVERRIDE;
+ QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories) Q_DECL_OVERRIDE;
private Q_SLOTS:
void timeout();
diff --git a/src/corelib/io/qfsfileengine_iterator_p.h b/src/corelib/io/qfsfileengine_iterator_p.h
index cc5b36fc57..35cb89673c 100644
--- a/src/corelib/io/qfsfileengine_iterator_p.h
+++ b/src/corelib/io/qfsfileengine_iterator_p.h
@@ -62,11 +62,11 @@ public:
QFSFileEngineIterator(QDir::Filters filters, const QStringList &filterNames);
~QFSFileEngineIterator();
- QString next();
- bool hasNext() const;
+ QString next() Q_DECL_OVERRIDE;
+ bool hasNext() const Q_DECL_OVERRIDE;
- QString currentFileName() const;
- QFileInfo currentFileInfo() const;
+ QString currentFileName() const Q_DECL_OVERRIDE;
+ QFileInfo currentFileInfo() const Q_DECL_OVERRIDE;
private:
void advance() const;
diff --git a/src/corelib/io/qfsfileengine_p.h b/src/corelib/io/qfsfileengine_p.h
index 3963a9cb11..f843a870b8 100644
--- a/src/corelib/io/qfsfileengine_p.h
+++ b/src/corelib/io/qfsfileengine_p.h
@@ -69,46 +69,46 @@ public:
explicit QFSFileEngine(const QString &file);
~QFSFileEngine();
- bool open(QIODevice::OpenMode openMode);
+ bool open(QIODevice::OpenMode openMode) Q_DECL_OVERRIDE;
bool open(QIODevice::OpenMode flags, FILE *fh);
- bool close();
- bool flush();
- bool syncToDisk();
- qint64 size() const;
- qint64 pos() const;
- bool seek(qint64);
- bool isSequential() const;
- bool remove();
- bool copy(const QString &newName);
- bool rename(const QString &newName);
- bool renameOverwrite(const QString &newName);
- bool link(const QString &newName);
- bool mkdir(const QString &dirName, bool createParentDirectories) const;
- bool rmdir(const QString &dirName, bool recurseParentDirectories) const;
- bool setSize(qint64 size);
- bool caseSensitive() const;
- bool isRelativePath() const;
- QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const;
- FileFlags fileFlags(FileFlags type) const;
- bool setPermissions(uint perms);
- QString fileName(FileName file) const;
- uint ownerId(FileOwner) const;
- QString owner(FileOwner) const;
- QDateTime fileTime(FileTime time) const;
- void setFileName(const QString &file);
- int handle() const;
+ bool close() Q_DECL_OVERRIDE;
+ bool flush() Q_DECL_OVERRIDE;
+ bool syncToDisk() Q_DECL_OVERRIDE;
+ qint64 size() const Q_DECL_OVERRIDE;
+ qint64 pos() const Q_DECL_OVERRIDE;
+ bool seek(qint64) Q_DECL_OVERRIDE;
+ bool isSequential() const Q_DECL_OVERRIDE;
+ bool remove() Q_DECL_OVERRIDE;
+ bool copy(const QString &newName) Q_DECL_OVERRIDE;
+ bool rename(const QString &newName) Q_DECL_OVERRIDE;
+ bool renameOverwrite(const QString &newName) Q_DECL_OVERRIDE;
+ bool link(const QString &newName) Q_DECL_OVERRIDE;
+ bool mkdir(const QString &dirName, bool createParentDirectories) const Q_DECL_OVERRIDE;
+ bool rmdir(const QString &dirName, bool recurseParentDirectories) const Q_DECL_OVERRIDE;
+ bool setSize(qint64 size) Q_DECL_OVERRIDE;
+ bool caseSensitive() const Q_DECL_OVERRIDE;
+ bool isRelativePath() const Q_DECL_OVERRIDE;
+ QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const Q_DECL_OVERRIDE;
+ FileFlags fileFlags(FileFlags type) const Q_DECL_OVERRIDE;
+ bool setPermissions(uint perms) Q_DECL_OVERRIDE;
+ QString fileName(FileName file) const Q_DECL_OVERRIDE;
+ uint ownerId(FileOwner) const Q_DECL_OVERRIDE;
+ QString owner(FileOwner) const Q_DECL_OVERRIDE;
+ QDateTime fileTime(FileTime time) const Q_DECL_OVERRIDE;
+ void setFileName(const QString &file) Q_DECL_OVERRIDE;
+ int handle() const Q_DECL_OVERRIDE;
#ifndef QT_NO_FILESYSTEMITERATOR
- Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames);
- Iterator *endEntryList();
+ Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) Q_DECL_OVERRIDE;
+ Iterator *endEntryList() Q_DECL_OVERRIDE;
#endif
- qint64 read(char *data, qint64 maxlen);
- qint64 readLine(char *data, qint64 maxlen);
- qint64 write(const char *data, qint64 len);
+ qint64 read(char *data, qint64 maxlen) Q_DECL_OVERRIDE;
+ qint64 readLine(char *data, qint64 maxlen) Q_DECL_OVERRIDE;
+ qint64 write(const char *data, qint64 len) Q_DECL_OVERRIDE;
- bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0);
- bool supportsExtension(Extension extension) const;
+ bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0) Q_DECL_OVERRIDE;
+ bool supportsExtension(Extension extension) const Q_DECL_OVERRIDE;
//FS only!!
bool open(QIODevice::OpenMode flags, int fd);
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp
index 72ec6ff403..d7ce8731c5 100644
--- a/src/corelib/io/qiodevice.cpp
+++ b/src/corelib/io/qiodevice.cpp
@@ -783,27 +783,20 @@ qint64 QIODevice::read(char *data, qint64 maxSize)
CHECK_MAXLEN(read, qint64(-1));
qint64 readSoFar = 0;
- bool moreToRead = true;
- do {
+ bool madeBufferReadsOnly = true;
+ bool deviceAtEof = false;
+ char *readPtr = data;
+ forever {
// Try reading from the buffer.
- qint64 lastReadChunkSize = d->buffer.read(data, maxSize);
- if (lastReadChunkSize > 0) {
- *d->pPos += lastReadChunkSize;
- readSoFar += lastReadChunkSize;
- // fast exit when satisfied by buffer
- if (lastReadChunkSize == maxSize && !(d->openMode & Text)) {
- if (d->buffer.isEmpty()) {
- d->buffer.clear();
- readData(data, 0);
- }
- return readSoFar;
- }
-
- data += lastReadChunkSize;
- maxSize -= lastReadChunkSize;
+ qint64 bufferReadChunkSize = d->buffer.read(data, maxSize);
+ if (bufferReadChunkSize > 0) {
+ *d->pPos += bufferReadChunkSize;
+ readSoFar += bufferReadChunkSize;
+ data += bufferReadChunkSize;
+ maxSize -= bufferReadChunkSize;
#if defined QIODEVICE_DEBUG
- printf("%p \treading %d bytes from buffer into position %d\n", this, lastReadChunkSize,
- int(readSoFar) - lastReadChunkSize);
+ printf("%p \treading %d bytes from buffer into position %d\n", this,
+ bufferReadChunkSize, int(readSoFar) - bufferReadChunkSize);
#endif
} else {
if (d->firstRead) {
@@ -816,100 +809,84 @@ qint64 QIODevice::read(char *data, qint64 maxSize)
d->pDevicePos = &d->seqDumpPos;
}
}
+ }
- if (!maxSize)
- return readSoFar;
-
- if ((d->openMode & Unbuffered) == 0 && maxSize < QIODEVICE_BUFFERSIZE) {
- // In buffered mode, we try to fill up the QIODevice buffer before
- // we do anything else.
- // buffer is empty at this point, try to fill it
- const int bytesToBuffer = QIODEVICE_BUFFERSIZE;
- char *writePointer = d->buffer.reserve(bytesToBuffer);
-
- // Make sure the device is positioned correctly.
- if (d->pos != d->devicePos && !d->isSequential() && !seek(d->pos))
- return readSoFar ? readSoFar : qint64(-1);
- qint64 readFromDevice = readData(writePointer, bytesToBuffer);
- d->buffer.chop(bytesToBuffer - (readFromDevice < 0 ? 0 : int(readFromDevice)));
-
- if (readFromDevice > 0) {
- *d->pDevicePos += readFromDevice;
+ if (maxSize > 0 && !deviceAtEof) {
+ qint64 readFromDevice = 0;
+ // Make sure the device is positioned correctly.
+ if (d->pos == d->devicePos || d->isSequential() || seek(d->pos)) {
+ madeBufferReadsOnly = false; // fix readData attempt
+ if (maxSize >= QIODEVICE_BUFFERSIZE || (d->openMode & Unbuffered)) {
+ // Read big chunk directly to output buffer
+ readFromDevice = readData(data, maxSize);
+ deviceAtEof = (readFromDevice != maxSize);
#if defined QIODEVICE_DEBUG
- printf("%p \treading %d from device into buffer\n", this, int(readFromDevice));
+ printf("%p \treading %d bytes from device (total %d)\n", this,
+ int(readFromDevice), int(readSoFar));
#endif
-
- if (!d->buffer.isEmpty()) {
- lastReadChunkSize = d->buffer.read(data, maxSize);
- readSoFar += lastReadChunkSize;
- data += lastReadChunkSize;
- maxSize -= lastReadChunkSize;
- *d->pPos += lastReadChunkSize;
+ if (readFromDevice > 0) {
+ readSoFar += readFromDevice;
+ data += readFromDevice;
+ maxSize -= readFromDevice;
+ *d->pPos += readFromDevice;
+ *d->pDevicePos += readFromDevice;
+ }
+ } else {
+ const int bytesToBuffer = QIODEVICE_BUFFERSIZE;
+ // Try to fill QIODevice buffer by single read
+ readFromDevice = readData(d->buffer.reserve(bytesToBuffer), bytesToBuffer);
+ deviceAtEof = (readFromDevice != bytesToBuffer);
+ d->buffer.chop(bytesToBuffer - qMax(0, int(readFromDevice)));
+ if (readFromDevice > 0) {
+ *d->pDevicePos += readFromDevice;
#if defined QIODEVICE_DEBUG
- printf("%p \treading %d bytes from buffer at position %d\n", this,
- lastReadChunkSize, int(readSoFar));
+ printf("%p \treading %d from device into buffer\n", this,
+ int(readFromDevice));
#endif
+ continue;
}
}
+ } else {
+ readFromDevice = -1;
}
- }
- // If we need more, try reading from the device.
- if (maxSize > 0) {
- // Make sure the device is positioned correctly.
- if (d->pos != d->devicePos && !d->isSequential() && !seek(d->pos))
- return readSoFar ? readSoFar : qint64(-1);
- qint64 readFromDevice = readData(data, maxSize);
-#if defined QIODEVICE_DEBUG
- printf("%p \treading %d bytes from device (total %d)\n", this, int(readFromDevice), int(readSoFar));
-#endif
- if (readFromDevice == -1 && readSoFar == 0) {
+ if (readFromDevice < 0 && readSoFar == 0) {
// error and we haven't read anything: return immediately
- return -1;
- }
- if (readFromDevice > 0) {
- lastReadChunkSize += int(readFromDevice);
- readSoFar += readFromDevice;
- data += readFromDevice;
- maxSize -= readFromDevice;
- *d->pPos += readFromDevice;
- *d->pDevicePos += readFromDevice;
+ return qint64(-1);
}
}
- // Best attempt has been made to read data, don't try again except for text mode adjustment below
- moreToRead = false;
- if (readSoFar && d->openMode & Text) {
- char *readPtr = data - lastReadChunkSize;
+ if ((d->openMode & Text) && readPtr < data) {
const char *endPtr = data;
- if (readPtr < endPtr) {
- // optimization to avoid initial self-assignment
- while (*readPtr != '\r') {
- if (++readPtr == endPtr)
- return readSoFar;
- }
+ // optimization to avoid initial self-assignment
+ while (*readPtr != '\r') {
+ if (++readPtr == endPtr)
+ break;
+ }
- char *writePtr = readPtr;
+ char *writePtr = readPtr;
- while (readPtr < endPtr) {
- char ch = *readPtr++;
- if (ch != '\r')
- *writePtr++ = ch;
- else {
- --readSoFar;
- --data;
- ++maxSize;
- }
+ while (readPtr < endPtr) {
+ char ch = *readPtr++;
+ if (ch != '\r')
+ *writePtr++ = ch;
+ else {
+ --readSoFar;
+ --data;
+ ++maxSize;
}
-
- // Make sure we get more data if there is room for more. This
- // is very important for when someone seeks to the start of a
- // '\r\n' and reads one character - they should get the '\n'.
- moreToRead = (readPtr != writePtr);
}
+
+ // Make sure we get more data if there is room for more. This
+ // is very important for when someone seeks to the start of a
+ // '\r\n' and reads one character - they should get the '\n'.
+ readPtr = data;
+ continue;
}
- } while (moreToRead);
+
+ break;
+ }
#if defined QIODEVICE_DEBUG
printf("%p \treturning %d, d->pos == %d, d->buffer.size() == %d\n", this,
@@ -917,8 +894,10 @@ qint64 QIODevice::read(char *data, qint64 maxSize)
debugBinaryString(data - readSoFar, readSoFar);
#endif
- if (d->buffer.isEmpty())
+ if (madeBufferReadsOnly && d->buffer.isEmpty()) {
+ d->buffer.clear();
readData(data, 0);
+ }
return readSoFar;
}
diff --git a/src/corelib/io/qipaddress.cpp b/src/corelib/io/qipaddress.cpp
index 44da22489d..d436cd2dd6 100644
--- a/src/corelib/io/qipaddress.cpp
+++ b/src/corelib/io/qipaddress.cpp
@@ -33,6 +33,7 @@
#include "qipaddress_p.h"
#include "private/qlocale_tools_p.h"
+#include "private/qtools_p.h"
#include "qvarlengtharray.h"
QT_BEGIN_NAMESPACE
@@ -240,7 +241,7 @@ const QChar *parseIp6(IPv6Address &address, const QChar *begin, const QChar *end
static inline QChar toHex(uchar c)
{
- return ushort(c > 9 ? c + 'a' - 0xA : c + '0');
+ return QtMiscUtils::toHexLower(c);
}
void toString(QString &appendTo, IPv6Address address)
diff --git a/src/corelib/io/qnoncontiguousbytedevice_p.h b/src/corelib/io/qnoncontiguousbytedevice_p.h
index c05ae11b0f..1be28ff4b3 100644
--- a/src/corelib/io/qnoncontiguousbytedevice_p.h
+++ b/src/corelib/io/qnoncontiguousbytedevice_p.h
@@ -101,11 +101,11 @@ class QNonContiguousByteDeviceByteArrayImpl : public QNonContiguousByteDevice
public:
QNonContiguousByteDeviceByteArrayImpl(QByteArray *ba);
~QNonContiguousByteDeviceByteArrayImpl();
- const char* readPointer(qint64 maximumLength, qint64 &len);
- bool advanceReadPointer(qint64 amount);
- bool atEnd();
- bool reset();
- qint64 size();
+ const char* readPointer(qint64 maximumLength, qint64 &len) Q_DECL_OVERRIDE;
+ bool advanceReadPointer(qint64 amount) Q_DECL_OVERRIDE;
+ bool atEnd() Q_DECL_OVERRIDE;
+ bool reset() Q_DECL_OVERRIDE;
+ qint64 size() Q_DECL_OVERRIDE;
protected:
QByteArray* byteArray;
qint64 currentPosition;
@@ -116,11 +116,11 @@ class QNonContiguousByteDeviceRingBufferImpl : public QNonContiguousByteDevice
public:
QNonContiguousByteDeviceRingBufferImpl(QSharedPointer<QRingBuffer> rb);
~QNonContiguousByteDeviceRingBufferImpl();
- const char* readPointer(qint64 maximumLength, qint64 &len);
- bool advanceReadPointer(qint64 amount);
- bool atEnd();
- bool reset();
- qint64 size();
+ const char* readPointer(qint64 maximumLength, qint64 &len) Q_DECL_OVERRIDE;
+ bool advanceReadPointer(qint64 amount) Q_DECL_OVERRIDE;
+ bool atEnd() Q_DECL_OVERRIDE;
+ bool reset() Q_DECL_OVERRIDE;
+ qint64 size() Q_DECL_OVERRIDE;
protected:
QSharedPointer<QRingBuffer> ringBuffer;
qint64 currentPosition;
@@ -133,11 +133,11 @@ class QNonContiguousByteDeviceIoDeviceImpl : public QNonContiguousByteDevice
public:
QNonContiguousByteDeviceIoDeviceImpl(QIODevice *d);
~QNonContiguousByteDeviceIoDeviceImpl();
- const char* readPointer(qint64 maximumLength, qint64 &len);
- bool advanceReadPointer(qint64 amount);
- bool atEnd();
- bool reset();
- qint64 size();
+ const char* readPointer(qint64 maximumLength, qint64 &len) Q_DECL_OVERRIDE;
+ bool advanceReadPointer(qint64 amount) Q_DECL_OVERRIDE;
+ bool atEnd() Q_DECL_OVERRIDE;
+ bool reset() Q_DECL_OVERRIDE;
+ qint64 size() Q_DECL_OVERRIDE;
protected:
QIODevice* device;
QByteArray* currentReadBuffer;
@@ -155,11 +155,11 @@ class QNonContiguousByteDeviceBufferImpl : public QNonContiguousByteDevice
public:
QNonContiguousByteDeviceBufferImpl(QBuffer *b);
~QNonContiguousByteDeviceBufferImpl();
- const char* readPointer(qint64 maximumLength, qint64 &len);
- bool advanceReadPointer(qint64 amount);
- bool atEnd();
- bool reset();
- qint64 size();
+ const char* readPointer(qint64 maximumLength, qint64 &len) Q_DECL_OVERRIDE;
+ bool advanceReadPointer(qint64 amount) Q_DECL_OVERRIDE;
+ bool atEnd() Q_DECL_OVERRIDE;
+ bool reset() Q_DECL_OVERRIDE;
+ qint64 size() Q_DECL_OVERRIDE;
protected:
QBuffer* buffer;
QByteArray byteArray;
@@ -172,13 +172,13 @@ class QByteDeviceWrappingIoDevice : public QIODevice
public:
QByteDeviceWrappingIoDevice (QNonContiguousByteDevice *bd);
~QByteDeviceWrappingIoDevice ();
- virtual bool isSequential () const;
- virtual bool atEnd () const;
- virtual bool reset ();
- virtual qint64 size () const;
+ virtual bool isSequential () const Q_DECL_OVERRIDE;
+ virtual bool atEnd () const Q_DECL_OVERRIDE;
+ virtual bool reset () Q_DECL_OVERRIDE;
+ virtual qint64 size () const Q_DECL_OVERRIDE;
protected:
- virtual qint64 readData ( char * data, qint64 maxSize );
- virtual qint64 writeData ( const char * data, qint64 maxSize );
+ virtual qint64 readData ( char * data, qint64 maxSize ) Q_DECL_OVERRIDE;
+ virtual qint64 writeData ( const char * data, qint64 maxSize ) Q_DECL_OVERRIDE;
QNonContiguousByteDevice *byteDevice;
};
diff --git a/src/corelib/io/qprocess.h b/src/corelib/io/qprocess.h
index 8d90177c8b..af3db4ecf6 100644
--- a/src/corelib/io/qprocess.h
+++ b/src/corelib/io/qprocess.h
@@ -182,8 +182,8 @@ public:
qint64 processId() const;
bool waitForStarted(int msecs = 30000);
- bool waitForReadyRead(int msecs = 30000);
- bool waitForBytesWritten(int msecs = 30000);
+ bool waitForReadyRead(int msecs = 30000) Q_DECL_OVERRIDE;
+ bool waitForBytesWritten(int msecs = 30000) Q_DECL_OVERRIDE;
bool waitForFinished(int msecs = 30000);
QByteArray readAllStandardOutput();
@@ -193,12 +193,12 @@ public:
QProcess::ExitStatus exitStatus() const;
// QIODevice
- qint64 bytesAvailable() const;
- qint64 bytesToWrite() const;
- bool isSequential() const;
- bool canReadLine() const;
- void close();
- bool atEnd() const;
+ qint64 bytesAvailable() const Q_DECL_OVERRIDE;
+ qint64 bytesToWrite() const Q_DECL_OVERRIDE;
+ bool isSequential() const Q_DECL_OVERRIDE;
+ bool canReadLine() const Q_DECL_OVERRIDE;
+ void close() Q_DECL_OVERRIDE;
+ bool atEnd() const Q_DECL_OVERRIDE;
static int execute(const QString &program, const QStringList &arguments);
static int execute(const QString &command);
@@ -254,8 +254,8 @@ protected:
virtual void setupChildProcess();
// QIODevice
- qint64 readData(char *data, qint64 maxlen);
- qint64 writeData(const char *data, qint64 len);
+ qint64 readData(char *data, qint64 maxlen) Q_DECL_OVERRIDE;
+ qint64 writeData(const char *data, qint64 len) Q_DECL_OVERRIDE;
private:
Q_DECLARE_PRIVATE(QProcess)
diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp
index cc154cfbc5..cfee5f1d46 100644
--- a/src/corelib/io/qprocess_unix.cpp
+++ b/src/corelib/io/qprocess_unix.cpp
@@ -165,7 +165,7 @@ public:
QProcessManager();
~QProcessManager();
- void run();
+ void run() Q_DECL_OVERRIDE;
void catchDeadChildren();
void add(pid_t pid, QProcess *process);
void remove(QProcess *process);
diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp
index ed6bfb4e0d..d9b51cd288 100644
--- a/src/corelib/io/qresource.cpp
+++ b/src/corelib/io/qresource.cpp
@@ -873,10 +873,16 @@ public:
inline QDynamicBufferResourceRoot(const QString &_root) : root(_root), buffer(0) { }
inline ~QDynamicBufferResourceRoot() { }
inline const uchar *mappingBuffer() const { return buffer; }
- virtual QString mappingRoot() const { return root; }
- virtual ResourceRootType type() const { return Resource_Buffer; }
+ virtual QString mappingRoot() const Q_DECL_OVERRIDE { return root; }
+ virtual ResourceRootType type() const Q_DECL_OVERRIDE { return Resource_Buffer; }
+
+ // size == -1 means "unknown"
+ bool registerSelf(const uchar *b, int size)
+ {
+ // 5 int "pointers"
+ if (size >= 0 && size < 20)
+ return false;
- bool registerSelf(const uchar *b) {
//setup the data now
int offset = 0;
@@ -903,6 +909,10 @@ public:
(b[offset+2] << 8) + (b[offset+3] << 0);
offset += 4;
+ // Some sanity checking for sizes. This is _not_ a security measure.
+ if (size >= 0 && (tree_offset >= size || data_offset >= size || name_offset >= size))
+ return false;
+
if(version == 0x01) {
buffer = b;
setSource(b+tree_offset, b+name_offset, b+data_offset);
@@ -950,7 +960,7 @@ public:
}
}
QString mappingFile() const { return fileName; }
- virtual ResourceRootType type() const { return Resource_File; }
+ virtual ResourceRootType type() const Q_DECL_OVERRIDE { return Resource_File; }
bool registerSelf(const QString &f) {
bool fromMM = false;
@@ -1009,7 +1019,7 @@ public:
}
fromMM = false;
}
- if(data && QDynamicBufferResourceRoot::registerSelf(data)) {
+ if (data && QDynamicBufferResourceRoot::registerSelf(data, data_len)) {
if(fromMM) {
unmapPointer = data;
unmapLength = data_len;
@@ -1124,7 +1134,7 @@ QResource::registerResource(const uchar *rccData, const QString &resourceRoot)
}
QDynamicBufferResourceRoot *root = new QDynamicBufferResourceRoot(r);
- if(root->registerSelf(rccData)) {
+ if (root->registerSelf(rccData, -1)) {
root->ref.ref();
QMutexLocker lock(resourceMutex());
resourceList()->append(root);
diff --git a/src/corelib/io/qresource_iterator_p.h b/src/corelib/io/qresource_iterator_p.h
index 451773ec63..dce298fb44 100644
--- a/src/corelib/io/qresource_iterator_p.h
+++ b/src/corelib/io/qresource_iterator_p.h
@@ -57,10 +57,10 @@ public:
QResourceFileEngineIterator(QDir::Filters filters, const QStringList &filterNames);
~QResourceFileEngineIterator();
- QString next();
- bool hasNext() const;
+ QString next() Q_DECL_OVERRIDE;
+ bool hasNext() const Q_DECL_OVERRIDE;
- QString currentFileName() const;
+ QString currentFileName() const Q_DECL_OVERRIDE;
private:
mutable QStringList entries;
diff --git a/src/corelib/io/qresource_p.h b/src/corelib/io/qresource_p.h
index 030d1587e5..11b2836215 100644
--- a/src/corelib/io/qresource_p.h
+++ b/src/corelib/io/qresource_p.h
@@ -58,52 +58,52 @@ public:
explicit QResourceFileEngine(const QString &path);
~QResourceFileEngine();
- virtual void setFileName(const QString &file);
+ virtual void setFileName(const QString &file) Q_DECL_OVERRIDE;
- virtual bool open(QIODevice::OpenMode flags) ;
- virtual bool close();
- virtual bool flush();
- virtual qint64 size() const;
- virtual qint64 pos() const;
+ virtual bool open(QIODevice::OpenMode flags) Q_DECL_OVERRIDE ;
+ virtual bool close() Q_DECL_OVERRIDE;
+ virtual bool flush() Q_DECL_OVERRIDE;
+ virtual qint64 size() const Q_DECL_OVERRIDE;
+ virtual qint64 pos() const Q_DECL_OVERRIDE;
virtual bool atEnd() const;
- virtual bool seek(qint64);
- virtual qint64 read(char *data, qint64 maxlen);
- virtual qint64 write(const char *data, qint64 len);
+ virtual bool seek(qint64) Q_DECL_OVERRIDE;
+ virtual qint64 read(char *data, qint64 maxlen) Q_DECL_OVERRIDE;
+ virtual qint64 write(const char *data, qint64 len) Q_DECL_OVERRIDE;
- virtual bool remove();
- virtual bool copy(const QString &newName);
- virtual bool rename(const QString &newName);
- virtual bool link(const QString &newName);
+ virtual bool remove() Q_DECL_OVERRIDE;
+ virtual bool copy(const QString &newName) Q_DECL_OVERRIDE;
+ virtual bool rename(const QString &newName) Q_DECL_OVERRIDE;
+ virtual bool link(const QString &newName) Q_DECL_OVERRIDE;
- virtual bool isSequential() const;
+ virtual bool isSequential() const Q_DECL_OVERRIDE;
- virtual bool isRelativePath() const;
+ virtual bool isRelativePath() const Q_DECL_OVERRIDE;
- virtual bool mkdir(const QString &dirName, bool createParentDirectories) const;
- virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const;
+ virtual bool mkdir(const QString &dirName, bool createParentDirectories) const Q_DECL_OVERRIDE;
+ virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const Q_DECL_OVERRIDE;
- virtual bool setSize(qint64 size);
+ virtual bool setSize(qint64 size) Q_DECL_OVERRIDE;
- virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const;
+ virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const Q_DECL_OVERRIDE;
- virtual bool caseSensitive() const;
+ virtual bool caseSensitive() const Q_DECL_OVERRIDE;
- virtual FileFlags fileFlags(FileFlags type) const;
+ virtual FileFlags fileFlags(FileFlags type) const Q_DECL_OVERRIDE;
- virtual bool setPermissions(uint perms);
+ virtual bool setPermissions(uint perms) Q_DECL_OVERRIDE;
- virtual QString fileName(QAbstractFileEngine::FileName file) const;
+ virtual QString fileName(QAbstractFileEngine::FileName file) const Q_DECL_OVERRIDE;
- virtual uint ownerId(FileOwner) const;
- virtual QString owner(FileOwner) const;
+ virtual uint ownerId(FileOwner) const Q_DECL_OVERRIDE;
+ virtual QString owner(FileOwner) const Q_DECL_OVERRIDE;
- virtual QDateTime fileTime(FileTime time) const;
+ virtual QDateTime fileTime(FileTime time) const Q_DECL_OVERRIDE;
- virtual Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames);
- virtual Iterator *endEntryList();
+ virtual Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) Q_DECL_OVERRIDE;
+ virtual Iterator *endEntryList() Q_DECL_OVERRIDE;
- bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0);
- bool supportsExtension(Extension extension) const;
+ bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0) Q_DECL_OVERRIDE;
+ bool supportsExtension(Extension extension) const Q_DECL_OVERRIDE;
};
QT_END_NAMESPACE
diff --git a/src/corelib/io/qsettings.h b/src/corelib/io/qsettings.h
index 4986c06896..1ce2865c63 100644
--- a/src/corelib/io/qsettings.h
+++ b/src/corelib/io/qsettings.h
@@ -177,7 +177,7 @@ public:
protected:
#ifndef QT_NO_QOBJECT
- bool event(QEvent *event);
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
#endif
private:
diff --git a/src/corelib/io/qsettings_p.h b/src/corelib/io/qsettings_p.h
index 715f13530a..0525fab77a 100644
--- a/src/corelib/io/qsettings_p.h
+++ b/src/corelib/io/qsettings_p.h
@@ -270,17 +270,17 @@ public:
QConfFileSettingsPrivate(const QString &fileName, QSettings::Format format);
~QConfFileSettingsPrivate();
- void remove(const QString &key);
- void set(const QString &key, const QVariant &value);
- bool get(const QString &key, QVariant *value) const;
+ void remove(const QString &key) Q_DECL_OVERRIDE;
+ void set(const QString &key, const QVariant &value) Q_DECL_OVERRIDE;
+ bool get(const QString &key, QVariant *value) const Q_DECL_OVERRIDE;
- QStringList children(const QString &prefix, ChildSpec spec) const;
+ QStringList children(const QString &prefix, ChildSpec spec) const Q_DECL_OVERRIDE;
- void clear();
- void sync();
- void flush();
- bool isWritable() const;
- QString fileName() const;
+ void clear() Q_DECL_OVERRIDE;
+ void sync() Q_DECL_OVERRIDE;
+ void flush() Q_DECL_OVERRIDE;
+ bool isWritable() const Q_DECL_OVERRIDE;
+ QString fileName() const Q_DECL_OVERRIDE;
bool readIniFile(const QByteArray &data, UnparsedSettingsMap *unparsedIniSections);
static bool readIniSection(const QSettingsKey &section, const QByteArray &data,
diff --git a/src/corelib/io/qstorageinfo_p.h b/src/corelib/io/qstorageinfo_p.h
index 9c8e51f475..dea25d440d 100644
--- a/src/corelib/io/qstorageinfo_p.h
+++ b/src/corelib/io/qstorageinfo_p.h
@@ -73,14 +73,14 @@ public:
protected:
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)
- void retreiveVolumeInfo();
- void retreiveDiskFreeSpace();
+ void retrieveVolumeInfo();
+ void retrieveDiskFreeSpace();
#elif defined(Q_OS_MAC)
void retrievePosixInfo();
void retrieveUrlProperties(bool initRootPath = false);
void retrieveLabel();
#elif defined(Q_OS_UNIX)
- void retreiveVolumeInfo();
+ void retrieveVolumeInfo();
#endif
public:
diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp
index 857464f578..1af2145296 100644
--- a/src/corelib/io/qstorageinfo_unix.cpp
+++ b/src/corelib/io/qstorageinfo_unix.cpp
@@ -402,11 +402,11 @@ void QStorageInfoPrivate::doStat()
if (rootPath.isEmpty())
return;
- retreiveVolumeInfo();
+ retrieveVolumeInfo();
name = retrieveLabel(device);
}
-void QStorageInfoPrivate::retreiveVolumeInfo()
+void QStorageInfoPrivate::retrieveVolumeInfo()
{
QT_STATFSBUF statfs_buf;
int result;
diff --git a/src/corelib/io/qstorageinfo_win.cpp b/src/corelib/io/qstorageinfo_win.cpp
index 8c276b2798..51a268f58c 100644
--- a/src/corelib/io/qstorageinfo_win.cpp
+++ b/src/corelib/io/qstorageinfo_win.cpp
@@ -114,12 +114,12 @@ void QStorageInfoPrivate::doStat()
if (rootPath.isEmpty())
return;
- retreiveVolumeInfo();
+ retrieveVolumeInfo();
device = getDevice(rootPath);
- retreiveDiskFreeSpace();
+ retrieveDiskFreeSpace();
}
-void QStorageInfoPrivate::retreiveVolumeInfo()
+void QStorageInfoPrivate::retrieveVolumeInfo()
{
const UINT oldmode = ::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
@@ -151,7 +151,7 @@ void QStorageInfoPrivate::retreiveVolumeInfo()
::SetErrorMode(oldmode);
}
-void QStorageInfoPrivate::retreiveDiskFreeSpace()
+void QStorageInfoPrivate::retrieveDiskFreeSpace()
{
const UINT oldmode = ::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index 4a9aafcf0b..c96d0504f4 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -222,6 +222,7 @@ static bool createFileFromTemplate(NativeFileHandle &file,
}
Q_ASSERT(false);
+ return false;
}
//************* QTemporaryFileEngine
diff --git a/src/corelib/io/qtemporaryfile.h b/src/corelib/io/qtemporaryfile.h
index 908cc231af..f21f87fd21 100644
--- a/src/corelib/io/qtemporaryfile.h
+++ b/src/corelib/io/qtemporaryfile.h
@@ -71,7 +71,7 @@ public:
// ### Hides open(flags)
bool open() { return open(QIODevice::ReadWrite); }
- QString fileName() const;
+ QString fileName() const Q_DECL_OVERRIDE;
QString fileTemplate() const;
void setFileTemplate(const QString &name);
#if QT_DEPRECATED_SINCE(5,1)
@@ -85,7 +85,7 @@ public:
static QTemporaryFile *createNativeFile(QFile &file);
protected:
- bool open(OpenMode flags);
+ bool open(OpenMode flags) Q_DECL_OVERRIDE;
private:
friend class QFile;
diff --git a/src/corelib/io/qtextstream.cpp b/src/corelib/io/qtextstream.cpp
index 089a915a36..5f3177e58f 100644
--- a/src/corelib/io/qtextstream.cpp
+++ b/src/corelib/io/qtextstream.cpp
@@ -681,15 +681,9 @@ bool QTextStreamPrivate::scan(const QChar **ptr, int *length, int maxlen, TokenD
&& (!maxlen || totalSize < maxlen)
&& (device && (canStillReadFromDevice = fillReadBuffer())));
- // if the token was not found, but we reached the end of input,
- // then we accept what we got. if we are not at the end of input,
- // we return false.
- if (!foundToken && (!maxlen || totalSize < maxlen)
- && (totalSize == 0
- || (string && stringOffset + totalSize < string->size())
- || (device && !device->atEnd() && canStillReadFromDevice))) {
+ if (totalSize == 0) {
#if defined (QTEXTSTREAM_DEBUG)
- qDebug("QTextStreamPrivate::scan() did not find the token.");
+ qDebug("QTextStreamPrivate::scan() reached the end of input.");
#endif
return false;
}
@@ -812,13 +806,28 @@ inline void QTextStreamPrivate::restoreToSavedConverterState()
/*!
\internal
*/
-inline void QTextStreamPrivate::write(const QString &data)
+inline void QTextStreamPrivate::write(const QChar *data, int len)
{
if (string) {
// ### What about seek()??
- string->append(data);
+ string->append(data, len);
} else {
- writeBuffer += data;
+ writeBuffer.append(data, len);
+ if (writeBuffer.size() > QTEXTSTREAM_BUFFERSIZE)
+ flushWriteBuffer();
+ }
+}
+
+/*!
+ \internal
+*/
+inline void QTextStreamPrivate::write(QChar ch)
+{
+ if (string) {
+ // ### What about seek()??
+ string->append(ch);
+ } else {
+ writeBuffer += ch;
if (writeBuffer.size() > QTEXTSTREAM_BUFFERSIZE)
flushWriteBuffer();
}
@@ -865,45 +874,53 @@ inline void QTextStreamPrivate::ungetChar(QChar ch)
/*!
\internal
*/
-inline void QTextStreamPrivate::putString(const QString &s, bool number)
+inline void QTextStreamPrivate::putChar(QChar ch)
+{
+ if (params.fieldWidth > 0)
+ putString(&ch, 1);
+ else
+ write(ch);
+}
+
+/*!
+ \internal
+*/
+inline void QTextStreamPrivate::putString(const QChar *data, int len, bool number)
{
- QString tmp = s;
+ QString pad;
+ int padLeft = 0, padRight = 0;
// handle padding
- int padSize = params.fieldWidth - s.size();
+ int padSize = params.fieldWidth - len;
if (padSize > 0) {
- QString pad(padSize, params.padChar);
+ pad = QString(padSize, params.padChar);
switch (params.fieldAlignment) {
case QTextStream::AlignLeft:
- tmp.append(pad);
+ padRight = padSize;
break;
case QTextStream::AlignRight:
case QTextStream::AlignAccountingStyle:
- tmp.prepend(pad);
+ padLeft = padSize;
if (params.fieldAlignment == QTextStream::AlignAccountingStyle && number) {
- const QChar sign = s.size() > 0 ? s.at(0) : QChar();
+ const QChar sign = len > 0 ? data[0] : QChar();
if (sign == locale.negativeSign() || sign == locale.positiveSign()) {
- QChar *data = tmp.data();
- data[padSize] = tmp.at(0);
- data[0] = sign;
+ // write the sign before the padding, then skip it later
+ write(&sign, 1);
+ ++data;
+ --len;
}
- }
+ }
break;
case QTextStream::AlignCenter:
- tmp.prepend(QString(padSize/2, params.padChar));
- tmp.append(QString(padSize - padSize/2, params.padChar));
+ padLeft = padSize/2;
+ padRight = padSize - padSize/2;
break;
}
}
-#if defined (QTEXTSTREAM_DEBUG)
- QByteArray a = s.toUtf8();
- QByteArray b = tmp.toUtf8();
- qDebug("QTextStreamPrivate::putString(\"%s\") calls write(\"%s\")",
- qt_prettyDebug(a.constData(), a.size(), qMax(16, a.size())).constData(),
- qt_prettyDebug(b.constData(), b.size(), qMax(16, b.size())).constData());
-#endif
- write(tmp);
+ write(pad.constData(), padLeft);
+ write(data, len);
+ write(pad.constData(), padRight);
}
/*!
@@ -2232,7 +2249,7 @@ QTextStream &QTextStream::operator<<(QChar c)
{
Q_D(QTextStream);
CHECK_VALID_STREAM(*this);
- d->putString(QString(c));
+ d->putChar(c);
return *this;
}
@@ -2245,7 +2262,7 @@ QTextStream &QTextStream::operator<<(char c)
{
Q_D(QTextStream);
CHECK_VALID_STREAM(*this);
- d->putString(QString(QChar::fromLatin1(c)));
+ d->putChar(QChar::fromLatin1(c));
return *this;
}
diff --git a/src/corelib/io/qtextstream_p.h b/src/corelib/io/qtextstream_p.h
index 5f99f44cc2..f8c151b76c 100644
--- a/src/corelib/io/qtextstream_p.h
+++ b/src/corelib/io/qtextstream_p.h
@@ -165,8 +165,12 @@ public:
NumberParsingStatus getNumber(qulonglong *l);
bool getReal(double *f);
- inline void write(const QString &data);
- inline void putString(const QString &ch, bool number = false);
+ inline void write(const QString &data) { write(data.begin(), data.length()); }
+ inline void write(QChar ch);
+ void write(const QChar *data, int len);
+ inline void putString(const QString &ch, bool number = false) { putString(ch.constData(), ch.length(), number); }
+ void putString(const QChar *data, int len, bool number = false);
+ inline void putChar(QChar ch);
void putNumber(qulonglong number, bool negative);
// buffers
diff --git a/src/corelib/io/qurlrecode.cpp b/src/corelib/io/qurlrecode.cpp
index 9aad2a12bd..4cf471a248 100644
--- a/src/corelib/io/qurlrecode.cpp
+++ b/src/corelib/io/qurlrecode.cpp
@@ -33,6 +33,7 @@
#include "qurl.h"
#include "private/qutfcodec_p.h"
+#include "private/qtools_p.h"
QT_BEGIN_NAMESPACE
@@ -197,8 +198,7 @@ static inline ushort decodePercentEncoding(const ushort *input)
static inline ushort encodeNibble(ushort c)
{
- static const uchar hexnumbers[] = "0123456789ABCDEF";
- return hexnumbers[c & 0xf];
+ return ushort(QtMiscUtils::toHexUpper(c));
}
static void ensureDetached(QString &result, ushort *&output, const ushort *begin, const ushort *input, const ushort *end,
diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp
index a9cfa3e7ca..88e39f9441 100644
--- a/src/corelib/itemmodels/qabstractitemmodel.cpp
+++ b/src/corelib/itemmodels/qabstractitemmodel.cpp
@@ -468,12 +468,12 @@ class QEmptyItemModel : public QAbstractItemModel
{
public:
explicit QEmptyItemModel(QObject *parent = 0) : QAbstractItemModel(parent) {}
- QModelIndex index(int, int, const QModelIndex &) const { return QModelIndex(); }
- QModelIndex parent(const QModelIndex &) const { return QModelIndex(); }
- int rowCount(const QModelIndex &) const { return 0; }
- int columnCount(const QModelIndex &) const { return 0; }
- bool hasChildren(const QModelIndex &) const { return false; }
- QVariant data(const QModelIndex &, int) const { return QVariant(); }
+ QModelIndex index(int, int, const QModelIndex &) const Q_DECL_OVERRIDE { return QModelIndex(); }
+ QModelIndex parent(const QModelIndex &) const Q_DECL_OVERRIDE { return QModelIndex(); }
+ int rowCount(const QModelIndex &) const Q_DECL_OVERRIDE { return 0; }
+ int columnCount(const QModelIndex &) const Q_DECL_OVERRIDE { return 0; }
+ bool hasChildren(const QModelIndex &) const Q_DECL_OVERRIDE { return false; }
+ QVariant data(const QModelIndex &, int) const Q_DECL_OVERRIDE { return QVariant(); }
};
Q_GLOBAL_STATIC(QEmptyItemModel, qEmptyModel)
@@ -1264,11 +1264,6 @@ void QAbstractItemModel::resetInternalData()
*/
/*!
- \fn QObject *QAbstractItemModel::parent() const
- \internal
-*/
-
-/*!
\fn QModelIndex QAbstractItemModel::parent(const QModelIndex &index) const = 0
Returns the parent of the model item with the given \a index. If the item
diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h
index 32d88e9d96..5761084055 100644
--- a/src/corelib/itemmodels/qabstractitemmodel.h
+++ b/src/corelib/itemmodels/qabstractitemmodel.h
@@ -230,11 +230,7 @@ public:
virtual QHash<int,QByteArray> roleNames() const;
-#ifdef Q_NO_USING_KEYWORD
- inline QObject *parent() const { return QObject::parent(); }
-#else
using QObject::parent;
-#endif
enum LayoutChangeHint
{
@@ -419,27 +415,21 @@ public:
explicit QAbstractTableModel(QObject *parent = 0);
~QAbstractTableModel();
- QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
+ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
bool dropMimeData(const QMimeData *data, Qt::DropAction action,
- int row, int column, const QModelIndex &parent);
+ int row, int column, const QModelIndex &parent) Q_DECL_OVERRIDE;
Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
-#ifdef Q_NO_USING_KEYWORD
-#ifndef Q_QDOC
- inline QObject *parent() const { return QAbstractItemModel::parent(); }
-#endif
-#else
using QObject::parent;
-#endif
protected:
QAbstractTableModel(QAbstractItemModelPrivate &dd, QObject *parent);
private:
Q_DISABLE_COPY(QAbstractTableModel)
- QModelIndex parent(const QModelIndex &child) const;
- bool hasChildren(const QModelIndex &parent) const;
+ QModelIndex parent(const QModelIndex &child) const Q_DECL_OVERRIDE;
+ bool hasChildren(const QModelIndex &parent) const Q_DECL_OVERRIDE;
};
class Q_CORE_EXPORT QAbstractListModel : public QAbstractItemModel
@@ -450,28 +440,22 @@ public:
explicit QAbstractListModel(QObject *parent = 0);
~QAbstractListModel();
- QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
+ QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
bool dropMimeData(const QMimeData *data, Qt::DropAction action,
- int row, int column, const QModelIndex &parent);
+ int row, int column, const QModelIndex &parent) Q_DECL_OVERRIDE;
Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
-#ifdef Q_NO_USING_KEYWORD
-#ifndef Q_QDOC
- inline QObject *parent() const { return QAbstractItemModel::parent(); }
-#endif
-#else
using QObject::parent;
-#endif
protected:
QAbstractListModel(QAbstractItemModelPrivate &dd, QObject *parent);
private:
Q_DISABLE_COPY(QAbstractListModel)
- QModelIndex parent(const QModelIndex &child) const;
- int columnCount(const QModelIndex &parent) const;
- bool hasChildren(const QModelIndex &parent) const;
+ QModelIndex parent(const QModelIndex &child) const Q_DECL_OVERRIDE;
+ int columnCount(const QModelIndex &parent) const Q_DECL_OVERRIDE;
+ bool hasChildren(const QModelIndex &parent) const Q_DECL_OVERRIDE;
};
// inline implementations
diff --git a/src/corelib/itemmodels/qabstractproxymodel.h b/src/corelib/itemmodels/qabstractproxymodel.h
index a11fb592ab..93517e943f 100644
--- a/src/corelib/itemmodels/qabstractproxymodel.h
+++ b/src/corelib/itemmodels/qabstractproxymodel.h
@@ -62,34 +62,34 @@ public:
virtual QItemSelection mapSelectionToSource(const QItemSelection &selection) const;
virtual QItemSelection mapSelectionFromSource(const QItemSelection &selection) const;
- bool submit();
- void revert();
-
- QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const;
- QVariant headerData(int section, Qt::Orientation orientation, int role) const;
- QMap<int, QVariant> itemData(const QModelIndex &index) const;
- Qt::ItemFlags flags(const QModelIndex &index) const;
-
- bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
- bool setItemData(const QModelIndex& index, const QMap<int, QVariant> &roles);
- bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
-
- QModelIndex buddy(const QModelIndex &index) const;
- bool canFetchMore(const QModelIndex &parent) const;
- void fetchMore(const QModelIndex &parent);
- void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
- QSize span(const QModelIndex &index) const;
- bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
- QModelIndex sibling(int row, int column, const QModelIndex &idx) const;
-
- QMimeData* mimeData(const QModelIndexList &indexes) const;
+ bool submit() Q_DECL_OVERRIDE;
+ void revert() Q_DECL_OVERRIDE;
+
+ QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
+ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
+ QMap<int, QVariant> itemData(const QModelIndex &index) const Q_DECL_OVERRIDE;
+ Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
+
+ bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE;
+ bool setItemData(const QModelIndex& index, const QMap<int, QVariant> &roles) Q_DECL_OVERRIDE;
+ bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE;
+
+ QModelIndex buddy(const QModelIndex &index) const Q_DECL_OVERRIDE;
+ bool canFetchMore(const QModelIndex &parent) const Q_DECL_OVERRIDE;
+ void fetchMore(const QModelIndex &parent) Q_DECL_OVERRIDE;
+ void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) Q_DECL_OVERRIDE;
+ QSize span(const QModelIndex &index) const Q_DECL_OVERRIDE;
+ bool hasChildren(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QModelIndex sibling(int row, int column, const QModelIndex &idx) const Q_DECL_OVERRIDE;
+
+ QMimeData* mimeData(const QModelIndexList &indexes) const Q_DECL_OVERRIDE;
bool canDropMimeData(const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &parent) const Q_DECL_OVERRIDE;
bool dropMimeData(const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &parent) Q_DECL_OVERRIDE;
- QStringList mimeTypes() const;
- Qt::DropActions supportedDragActions() const;
- Qt::DropActions supportedDropActions() const;
+ QStringList mimeTypes() const Q_DECL_OVERRIDE;
+ Qt::DropActions supportedDragActions() const Q_DECL_OVERRIDE;
+ Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE;
Q_SIGNALS:
void sourceModelChanged(
diff --git a/src/corelib/itemmodels/qidentityproxymodel.cpp b/src/corelib/itemmodels/qidentityproxymodel.cpp
index 27100c9ff7..e3b363f190 100644
--- a/src/corelib/itemmodels/qidentityproxymodel.cpp
+++ b/src/corelib/itemmodels/qidentityproxymodel.cpp
@@ -152,11 +152,8 @@ QModelIndex QIdentityProxyModel::index(int row, int column, const QModelIndex& p
{
Q_ASSERT(parent.isValid() ? parent.model() == this : true);
Q_D(const QIdentityProxyModel);
- if (!hasIndex(row, column, parent))
- return QModelIndex();
const QModelIndex sourceParent = mapToSource(parent);
const QModelIndex sourceIndex = d->model->index(row, column, sourceParent);
- Q_ASSERT(sourceIndex.isValid());
return mapFromSource(sourceIndex);
}
diff --git a/src/corelib/itemmodels/qidentityproxymodel.h b/src/corelib/itemmodels/qidentityproxymodel.h
index 7eaa1f4e04..5a9491d669 100644
--- a/src/corelib/itemmodels/qidentityproxymodel.h
+++ b/src/corelib/itemmodels/qidentityproxymodel.h
@@ -51,25 +51,25 @@ public:
explicit QIdentityProxyModel(QObject* parent = 0);
~QIdentityProxyModel();
- int columnCount(const QModelIndex& parent = QModelIndex()) const;
- QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
- QModelIndex mapFromSource(const QModelIndex& sourceIndex) const;
- QModelIndex mapToSource(const QModelIndex& proxyIndex) const;
- QModelIndex parent(const QModelIndex& child) const;
- int rowCount(const QModelIndex& parent = QModelIndex()) const;
- QVariant headerData(int section, Qt::Orientation orientation, int role) const;
- bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent);
- QModelIndex sibling(int row, int column, const QModelIndex &idx) const;
-
- QItemSelection mapSelectionFromSource(const QItemSelection& selection) const;
- QItemSelection mapSelectionToSource(const QItemSelection& selection) const;
- QModelIndexList match(const QModelIndex& start, int role, const QVariant& value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const;
- void setSourceModel(QAbstractItemModel* sourceModel);
-
- bool insertColumns(int column, int count, const QModelIndex& parent = QModelIndex());
- bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex());
- bool removeColumns(int column, int count, const QModelIndex& parent = QModelIndex());
- bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
+ int columnCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QModelIndex mapFromSource(const QModelIndex& sourceIndex) const Q_DECL_OVERRIDE;
+ QModelIndex mapToSource(const QModelIndex& proxyIndex) const Q_DECL_OVERRIDE;
+ QModelIndex parent(const QModelIndex& child) const Q_DECL_OVERRIDE;
+ int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
+ bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) Q_DECL_OVERRIDE;
+ QModelIndex sibling(int row, int column, const QModelIndex &idx) const Q_DECL_OVERRIDE;
+
+ QItemSelection mapSelectionFromSource(const QItemSelection& selection) const Q_DECL_OVERRIDE;
+ QItemSelection mapSelectionToSource(const QItemSelection& selection) const Q_DECL_OVERRIDE;
+ QModelIndexList match(const QModelIndex& start, int role, const QVariant& value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const Q_DECL_OVERRIDE;
+ void setSourceModel(QAbstractItemModel* sourceModel) Q_DECL_OVERRIDE;
+
+ bool insertColumns(int column, int count, const QModelIndex& parent = QModelIndex()) Q_DECL_OVERRIDE;
+ bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) Q_DECL_OVERRIDE;
+ bool removeColumns(int column, int count, const QModelIndex& parent = QModelIndex()) Q_DECL_OVERRIDE;
+ bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) Q_DECL_OVERRIDE;
protected:
QIdentityProxyModel(QIdentityProxyModelPrivate &dd, QObject* parent);
diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp
index 0b2b0e4188..e64d588432 100644
--- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp
+++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp
@@ -195,7 +195,8 @@ public:
}
void _q_sourceDataChanged(const QModelIndex &source_top_left,
- const QModelIndex &source_bottom_right);
+ const QModelIndex &source_bottom_right,
+ const QVector<int> &roles);
void _q_sourceHeaderDataChanged(Qt::Orientation orientation, int start, int end);
void _q_sourceAboutToBeReset();
@@ -279,7 +280,7 @@ public:
void updateChildrenMapping(const QModelIndex &source_parent, Mapping *parent_mapping,
Qt::Orientation orient, int start, int end, int delta_item_count, bool remove);
- virtual void _q_sourceModelDestroyed();
+ virtual void _q_sourceModelDestroyed() Q_DECL_OVERRIDE;
};
typedef QHash<QModelIndex, QSortFilterProxyModelPrivate::Mapping *> IndexMap;
@@ -1131,7 +1132,8 @@ QSet<int> QSortFilterProxyModelPrivate::handle_filter_changed(
}
void QSortFilterProxyModelPrivate::_q_sourceDataChanged(const QModelIndex &source_top_left,
- const QModelIndex &source_bottom_right)
+ const QModelIndex &source_bottom_right,
+ const QVector<int> &roles)
{
Q_Q(QSortFilterProxyModel);
if (!source_top_left.isValid() || !source_bottom_right.isValid())
@@ -1224,7 +1226,7 @@ void QSortFilterProxyModelPrivate::_q_sourceDataChanged(const QModelIndex &sourc
--source_right_column;
const QModelIndex proxy_bottom_right = create_index(
proxy_end_row, m->proxy_columns.at(source_right_column), it);
- emit q->dataChanged(proxy_top_left, proxy_bottom_right);
+ emit q->dataChanged(proxy_top_left, proxy_bottom_right, roles);
}
}
@@ -1728,8 +1730,8 @@ void QSortFilterProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
beginResetModel();
- disconnect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
- this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex)));
+ disconnect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)),
+ this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex,QVector<int>)));
disconnect(d->model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
this, SLOT(_q_sourceHeaderDataChanged(Qt::Orientation,int,int)));
@@ -1781,8 +1783,8 @@ void QSortFilterProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
QAbstractProxyModel::setSourceModel(sourceModel);
- connect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
- this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex)));
+ connect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)),
+ this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex,QVector<int>)));
connect(d->model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
this, SLOT(_q_sourceHeaderDataChanged(Qt::Orientation,int,int)));
@@ -2740,11 +2742,6 @@ QItemSelection QSortFilterProxyModel::mapSelectionFromSource(const QItemSelectio
return QAbstractProxyModel::mapSelectionFromSource(sourceSelection);
}
-/*!
- \fn QObject *QSortFilterProxyModel::parent() const
- \internal
-*/
-
QT_END_NAMESPACE
#include "moc_qsortfilterproxymodel.cpp"
diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.h b/src/corelib/itemmodels/qsortfilterproxymodel.h
index 5f7235876e..9df785756c 100644
--- a/src/corelib/itemmodels/qsortfilterproxymodel.h
+++ b/src/corelib/itemmodels/qsortfilterproxymodel.h
@@ -66,13 +66,13 @@ public:
explicit QSortFilterProxyModel(QObject *parent = 0);
~QSortFilterProxyModel();
- void setSourceModel(QAbstractItemModel *sourceModel);
+ void setSourceModel(QAbstractItemModel *sourceModel) Q_DECL_OVERRIDE;
- QModelIndex mapToSource(const QModelIndex &proxyIndex) const;
- QModelIndex mapFromSource(const QModelIndex &sourceIndex) const;
+ QModelIndex mapToSource(const QModelIndex &proxyIndex) const Q_DECL_OVERRIDE;
+ QModelIndex mapFromSource(const QModelIndex &sourceIndex) const Q_DECL_OVERRIDE;
- QItemSelection mapSelectionToSource(const QItemSelection &proxySelection) const;
- QItemSelection mapSelectionFromSource(const QItemSelection &sourceSelection) const;
+ QItemSelection mapSelectionToSource(const QItemSelection &proxySelection) const Q_DECL_OVERRIDE;
+ QItemSelection mapSelectionFromSource(const QItemSelection &sourceSelection) const Q_DECL_OVERRIDE;
QRegExp filterRegExp() const;
void setFilterRegExp(const QRegExp &regExp);
@@ -117,55 +117,51 @@ protected:
void invalidateFilter();
public:
-#ifdef Q_NO_USING_KEYWORD
- inline QObject *parent() const { return QObject::parent(); }
-#else
using QObject::parent;
-#endif
- QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
- QModelIndex parent(const QModelIndex &child) const;
- QModelIndex sibling(int row, int column, const QModelIndex &idx) const;
+ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QModelIndex parent(const QModelIndex &child) const Q_DECL_OVERRIDE;
+ QModelIndex sibling(int row, int column, const QModelIndex &idx) const Q_DECL_OVERRIDE;
- int rowCount(const QModelIndex &parent = QModelIndex()) const;
- int columnCount(const QModelIndex &parent = QModelIndex()) const;
- bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ bool hasChildren(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
+ bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE;
- QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
bool setHeaderData(int section, Qt::Orientation orientation,
- const QVariant &value, int role = Qt::EditRole);
+ const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE;
- QMimeData *mimeData(const QModelIndexList &indexes) const;
+ QMimeData *mimeData(const QModelIndexList &indexes) const Q_DECL_OVERRIDE;
bool dropMimeData(const QMimeData *data, Qt::DropAction action,
- int row, int column, const QModelIndex &parent);
+ int row, int column, const QModelIndex &parent) Q_DECL_OVERRIDE;
- bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
- bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex());
- bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
- bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex());
+ bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
+ bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
+ bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
+ bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
- void fetchMore(const QModelIndex &parent);
- bool canFetchMore(const QModelIndex &parent) const;
- Qt::ItemFlags flags(const QModelIndex &index) const;
+ void fetchMore(const QModelIndex &parent) Q_DECL_OVERRIDE;
+ bool canFetchMore(const QModelIndex &parent) const Q_DECL_OVERRIDE;
+ Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
- QModelIndex buddy(const QModelIndex &index) const;
+ QModelIndex buddy(const QModelIndex &index) const Q_DECL_OVERRIDE;
QModelIndexList match(const QModelIndex &start, int role,
const QVariant &value, int hits = 1,
Qt::MatchFlags flags =
- Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const;
- QSize span(const QModelIndex &index) const;
- void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
+ Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const Q_DECL_OVERRIDE;
+ QSize span(const QModelIndex &index) const Q_DECL_OVERRIDE;
+ void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) Q_DECL_OVERRIDE;
- QStringList mimeTypes() const;
- Qt::DropActions supportedDropActions() const;
+ QStringList mimeTypes() const Q_DECL_OVERRIDE;
+ Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE;
private:
Q_DECLARE_PRIVATE(QSortFilterProxyModel)
Q_DISABLE_COPY(QSortFilterProxyModel)
- Q_PRIVATE_SLOT(d_func(), void _q_sourceDataChanged(const QModelIndex &source_top_left, const QModelIndex &source_bottom_right))
+ Q_PRIVATE_SLOT(d_func(), void _q_sourceDataChanged(const QModelIndex &source_top_left, const QModelIndex &source_bottom_right, const QVector<int> &roles))
Q_PRIVATE_SLOT(d_func(), void _q_sourceHeaderDataChanged(Qt::Orientation orientation, int start, int end))
Q_PRIVATE_SLOT(d_func(), void _q_sourceAboutToBeReset())
Q_PRIVATE_SLOT(d_func(), void _q_sourceReset())
diff --git a/src/corelib/itemmodels/qstringlistmodel.h b/src/corelib/itemmodels/qstringlistmodel.h
index 0db2d550af..764d79ba6f 100644
--- a/src/corelib/itemmodels/qstringlistmodel.h
+++ b/src/corelib/itemmodels/qstringlistmodel.h
@@ -49,23 +49,23 @@ public:
explicit QStringListModel(QObject *parent = 0);
explicit QStringListModel(const QStringList &strings, QObject *parent = 0);
- int rowCount(const QModelIndex &parent = QModelIndex()) const;
- QModelIndex sibling(int row, int column, const QModelIndex &idx) const;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QModelIndex sibling(int row, int column, const QModelIndex &idx) const Q_DECL_OVERRIDE;
- QVariant data(const QModelIndex &index, int role) const;
- bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
+ QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
+ bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE;
- Qt::ItemFlags flags(const QModelIndex &index) const;
+ Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
- bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
- bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
+ bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
+ bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
- void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
+ void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) Q_DECL_OVERRIDE;
QStringList stringList() const;
void setStringList(const QStringList &strings);
- Qt::DropActions supportedDropActions() const;
+ Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(QStringListModel)
diff --git a/src/corelib/json/qjsonobject.cpp b/src/corelib/json/qjsonobject.cpp
index bc74092f59..df604e4433 100644
--- a/src/corelib/json/qjsonobject.cpp
+++ b/src/corelib/json/qjsonobject.cpp
@@ -192,7 +192,7 @@ QJsonObject &QJsonObject::operator =(const QJsonObject &other)
The keys in \a map will be used as the keys in the JSON object,
and the QVariant values will be converted to JSON values.
- \sa toVariantMap(), QJsonValue::fromVariant()
+ \sa fromVariantHash(), toVariantMap(), QJsonValue::fromVariant()
*/
QJsonObject QJsonObject::fromVariantMap(const QVariantMap &map)
{
@@ -208,6 +208,8 @@ QJsonObject QJsonObject::fromVariantMap(const QVariantMap &map)
Converts this object to a QVariantMap.
Returns the created map.
+
+ \sa toVariantHash()
*/
QVariantMap QJsonObject::toVariantMap() const
{
@@ -222,6 +224,45 @@ QVariantMap QJsonObject::toVariantMap() const
}
/*!
+ Converts the variant hash \a hash to a QJsonObject.
+ \since 5.5
+
+ The keys in \a hash will be used as the keys in the JSON object,
+ and the QVariant values will be converted to JSON values.
+
+ \sa fromVariantMap(), toVariantHash(), QJsonValue::fromVariant()
+ */
+QJsonObject QJsonObject::fromVariantHash(const QVariantHash &hash)
+{
+ // ### this is implemented the trivial way, not the most efficient way
+
+ QJsonObject object;
+ for (QVariantHash::const_iterator it = hash.constBegin(); it != hash.constEnd(); ++it)
+ object.insert(it.key(), QJsonValue::fromVariant(it.value()));
+ return object;
+}
+
+/*!
+ Converts this object to a QVariantHash.
+ \since 5.5
+
+ Returns the created hash.
+
+ \sa toVariantMap()
+ */
+QVariantHash QJsonObject::toVariantHash() const
+{
+ QVariantHash hash;
+ if (o) {
+ for (uint i = 0; i < o->length; ++i) {
+ QJsonPrivate::Entry *e = o->entryAt(i);
+ hash.insert(e->key(), QJsonValue(d, o, e->value).toVariant());
+ }
+ }
+ return hash;
+}
+
+/*!
Returns a list of all keys in this object.
*/
QStringList QJsonObject::keys() const
diff --git a/src/corelib/json/qjsonobject.h b/src/corelib/json/qjsonobject.h
index 9abdb047ed..272cf14b01 100644
--- a/src/corelib/json/qjsonobject.h
+++ b/src/corelib/json/qjsonobject.h
@@ -46,6 +46,8 @@ QT_BEGIN_NAMESPACE
class QDebug;
template <class Key, class T> class QMap;
typedef QMap<QString, QVariant> QVariantMap;
+template <class Key, class T> class QHash;
+typedef QHash<QString, QVariant> QVariantHash;
class Q_CORE_EXPORT QJsonObject
{
@@ -68,6 +70,8 @@ public:
static QJsonObject fromVariantMap(const QVariantMap &map);
QVariantMap toVariantMap() const;
+ static QJsonObject fromVariantHash(const QVariantHash &map);
+ QVariantHash toVariantHash() const;
QStringList keys() const;
int size() const;
diff --git a/src/corelib/json/qjsonvalue.cpp b/src/corelib/json/qjsonvalue.cpp
index ac4fcb89c1..4c5d9e3308 100644
--- a/src/corelib/json/qjsonvalue.cpp
+++ b/src/corelib/json/qjsonvalue.cpp
@@ -373,6 +373,7 @@ QJsonValue &QJsonValue::operator =(const QJsonValue &other)
\li
\list
\li QMetaType::QVariantMap
+ \li QMetaType::QVariantHash
\endlist
\li QJsonValue::Object
\endtable
@@ -402,6 +403,8 @@ QJsonValue QJsonValue::fromVariant(const QVariant &variant)
return QJsonValue(QJsonArray::fromVariantList(variant.toList()));
case QVariant::Map:
return QJsonValue(QJsonObject::fromVariantMap(variant.toMap()));
+ case QVariant::Hash:
+ return QJsonValue(QJsonObject::fromVariantHash(variant.toHash()));
default:
break;
}
diff --git a/src/corelib/kernel/kernel.pri b/src/corelib/kernel/kernel.pri
index 55625f3571..0ece4a395c 100644
--- a/src/corelib/kernel/kernel.pri
+++ b/src/corelib/kernel/kernel.pri
@@ -99,20 +99,22 @@ winrt {
}
mac {
+ HEADERS += \
+ kernel/qcore_mac_p.h
+
SOURCES += \
- kernel/qcoreapplication_mac.cpp
-}
+ kernel/qcoreapplication_mac.cpp \
+ kernel/qcore_mac.cpp
+
+ OBJECTIVE_SOURCES += \
+ kernel/qcore_mac_objc.mm
+
+ LIBS_PRIVATE += -framework Foundation
-mac:!nacl {
- HEADERS += \
- kernel/qcore_mac_p.h
- SOURCES += \
- kernel/qcore_mac.cpp
- OBJECTIVE_SOURCES += \
- kernel/qcore_mac_objc.mm
+ osx: LIBS_PRIVATE += -framework CoreServices
- # We need UIKit for UIDevice
- ios: LIBS_PRIVATE += -framework UIKit
+ # We need UIKit for UIDevice
+ ios: LIBS_PRIVATE += -framework UIKit
}
nacl {
diff --git a/src/corelib/kernel/qcore_mac_objc.mm b/src/corelib/kernel/qcore_mac_objc.mm
index 73f8296021..8ac062a154 100644
--- a/src/corelib/kernel/qcore_mac_objc.mm
+++ b/src/corelib/kernel/qcore_mac_objc.mm
@@ -1,6 +1,7 @@
/****************************************************************************
**
- ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+ ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+ ** Copyright (C) 2014 Petroules Corporation.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -47,6 +48,8 @@
QT_BEGIN_NAMESPACE
+typedef qint16 (*GestaltFunction)(quint32 selector, qint32 *response);
+
NSString *QCFString::toNSString(const QString &string)
{
// The const cast below is safe: CfStringRef is immutable and so is NSString.
@@ -58,31 +61,49 @@ QString QCFString::toQString(const NSString *nsstr)
return toQString(reinterpret_cast<CFStringRef>(nsstr));
}
-#ifdef Q_OS_IOS
-QSysInfo::MacVersion qt_ios_version()
+QAppleOperatingSystemVersion qt_apple_os_version()
{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
- int major = 0, minor = 0;
- NSArray *components = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
- switch ([components count]) {
- case 3:
- // We don't care about the patch version
- case 2:
- minor = [[components objectAtIndex:1] intValue];
- // fall through
- case 1:
- major = [[components objectAtIndex:0] intValue];
- break;
- default:
- Q_UNREACHABLE();
+ QAppleOperatingSystemVersion v = {0, 0, 0};
+#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_10, __IPHONE_8_0)
+ if ([NSProcessInfo instancesRespondToSelector:@selector(operatingSystemVersion)]) {
+ NSOperatingSystemVersion osv = NSProcessInfo.processInfo.operatingSystemVersion;
+ v.major = osv.majorVersion;
+ v.minor = osv.minorVersion;
+ v.patch = osv.patchVersion;
+ return v;
}
-
- [pool release];
-
- return QSysInfo::MacVersion(Q_MV_IOS(major, minor));
-}
#endif
+ // Use temporary variables so we can return 0.0.0 (unknown version)
+ // in case of an error partway through determining the OS version
+ qint32 major = 0, minor = 0, patch = 0;
+#if defined(Q_OS_IOS)
+ @autoreleasepool {
+ NSArray *parts = [UIDevice.currentDevice.systemVersion componentsSeparatedByString:@"."];
+ major = parts.count > 0 ? [[parts objectAtIndex:0] intValue] : 0;
+ minor = parts.count > 1 ? [[parts objectAtIndex:1] intValue] : 0;
+ patch = parts.count > 2 ? [[parts objectAtIndex:2] intValue] : 0;
+ }
+#elif defined(Q_OS_OSX)
+ static GestaltFunction pGestalt = 0;
+ if (!pGestalt) {
+ CFBundleRef b = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.CoreServices"));
+ pGestalt = reinterpret_cast<GestaltFunction>(CFBundleGetFunctionPointerForName(b,
+ CFSTR("Gestalt")));
+ }
+ if (!pGestalt)
+ return v;
+ if (pGestalt('sys1', &major) != 0)
+ return v;
+ if (pGestalt('sys2', &minor) != 0)
+ return v;
+ if (pGestalt('sys3', &patch) != 0)
+ return v;
+#endif
+ v.major = major;
+ v.minor = minor;
+ v.patch = patch;
+ return v;
+}
QT_END_NAMESPACE
diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h
index 842e2ef9f1..9b13f8d2b1 100644
--- a/src/corelib/kernel/qcore_mac_p.h
+++ b/src/corelib/kernel/qcore_mac_p.h
@@ -135,9 +135,11 @@ private:
QString string;
};
-#ifdef Q_OS_IOS
-QSysInfo::MacVersion qt_ios_version();
-#endif
+typedef struct {
+ int major, minor, patch;
+} QAppleOperatingSystemVersion;
+
+QAppleOperatingSystemVersion qt_apple_os_version();
QT_END_NAMESPACE
diff --git a/src/corelib/kernel/qcoreapplication.h b/src/corelib/kernel/qcoreapplication.h
index ff1dd5c43a..db1245430b 100644
--- a/src/corelib/kernel/qcoreapplication.h
+++ b/src/corelib/kernel/qcoreapplication.h
@@ -183,7 +183,7 @@ Q_SIGNALS:
void applicationVersionChanged();
protected:
- bool event(QEvent *);
+ bool event(QEvent *) Q_DECL_OVERRIDE;
virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
#endif // QT_NO_QOBJECT
diff --git a/src/corelib/kernel/qcoreevent.cpp b/src/corelib/kernel/qcoreevent.cpp
index 191ceaa37b..93ab90fb94 100644
--- a/src/corelib/kernel/qcoreevent.cpp
+++ b/src/corelib/kernel/qcoreevent.cpp
@@ -183,6 +183,7 @@ QT_BEGIN_NAMESPACE
\value ParentAboutToChange The widget parent is about to change.
\value ParentChange The widget parent has changed.
\value PlatformPanel A platform specific panel has been requested.
+ \value PlatformSurface A native platform surface has been created or is about to be destroyed (QPlatformSurfaceEvent).
\value Polish The widget is polished.
\value PolishRequest The widget should be polished.
\value QueryWhatsThis The widget should accept the event if it has "What's This?" help.
diff --git a/src/corelib/kernel/qcoreevent.h b/src/corelib/kernel/qcoreevent.h
index 170f319ec9..0807721432 100644
--- a/src/corelib/kernel/qcoreevent.h
+++ b/src/corelib/kernel/qcoreevent.h
@@ -275,6 +275,8 @@ public:
WindowChangeInternal = 215, // internal for QQuickWidget
ScreenChangeInternal = 216,
+ PlatformSurface = 217, // Platform surface created or about to be destroyed
+
// 512 reserved for Qt Jambi's MetaCall event
// 513 reserved for Qt Jambi's DeleteOnMainThread event
diff --git a/src/corelib/kernel/qeventdispatcher_glib_p.h b/src/corelib/kernel/qeventdispatcher_glib_p.h
index 50820f478b..5950a4221a 100644
--- a/src/corelib/kernel/qeventdispatcher_glib_p.h
+++ b/src/corelib/kernel/qeventdispatcher_glib_p.h
@@ -66,8 +66,8 @@ public:
explicit QEventDispatcherGlib(GMainContext *context, QObject *parent = 0);
~QEventDispatcherGlib();
- bool processEvents(QEventLoop::ProcessEventsFlags flags);
- bool hasPendingEvents();
+ bool processEvents(QEventLoop::ProcessEventsFlags flags) Q_DECL_OVERRIDE;
+ bool hasPendingEvents() Q_DECL_OVERRIDE;
void registerSocketNotifier(QSocketNotifier *socketNotifier) Q_DECL_FINAL;
void unregisterSocketNotifier(QSocketNotifier *socketNotifier) Q_DECL_FINAL;
diff --git a/src/corelib/kernel/qeventdispatcher_unix_p.h b/src/corelib/kernel/qeventdispatcher_unix_p.h
index 37f180486e..3ec2c2eb3f 100644
--- a/src/corelib/kernel/qeventdispatcher_unix_p.h
+++ b/src/corelib/kernel/qeventdispatcher_unix_p.h
@@ -101,8 +101,8 @@ public:
explicit QEventDispatcherUNIX(QObject *parent = 0);
~QEventDispatcherUNIX();
- bool processEvents(QEventLoop::ProcessEventsFlags flags);
- bool hasPendingEvents();
+ bool processEvents(QEventLoop::ProcessEventsFlags flags) Q_DECL_OVERRIDE;
+ bool hasPendingEvents() Q_DECL_OVERRIDE;
void registerSocketNotifier(QSocketNotifier *notifier) FINAL_EXCEPT_BLACKBERRY;
void unregisterSocketNotifier(QSocketNotifier *notifier) FINAL_EXCEPT_BLACKBERRY;
@@ -116,7 +116,7 @@ public:
void wakeUp() FINAL_EXCEPT_BLACKBERRY;
void interrupt() Q_DECL_FINAL;
- void flush();
+ void flush() Q_DECL_OVERRIDE;
protected:
QEventDispatcherUNIX(QEventDispatcherUNIXPrivate &dd, QObject *parent = 0);
diff --git a/src/corelib/kernel/qeventloop.h b/src/corelib/kernel/qeventloop.h
index 31cd1d402a..be7a40e44d 100644
--- a/src/corelib/kernel/qeventloop.h
+++ b/src/corelib/kernel/qeventloop.h
@@ -70,7 +70,7 @@ public:
void wakeUp();
- bool event(QEvent *event);
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
public Q_SLOTS:
void quit();
diff --git a/src/corelib/kernel/qfunctions_wince.h b/src/corelib/kernel/qfunctions_wince.h
index cc5e0ca83f..8cbde6c465 100644
--- a/src/corelib/kernel/qfunctions_wince.h
+++ b/src/corelib/kernel/qfunctions_wince.h
@@ -208,7 +208,7 @@ int qt_wince_SetErrorMode(int);
bool qt_wince__chmod(const char *file, int mode);
bool qt_wince__wchmod(const wchar_t *file, int mode);
-#pragma warning(disable: 4273)
+QT_WARNING_DISABLE_MSVC(4273)
HANDLE qt_wince_CreateFileA(LPCSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE);
// Printer ----------------------------------------------------------
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp
index b54cb0c344..3e2fb46143 100644
--- a/src/corelib/kernel/qmetaobject.cpp
+++ b/src/corelib/kernel/qmetaobject.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -2298,6 +2299,112 @@ bool QMetaMethod::invoke(QObject *object,
*/
/*!
+ \since 5.5
+
+ Invokes this method on a Q_GADGET. Returns \c true if the member could be invoked.
+ Returns \c false if there is no such member or the parameters did not match.
+
+ The pointer \a gadget must point to an instance of the gadget class.
+
+ The invocation is always synchronous.
+
+ The return value of this method call is placed in \a
+ returnValue. You can pass up to ten arguments (\a val0, \a val1,
+ \a val2, \a val3, \a val4, \a val5, \a val6, \a val7, \a val8,
+ and \a val9) to this method call.
+
+ \warning this method will not test the validity of the arguments: \a gadget
+ must be an instance of the class of the QMetaObject of which this QMetaMethod
+ has been constructed with. The arguments must have the same type as the ones
+ expected by the method, else, the behavior is undefined.
+
+ \sa Q_ARG(), Q_RETURN_ARG(), qRegisterMetaType(), QMetaObject::invokeMethod()
+*/
+bool QMetaMethod::invokeOnGadget(void* gadget, QGenericReturnArgument returnValue, QGenericArgument val0, QGenericArgument val1, QGenericArgument val2, QGenericArgument val3, QGenericArgument val4, QGenericArgument val5, QGenericArgument val6, QGenericArgument val7, QGenericArgument val8, QGenericArgument val9) const
+{
+ if (!gadget || !mobj)
+ return false;
+
+ // check return type
+ if (returnValue.data()) {
+ const char *retType = typeName();
+ if (qstrcmp(returnValue.name(), retType) != 0) {
+ // normalize the return value as well
+ QByteArray normalized = QMetaObject::normalizedType(returnValue.name());
+ if (qstrcmp(normalized.constData(), retType) != 0) {
+ // String comparison failed, try compare the metatype.
+ int t = returnType();
+ if (t == QMetaType::UnknownType || t != QMetaType::type(normalized))
+ return false;
+ }
+ }
+ }
+
+ // check argument count (we don't allow invoking a method if given too few arguments)
+ const char *typeNames[] = {
+ returnValue.name(),
+ val0.name(),
+ val1.name(),
+ val2.name(),
+ val3.name(),
+ val4.name(),
+ val5.name(),
+ val6.name(),
+ val7.name(),
+ val8.name(),
+ val9.name()
+ };
+ int paramCount;
+ for (paramCount = 1; paramCount < MaximumParamCount; ++paramCount) {
+ if (qstrlen(typeNames[paramCount]) <= 0)
+ break;
+ }
+ if (paramCount <= QMetaMethodPrivate::get(this)->parameterCount())
+ return false;
+
+ // invoke!
+ void *param[] = {
+ returnValue.data(),
+ val0.data(),
+ val1.data(),
+ val2.data(),
+ val3.data(),
+ val4.data(),
+ val5.data(),
+ val6.data(),
+ val7.data(),
+ val8.data(),
+ val9.data()
+ };
+ int idx_relative = QMetaMethodPrivate::get(this)->ownMethodIndex();
+ Q_ASSERT(QMetaObjectPrivate::get(mobj)->revision >= 6);
+ QObjectPrivate::StaticMetaCallFunction callFunction = mobj->d.static_metacall;
+ if (!callFunction)
+ return false;
+ callFunction(reinterpret_cast<QObject*>(gadget), QMetaObject::InvokeMetaMethod, idx_relative, param);
+ return true;
+}
+
+/*!
+ \fn bool QMetaMethod::invokeOnGadget(void *gadget,
+ QGenericArgument val0 = QGenericArgument(0),
+ QGenericArgument val1 = QGenericArgument(),
+ QGenericArgument val2 = QGenericArgument(),
+ QGenericArgument val3 = QGenericArgument(),
+ QGenericArgument val4 = QGenericArgument(),
+ QGenericArgument val5 = QGenericArgument(),
+ QGenericArgument val6 = QGenericArgument(),
+ QGenericArgument val7 = QGenericArgument(),
+ QGenericArgument val8 = QGenericArgument(),
+ QGenericArgument val9 = QGenericArgument()) const
+
+ \overload
+ \since 5.5
+
+ This overload invokes this method for a \a gadget and ignores return values.
+*/
+
+/*!
\class QMetaEnum
\inmodule QtCore
\brief The QMetaEnum class provides meta-data about an enumerator.
@@ -2713,9 +2820,8 @@ int QMetaProperty::userType() const
if (isEnumType()) {
type = QMetaType::type(qualifiedName(menum));
if (type == QMetaType::UnknownType) {
- void *argv[] = { &type };
- mobj->static_metacall(QMetaObject::RegisterPropertyMetaType, idx, argv);
- if (type == -1 || type == QMetaType::UnknownType)
+ type = registerPropertyType();
+ if (type == QMetaType::UnknownType)
return QVariant::Int; // Match behavior of QMetaType::type()
}
return type;
@@ -2723,11 +2829,7 @@ int QMetaProperty::userType() const
type = QMetaType::type(typeName());
if (type != QMetaType::UnknownType)
return type;
- void *argv[] = { &type };
- mobj->static_metacall(QMetaObject::RegisterPropertyMetaType, idx, argv);
- if (type != -1)
- return type;
- return QMetaType::UnknownType;
+ return registerPropertyType();
}
/*!
@@ -2791,6 +2893,20 @@ bool QMetaProperty::hasStdCppSet() const
}
/*!
+ \internal
+ Executes metacall with QMetaObject::RegisterPropertyMetaType flag.
+ Returns id of registered type or QMetaType::UnknownType if a type
+ could not be registered for any reason.
+*/
+int QMetaProperty::registerPropertyType() const
+{
+ int registerResult = -1;
+ void *argv[] = { &registerResult };
+ mobj->static_metacall(QMetaObject::RegisterPropertyMetaType, idx, argv);
+ return registerResult == -1 ? QMetaType::UnknownType : registerResult;
+}
+
+/*!
Returns the enumerator if this property's type is an enumerator
type; otherwise the returned value is undefined.
@@ -2835,15 +2951,11 @@ QVariant QMetaProperty::read(const QObject *object) const
}
if (t == QMetaType::UnknownType) {
// Try to register the type and try again before reporting an error.
- int registerResult = -1;
- void *argv[] = { &registerResult };
- QMetaObject::metacall(const_cast<QObject*>(object), QMetaObject::RegisterPropertyMetaType,
- idx + mobj->propertyOffset(), argv);
- if (registerResult == -1) {
+ t = registerPropertyType();
+ if (t == QMetaType::UnknownType) {
qWarning("QMetaProperty::read: Unable to handle unregistered datatype '%s' for property '%s::%s'", typeName, mobj->className(), name());
return QVariant();
}
- t = registerResult;
}
}
@@ -2861,8 +2973,12 @@ QVariant QMetaProperty::read(const QObject *object) const
value = QVariant(t, (void*)0);
argv[0] = value.data();
}
- QMetaObject::metacall(const_cast<QObject*>(object), QMetaObject::ReadProperty,
- idx + mobj->propertyOffset(), argv);
+ if (priv(mobj->d.data)->flags & PropertyAccessInStaticMetaCall && mobj->d.static_metacall) {
+ mobj->d.static_metacall(const_cast<QObject*>(object), QMetaObject::ReadProperty, idx, argv);
+ } else {
+ QMetaObject::metacall(const_cast<QObject*>(object), QMetaObject::ReadProperty,
+ idx + mobj->propertyOffset(), argv);
+ }
if (status != -1)
return value;
@@ -2911,9 +3027,11 @@ bool QMetaProperty::write(QObject *object, const QVariant &value) const
else {
typeName = rawStringData(mobj, typeInfo & TypeNameIndexMask);
t = QMetaType::type(typeName);
+ if (t == QMetaType::UnknownType)
+ t = registerPropertyType();
+ if (t == QMetaType::UnknownType)
+ return false;
}
- if (t == QMetaType::UnknownType)
- return false;
if (t != QMetaType::QVariant && t != (uint)value.userType() && (t < QMetaType::User && !v.convert((QVariant::Type)t)))
return false;
}
@@ -2932,7 +3050,11 @@ bool QMetaProperty::write(QObject *object, const QVariant &value) const
argv[0] = &v;
else
argv[0] = v.data();
- QMetaObject::metacall(object, QMetaObject::WriteProperty, idx + mobj->propertyOffset(), argv);
+ if (priv(mobj->d.data)->flags & PropertyAccessInStaticMetaCall && mobj->d.static_metacall)
+ mobj->d.static_metacall(object, QMetaObject::WriteProperty, idx, argv);
+ else
+ QMetaObject::metacall(object, QMetaObject::WriteProperty, idx + mobj->propertyOffset(), argv);
+
return status;
}
@@ -2949,9 +3071,55 @@ bool QMetaProperty::reset(QObject *object) const
if (!object || !mobj || !isResettable())
return false;
void *argv[] = { 0 };
- QMetaObject::metacall(object, QMetaObject::ResetProperty, idx + mobj->propertyOffset(), argv);
+ if (priv(mobj->d.data)->flags & PropertyAccessInStaticMetaCall && mobj->d.static_metacall)
+ mobj->d.static_metacall(object, QMetaObject::ResetProperty, idx, argv);
+ else
+ QMetaObject::metacall(object, QMetaObject::ResetProperty, idx + mobj->propertyOffset(), argv);
return true;
}
+/*!
+ \since 5.5
+
+ Reads the property's value from the given \a gadget. Returns the value
+ if it was able to read it; otherwise returns an invalid variant.
+
+ This function should only be used if this is a property of a Q_GADGET
+*/
+QVariant QMetaProperty::readOnGadget(const void *gadget) const
+{
+ Q_ASSERT(priv(mobj->d.data)->flags & PropertyAccessInStaticMetaCall && mobj->d.static_metacall);
+ return read(reinterpret_cast<const QObject*>(gadget));
+}
+
+/*!
+ \since 5.5
+
+ Writes \a value as the property's value to the given \a gadget. Returns
+ true if the write succeeded; otherwise returns \c false.
+
+ This function should only be used if this is a property of a Q_GADGET
+*/
+bool QMetaProperty::writeOnGadget(void *gadget, const QVariant &value) const
+{
+ Q_ASSERT(priv(mobj->d.data)->flags & PropertyAccessInStaticMetaCall && mobj->d.static_metacall);
+ return write(reinterpret_cast<QObject*>(gadget), value);
+}
+
+/*!
+ \since 5.5
+
+ Resets the property for the given \a gadget with a reset method.
+ Returns \c true if the reset worked; otherwise returns \c false.
+
+ Reset methods are optional; only a few properties support them.
+
+ This function should only be used if this is a property of a Q_GADGET
+*/
+bool QMetaProperty::resetOnGadget(void *gadget) const
+{
+ Q_ASSERT(priv(mobj->d.data)->flags & PropertyAccessInStaticMetaCall && mobj->d.static_metacall);
+ return reset(reinterpret_cast<QObject*>(gadget));
+}
/*!
Returns \c true if this property can be reset to a default value; otherwise
diff --git a/src/corelib/kernel/qmetaobject.h b/src/corelib/kernel/qmetaobject.h
index 2a874697c3..fdbcf5171d 100644
--- a/src/corelib/kernel/qmetaobject.h
+++ b/src/corelib/kernel/qmetaobject.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -131,6 +132,34 @@ public:
val0, val1, val2, val3, val4, val5, val6, val7, val8, val9);
}
+ bool invokeOnGadget(void *gadget,
+ QGenericReturnArgument returnValue,
+ QGenericArgument val0 = QGenericArgument(0),
+ QGenericArgument val1 = QGenericArgument(),
+ QGenericArgument val2 = QGenericArgument(),
+ QGenericArgument val3 = QGenericArgument(),
+ QGenericArgument val4 = QGenericArgument(),
+ QGenericArgument val5 = QGenericArgument(),
+ QGenericArgument val6 = QGenericArgument(),
+ QGenericArgument val7 = QGenericArgument(),
+ QGenericArgument val8 = QGenericArgument(),
+ QGenericArgument val9 = QGenericArgument()) const;
+ inline bool invokeOnGadget(void *gadget,
+ QGenericArgument val0 = QGenericArgument(0),
+ QGenericArgument val1 = QGenericArgument(),
+ QGenericArgument val2 = QGenericArgument(),
+ QGenericArgument val3 = QGenericArgument(),
+ QGenericArgument val4 = QGenericArgument(),
+ QGenericArgument val5 = QGenericArgument(),
+ QGenericArgument val6 = QGenericArgument(),
+ QGenericArgument val7 = QGenericArgument(),
+ QGenericArgument val8 = QGenericArgument(),
+ QGenericArgument val9 = QGenericArgument()) const
+ {
+ return invokeOnGadget(gadget, QGenericReturnArgument(),
+ val0, val1, val2, val3, val4, val5, val6, val7, val8, val9);
+ }
+
inline bool isValid() const { return mobj != 0; }
#ifdef Q_QDOC
@@ -237,11 +266,17 @@ public:
bool write(QObject *obj, const QVariant &value) const;
bool reset(QObject *obj) const;
+ QVariant readOnGadget(const void *gadget) const;
+ bool writeOnGadget(void *gadget, const QVariant &value) const;
+ bool resetOnGadget(void *gadget) const;
+
bool hasStdCppSet() const;
inline bool isValid() const { return isReadable(); }
inline const QMetaObject *enclosingMetaObject() const { return mobj; }
private:
+ int registerPropertyType() const;
+
const QMetaObject *mobj;
uint handle;
int idx;
diff --git a/src/corelib/kernel/qmetaobject_p.h b/src/corelib/kernel/qmetaobject_p.h
index c08838e456..45fe56ec8a 100644
--- a/src/corelib/kernel/qmetaobject_p.h
+++ b/src/corelib/kernel/qmetaobject_p.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -98,7 +99,8 @@ enum MethodFlags {
enum MetaObjectFlags {
DynamicMetaObject = 0x01,
- RequiresVariantMetaObject = 0x02
+ RequiresVariantMetaObject = 0x02,
+ PropertyAccessInStaticMetaCall = 0x04 // since Qt 5.5, property code is in the static metacall
};
enum MetaDataFlags {
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp
index 311648c33a..294b1fc07c 100644
--- a/src/corelib/kernel/qmetatype.cpp
+++ b/src/corelib/kernel/qmetatype.cpp
@@ -283,10 +283,11 @@ struct DefinedTypesFilter {
\value MovableType An instance of a type having this attribute can be safely moved by memcpy.
\omitvalue SharedPointerToQObject
\omitvalue IsEnumeration
- \omitvalue PointerToQObject
+ \value PointerToQObject This type is a pointer to a derived of QObject
\omitvalue WeakPointerToQObject
\omitvalue TrackingPointerToQObject
\omitvalue WasDeclaredAsMetaType
+ \value IsGadget This type is a Q_GADGET and it's corresponding QMetaObject can be accessed with QMetaType::metaObject Since 5.5.
*/
/*!
@@ -363,8 +364,19 @@ struct DefinedTypesFilter {
/*!
\fn const QMetaObject *QMetaType::metaObject() const
- \since 5.0
- \internal
+ \since 5.5
+
+ return a QMetaObject relative to this type.
+
+ If the type is a pointer type to a subclass of QObject, flags contains
+ QMetaType::PointerToQObject and this function returns the corresponding QMetaObject. This can
+ be used to in combinaison with QMetaObject::construct to create QObject of this type.
+
+ If the type is a Q_GADGET, flags contains QMetaType::IsGadget, and this function returns its
+ QMetaObject. This can be used to retrieve QMetaMethod and QMetaProperty and use them on a
+ pointer of this type. (given by QVariant::data for example)
+
+ \sa QMetaType::metaObjectForType(), QMetaType::flags()
*/
/*!
@@ -801,7 +813,7 @@ static inline int qMetaTypeStaticType(const char *typeName, int length)
{
int i = 0;
while (types[i].typeName && ((length != types[i].typeNameLength)
- || strcmp(typeName, types[i].typeName))) {
+ || memcmp(typeName, types[i].typeName, length))) {
++i;
}
return types[i].type;
@@ -821,7 +833,7 @@ static int qMetaTypeCustomType_unlocked(const char *typeName, int length)
for (int v = 0; v < ct->count(); ++v) {
const QCustomTypeInfo &customInfo = ct->at(v);
if ((length == customInfo.typeName.size())
- && !strcmp(typeName, customInfo.typeName.constData())) {
+ && !memcmp(typeName, customInfo.typeName.constData(), length)) {
if (customInfo.alias >= 0)
return customInfo.alias;
return v + QMetaType::User;
@@ -870,24 +882,43 @@ int QMetaType::registerType(const char *typeName, Deleter deleter,
/*!
- \internal
- \since 5.0
+ \internal
+ \since 5.0
+ \overload
+ Don't use, kept for binary compatibility
- Registers a user type for marshalling, with \a normalizedTypeName, a \a
- deleter, a \a creator, a \a destructor, a \a constructor, and
- a \a size. Returns the type's handle, or -1 if the type could
- not be registered. Note that normalizedTypeName is not checked for
- conformance with Qt's normalized format, so it must already
- conform.
- */
+ ### TODO Qt6: remove me
+*/
int QMetaType::registerNormalizedType(const NS(QByteArray) &normalizedTypeName, Deleter deleter,
Creator creator,
Destructor destructor,
Constructor constructor,
int size, TypeFlags flags, const QMetaObject *metaObject)
{
+ Q_UNUSED(deleter);
+ Q_UNUSED(creator);
+ return registerNormalizedType(normalizedTypeName, destructor, constructor, size, flags, metaObject);
+}
+
+
+/*!
+ \internal
+ \since 5.5
+
+ Registers a user type for marshalling, with \a normalizedTypeName,
+ a \a destructor, a \a constructor, and a \a size. Returns the type's
+ handle, or -1 if the type could not be registered.
+
+ \note normalizedTypeName is not checked for conformance with
+ Qt's normalized format, so it must already conform.
+ */
+int QMetaType::registerNormalizedType(const NS(QByteArray) &normalizedTypeName,
+ Destructor destructor,
+ Constructor constructor,
+ int size, TypeFlags flags, const QMetaObject *metaObject)
+{
QVector<QCustomTypeInfo> *ct = customTypes();
- if (!ct || normalizedTypeName.isEmpty() || !deleter || !creator || !destructor || !constructor)
+ if (!ct || normalizedTypeName.isEmpty() || !destructor || !constructor)
return -1;
int idx = qMetaTypeStaticType(normalizedTypeName.constData(),
@@ -902,8 +933,6 @@ int QMetaType::registerNormalizedType(const NS(QByteArray) &normalizedTypeName,
if (idx == UnknownType) {
QCustomTypeInfo inf;
inf.typeName = normalizedTypeName;
- inf.creator = creator;
- inf.deleter = deleter;
#ifndef QT_NO_DATASTREAM
inf.loadOp = 0;
inf.saveOp = 0;
@@ -1004,8 +1033,6 @@ int QMetaType::registerNormalizedTypedef(const NS(QByteArray) &normalizedTypeNam
QCustomTypeInfo inf;
inf.typeName = normalizedTypeName;
inf.alias = aliasId;
- inf.creator = 0;
- inf.deleter = 0;
ct->append(inf);
return aliasId;
}
@@ -1048,9 +1075,8 @@ bool QMetaType::isRegistered(int type)
Implementation of QMetaType::type().
*/
template <bool tryNormalizedType>
-static inline int qMetaTypeTypeImpl(const char *typeName)
+static inline int qMetaTypeTypeImpl(const char *typeName, int length)
{
- int length = qstrlen(typeName);
if (!length)
return QMetaType::UnknownType;
int type = qMetaTypeStaticType(typeName, length);
@@ -1080,7 +1106,7 @@ static inline int qMetaTypeTypeImpl(const char *typeName)
*/
int QMetaType::type(const char *typeName)
{
- return qMetaTypeTypeImpl</*tryNormalizedType=*/true>(typeName);
+ return qMetaTypeTypeImpl</*tryNormalizedType=*/true>(typeName, qstrlen(typeName));
}
/*!
@@ -1092,7 +1118,21 @@ int QMetaType::type(const char *typeName)
*/
int qMetaTypeTypeInternal(const char *typeName)
{
- return qMetaTypeTypeImpl</*tryNormalizedType=*/false>(typeName);
+ return qMetaTypeTypeImpl</*tryNormalizedType=*/false>(typeName, qstrlen(typeName));
+}
+
+/*!
+ \since 5.5
+ \overload
+
+ Returns a handle to the type called \a typeName, or 0 if there is
+ no such type.
+
+ \sa isRegistered(), typeName()
+*/
+int QMetaType::type(const QT_PREPEND_NAMESPACE(QByteArray) &typeName)
+{
+ return qMetaTypeTypeImpl</*tryNormalizedType=*/true>(typeName.constData(), typeName.size());
}
#ifndef QT_NO_DATASTREAM
@@ -1541,60 +1581,6 @@ bool QMetaType::load(QDataStream &stream, int type, void *data)
return true;
}
#endif // QT_NO_DATASTREAM
-namespace {
-class TypeCreator {
- template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted>
- struct CreatorImpl {
- static void *Create(const int /* type */, const void *copy)
- {
- // Using QMetaTypeFunctionHelper<T>::Create adds function call cost, even if it is a template (gcc).
- // This "copy" check is moved out from the switcher by compiler (at least by gcc)
- return copy ? new T(*static_cast<const T*>(copy)) : new T();
- }
- };
- template<typename T>
- struct CreatorImpl<T, /* IsAcceptedType = */ false> {
- static void *Create(const int type, const void *copy)
- {
- if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) {
- if (Q_LIKELY(qMetaTypeGuiHelper))
- return qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].creator(copy);
- }
- if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) {
- if (Q_LIKELY(qMetaTypeWidgetsHelper))
- return qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].creator(copy);
- }
- // This point can be reached only for known types that definition is not available, for example
- // in bootstrap mode. We have no other choice then ignore it.
- return 0;
- }
- };
-public:
- TypeCreator(const int type)
- : m_type(type)
- {}
-
- template<typename T>
- void *delegate(const T *copy) { return CreatorImpl<T>::Create(m_type, copy); }
- void *delegate(const void*) { return 0; }
- void *delegate(const QMetaTypeSwitcher::UnknownType *) { return 0; }
- void *delegate(const QMetaTypeSwitcher::NotBuiltinType *copy)
- {
- QMetaType::Creator creator;
- const QVector<QCustomTypeInfo> * const ct = customTypes();
- {
- QReadLocker locker(customTypesLock());
- if (Q_UNLIKELY(m_type < QMetaType::User || !ct || ct->count() <= m_type - QMetaType::User))
- return 0;
- creator = ct->at(m_type - QMetaType::User).creator;
- }
- Q_ASSERT_X(creator, "void *QMetaType::create(int type, const void *copy)", "The type was not properly registered");
- return creator(copy);
- }
-private:
- const int m_type;
-};
-} // namespace
/*!
Returns a copy of \a copy, assuming it is of type \a type. If \a
@@ -1604,65 +1590,11 @@ private:
*/
void *QMetaType::create(int type, const void *copy)
{
- TypeCreator typeCreator(type);
- return QMetaTypeSwitcher::switcher<void*>(typeCreator, type, copy);
+ QMetaType info(type);
+ int size = info.sizeOf();
+ return info.construct(operator new(size), copy);
}
-namespace {
-class TypeDestroyer {
- template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted>
- struct DestroyerImpl {
- static void Destroy(const int /* type */, void *where) { QtMetaTypePrivate::QMetaTypeFunctionHelper<T>::Delete(where); }
- };
- template<typename T>
- struct DestroyerImpl<T, /* IsAcceptedType = */ false> {
- static void Destroy(const int type, void *where)
- {
- if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) {
- if (Q_LIKELY(qMetaTypeGuiHelper))
- qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].deleter(where);
- return;
- }
- if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) {
- if (Q_LIKELY(qMetaTypeWidgetsHelper))
- qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].deleter(where);
- return;
- }
- // This point can be reached only for known types that definition is not available, for example
- // in bootstrap mode. We have no other choice then ignore it.
- }
- };
-public:
- TypeDestroyer(const int type)
- : m_type(type)
- {}
-
- template<typename T>
- void delegate(const T *where) { DestroyerImpl<T>::Destroy(m_type, const_cast<T*>(where)); }
- void delegate(const void *) {}
- void delegate(const QMetaTypeSwitcher::UnknownType*) {}
- void delegate(const QMetaTypeSwitcher::NotBuiltinType *where) { customTypeDestroyer(m_type, (void*)where); }
-
-private:
- static void customTypeDestroyer(const int type, void *where)
- {
- QMetaType::Destructor deleter;
- const QVector<QCustomTypeInfo> * const ct = customTypes();
- {
- QReadLocker locker(customTypesLock());
- if (Q_UNLIKELY(type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User))
- return;
- deleter = ct->at(type - QMetaType::User).deleter;
- }
- Q_ASSERT_X(deleter, "void QMetaType::destroy(int type, void *data)", "The type was not properly registered");
- deleter(where);
- }
-
- const int m_type;
-};
-} // namespace
-
-
/*!
Destroys the \a data, assuming it is of the \a type given.
@@ -1670,8 +1602,9 @@ private:
*/
void QMetaType::destroy(int type, void *data)
{
- TypeDestroyer deleter(type);
- QMetaTypeSwitcher::switcher<void>(deleter, type, data);
+ QMetaType info(type);
+ info.destruct(data);
+ operator delete(data);
}
namespace {
@@ -1969,8 +1902,27 @@ public:
MetaObject(const int type)
: m_type(type)
{}
+
+ template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted>
+ struct MetaObjectImpl
+ {
+ static const QMetaObject *MetaObject(int /*type*/)
+ { return QtPrivate::MetaObjectForType<T>::value(); }
+ };
template<typename T>
- const QMetaObject *delegate(const T*) { return QtPrivate::MetaObjectForType<T>::value(); }
+ struct MetaObjectImpl<T, /* IsAcceptedType = */ false>
+ {
+ static const QMetaObject *MetaObject(int type) {
+ if (QModulesPrivate::QTypeModuleInfo<T>::IsGui)
+ return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].metaObject : 0;
+ if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget)
+ return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].metaObject : 0;
+ return 0;
+ }
+ };
+
+ template <typename T>
+ const QMetaObject *delegate(const T *) { return MetaObjectImpl<T>::MetaObject(m_type); }
const QMetaObject *delegate(const void*) { return 0; }
const QMetaObject *delegate(const QMetaTypeSwitcher::UnknownType*) { return 0; }
const QMetaObject *delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customMetaObject(m_type); }
@@ -1993,7 +1945,9 @@ private:
/*!
\since 5.0
- Returns QMetaObject of a given \a type, if the \a type is a pointer to type derived from QObject.
+ returns QMetaType::metaObject for \a type
+
+ \sa metaObject()
*/
const QMetaObject *QMetaType::metaObjectForType(int type)
{
@@ -2200,10 +2154,10 @@ QMetaType QMetaType::typeInfo(const int type)
{
TypeInfo typeInfo(type);
QMetaTypeSwitcher::switcher<void>(typeInfo, type, 0);
- return typeInfo.info.creator ? QMetaType(QMetaType::NoExtensionFlags
+ return typeInfo.info.constructor ? QMetaType(static_cast<ExtensionFlag>(QMetaType::CreateEx | QMetaType::DestroyEx)
, static_cast<const QMetaTypeInterface *>(0) // typeInfo::info is a temporary variable, we can't return address of it.
- , typeInfo.info.creator
- , typeInfo.info.deleter
+ , 0 // unused
+ , 0 // unused
, typeInfo.info.saveOp
, typeInfo.info.loadOp
, typeInfo.info.constructor
@@ -2245,8 +2199,8 @@ QMetaType::QMetaType(const int typeId)
Copy constructs a QMetaType object.
*/
QMetaType::QMetaType(const QMetaType &other)
- : m_creator(other.m_creator)
- , m_deleter(other.m_deleter)
+ : m_creator_unused(other.m_creator_unused)
+ , m_deleter_unused(other.m_deleter_unused)
, m_saveOp(other.m_saveOp)
, m_loadOp(other.m_loadOp)
, m_constructor(other.m_constructor)
@@ -2261,8 +2215,8 @@ QMetaType::QMetaType(const QMetaType &other)
QMetaType &QMetaType::operator =(const QMetaType &other)
{
- m_creator = other.m_creator;
- m_deleter = other.m_deleter;
+ m_creator_unused = other.m_creator_unused;
+ m_deleter_unused = other.m_deleter_unused;
m_saveOp = other.m_saveOp;
m_loadOp = other.m_loadOp;
m_constructor = other.m_constructor;
@@ -2311,11 +2265,14 @@ void QMetaType::dtor()
Method used for future binary compatible extensions. The function may be called
during QMetaType::create to force library call from inlined code.
+
+ ### TODO Qt6 remove the extension
*/
void *QMetaType::createExtended(const void *copy) const
{
- Q_UNUSED(copy);
- return 0;
+ if (m_typeId == QMetaType::UnknownType)
+ return 0;
+ return m_constructor(operator new(m_size), copy);
}
/*!
@@ -2324,10 +2281,13 @@ void *QMetaType::createExtended(const void *copy) const
Method used for future binary compatible extensions. The function may be called
during QMetaType::destroy to force library call from inlined code.
+
+ ### TODO Qt6 remove the extension
*/
void QMetaType::destroyExtended(void *data) const
{
- Q_UNUSED(data);
+ m_destructor(data);
+ operator delete(data);
}
/*!
diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h
index 7a45e21253..0e817da8ce 100644
--- a/src/corelib/kernel/qmetatype.h
+++ b/src/corelib/kernel/qmetatype.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -62,6 +63,7 @@ template <typename T>
inline Q_DECL_CONSTEXPR int qMetaTypeId();
// F is a tuple: (QMetaType::TypeName, QMetaType::TypeNameID, RealType)
+// ### Qt6: reorder the types to match the C++ integral type ranking
#define QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(F)\
F(Void, 43, void) \
F(Bool, 1, bool) \
@@ -435,7 +437,8 @@ public:
SharedPointerToQObject = 0x20,
WeakPointerToQObject = 0x40,
TrackingPointerToQObject = 0x80,
- WasDeclaredAsMetaType = 0x100
+ WasDeclaredAsMetaType = 0x100,
+ IsGadget = 0x200
};
Q_DECLARE_FLAGS(TypeFlags, TypeFlag)
@@ -469,9 +472,19 @@ public:
int size,
QMetaType::TypeFlags flags,
const QMetaObject *metaObject);
+ static int registerNormalizedType(const QT_PREPEND_NAMESPACE(QByteArray) &normalizedTypeName, Destructor destructor,
+ Constructor constructor,
+ int size,
+ QMetaType::TypeFlags flags,
+ const QMetaObject *metaObject);
static int registerTypedef(const char *typeName, int aliasId);
static int registerNormalizedTypedef(const QT_PREPEND_NAMESPACE(QByteArray) &normalizedTypeName, int aliasId);
static int type(const char *typeName);
+#ifndef Q_QDOC
+ static int type(const QT_PREPEND_NAMESPACE(QByteArray) &typeName);
+#else
+ static int type(const QByteArray &typeName);
+#endif
static const char *typeName(int type);
static int sizeOf(int type);
static TypeFlags typeFlags(int type);
@@ -661,8 +674,8 @@ public:
static void unregisterConverterFunction(int from, int to);
private:
- Creator m_creator;
- Deleter m_deleter;
+ Creator m_creator_unused;
+ Deleter m_deleter_unused;
SaveOperator m_saveOp;
LoadOperator m_loadOp;
Constructor m_constructor;
@@ -702,18 +715,6 @@ ConverterFunctor<From, To, UnaryFunction>::~ConverterFunctor()
namespace QtMetaTypePrivate {
template <typename T, bool Accepted = true>
struct QMetaTypeFunctionHelper {
- static void Delete(void *t)
- {
- delete static_cast<T*>(t);
- }
-
- static void *Create(const void *t)
- {
- if (t)
- return new T(*static_cast<const T*>(t));
- return new T();
- }
-
static void Destruct(void *t)
{
Q_UNUSED(t) // Silence MSVC that warns for POD types.
@@ -741,8 +742,6 @@ struct QMetaTypeFunctionHelper {
template <typename T>
struct QMetaTypeFunctionHelper<T, /* Accepted */ false> {
- static void Delete(void *) {}
- static void *Create(const void *) { return 0; }
static void Destruct(void *) {}
static void *Construct(void *, const void *) { return 0; }
#ifndef QT_NO_DATASTREAM
@@ -1330,14 +1329,27 @@ namespace QtPrivate
enum { Value = sizeof(checkType(static_cast<T*>(0))) == sizeof(yes_type) };
};
- template<typename T, bool = IsPointerToTypeDerivedFromQObject<T>::Value>
+ template<typename T>
+ struct IsGadgetHelper
+ {
+ template<typename X> static typename X::QtGadgetHelper *checkType(X*);
+ static char checkType(void*);
+ enum { Value = sizeof(checkType(static_cast<T*>(0))) == sizeof(void*) };
+ };
+
+ template<typename T, typename Enable = void>
struct MetaObjectForType
{
static inline const QMetaObject *value() { return 0; }
};
template<typename T>
- struct MetaObjectForType<T*, /* isPointerToTypeDerivedFromQObject = */ true>
+ struct MetaObjectForType<T*, typename QEnableIf<IsPointerToTypeDerivedFromQObject<T*>::Value>::Type>
+ {
+ static inline const QMetaObject *value() { return &T::staticMetaObject; }
+ };
+ template<typename T>
+ struct MetaObjectForType<T, typename QEnableIf<IsGadgetHelper<T>::Value>::Type>
{
static inline const QMetaObject *value() { return &T::staticMetaObject; }
};
@@ -1512,6 +1524,9 @@ struct QMetaTypeId2
template <typename T>
struct QMetaTypeId2<const T&> : QMetaTypeId2<T> {};
+template <typename T>
+struct QMetaTypeId2<T&> { enum {Defined = false }; };
+
namespace QtPrivate {
template <typename T, bool Defined = QMetaTypeId2<T>::Defined>
struct QMetaTypeIdHelper {
@@ -1545,6 +1560,7 @@ namespace QtPrivate {
| (IsWeakPointerToTypeDerivedFromQObject<T>::Value ? QMetaType::WeakPointerToQObject : 0)
| (IsTrackingPointerToTypeDerivedFromQObject<T>::Value ? QMetaType::TrackingPointerToQObject : 0)
| (Q_IS_ENUM(T) ? QMetaType::IsEnumeration : 0)
+ | (IsGadgetHelper<T>::Value ? QMetaType::IsGadget : 0)
};
};
@@ -1594,8 +1610,6 @@ int qRegisterNormalizedMetaType(const QT_PREPEND_NAMESPACE(QByteArray) &normaliz
flags |= QMetaType::WasDeclaredAsMetaType;
const int id = QMetaType::registerNormalizedType(normalizedTypeName,
- QtMetaTypePrivate::QMetaTypeFunctionHelper<T>::Delete,
- QtMetaTypePrivate::QMetaTypeFunctionHelper<T>::Create,
QtMetaTypePrivate::QMetaTypeFunctionHelper<T>::Destruct,
QtMetaTypePrivate::QMetaTypeFunctionHelper<T>::Construct,
int(sizeof(T)),
@@ -1964,8 +1978,8 @@ inline QMetaType::QMetaType(const ExtensionFlag extensionFlags, const QMetaTypeI
uint theTypeFlags,
int typeId,
const QMetaObject *_metaObject)
- : m_creator(creator)
- , m_deleter(deleter)
+ : m_creator_unused(creator)
+ , m_deleter_unused(deleter)
, m_saveOp(saveOp)
, m_loadOp(loadOp)
, m_constructor(constructor)
@@ -1999,16 +2013,14 @@ inline bool QMetaType::isRegistered() const
inline void *QMetaType::create(const void *copy) const
{
- if (Q_UNLIKELY(isExtended(CreateEx)))
- return createExtended(copy);
- return m_creator(copy);
+ // ### TODO Qt6 remove the extension
+ return createExtended(copy);
}
inline void QMetaType::destroy(void *data) const
{
- if (Q_UNLIKELY(isExtended(DestroyEx)))
- return destroyExtended(data);
- m_deleter(data);
+ // ### TODO Qt6 remove the extension
+ destroyExtended(data);
}
inline void *QMetaType::construct(void *where, const void *copy) const
diff --git a/src/corelib/kernel/qmetatype_p.h b/src/corelib/kernel/qmetatype_p.h
index c75d5ee792..97c0a08729 100644
--- a/src/corelib/kernel/qmetatype_p.h
+++ b/src/corelib/kernel/qmetatype_p.h
@@ -114,8 +114,6 @@ QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_DECLARE_WIDGETS_MODULE_TYPES_ITER)
class QMetaTypeInterface
{
public:
- QMetaType::Creator creator;
- QMetaType::Deleter deleter;
QMetaType::SaveOperator saveOp;
QMetaType::LoadOperator loadOp;
QMetaType::Constructor constructor;
@@ -148,8 +146,6 @@ public:
#define QT_METATYPE_INTERFACE_INIT_IMPL(Type, DATASTREAM_DELEGATE) \
{ \
- /*creator*/(QtMetaTypePrivate::QMetaTypeFunctionHelper<Type, QtMetaTypePrivate::TypeDefinition<Type>::IsAvailable>::Create), \
- /*deleter*/(QtMetaTypePrivate::QMetaTypeFunctionHelper<Type, QtMetaTypePrivate::TypeDefinition<Type>::IsAvailable>::Delete), \
DATASTREAM_DELEGATE(Type) \
/*constructor*/(QtMetaTypePrivate::QMetaTypeFunctionHelper<Type, QtMetaTypePrivate::TypeDefinition<Type>::IsAvailable>::Construct), \
/*destructor*/(QtMetaTypePrivate::QMetaTypeFunctionHelper<Type, QtMetaTypePrivate::TypeDefinition<Type>::IsAvailable>::Destruct), \
@@ -173,8 +169,6 @@ public:
#define QT_METATYPE_INTERFACE_INIT_NO_DATASTREAM(Type) QT_METATYPE_INTERFACE_INIT_IMPL(Type, QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL)
#define QT_METATYPE_INTERFACE_INIT_EMPTY() \
{ \
- /*creator*/ 0, \
- /*deleter*/ 0, \
QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(void) \
/*constructor*/ 0, \
/*destructor*/ 0, \
diff --git a/src/corelib/kernel/qmimedata.cpp b/src/corelib/kernel/qmimedata.cpp
index 15fdf57747..45aec88429 100644
--- a/src/corelib/kernel/qmimedata.cpp
+++ b/src/corelib/kernel/qmimedata.cpp
@@ -286,6 +286,11 @@ QVariant QMimeDataPrivate::retrieveTypedData(const QString &format, QVariant::Ty
The \c value declaration of each format describes the way in which the
data is encoded.
+ In some cases (e.g. dropping multiple email attachments), multiple data
+ values are available. They can be accessed by adding an \c index value:
+
+ \snippet code/src_corelib_kernel_qmimedata.cpp 8
+
On Windows, the MIME format does not always map directly to the
clipboard formats. Qt provides QWinMime to map clipboard
formats to open-standard MIME formats. Similarly, the
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 492031d7fe..223de0c8e0 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -2661,8 +2661,8 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const char *sign
const char *method_arg = method;
++method; // skip code
- QByteArray methodName;
QArgumentTypeArray methodTypes;
+ QByteArray methodName = QMetaObjectPrivate::decodeMethodSignature(method, methodTypes);
const QMetaObject *rmeta = receiver->metaObject();
int method_index_relative = -1;
Q_ASSERT(QMetaObjectPrivate::get(rmeta)->revision >= 7);
@@ -4093,14 +4093,16 @@ QObjectUserData* QObject::userData(uint id) const
#ifndef QT_NO_DEBUG_STREAM
-QDebug operator<<(QDebug dbg, const QObject *o) {
+QDebug operator<<(QDebug dbg, const QObject *o)
+{
+ QDebugStateSaver saver(dbg);
if (!o)
- return dbg << "QObject(0x0) ";
+ return dbg << "QObject(0x0)";
dbg.nospace() << o->metaObject()->className() << '(' << (void *)o;
if (!o->objectName().isEmpty())
dbg << ", name = " << o->objectName();
dbg << ')';
- return dbg.space();
+ return dbg;
}
#endif
diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h
index ba26ff7bfb..b663bc8d8c 100644
--- a/src/corelib/kernel/qobject_p.h
+++ b/src/corelib/kernel/qobject_p.h
@@ -414,9 +414,9 @@ struct Q_CORE_EXPORT QDynamicMetaObjectData
struct Q_CORE_EXPORT QAbstractDynamicMetaObject : public QDynamicMetaObjectData, public QMetaObject
{
- virtual QAbstractDynamicMetaObject *toDynamicMetaObject(QObject *) { return this; }
+ virtual QAbstractDynamicMetaObject *toDynamicMetaObject(QObject *) Q_DECL_OVERRIDE { return this; }
virtual int createProperty(const char *, const char *) { return -1; }
- virtual int metaCall(QObject *, QMetaObject::Call c, int _id, void **a)
+ virtual int metaCall(QObject *, QMetaObject::Call c, int _id, void **a) Q_DECL_OVERRIDE
{ return metaCall(c, _id, a); }
virtual int metaCall(QMetaObject::Call, int _id, void **) { return _id; } // Compat overload
};
diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h
index 25e43d0ca0..84e7a65a54 100644
--- a/src/corelib/kernel/qobjectdefs.h
+++ b/src/corelib/kernel/qobjectdefs.h
@@ -138,15 +138,24 @@ inline void qYouForgotTheQ_OBJECT_Macro(T1, T2) {}
# define Q_DECL_HIDDEN_STATIC_METACALL Q_DECL_HIDDEN
#endif
+#if defined(Q_CC_CLANG) && Q_CC_CLANG >= 306
+# define Q_OBJECT_NO_OVERRIDE_WARNING QT_WARNING_DISABLE_CLANG("-Winconsistent-missing-override")
+#else
+# define Q_OBJECT_NO_OVERRIDE_WARNING
+#endif
+
/* qmake ignore Q_OBJECT */
#define Q_OBJECT \
public: \
Q_OBJECT_CHECK \
+ QT_WARNING_PUSH \
+ Q_OBJECT_NO_OVERRIDE_WARNING \
static const QMetaObject staticMetaObject; \
virtual const QMetaObject *metaObject() const; \
virtual void *qt_metacast(const char *); \
- QT_TR_FUNCTIONS \
virtual int qt_metacall(QMetaObject::Call, int, void **); \
+ QT_WARNING_POP \
+ QT_TR_FUNCTIONS \
private: \
Q_DECL_HIDDEN_STATIC_METACALL static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); \
struct QPrivateSignal {};
@@ -159,7 +168,9 @@ private: \
#define Q_GADGET \
public: \
static const QMetaObject staticMetaObject; \
-private:
+ typedef void QtGadgetHelper; \
+private: \
+ Q_DECL_HIDDEN_STATIC_METACALL static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **);
#endif // QT_NO_META_MACROS
#else // Q_MOC_RUN
diff --git a/src/corelib/kernel/qsocketnotifier.h b/src/corelib/kernel/qsocketnotifier.h
index 57535b0d71..978e2912cc 100644
--- a/src/corelib/kernel/qsocketnotifier.h
+++ b/src/corelib/kernel/qsocketnotifier.h
@@ -66,7 +66,7 @@ Q_SIGNALS:
);
protected:
- bool event(QEvent *);
+ bool event(QEvent *) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(QSocketNotifier)
diff --git a/src/corelib/kernel/qtimer.cpp b/src/corelib/kernel/qtimer.cpp
index 0803cf302e..cb9219df14 100644
--- a/src/corelib/kernel/qtimer.cpp
+++ b/src/corelib/kernel/qtimer.cpp
@@ -263,7 +263,7 @@ public:
Q_SIGNALS:
void timeout();
protected:
- void timerEvent(QTimerEvent *);
+ void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE;
};
QSingleShotTimer::QSingleShotTimer(int msec, Qt::TimerType timerType, const QObject *r, const char *member)
diff --git a/src/corelib/kernel/qtimer.h b/src/corelib/kernel/qtimer.h
index 2890f3ef08..a48113abf6 100644
--- a/src/corelib/kernel/qtimer.h
+++ b/src/corelib/kernel/qtimer.h
@@ -148,7 +148,7 @@ Q_SIGNALS:
);
protected:
- void timerEvent(QTimerEvent *);
+ void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(QTimer)
diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp
index c2d8397ae0..a9c608384a 100644
--- a/src/corelib/kernel/qtranslator.cpp
+++ b/src/corelib/kernel/qtranslator.cpp
@@ -273,6 +273,7 @@ static uint numerusHelper(int n, const uchar *rules, uint rulesSize)
}
Q_ASSERT(false);
+ return 0;
}
class QTranslatorPrivate : public QObjectPrivate
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index 2ac1bb11fb..1e71bb8978 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -69,13 +69,18 @@
QT_BEGIN_NAMESPACE
-#ifndef DBL_DIG
-# define DBL_DIG 10
+#ifndef DBL_MANT_DIG
+# define DBL_MANT_DIG 53
#endif
-#ifndef FLT_DIG
-# define FLT_DIG 6
+#ifndef FLT_MANT_DIG
+# define FLT_MANT_DIG 24
#endif
+const int log10_2_10000 = 30103; // log10(2) * 100000
+// same as C++11 std::numeric_limits<T>::max_digits10
+const int max_digits10_double = (DBL_MANT_DIG * log10_2_10000) / 100000 + 2;
+const int max_digits10_float = (FLT_MANT_DIG * log10_2_10000) / 100000 + 2;
+
namespace {
class HandlersManager
{
@@ -215,8 +220,9 @@ static qlonglong qConvertToNumber(const QVariant::Private *d, bool *ok)
return qlonglong(qMetaTypeUNumber(d));
}
- if (QMetaType::typeFlags(d->type) & QMetaType::IsEnumeration) {
- switch (QMetaType::sizeOf(d->type)) {
+ QMetaType typeInfo(d->type);
+ if (typeInfo.flags() & QMetaType::IsEnumeration) {
+ switch (typeInfo.sizeOf()) {
case 1:
return d->is_shared ? *reinterpret_cast<signed char *>(d->data.shared->ptr) : d->data.sc;
case 2:
@@ -232,6 +238,26 @@ static qlonglong qConvertToNumber(const QVariant::Private *d, bool *ok)
return Q_INT64_C(0);
}
+static qreal qConvertToRealNumber(const QVariant::Private *d, bool *ok)
+{
+ *ok = true;
+ switch (uint(d->type)) {
+ case QVariant::Double:
+ return qreal(d->data.d);
+ case QMetaType::Float:
+ return qreal(d->data.f);
+ case QVariant::ULongLong:
+ case QVariant::UInt:
+ case QMetaType::UChar:
+ case QMetaType::UShort:
+ case QMetaType::ULong:
+ return qreal(qMetaTypeUNumber(d));
+ default:
+ // includes enum conversion as well as invalid types
+ return qreal(qConvertToNumber(d, ok));
+ }
+}
+
static qulonglong qConvertToUnsignedNumber(const QVariant::Private *d, bool *ok)
{
*ok = true;
@@ -263,8 +289,9 @@ static qulonglong qConvertToUnsignedNumber(const QVariant::Private *d, bool *ok)
return qMetaTypeUNumber(d);
}
- if (QMetaType::typeFlags(d->type) & QMetaType::IsEnumeration) {
- switch (QMetaType::sizeOf(d->type)) {
+ QMetaType typeInfo(d->type);
+ if (typeInfo.flags() & QMetaType::IsEnumeration) {
+ switch (typeInfo.sizeOf()) {
case 1:
return d->is_shared ? *reinterpret_cast<uchar *>(d->data.shared->ptr) : d->data.uc;
case 2:
@@ -355,10 +382,10 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
*str = QString::number(qMetaTypeUNumber(d));
break;
case QMetaType::Float:
- *str = QString::number(d->data.f, 'g', FLT_DIG);
+ *str = QString::number(d->data.f, 'g', max_digits10_float);
break;
case QVariant::Double:
- *str = QString::number(d->data.d, 'g', DBL_DIG);
+ *str = QString::number(d->data.d, 'g', max_digits10_double);
break;
#if !defined(QT_NO_DATESTRING)
case QVariant::Date:
@@ -535,10 +562,10 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
*ba = v_cast<QString>(d)->toUtf8();
break;
case QVariant::Double:
- *ba = QByteArray::number(d->data.d, 'g', DBL_DIG);
+ *ba = QByteArray::number(d->data.d, 'g', max_digits10_double);
break;
case QMetaType::Float:
- *ba = QByteArray::number(d->data.f, 'g', FLT_DIG);
+ *ba = QByteArray::number(d->data.f, 'g', max_digits10_float);
break;
case QMetaType::Char:
case QMetaType::SChar:
@@ -3133,8 +3160,22 @@ bool QVariant::convert(const int type, void *ptr) const
static bool qIsNumericType(uint tp)
{
- return (tp >= QVariant::Bool && tp <= QVariant::Double)
- || (tp >= QMetaType::Long && tp <= QMetaType::Float);
+ static const qulonglong numericTypeBits =
+ Q_UINT64_C(1) << QMetaType::Bool |
+ Q_UINT64_C(1) << QMetaType::Double |
+ Q_UINT64_C(1) << QMetaType::Float |
+ Q_UINT64_C(1) << QMetaType::Char |
+ Q_UINT64_C(1) << QMetaType::SChar |
+ Q_UINT64_C(1) << QMetaType::UChar |
+ Q_UINT64_C(1) << QMetaType::Short |
+ Q_UINT64_C(1) << QMetaType::UShort |
+ Q_UINT64_C(1) << QMetaType::Int |
+ Q_UINT64_C(1) << QMetaType::UInt |
+ Q_UINT64_C(1) << QMetaType::Long |
+ Q_UINT64_C(1) << QMetaType::ULong |
+ Q_UINT64_C(1) << QMetaType::LongLong |
+ Q_UINT64_C(1) << QMetaType::ULongLong;
+ return tp < (CHAR_BIT * sizeof numericTypeBits) ? numericTypeBits & (Q_UINT64_C(1) << tp) : false;
}
static bool qIsFloatingPoint(uint tp)
@@ -3142,22 +3183,133 @@ static bool qIsFloatingPoint(uint tp)
return tp == QVariant::Double || tp == QMetaType::Float;
}
+static int normalizeLowerRanks(uint tp)
+{
+ static const qulonglong numericTypeBits =
+ Q_UINT64_C(1) << QMetaType::Bool |
+ Q_UINT64_C(1) << QMetaType::Char |
+ Q_UINT64_C(1) << QMetaType::SChar |
+ Q_UINT64_C(1) << QMetaType::UChar |
+ Q_UINT64_C(1) << QMetaType::Short |
+ Q_UINT64_C(1) << QMetaType::UShort;
+ return numericTypeBits & (Q_UINT64_C(1) << tp) ? QVariant::Int : tp;
+}
+
+static int normalizeLong(uint tp)
+{
+ const uint IntType = sizeof(long) == sizeof(int) ? QVariant::Int : QVariant::LongLong;
+ const uint UIntType = sizeof(ulong) == sizeof(uint) ? QVariant::UInt : QVariant::ULongLong;
+ return tp == QMetaType::Long ? IntType :
+ tp == QMetaType::ULong ? UIntType : tp;
+}
+
+static int numericTypePromotion(uint t1, uint t2)
+{
+ Q_ASSERT(qIsNumericType(t1));
+ Q_ASSERT(qIsNumericType(t2));
+
+ // C++ integral ranks: (4.13 Integer conversion rank [conv.rank])
+ // bool < signed char < short < int < long < long long
+ // unsigneds have the same rank as their signed counterparts
+ // C++ integral promotion rules (4.5 Integral Promotions [conv.prom])
+ // - any type with rank less than int can be converted to int or unsigned int
+ // 5 Expressions [expr] paragraph 9:
+ // - if either operand is double, the other shall be converted to double
+ // - " " float, " " " float
+ // - if both operands have the same type, no further conversion is needed.
+ // - if both are signed or if both are unsigned, convert to the one with highest rank
+ // - if the unsigned has higher or same rank, convert the signed to the unsigned one
+ // - if the signed can represent all values of the unsigned, convert to the signed
+ // - otherwise, convert to the unsigned corresponding to the rank of the signed
+
+ // floating point: we deviate from the C++ standard by always using qreal
+ if (qIsFloatingPoint(t1) || qIsFloatingPoint(t2))
+ return QMetaType::QReal;
+
+ // integral rules:
+ // for all platforms we support, int can always hold the values of lower-ranked types
+ t1 = normalizeLowerRanks(t1);
+ t2 = normalizeLowerRanks(t2);
+
+ // normalize long / ulong: in all platforms we run, they're either the same as int or as long long
+ t1 = normalizeLong(t1);
+ t2 = normalizeLong(t2);
+
+ // implement the other rules
+ // the four possibilities are Int, UInt, LongLong and ULongLong
+ // if any of the two is ULongLong, then it wins (highest rank, unsigned)
+ // otherwise, if one of the two is LongLong, then the other is either LongLong too or lower-ranked
+ // otherwise, if one of the two is UInt, then the other is either UInt too or Int
+ if (t1 == QVariant::ULongLong || t2 == QVariant::ULongLong)
+ return QVariant::ULongLong;
+ if (t1 == QVariant::LongLong || t2 == QVariant::LongLong)
+ return QVariant::LongLong;
+ if (t1 == QVariant::UInt || t2 == QVariant::UInt)
+ return QVariant::UInt;
+ return QVariant::Int;
+}
+
+static int integralCompare(uint promotedType, const QVariant::Private *d1, const QVariant::Private *d2)
+{
+ // use toLongLong to retrieve the data, it gets us all the bits
+ bool ok;
+ qlonglong l1 = qConvertToNumber(d1, &ok);
+ Q_ASSERT(ok);
+
+ qlonglong l2 = qConvertToNumber(d2, &ok);
+ Q_ASSERT(ok);
+
+ if (promotedType == QVariant::Int)
+ return int(l1) < int(l2) ? -1 : int(l1) == int(l2) ? 0 : 1;
+ if (promotedType == QVariant::UInt)
+ return uint(l1) < uint(l2) ? -1 : uint(l1) == uint(l2) ? 0 : 1;
+ if (promotedType == QVariant::LongLong)
+ return l1 < l2 ? -1 : l1 == l2 ? 0 : 1;
+ if (promotedType == QVariant::ULongLong)
+ return qulonglong(l1) < qulonglong(l2) ? -1 : qulonglong(l1) == qulonglong(l2) ? 0 : 1;
+
+ Q_UNREACHABLE();
+ return 0;
+}
+
+static int numericCompare(const QVariant::Private *d1, const QVariant::Private *d2)
+{
+ uint promotedType = numericTypePromotion(d1->type, d2->type);
+ if (promotedType != QMetaType::QReal)
+ return integralCompare(promotedType, d1, d2);
+
+ // qreal comparisons
+ bool ok;
+ qreal r1 = qConvertToRealNumber(d1, &ok);
+ Q_ASSERT(ok);
+ qreal r2 = qConvertToRealNumber(d2, &ok);
+ Q_ASSERT(ok);
+ if (qFuzzyCompare(r1, r2))
+ return 0;
+ return r1 < r2 ? -1 : 1;
+}
+
/*!
\internal
*/
bool QVariant::cmp(const QVariant &v) const
{
+ // try numerics first, with C++ type promotion rules (no conversion)
+ if (qIsNumericType(d.type) && qIsNumericType(v.d.type))
+ return numericCompare(&d, &v.d) == 0;
+
QVariant v1 = *this;
QVariant v2 = v;
if (d.type != v2.d.type) {
- if (qIsNumericType(d.type) && qIsNumericType(v.d.type)) {
- if (qIsFloatingPoint(d.type) || qIsFloatingPoint(v.d.type))
- return qFuzzyCompare(toReal(), v.toReal());
- else
- return toLongLong() == v.toLongLong();
+ if (v2.canConvert(v1.d.type)) {
+ if (!v2.convert(v1.d.type))
+ return false;
+ } else {
+ // try the opposite conversion, it might work
+ qSwap(v1, v2);
+ if (!v2.convert(v1.d.type))
+ return false;
}
- if (!v2.canConvert(v1.d.type) || !v2.convert(v1.d.type))
- return false;
}
if (v1.d.type >= QMetaType::User) {
int result;
@@ -3172,10 +3324,17 @@ bool QVariant::cmp(const QVariant &v) const
*/
int QVariant::compare(const QVariant &v) const
{
+ // try numerics first, with C++ type promotion rules (no conversion)
+ if (qIsNumericType(d.type) && qIsNumericType(v.d.type))
+ return numericCompare(&d, &v.d);
+
+ // check for equality next, as more types implement operator== than operator<
if (cmp(v))
return 0;
+
QVariant v1 = *this;
QVariant v2 = v;
+
if (v1.d.type != v2.d.type) {
// if both types differ, try to convert
if (v2.canConvert(v1.d.type)) {
@@ -3197,18 +3356,16 @@ int QVariant::compare(const QVariant &v) const
}
return r;
}
+
+ // did we end up with two numerics? If so, restart
+ if (qIsNumericType(v1.d.type) && qIsNumericType(v2.d.type))
+ return v1.compare(v2);
}
if (v1.d.type >= QMetaType::User) {
int result;
if (QMetaType::compare(QT_PREPEND_NAMESPACE(constData(d)), QT_PREPEND_NAMESPACE(constData(v2.d)), d.type, &result))
return result;
}
- if (qIsNumericType(v1.d.type)) {
- if (qIsFloatingPoint(v1.d.type))
- return v1.toReal() < v2.toReal() ? -1 : 1;
- else
- return v1.toLongLong() < v2.toLongLong() ? -1 : 1;
- }
switch (v1.d.type) {
case QVariant::Date:
return v1.toDate() < v2.toDate() ? -1 : 1;
diff --git a/src/corelib/mimetypes/qmimedatabase_p.h b/src/corelib/mimetypes/qmimedatabase_p.h
index 21669328db..b1e747c62e 100644
--- a/src/corelib/mimetypes/qmimedatabase_p.h
+++ b/src/corelib/mimetypes/qmimedatabase_p.h
@@ -54,6 +54,7 @@
QT_BEGIN_NAMESPACE
+class QIODevice;
class QMimeDatabase;
class QMimeProviderBase;
diff --git a/src/corelib/mimetypes/qmimeprovider_p.h b/src/corelib/mimetypes/qmimeprovider_p.h
index 027fddd2c8..1d480668e3 100644
--- a/src/corelib/mimetypes/qmimeprovider_p.h
+++ b/src/corelib/mimetypes/qmimeprovider_p.h
@@ -86,17 +86,17 @@ public:
QMimeBinaryProvider(QMimeDatabasePrivate *db);
virtual ~QMimeBinaryProvider();
- virtual bool isValid();
- virtual QMimeType mimeTypeForName(const QString &name);
- virtual QStringList findByFileName(const QString &fileName, QString *foundSuffix);
- virtual QStringList parents(const QString &mime);
- virtual QString resolveAlias(const QString &name);
- virtual QStringList listAliases(const QString &name);
- virtual QMimeType findByMagic(const QByteArray &data, int *accuracyPtr);
- virtual QList<QMimeType> allMimeTypes();
- virtual void loadMimeTypePrivate(QMimeTypePrivate &);
- virtual void loadIcon(QMimeTypePrivate &);
- virtual void loadGenericIcon(QMimeTypePrivate &);
+ virtual bool isValid() Q_DECL_OVERRIDE;
+ virtual QMimeType mimeTypeForName(const QString &name) Q_DECL_OVERRIDE;
+ virtual QStringList findByFileName(const QString &fileName, QString *foundSuffix) Q_DECL_OVERRIDE;
+ virtual QStringList parents(const QString &mime) Q_DECL_OVERRIDE;
+ virtual QString resolveAlias(const QString &name) Q_DECL_OVERRIDE;
+ virtual QStringList listAliases(const QString &name) Q_DECL_OVERRIDE;
+ virtual QMimeType findByMagic(const QByteArray &data, int *accuracyPtr) Q_DECL_OVERRIDE;
+ virtual QList<QMimeType> allMimeTypes() Q_DECL_OVERRIDE;
+ virtual void loadMimeTypePrivate(QMimeTypePrivate &) Q_DECL_OVERRIDE;
+ virtual void loadIcon(QMimeTypePrivate &) Q_DECL_OVERRIDE;
+ virtual void loadGenericIcon(QMimeTypePrivate &) Q_DECL_OVERRIDE;
private:
struct CacheFile;
@@ -128,14 +128,14 @@ class QMimeXMLProvider : public QMimeProviderBase
public:
QMimeXMLProvider(QMimeDatabasePrivate *db);
- virtual bool isValid();
- virtual QMimeType mimeTypeForName(const QString &name);
- virtual QStringList findByFileName(const QString &fileName, QString *foundSuffix);
- virtual QStringList parents(const QString &mime);
- virtual QString resolveAlias(const QString &name);
- virtual QStringList listAliases(const QString &name);
- virtual QMimeType findByMagic(const QByteArray &data, int *accuracyPtr);
- virtual QList<QMimeType> allMimeTypes();
+ virtual bool isValid() Q_DECL_OVERRIDE;
+ virtual QMimeType mimeTypeForName(const QString &name) Q_DECL_OVERRIDE;
+ virtual QStringList findByFileName(const QString &fileName, QString *foundSuffix) Q_DECL_OVERRIDE;
+ virtual QStringList parents(const QString &mime) Q_DECL_OVERRIDE;
+ virtual QString resolveAlias(const QString &name) Q_DECL_OVERRIDE;
+ virtual QStringList listAliases(const QString &name) Q_DECL_OVERRIDE;
+ virtual QMimeType findByMagic(const QByteArray &data, int *accuracyPtr) Q_DECL_OVERRIDE;
+ virtual QList<QMimeType> allMimeTypes() Q_DECL_OVERRIDE;
bool load(const QString &fileName, QString *errorMessage);
diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp
index 832ee250c7..c9ce5c342e 100644
--- a/src/corelib/plugin/qlibrary.cpp
+++ b/src/corelib/plugin/qlibrary.cpp
@@ -168,6 +168,11 @@ QT_BEGIN_NAMESPACE
Prevents the library from being unloaded from the address space if close()
is called. The library's static variables are not reinitialized if open()
is called at a later time.
+ \value DeepBindHint
+ Instructs the linker to prefer definitions in the loaded library
+ over exported definitions in the loading application when resolving
+ external symbols in the loaded library. This option is only supported
+ on Linux.
\sa loadHints
*/
@@ -1121,10 +1126,7 @@ QLibrary::LoadHints QLibrary::loadHints() const
/* Internal, for debugging */
bool qt_debug_component()
{
- static int debug_env = -1;
- if (debug_env == -1)
- debug_env = QT_PREPEND_NAMESPACE(qgetenv)("QT_DEBUG_PLUGINS").toInt();
-
+ static int debug_env = QT_PREPEND_NAMESPACE(qEnvironmentVariableIntValue)("QT_DEBUG_PLUGINS");
return debug_env != 0;
}
diff --git a/src/corelib/plugin/qlibrary.h b/src/corelib/plugin/qlibrary.h
index 77fe432761..327af8aada 100644
--- a/src/corelib/plugin/qlibrary.h
+++ b/src/corelib/plugin/qlibrary.h
@@ -53,7 +53,8 @@ public:
ResolveAllSymbolsHint = 0x01,
ExportExternalSymbolsHint = 0x02,
LoadArchiveMemberHint = 0x04,
- PreventUnloadHint = 0x08
+ PreventUnloadHint = 0x08,
+ DeepBindHint = 0x10
};
Q_DECLARE_FLAGS(LoadHints, LoadHint)
diff --git a/src/corelib/plugin/qlibrary_unix.cpp b/src/corelib/plugin/qlibrary_unix.cpp
index 4f96f3bccf..b178c173c5 100644
--- a/src/corelib/plugin/qlibrary_unix.cpp
+++ b/src/corelib/plugin/qlibrary_unix.cpp
@@ -171,6 +171,10 @@ bool QLibraryPrivate::load_sys()
dlFlags |= RTLD_LOCAL;
}
#endif
+#if defined(RTLD_DEEPBIND)
+ if (loadHints & QLibrary::DeepBindHint)
+ dlFlags |= RTLD_DEEPBIND;
+#endif
// Provide access to RTLD_NODELETE flag on Unix
// From GNU documentation on RTLD_NODELETE:
diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp
index 4a5f4e791d..6df3f3b0d1 100644
--- a/src/corelib/plugin/quuid.cpp
+++ b/src/corelib/plugin/quuid.cpp
@@ -36,14 +36,13 @@
#include "qdatastream.h"
#include "qendian.h"
#include "qdebug.h"
+#include "private/qtools_p.h"
#ifndef QT_BOOTSTRAPPED
#include "qcryptographichash.h"
#endif
QT_BEGIN_NAMESPACE
-static const char digits[] = "0123456789abcdef";
-
template <class Char, class Integral>
void _q_toHex(Char *&dst, Integral value)
{
@@ -52,10 +51,8 @@ void _q_toHex(Char *&dst, Integral value)
const char* p = reinterpret_cast<const char*>(&value);
for (uint i = 0; i < sizeof(Integral); ++i, dst += 2) {
- uint j = (p[i] >> 4) & 0xf;
- dst[0] = Char(digits[j]);
- j = p[i] & 0xf;
- dst[1] = Char(digits[j]);
+ dst[0] = Char(QtMiscUtils::toHexLower((p[i] >> 4) & 0xf));
+ dst[1] = Char(QtMiscUtils::toHexLower(p[i] & 0xf));
}
}
@@ -65,15 +62,9 @@ bool _q_fromHex(const Char *&src, Integral &value)
value = 0;
for (uint i = 0; i < sizeof(Integral) * 2; ++i) {
- int ch = *src++;
- int tmp;
- if (ch >= '0' && ch <= '9')
- tmp = ch - '0';
- else if (ch >= 'a' && ch <= 'f')
- tmp = ch - 'a' + 10;
- else if (ch >= 'A' && ch <= 'F')
- tmp = ch - 'A' + 10;
- else
+ uint ch = *src++;
+ int tmp = QtMiscUtils::fromHex(ch);
+ if (tmp == -1)
return false;
value = value * 16 + tmp;
diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h
index add245e4e3..ec5eb6b0e6 100644
--- a/src/corelib/plugin/quuid.h
+++ b/src/corelib/plugin/quuid.h
@@ -114,21 +114,20 @@ public:
static QUuid fromRfc4122(const QByteArray &);
bool isNull() const;
- bool operator==(const QUuid &orig) const
+ Q_DECL_RELAXED_CONSTEXPR bool operator==(const QUuid &orig) const
{
- uint i;
if (data1 != orig.data1 || data2 != orig.data2 ||
data3 != orig.data3)
return false;
- for(i = 0; i < 8; i++)
+ for (uint i = 0; i < 8; i++)
if (data4[i] != orig.data4[i])
return false;
return true;
}
- bool operator!=(const QUuid &orig) const
+ Q_DECL_RELAXED_CONSTEXPR bool operator!=(const QUuid &orig) const
{
return !(*this == orig);
}
@@ -155,24 +154,24 @@ public:
}
#endif
- QUuid &operator=(const GUID &guid)
+ Q_DECL_RELAXED_CONSTEXPR QUuid &operator=(const GUID &guid)
{
*this = QUuid(guid);
return *this;
}
- operator GUID() const
+ Q_DECL_RELAXED_CONSTEXPR operator GUID() const
{
GUID guid = { data1, data2, data3, { data4[0], data4[1], data4[2], data4[3], data4[4], data4[5], data4[6], data4[7] } };
return guid;
}
- bool operator==(const GUID &guid) const
+ Q_DECL_RELAXED_CONSTEXPR bool operator==(const GUID &guid) const
{
return *this == QUuid(guid);
}
- bool operator!=(const GUID &guid) const
+ Q_DECL_RELAXED_CONSTEXPR bool operator!=(const GUID &guid) const
{
return !(*this == guid);
}
diff --git a/src/corelib/statemachine/qabstractstate.h b/src/corelib/statemachine/qabstractstate.h
index 5f2216a9da..a6a4753d71 100644
--- a/src/corelib/statemachine/qabstractstate.h
+++ b/src/corelib/statemachine/qabstractstate.h
@@ -76,7 +76,7 @@ protected:
virtual void onEntry(QEvent *event) = 0;
virtual void onExit(QEvent *event) = 0;
- bool event(QEvent *e);
+ bool event(QEvent *e) Q_DECL_OVERRIDE;
protected:
QAbstractState(QAbstractStatePrivate &dd, QState *parent);
diff --git a/src/corelib/statemachine/qabstracttransition.h b/src/corelib/statemachine/qabstracttransition.h
index 2676aba633..e9c757c3a2 100644
--- a/src/corelib/statemachine/qabstracttransition.h
+++ b/src/corelib/statemachine/qabstracttransition.h
@@ -99,7 +99,7 @@ protected:
virtual void onTransition(QEvent *event) = 0;
- bool event(QEvent *e);
+ bool event(QEvent *e) Q_DECL_OVERRIDE;
protected:
QAbstractTransition(QAbstractTransitionPrivate &dd, QState *parent);
diff --git a/src/corelib/statemachine/qeventtransition.h b/src/corelib/statemachine/qeventtransition.h
index bf282242d6..861aacd51a 100644
--- a/src/corelib/statemachine/qeventtransition.h
+++ b/src/corelib/statemachine/qeventtransition.h
@@ -60,10 +60,10 @@ public:
void setEventType(QEvent::Type type);
protected:
- bool eventTest(QEvent *event);
- void onTransition(QEvent *event);
+ bool eventTest(QEvent *event) Q_DECL_OVERRIDE;
+ void onTransition(QEvent *event) Q_DECL_OVERRIDE;
- bool event(QEvent *e);
+ bool event(QEvent *e) Q_DECL_OVERRIDE;
protected:
QEventTransition(QEventTransitionPrivate &dd, QState *parent);
diff --git a/src/corelib/statemachine/qfinalstate.h b/src/corelib/statemachine/qfinalstate.h
index 804851c321..ca8875abea 100644
--- a/src/corelib/statemachine/qfinalstate.h
+++ b/src/corelib/statemachine/qfinalstate.h
@@ -50,10 +50,10 @@ public:
~QFinalState();
protected:
- void onEntry(QEvent *event);
- void onExit(QEvent *event);
+ void onEntry(QEvent *event) Q_DECL_OVERRIDE;
+ void onExit(QEvent *event) Q_DECL_OVERRIDE;
- bool event(QEvent *e);
+ bool event(QEvent *e) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(QFinalState)
diff --git a/src/corelib/statemachine/qhistorystate.h b/src/corelib/statemachine/qhistorystate.h
index d05e4ba5eb..ee80a0bc15 100644
--- a/src/corelib/statemachine/qhistorystate.h
+++ b/src/corelib/statemachine/qhistorystate.h
@@ -77,10 +77,10 @@ Q_SIGNALS:
);
protected:
- void onEntry(QEvent *event);
- void onExit(QEvent *event);
+ void onEntry(QEvent *event) Q_DECL_OVERRIDE;
+ void onExit(QEvent *event) Q_DECL_OVERRIDE;
- bool event(QEvent *e);
+ bool event(QEvent *e) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(QHistoryState)
diff --git a/src/corelib/statemachine/qsignaltransition.h b/src/corelib/statemachine/qsignaltransition.h
index 545374eb5c..8300c77b9e 100644
--- a/src/corelib/statemachine/qsignaltransition.h
+++ b/src/corelib/statemachine/qsignaltransition.h
@@ -61,10 +61,10 @@ public:
void setSignal(const QByteArray &signal);
protected:
- bool eventTest(QEvent *event);
- void onTransition(QEvent *event);
+ bool eventTest(QEvent *event) Q_DECL_OVERRIDE;
+ void onTransition(QEvent *event) Q_DECL_OVERRIDE;
- bool event(QEvent *e);
+ bool event(QEvent *e) Q_DECL_OVERRIDE;
Q_SIGNALS:
void senderObjectChanged(
diff --git a/src/corelib/statemachine/qsignaltransition_p.h b/src/corelib/statemachine/qsignaltransition_p.h
index 1d09babe88..f394bfc74f 100644
--- a/src/corelib/statemachine/qsignaltransition_p.h
+++ b/src/corelib/statemachine/qsignaltransition_p.h
@@ -61,7 +61,7 @@ public:
void unregister();
void maybeRegister();
- virtual void callOnTransition(QEvent *e);
+ virtual void callOnTransition(QEvent *e) Q_DECL_OVERRIDE;
const QObject *sender;
QByteArray signal;
diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp
index 29698d204f..15f6e29fcb 100644
--- a/src/corelib/statemachine/qstate.cpp
+++ b/src/corelib/statemachine/qstate.cpp
@@ -339,6 +339,17 @@ void QState::addTransition(QAbstractTransition *transition)
}
/*!
+ \fn QState::addTransition(const QObject *sender, PointerToMemberFunction signal,
+ QAbstractState *target);
+ \since 5.5
+ \overload
+
+ Adds a transition associated with the given \a signal of the given \a sender
+ object, and returns the new QSignalTransition object. The transition has
+ this state as the source, and the given \a target as the target state.
+*/
+
+/*!
Adds a transition associated with the given \a signal of the given \a sender
object, and returns the new QSignalTransition object. The transition has
this state as the source, and the given \a target as the target state.
@@ -383,8 +394,8 @@ public:
: QAbstractTransition()
{ setTargetState(target); }
protected:
- void onTransition(QEvent *) {}
- bool eventTest(QEvent *) { return true; }
+ void onTransition(QEvent *) Q_DECL_OVERRIDE {}
+ bool eventTest(QEvent *) Q_DECL_OVERRIDE { return true; }
};
} // namespace
diff --git a/src/corelib/statemachine/qstate.h b/src/corelib/statemachine/qstate.h
index dbc1ca97f9..8a308cf38e 100644
--- a/src/corelib/statemachine/qstate.h
+++ b/src/corelib/statemachine/qstate.h
@@ -35,8 +35,8 @@
#define QSTATE_H
#include <QtCore/qabstractstate.h>
-
#include <QtCore/qlist.h>
+#include <QtCore/qmetaobject.h>
QT_BEGIN_NAMESPACE
@@ -74,6 +74,18 @@ public:
void addTransition(QAbstractTransition *transition);
QSignalTransition *addTransition(const QObject *sender, const char *signal, QAbstractState *target);
+#ifdef Q_QDOC
+ QSignalTransition *addTransition(const QObject *sender, PointerToMemberFunction signal,
+ QAbstractState *target);
+#else
+ template <typename Func>
+ QSignalTransition *addTransition(const typename QtPrivate::FunctionPointer<Func>::Object *obj,
+ Func signal, QAbstractState *target)
+ {
+ const QMetaMethod signalMetaMethod = QMetaMethod::fromSignal(signal);
+ return addTransition(obj, signalMetaMethod.methodSignature().constData(), target);
+ }
+#endif // Q_QDOC
QAbstractTransition *addTransition(QAbstractState *target);
void removeTransition(QAbstractTransition *transition);
QList<QAbstractTransition*> transitions() const;
@@ -117,10 +129,10 @@ Q_SIGNALS:
);
protected:
- void onEntry(QEvent *event);
- void onExit(QEvent *event);
+ void onEntry(QEvent *event) Q_DECL_OVERRIDE;
+ void onExit(QEvent *event) Q_DECL_OVERRIDE;
- bool event(QEvent *e);
+ bool event(QEvent *e) Q_DECL_OVERRIDE;
protected:
QState(QStatePrivate &dd, QState *parent);
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
index 1350c8d99e..69e942d4fd 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -1303,8 +1303,8 @@ QAbstractTransition *QStateMachinePrivate::createInitialTransition() const
: QAbstractTransition()
{ setTargetStates(targets); }
protected:
- virtual bool eventTest(QEvent *) { return true; }
- virtual void onTransition(QEvent *) {}
+ virtual bool eventTest(QEvent *) Q_DECL_OVERRIDE { return true; }
+ virtual void onTransition(QEvent *) Q_DECL_OVERRIDE {}
};
QState *root = rootState();
@@ -1629,8 +1629,8 @@ public:
: QAbstractTransition()
{ setTargetState(target); }
protected:
- void onTransition(QEvent *) { deleteLater(); }
- bool eventTest(QEvent *) { return true; }
+ void onTransition(QEvent *) Q_DECL_OVERRIDE { deleteLater(); }
+ bool eventTest(QEvent *) Q_DECL_OVERRIDE { return true; }
};
} // namespace
diff --git a/src/corelib/statemachine/qstatemachine.h b/src/corelib/statemachine/qstatemachine.h
index 5f203d5ed4..3a4944a8db 100644
--- a/src/corelib/statemachine/qstatemachine.h
+++ b/src/corelib/statemachine/qstatemachine.h
@@ -136,7 +136,7 @@ public:
QSet<QAbstractState*> configuration() const;
#ifndef QT_NO_STATEMACHINE_EVENTFILTER
- bool eventFilter(QObject *watched, QEvent *event);
+ bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE;
#endif
public Q_SLOTS:
@@ -159,8 +159,8 @@ Q_SIGNALS:
protected:
- void onEntry(QEvent *event);
- void onExit(QEvent *event);
+ void onEntry(QEvent *event) Q_DECL_OVERRIDE;
+ void onExit(QEvent *event) Q_DECL_OVERRIDE;
virtual void beginSelectTransitions(QEvent *event);
virtual void endSelectTransitions(QEvent *event);
@@ -168,7 +168,7 @@ protected:
virtual void beginMicrostep(QEvent *event);
virtual void endMicrostep(QEvent *event);
- bool event(QEvent *e);
+ bool event(QEvent *e) Q_DECL_OVERRIDE;
protected:
QStateMachine(QStateMachinePrivate &dd, QObject *parent);
diff --git a/src/corelib/thread/qatomic.h b/src/corelib/thread/qatomic.h
index 7526cfe0e6..a665746db4 100644
--- a/src/corelib/thread/qatomic.h
+++ b/src/corelib/thread/qatomic.h
@@ -40,11 +40,8 @@
QT_BEGIN_NAMESPACE
-
-#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406) && !defined(Q_CC_INTEL)
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wextra"
-#endif
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_GCC("-Wextra")
// High-level atomic integer operations
template <typename T>
@@ -214,9 +211,7 @@ public:
#endif
};
-#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406) && !defined(Q_CC_INTEL)
-# pragma GCC diagnostic pop
-#endif
+QT_WARNING_POP
#ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS
# undef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS
diff --git a/src/corelib/thread/qexception.h b/src/corelib/thread/qexception.h
index 6c48b94a88..a1c3bbeb27 100644
--- a/src/corelib/thread/qexception.h
+++ b/src/corelib/thread/qexception.h
@@ -60,8 +60,8 @@ public:
class Q_CORE_EXPORT QUnhandledException : public QException
{
public:
- void raise() const;
- QUnhandledException *clone() const;
+ void raise() const Q_DECL_OVERRIDE;
+ QUnhandledException *clone() const Q_DECL_OVERRIDE;
};
namespace QtPrivate {
diff --git a/src/corelib/thread/qfutureinterface.cpp b/src/corelib/thread/qfutureinterface.cpp
index 1f417d3d74..a23c32a73b 100644
--- a/src/corelib/thread/qfutureinterface.cpp
+++ b/src/corelib/thread/qfutureinterface.cpp
@@ -292,7 +292,7 @@ void QFutureInterfaceBase::waitForResult(int resultIndex)
// To avoid deadlocks and reduce the number of threads used, try to
// run the runnable in the current thread.
- d->pool()->d_func()->stealRunnable(d->runnable);
+ d->pool()->d_func()->stealAndRunRunnable(d->runnable);
lock.relock();
@@ -313,7 +313,7 @@ void QFutureInterfaceBase::waitForFinished()
lock.unlock();
if (!alreadyFinished) {
- d->pool()->d_func()->stealRunnable(d->runnable);
+ d->pool()->d_func()->stealAndRunRunnable(d->runnable);
lock.relock();
diff --git a/src/corelib/thread/qfuturewatcher.h b/src/corelib/thread/qfuturewatcher.h
index 3ea4c4df4f..f84af0507a 100644
--- a/src/corelib/thread/qfuturewatcher.h
+++ b/src/corelib/thread/qfuturewatcher.h
@@ -70,7 +70,7 @@ public:
void setPendingResultsLimit(int limit);
- bool event(QEvent *event);
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
Q_SIGNALS:
void started();
@@ -92,8 +92,8 @@ public Q_SLOTS:
void togglePaused();
protected:
- void connectNotify (const QMetaMethod &signal);
- void disconnectNotify (const QMetaMethod &signal);
+ void connectNotify (const QMetaMethod &signal) Q_DECL_OVERRIDE;
+ void disconnectNotify (const QMetaMethod &signal) Q_DECL_OVERRIDE;
// called from setFuture() implemented in template sub-classes
void connectOutputInterface();
@@ -160,8 +160,8 @@ public Q_SLOTS:
private:
QFuture<T> m_future;
- const QFutureInterfaceBase &futureInterface() const { return m_future.d; }
- QFutureInterfaceBase &futureInterface() { return m_future.d; }
+ const QFutureInterfaceBase &futureInterface() const Q_DECL_OVERRIDE { return m_future.d; }
+ QFutureInterfaceBase &futureInterface() Q_DECL_OVERRIDE { return m_future.d; }
};
template <typename T>
@@ -191,8 +191,8 @@ public:
private:
QFuture<void> m_future;
- const QFutureInterfaceBase &futureInterface() const { return m_future.d; }
- QFutureInterfaceBase &futureInterface() { return m_future.d; }
+ const QFutureInterfaceBase &futureInterface() const Q_DECL_OVERRIDE { return m_future.d; }
+ QFutureInterfaceBase &futureInterface() Q_DECL_OVERRIDE { return m_future.d; }
};
Q_INLINE_TEMPLATE void QFutureWatcher<void>::setFuture(const QFuture<void> &_future)
diff --git a/src/corelib/thread/qfuturewatcher_p.h b/src/corelib/thread/qfuturewatcher_p.h
index 226642119a..84c608d1e0 100644
--- a/src/corelib/thread/qfuturewatcher_p.h
+++ b/src/corelib/thread/qfuturewatcher_p.h
@@ -63,8 +63,8 @@ class QFutureWatcherBasePrivate : public QObjectPrivate,
public:
QFutureWatcherBasePrivate();
- void postCallOutEvent(const QFutureCallOutEvent &callOutEvent);
- void callOutInterfaceDisconnected();
+ void postCallOutEvent(const QFutureCallOutEvent &callOutEvent) Q_DECL_OVERRIDE;
+ void callOutInterfaceDisconnected() Q_DECL_OVERRIDE;
void sendCallOutEvent(QFutureCallOutEvent *event);
diff --git a/src/corelib/thread/qthread.h b/src/corelib/thread/qthread.h
index 1d32580670..f9df407f72 100644
--- a/src/corelib/thread/qthread.h
+++ b/src/corelib/thread/qthread.h
@@ -89,7 +89,7 @@ public:
QAbstractEventDispatcher *eventDispatcher() const;
void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher);
- bool event(QEvent *event);
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
public Q_SLOTS:
void start(Priority = InheritPriority);
diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h
index 83693921be..9c67ce4471 100644
--- a/src/corelib/thread/qthread_p.h
+++ b/src/corelib/thread/qthread_p.h
@@ -305,7 +305,7 @@ public:
void init();
private:
- void run();
+ void run() Q_DECL_OVERRIDE;
};
QT_END_NAMESPACE
diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp
index c2a8bb0595..aaffdc2a4c 100644
--- a/src/corelib/thread/qthreadpool.cpp
+++ b/src/corelib/thread/qthreadpool.cpp
@@ -50,7 +50,7 @@ class QThreadPoolThread : public QThread
{
public:
QThreadPoolThread(QThreadPoolPrivate *manager);
- void run();
+ void run() Q_DECL_OVERRIDE;
void registerThreadInactive();
QWaitCondition runnableReady;
@@ -311,14 +311,12 @@ void QThreadPoolPrivate::clear()
/*!
\internal
Searches for \a runnable in the queue, removes it from the queue and
- runs it if found. This function does not return until the runnable
- has completed.
+ returns \c true if it was found in the queue
*/
-void QThreadPoolPrivate::stealRunnable(QRunnable *runnable)
+bool QThreadPoolPrivate::stealRunnable(QRunnable *runnable)
{
if (runnable == 0)
- return;
- bool found = false;
+ return false;
{
QMutexLocker locker(&mutex);
QList<QPair<QRunnable *, int> >::iterator it = queue.begin();
@@ -326,17 +324,26 @@ void QThreadPoolPrivate::stealRunnable(QRunnable *runnable)
while (it != end) {
if (it->first == runnable) {
- found = true;
queue.erase(it);
- break;
+ return true;
}
++it;
}
}
- if (!found)
- return;
+ return false;
+}
+ /*!
+ \internal
+ Searches for \a runnable in the queue, removes it from the queue and
+ runs it if found. This function does not return until the runnable
+ has completed.
+ */
+void QThreadPoolPrivate::stealAndRunRunnable(QRunnable *runnable)
+{
+ if (!stealRunnable(runnable))
+ return;
const bool autoDelete = runnable->autoDelete();
bool del = autoDelete && !--runnable->ref;
@@ -628,6 +635,25 @@ void QThreadPool::clear()
d->clear();
}
+/*!
+ \since 5.5
+
+ Removes the specified \a runnable from the queue if it is not yet started.
+ The runnables for which \l{QRunnable::autoDelete()}{runnable->autoDelete()}
+ returns \c true are deleted.
+
+ \sa start()
+*/
+void QThreadPool::cancel(QRunnable *runnable)
+{
+ Q_D(QThreadPool);
+ if (!d->stealRunnable(runnable))
+ return;
+ if (runnable->autoDelete() && !--runnable->ref) {
+ delete runnable;
+ }
+}
+
QT_END_NAMESPACE
#endif
diff --git a/src/corelib/thread/qthreadpool.h b/src/corelib/thread/qthreadpool.h
index e4d23cc200..c8cc5dfd89 100644
--- a/src/corelib/thread/qthreadpool.h
+++ b/src/corelib/thread/qthreadpool.h
@@ -77,6 +77,7 @@ public:
bool waitForDone(int msecs = -1);
void clear();
+ void cancel(QRunnable *runnable);
};
QT_END_NAMESPACE
diff --git a/src/corelib/thread/qthreadpool_p.h b/src/corelib/thread/qthreadpool_p.h
index d4308266a2..de2727adc1 100644
--- a/src/corelib/thread/qthreadpool_p.h
+++ b/src/corelib/thread/qthreadpool_p.h
@@ -76,7 +76,8 @@ public:
void reset();
bool waitForDone(int msecs);
void clear();
- void stealRunnable(QRunnable *);
+ bool stealRunnable(QRunnable *runnable);
+ void stealAndRunRunnable(QRunnable *runnable);
mutable QMutex mutex;
QSet<QThreadPoolThread *> allThreads;
diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp
index 98c484c1dd..dc419c3758 100644
--- a/src/corelib/tools/qarraydata.cpp
+++ b/src/corelib/tools/qarraydata.cpp
@@ -85,8 +85,20 @@ QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment,
headerSize += (alignment - Q_ALIGNOF(QArrayData));
// Allocate additional space if array is growing
- if (options & Grow)
- capacity = qAllocMore(int(objectSize * capacity), int(headerSize)) / int(objectSize);
+ if (options & Grow) {
+
+ // Guard against integer overflow when multiplying.
+ if (capacity > std::numeric_limits<size_t>::max() / objectSize)
+ return 0;
+
+ size_t alloc = objectSize * capacity;
+
+ // Make sure qAllocMore won't overflow.
+ if (headerSize > size_t(MaxAllocSize) || alloc > size_t(MaxAllocSize) - headerSize)
+ return 0;
+
+ capacity = qAllocMore(int(alloc), int(headerSize)) / int(objectSize);
+ }
size_t allocSize = headerSize + objectSize * capacity;
@@ -118,7 +130,8 @@ void QArrayData::deallocate(QArrayData *data, size_t objectSize,
return;
#endif
- Q_ASSERT_X(!data->ref.isStatic(), "QArrayData::deallocate", "Static data can not be deleted");
+ Q_ASSERT_X(data == 0 || !data->ref.isStatic(), "QArrayData::deallocate",
+ "Static data can not be deleted");
::free(data);
}
diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h
index f2cd3ec983..aef38bc20b 100644
--- a/src/corelib/tools/qarraydatapointer.h
+++ b/src/corelib/tools/qarraydatapointer.h
@@ -169,8 +169,10 @@ public:
private:
Data *clone(QArrayData::AllocationOptions options) const Q_REQUIRED_RESULT
{
- QArrayDataPointer copy(Data::allocate(d->detachCapacity(d->size),
- options));
+ Data *x = Data::allocate(d->detachCapacity(d->size), options);
+ Q_CHECK_PTR(x);
+ QArrayDataPointer copy(x);
+
if (d->size)
copy->copyAppend(d->begin(), d->end());
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index d8b2efbef3..a267dc6f7b 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Intel Corporation.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -38,6 +39,7 @@
#include "qlist.h"
#include "qlocale.h"
#include "qlocale_p.h"
+#include "qstringalgorithms_p.h"
#include "qscopedpointer.h"
#include <qdatastream.h>
#include <qmath.h>
@@ -54,6 +56,64 @@
QT_BEGIN_NAMESPACE
+// Latin 1 case system, used by QByteArray::to{Upper,Lower}() and qstr(n)icmp():
+/*
+#!/usr/bin/perl -l
+use feature "unicode_strings";
+for (0..255) {
+ $up = uc(chr($_));
+ $up = chr($_) if ord($up) > 0x100 || length $up > 1;
+ printf "0x%02x,", ord($up);
+ print "" if ($_ & 0xf) == 0xf;
+}
+*/
+static const uchar latin1_uppercased[256] = {
+ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
+ 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,
+ 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
+ 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
+ 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,
+ 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,
+ 0x60,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,
+ 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x7b,0x7c,0x7d,0x7e,0x7f,
+ 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
+ 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
+ 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,
+ 0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,
+ 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,
+ 0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,
+ 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,
+ 0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xf7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xff
+};
+
+/*
+#!/usr/bin/perl -l
+use feature "unicode_strings";
+for (0..255) {
+ $up = lc(chr($_));
+ $up = chr($_) if ord($up) > 0x100 || length $up > 1;
+ printf "0x%02x,", ord($up);
+ print "" if ($_ & 0xf) == 0xf;
+}
+*/
+static const uchar latin1_lowercased[256] = {
+ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
+ 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,
+ 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
+ 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
+ 0x40,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
+ 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x5b,0x5c,0x5d,0x5e,0x5f,
+ 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
+ 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,
+ 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
+ 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
+ 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,
+ 0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,
+ 0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,
+ 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xd7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xdf,
+ 0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,
+ 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
+};
int qFindByteArray(
const char *haystack0, int haystackLen, int from,
@@ -248,7 +308,7 @@ int qstricmp(const char *str1, const char *str2)
uchar c;
if (!s1 || !s2)
return s1 ? 1 : (s2 ? -1 : 0);
- for (; !(res = (c = QChar::toLower((ushort)*s1)) - QChar::toLower((ushort)*s2)); s1++, s2++)
+ for (; !(res = (c = latin1_lowercased[*s1]) - latin1_lowercased[*s2]); s1++, s2++)
if (!c) // strings are equal
break;
return res;
@@ -283,7 +343,7 @@ int qstrnicmp(const char *str1, const char *str2, uint len)
if (!s1 || !s2)
return s1 ? 1 : (s2 ? -1 : 0);
for (; len--; s1++, s2++) {
- if ((res = (c = QChar::toLower((ushort)*s1)) - QChar::toLower((ushort)*s2)))
+ if ((res = (c = latin1_lowercased[*s1]) - latin1_lowercased[*s2]))
return res;
if (!c) // strings are equal
break;
@@ -1494,8 +1554,11 @@ void QByteArray::reallocData(uint alloc, Data::AllocationOptions options)
Data::deallocate(d);
d = x;
} else {
- if (options & Data::Grow)
+ if (options & Data::Grow) {
+ if (alloc > uint(MaxAllocSize) - uint(sizeof(Data)))
+ qBadAlloc();
alloc = qAllocMore(alloc, sizeof(Data));
+ }
Data *x = static_cast<Data *>(::realloc(d, sizeof(Data) + alloc));
Q_CHECK_PTR(x);
x->alloc = alloc;
@@ -2686,6 +2749,8 @@ QByteArray QByteArray::mid(int pos, int len) const
}
/*!
+ \fn QByteArray QByteArray::toLower() const
+
Returns a lowercase copy of the byte array. The bytearray is
interpreted as a Latin-1 encoded string.
@@ -2694,21 +2759,56 @@ QByteArray QByteArray::mid(int pos, int len) const
\sa toUpper(), {8-bit Character Comparisons}
*/
-QByteArray QByteArray::toLower() const
+
+// noinline so that the compiler won't inline the function in each of
+// toLower and toUpper when the only difference is the table being used
+// (even with constant propagation, there's no gain in performance).
+template <typename T>
+#ifdef Q_CC_MSVC
+__declspec(noinline)
+#elif defined(Q_CC_GNU)
+__attribute__((noinline))
+#endif
+static QByteArray toCase_template(T &input, const uchar * table)
{
- QByteArray s(*this);
- uchar *p = reinterpret_cast<uchar *>(s.data());
- uchar *e = reinterpret_cast<uchar *>(s.end());
- if (p) {
- while (p != e) {
- *p = QChar::toLower((ushort)*p);
- p++;
- }
+ // find the first bad character in input
+ const char *orig_begin = input.constBegin();
+ const char *firstBad = orig_begin;
+ const char *e = input.constEnd();
+ for ( ; firstBad != e ; ++firstBad) {
+ uchar ch = uchar(*firstBad);
+ uchar converted = table[ch];
+ if (ch != converted)
+ break;
+ }
+
+ if (firstBad == e)
+ return qMove(input);
+
+ // transform the rest
+ QByteArray s = qMove(input); // will copy if T is const QByteArray
+ char *b = s.begin(); // will detach if necessary
+ char *p = b + (firstBad - orig_begin);
+ e = b + s.size();
+ for ( ; p != e; ++p) {
+ *p = char(uchar(table[uchar(*p)]));
}
return s;
}
+QByteArray QByteArray::toLower_helper(const QByteArray &a)
+{
+ return toCase_template(a, latin1_lowercased);
+}
+
+QByteArray QByteArray::toLower_helper(QByteArray &a)
+{
+ return toCase_template(a, latin1_lowercased);
+}
+
/*!
+ \fn QByteArray QByteArray::toUpper() const
+
Returns an uppercase copy of the byte array. The bytearray is
interpreted as a Latin-1 encoded string.
@@ -2718,18 +2818,14 @@ QByteArray QByteArray::toLower() const
\sa toLower(), {8-bit Character Comparisons}
*/
-QByteArray QByteArray::toUpper() const
+QByteArray QByteArray::toUpper_helper(const QByteArray &a)
{
- QByteArray s(*this);
- uchar *p = reinterpret_cast<uchar *>(s.data());
- uchar *e = reinterpret_cast<uchar *>(s.end());
- if (p) {
- while (p != e) {
- *p = QChar::toUpper((ushort)*p);
- p++;
- }
- }
- return s;
+ return toCase_template(a, latin1_uppercased);
+}
+
+QByteArray QByteArray::toUpper_helper(QByteArray &a)
+{
+ return toCase_template(a, latin1_uppercased);
}
/*! \fn void QByteArray::clear()
@@ -3109,6 +3205,8 @@ QDataStream &operator>>(QDataStream &in, QByteArray &ba)
*/
/*!
+ \fn QByteArray QByteArray::simplified() const
+
Returns a byte array that has whitespace removed from the start
and the end, and which has each sequence of internal whitespace
replaced with a single space.
@@ -3123,32 +3221,19 @@ QDataStream &operator>>(QDataStream &in, QByteArray &ba)
\sa trimmed()
*/
-QByteArray QByteArray::simplified() const
+QByteArray QByteArray::simplified_helper(const QByteArray &a)
{
- if (d->size == 0)
- return *this;
- QByteArray result(d->size, Qt::Uninitialized);
- const char *from = d->data();
- const char *fromend = from + d->size;
- int outc=0;
- char *to = result.d->data();
- for (;;) {
- while (from!=fromend && ascii_isspace(uchar(*from)))
- from++;
- while (from!=fromend && !ascii_isspace(uchar(*from)))
- to[outc++] = *from++;
- if (from!=fromend)
- to[outc++] = ' ';
- else
- break;
- }
- if (outc > 0 && to[outc-1] == ' ')
- outc--;
- result.resize(outc);
- return result;
+ return QStringAlgorithms<const QByteArray>::simplified_helper(a);
+}
+
+QByteArray QByteArray::simplified_helper(QByteArray &a)
+{
+ return QStringAlgorithms<QByteArray>::simplified_helper(a);
}
/*!
+ \fn QByteArray QByteArray::trimmed() const
+
Returns a byte array that has whitespace removed from the start
and the end.
@@ -3163,29 +3248,17 @@ QByteArray QByteArray::simplified() const
\sa simplified()
*/
-QByteArray QByteArray::trimmed() const
+QByteArray QByteArray::trimmed_helper(const QByteArray &a)
{
- if (d->size == 0)
- return *this;
- const char *s = d->data();
- if (!ascii_isspace(uchar(*s)) && !ascii_isspace(uchar(s[d->size-1])))
- return *this;
- int start = 0;
- int end = d->size - 1;
- while (start<=end && ascii_isspace(uchar(s[start]))) // skip white space from start
- start++;
- if (start <= end) { // only white space
- while (end && ascii_isspace(uchar(s[end]))) // skip white space from end
- end--;
- }
- int l = end - start + 1;
- if (l <= 0) {
- QByteArrayDataPtr empty = { Data::allocate(0) };
- return QByteArray(empty);
- }
- return QByteArray(s+start, l);
+ return QStringAlgorithms<const QByteArray>::trimmed_helper(a);
+}
+
+QByteArray QByteArray::trimmed_helper(QByteArray &a)
+{
+ return QStringAlgorithms<QByteArray>::trimmed_helper(a);
}
+
/*!
Returns a byte array of size \a width that contains this byte
array padded by the \a fill character.
@@ -4061,15 +4134,9 @@ QByteArray QByteArray::fromHex(const QByteArray &hexEncoded)
bool odd_digit = true;
for (int i = hexEncoded.size() - 1; i >= 0; --i) {
- int ch = hexEncoded.at(i);
- int tmp;
- if (ch >= '0' && ch <= '9')
- tmp = ch - '0';
- else if (ch >= 'a' && ch <= 'f')
- tmp = ch - 'a' + 10;
- else if (ch >= 'A' && ch <= 'F')
- tmp = ch - 'A' + 10;
- else
+ uchar ch = uchar(hexEncoded.at(i));
+ int tmp = QtMiscUtils::fromHex(ch);
+ if (tmp == -1)
continue;
if (odd_digit) {
--result;
@@ -4097,16 +4164,8 @@ QByteArray QByteArray::toHex() const
char *hexData = hex.data();
const uchar *data = (const uchar *)d->data();
for (int i = 0; i < d->size; ++i) {
- int j = (data[i] >> 4) & 0xf;
- if (j <= 9)
- hexData[i*2] = (j + '0');
- else
- hexData[i*2] = (j + 'a' - 10);
- j = data[i] & 0xf;
- if (j <= 9)
- hexData[i*2+1] = (j + '0');
- else
- hexData[i*2+1] = (j + 'a' - 10);
+ hexData[i*2] = QtMiscUtils::toHexLower(data[i] >> 4);
+ hexData[i*2+1] = QtMiscUtils::toHexLower(data[i] & 0xf);
}
return hex;
}
@@ -4301,12 +4360,6 @@ static inline bool q_strchr(const char str[], char chr)
return false;
}
-static inline char toHexHelper(char c)
-{
- static const char hexnumbers[] = "0123456789ABCDEF";
- return hexnumbers[c & 0xf];
-}
-
static void q_toPercentEncoding(QByteArray *ba, const char *dontEncode, const char *alsoEncode, char percent)
{
if (ba->isEmpty())
@@ -4339,8 +4392,8 @@ static void q_toPercentEncoding(QByteArray *ba, const char *dontEncode, const ch
output = ba->data();
}
output[length++] = percent;
- output[length++] = toHexHelper((c & 0xf0) >> 4);
- output[length++] = toHexHelper(c & 0xf);
+ output[length++] = QtMiscUtils::toHexUpper((c & 0xf0) >> 4);
+ output[length++] = QtMiscUtils::toHexUpper(c & 0xf);
}
}
if (output)
diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h
index 3bcc7b1f2a..6286624961 100644
--- a/src/corelib/tools/qbytearray.h
+++ b/src/corelib/tools/qbytearray.h
@@ -259,11 +259,40 @@ public:
void truncate(int pos);
void chop(int n);
+#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QSTRING_COMPAT_CPP)
+# if defined(Q_CC_GNU)
+ // required due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61941
+# pragma push_macro("Q_REQUIRED_RESULT")
+# undef Q_REQUIRED_RESULT
+# define Q_REQUIRED_RESULT
+# define Q_REQUIRED_RESULT_pushed
+# endif
+ QByteArray toLower() const & Q_REQUIRED_RESULT
+ { return toLower_helper(*this); }
+ QByteArray toLower() && Q_REQUIRED_RESULT
+ { return toLower_helper(*this); }
+ QByteArray toUpper() const & Q_REQUIRED_RESULT
+ { return toUpper_helper(*this); }
+ QByteArray toUpper() && Q_REQUIRED_RESULT
+ { return toUpper_helper(*this); }
+ QByteArray trimmed() const & Q_REQUIRED_RESULT
+ { return trimmed_helper(*this); }
+ QByteArray trimmed() && Q_REQUIRED_RESULT
+ { return trimmed_helper(*this); }
+ QByteArray simplified() const & Q_REQUIRED_RESULT
+ { return simplified_helper(*this); }
+ QByteArray simplified() && Q_REQUIRED_RESULT
+ { return simplified_helper(*this); }
+# ifdef Q_REQUIRED_RESULT_pushed
+# pragma pop_macro("Q_REQUIRED_RESULT")
+# endif
+#else
QByteArray toLower() const Q_REQUIRED_RESULT;
QByteArray toUpper() const Q_REQUIRED_RESULT;
-
QByteArray trimmed() const Q_REQUIRED_RESULT;
QByteArray simplified() const Q_REQUIRED_RESULT;
+#endif
+
QByteArray leftJustified(int width, char fill = ' ', bool truncate = false) const Q_REQUIRED_RESULT;
QByteArray rightJustified(int width, char fill = ' ', bool truncate = false) const Q_REQUIRED_RESULT;
@@ -417,6 +446,15 @@ private:
void expand(int i);
QByteArray nulTerminated() const;
+ static QByteArray toLower_helper(const QByteArray &a);
+ static QByteArray toLower_helper(QByteArray &a);
+ static QByteArray toUpper_helper(const QByteArray &a);
+ static QByteArray toUpper_helper(QByteArray &a);
+ static QByteArray trimmed_helper(const QByteArray &a);
+ static QByteArray trimmed_helper(QByteArray &a);
+ static QByteArray simplified_helper(const QByteArray &a);
+ static QByteArray simplified_helper(QByteArray &a);
+
friend class QByteRef;
friend class QString;
friend Q_CORE_EXPORT QByteArray qUncompress(const uchar *data, int nbytes);
diff --git a/src/corelib/tools/qchar.h b/src/corelib/tools/qchar.h
index 4db09e0f82..547c1ffda2 100644
--- a/src/corelib/tools/qchar.h
+++ b/src/corelib/tools/qchar.h
@@ -83,8 +83,10 @@ public:
#ifndef QT_NO_CAST_FROM_ASCII
QT_ASCII_CAST_WARN Q_DECL_CONSTEXPR explicit QChar(char c) : ucs(uchar(c)) { }
+#ifndef QT_RESTRICTED_CAST_FROM_ASCII
QT_ASCII_CAST_WARN Q_DECL_CONSTEXPR explicit QChar(uchar c) : ucs(c) { }
#endif
+#endif
// Unicode information
enum Category
@@ -377,68 +379,77 @@ public:
inline UnicodeVersion unicodeVersion() const { return QChar::unicodeVersion(ucs); }
#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED inline char toAscii() const { return toLatin1(); }
+ QT_DEPRECATED Q_DECL_CONSTEXPR inline char toAscii() const { return toLatin1(); }
#endif
- inline char toLatin1() const;
+ Q_DECL_CONSTEXPR inline char toLatin1() const;
Q_DECL_CONSTEXPR inline ushort unicode() const { return ucs; }
inline ushort &unicode() { return ucs; }
#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED static inline QChar fromAscii(char c)
+ QT_DEPRECATED static Q_DECL_CONSTEXPR inline QChar fromAscii(char c)
{ return fromLatin1(c); }
#endif
- static inline QChar fromLatin1(char c);
+ Q_DECL_CONSTEXPR static inline QChar fromLatin1(char c);
- inline bool isNull() const { return ucs == 0; }
+ Q_DECL_CONSTEXPR inline bool isNull() const { return ucs == 0; }
inline bool isPrint() const { return QChar::isPrint(ucs); }
- inline bool isSpace() const { return QChar::isSpace(ucs); }
+ Q_DECL_CONSTEXPR inline bool isSpace() const { return QChar::isSpace(ucs); }
inline bool isMark() const { return QChar::isMark(ucs); }
inline bool isPunct() const { return QChar::isPunct(ucs); }
inline bool isSymbol() const { return QChar::isSymbol(ucs); }
- inline bool isLetter() const { return QChar::isLetter(ucs); }
- inline bool isNumber() const { return QChar::isNumber(ucs); }
- inline bool isLetterOrNumber() const { return QChar::isLetterOrNumber(ucs); }
- inline bool isDigit() const { return QChar::isDigit(ucs); }
- inline bool isLower() const { return QChar::isLower(ucs); }
- inline bool isUpper() const { return QChar::isUpper(ucs); }
- inline bool isTitleCase() const { return QChar::isTitleCase(ucs); }
-
- inline bool isNonCharacter() const { return QChar::isNonCharacter(ucs); }
- inline bool isHighSurrogate() const { return QChar::isHighSurrogate(ucs); }
- inline bool isLowSurrogate() const { return QChar::isLowSurrogate(ucs); }
- inline bool isSurrogate() const { return QChar::isSurrogate(ucs); }
-
- inline uchar cell() const { return uchar(ucs & 0xff); }
- inline uchar row() const { return uchar((ucs>>8)&0xff); }
+ Q_DECL_CONSTEXPR inline bool isLetter() const { return QChar::isLetter(ucs); }
+ Q_DECL_CONSTEXPR inline bool isNumber() const { return QChar::isNumber(ucs); }
+ Q_DECL_CONSTEXPR inline bool isLetterOrNumber() const { return QChar::isLetterOrNumber(ucs); }
+ Q_DECL_CONSTEXPR inline bool isDigit() const { return QChar::isDigit(ucs); }
+ Q_DECL_CONSTEXPR inline bool isLower() const { return QChar::isLower(ucs); }
+ Q_DECL_CONSTEXPR inline bool isUpper() const { return QChar::isUpper(ucs); }
+ Q_DECL_CONSTEXPR inline bool isTitleCase() const { return QChar::isTitleCase(ucs); }
+
+ Q_DECL_CONSTEXPR inline bool isNonCharacter() const { return QChar::isNonCharacter(ucs); }
+ Q_DECL_CONSTEXPR inline bool isHighSurrogate() const { return QChar::isHighSurrogate(ucs); }
+ Q_DECL_CONSTEXPR inline bool isLowSurrogate() const { return QChar::isLowSurrogate(ucs); }
+ Q_DECL_CONSTEXPR inline bool isSurrogate() const { return QChar::isSurrogate(ucs); }
+
+ Q_DECL_CONSTEXPR inline uchar cell() const { return uchar(ucs & 0xff); }
+ Q_DECL_CONSTEXPR inline uchar row() const { return uchar((ucs>>8)&0xff); }
inline void setCell(uchar cell);
inline void setRow(uchar row);
- static inline bool isNonCharacter(uint ucs4) {
+ static Q_DECL_CONSTEXPR inline bool isNonCharacter(uint ucs4)
+ {
return ucs4 >= 0xfdd0 && (ucs4 <= 0xfdef || (ucs4 & 0xfffe) == 0xfffe);
}
- static inline bool isHighSurrogate(uint ucs4) {
+ static Q_DECL_CONSTEXPR inline bool isHighSurrogate(uint ucs4)
+ {
return ((ucs4 & 0xfffffc00) == 0xd800);
}
- static inline bool isLowSurrogate(uint ucs4) {
+ static Q_DECL_CONSTEXPR inline bool isLowSurrogate(uint ucs4)
+ {
return ((ucs4 & 0xfffffc00) == 0xdc00);
}
- static inline bool isSurrogate(uint ucs4) {
+ static Q_DECL_CONSTEXPR inline bool isSurrogate(uint ucs4)
+ {
return (ucs4 - 0xd800u < 2048u);
}
- static inline bool requiresSurrogates(uint ucs4) {
+ static Q_DECL_CONSTEXPR inline bool requiresSurrogates(uint ucs4)
+ {
return (ucs4 >= 0x10000);
}
- static inline uint surrogateToUcs4(ushort high, ushort low) {
+ static Q_DECL_CONSTEXPR inline uint surrogateToUcs4(ushort high, ushort low)
+ {
return (uint(high)<<10) + low - 0x35fdc00;
}
- static inline uint surrogateToUcs4(QChar high, QChar low) {
- return surrogateToUcs4(high.unicode(), low.unicode());
+ static Q_DECL_CONSTEXPR inline uint surrogateToUcs4(QChar high, QChar low)
+ {
+ return surrogateToUcs4(high.ucs, low.ucs);
}
- static inline ushort highSurrogate(uint ucs4) {
+ static Q_DECL_CONSTEXPR inline ushort highSurrogate(uint ucs4)
+ {
return ushort((ucs4>>10) + 0xd7c0);
}
- static inline ushort lowSurrogate(uint ucs4) {
+ static Q_DECL_CONSTEXPR inline ushort lowSurrogate(uint ucs4)
+ {
return ushort(ucs4%0x400 + 0xdc00);
}
@@ -469,17 +480,17 @@ public:
static UnicodeVersion QT_FASTCALL currentUnicodeVersion() Q_DECL_CONST_FUNCTION;
static bool QT_FASTCALL isPrint(uint ucs4) Q_DECL_CONST_FUNCTION;
- static inline bool isSpace(uint ucs4) Q_DECL_CONST_FUNCTION;
+ static Q_DECL_CONSTEXPR inline bool isSpace(uint ucs4) Q_DECL_CONST_FUNCTION;
static bool QT_FASTCALL isMark(uint ucs4) Q_DECL_CONST_FUNCTION;
static bool QT_FASTCALL isPunct(uint ucs4) Q_DECL_CONST_FUNCTION;
static bool QT_FASTCALL isSymbol(uint ucs4) Q_DECL_CONST_FUNCTION;
- static inline bool isLetter(uint ucs4) Q_DECL_CONST_FUNCTION;
- static inline bool isNumber(uint ucs4) Q_DECL_CONST_FUNCTION;
- static inline bool isLetterOrNumber(uint ucs4) Q_DECL_CONST_FUNCTION;
- static inline bool isDigit(uint ucs4) Q_DECL_CONST_FUNCTION;
- static inline bool isLower(uint ucs4) Q_DECL_CONST_FUNCTION;
- static inline bool isUpper(uint ucs4) Q_DECL_CONST_FUNCTION;
- static inline bool isTitleCase(uint ucs4) Q_DECL_CONST_FUNCTION;
+ static Q_DECL_CONSTEXPR inline bool isLetter(uint ucs4) Q_DECL_CONST_FUNCTION;
+ static Q_DECL_CONSTEXPR inline bool isNumber(uint ucs4) Q_DECL_CONST_FUNCTION;
+ static Q_DECL_CONSTEXPR inline bool isLetterOrNumber(uint ucs4) Q_DECL_CONST_FUNCTION;
+ static Q_DECL_CONSTEXPR inline bool isDigit(uint ucs4) Q_DECL_CONST_FUNCTION;
+ static Q_DECL_CONSTEXPR inline bool isLower(uint ucs4) Q_DECL_CONST_FUNCTION;
+ static Q_DECL_CONSTEXPR inline bool isUpper(uint ucs4) Q_DECL_CONST_FUNCTION;
+ static Q_DECL_CONSTEXPR inline bool isTitleCase(uint ucs4) Q_DECL_CONST_FUNCTION;
private:
static bool QT_FASTCALL isSpace_helper(uint ucs4) Q_DECL_CONST_FUNCTION;
@@ -491,53 +502,57 @@ private:
QChar(char c);
QChar(uchar c);
#endif
+
+ friend Q_DECL_CONSTEXPR bool operator==(QChar, QChar);
+ friend Q_DECL_CONSTEXPR bool operator< (QChar, QChar);
ushort ucs;
};
Q_DECLARE_TYPEINFO(QChar, Q_MOVABLE_TYPE);
-inline char QChar::toLatin1() const { return ucs > 0xff ? '\0' : char(ucs); }
-inline QChar QChar::fromLatin1(char c) { return QChar(ushort(uchar(c))); }
+Q_DECL_CONSTEXPR inline char QChar::toLatin1() const { return ucs > 0xff ? '\0' : char(ucs); }
+Q_DECL_CONSTEXPR inline QChar QChar::fromLatin1(char c) { return QChar(ushort(uchar(c))); }
inline void QChar::setCell(uchar acell)
{ ucs = ushort((ucs & 0xff00) + acell); }
inline void QChar::setRow(uchar arow)
{ ucs = ushort((ushort(arow)<<8) + (ucs&0xff)); }
-inline bool QChar::isSpace(uint ucs4)
+Q_DECL_CONSTEXPR inline bool QChar::isSpace(uint ucs4)
{
// note that [0x09..0x0d] + 0x85 are exceptional Cc-s and must be handled explicitly
return ucs4 == 0x20 || (ucs4 <= 0x0d && ucs4 >= 0x09)
|| (ucs4 > 127 && (ucs4 == 0x85 || ucs4 == 0xa0 || QChar::isSpace_helper(ucs4)));
}
-inline bool QChar::isLetter(uint ucs4)
+Q_DECL_CONSTEXPR inline bool QChar::isLetter(uint ucs4)
{
return (ucs4 >= 'A' && ucs4 <= 'z' && (ucs4 >= 'a' || ucs4 <= 'Z'))
|| (ucs4 > 127 && QChar::isLetter_helper(ucs4));
}
-inline bool QChar::isNumber(uint ucs4)
+Q_DECL_CONSTEXPR inline bool QChar::isNumber(uint ucs4)
{ return (ucs4 <= '9' && ucs4 >= '0') || (ucs4 > 127 && QChar::isNumber_helper(ucs4)); }
-inline bool QChar::isLetterOrNumber(uint ucs4)
+Q_DECL_CONSTEXPR inline bool QChar::isLetterOrNumber(uint ucs4)
{
return (ucs4 >= 'A' && ucs4 <= 'z' && (ucs4 >= 'a' || ucs4 <= 'Z'))
|| (ucs4 >= '0' && ucs4 <= '9')
|| (ucs4 > 127 && QChar::isLetterOrNumber_helper(ucs4));
}
-inline bool QChar::isDigit(uint ucs4)
+Q_DECL_CONSTEXPR inline bool QChar::isDigit(uint ucs4)
{ return (ucs4 <= '9' && ucs4 >= '0') || (ucs4 > 127 && QChar::category(ucs4) == Number_DecimalDigit); }
-inline bool QChar::isLower(uint ucs4)
+Q_DECL_CONSTEXPR inline bool QChar::isLower(uint ucs4)
{ return (ucs4 <= 'z' && ucs4 >= 'a') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Lowercase); }
-inline bool QChar::isUpper(uint ucs4)
+Q_DECL_CONSTEXPR inline bool QChar::isUpper(uint ucs4)
{ return (ucs4 <= 'Z' && ucs4 >= 'A') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Uppercase); }
-inline bool QChar::isTitleCase(uint ucs4)
+Q_DECL_CONSTEXPR inline bool QChar::isTitleCase(uint ucs4)
{ return ucs4 > 127 && QChar::category(ucs4) == Letter_Titlecase; }
-inline bool operator==(QChar c1, QChar c2) { return c1.unicode() == c2.unicode(); }
-inline bool operator!=(QChar c1, QChar c2) { return c1.unicode() != c2.unicode(); }
-inline bool operator<=(QChar c1, QChar c2) { return c1.unicode() <= c2.unicode(); }
-inline bool operator>=(QChar c1, QChar c2) { return c1.unicode() >= c2.unicode(); }
-inline bool operator<(QChar c1, QChar c2) { return c1.unicode() < c2.unicode(); }
-inline bool operator>(QChar c1, QChar c2) { return c1.unicode() > c2.unicode(); }
+Q_DECL_CONSTEXPR inline bool operator==(QChar c1, QChar c2) { return c1.ucs == c2.ucs; }
+Q_DECL_CONSTEXPR inline bool operator< (QChar c1, QChar c2) { return c1.ucs < c2.ucs; }
+
+Q_DECL_CONSTEXPR inline bool operator!=(QChar c1, QChar c2) { return !operator==(c1, c2); }
+Q_DECL_CONSTEXPR inline bool operator>=(QChar c1, QChar c2) { return !operator< (c1, c2); }
+Q_DECL_CONSTEXPR inline bool operator> (QChar c1, QChar c2) { return operator< (c2, c1); }
+Q_DECL_CONSTEXPR inline bool operator<=(QChar c1, QChar c2) { return !operator< (c2, c1); }
#ifndef QT_NO_DATASTREAM
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, QChar);
diff --git a/src/corelib/tools/qcommandlineparser.cpp b/src/corelib/tools/qcommandlineparser.cpp
index 01772b2ad5..117ce381f1 100644
--- a/src/corelib/tools/qcommandlineparser.cpp
+++ b/src/corelib/tools/qcommandlineparser.cpp
@@ -37,6 +37,10 @@
#include <qcoreapplication.h>
#include <qhash.h>
#include <qvector.h>
+#include <qdebug.h>
+#if defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)
+# include <qt_windows.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
@@ -209,7 +213,10 @@ QStringList QCommandLineParserPrivate::aliases(const QString &optionName) const
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
+ On Windows, QCommandLineParser uses message boxes to display usage information
+ and errors if no console window can be obtained.
+
+ For other platforms, 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:
@@ -219,36 +226,20 @@ QStringList QCommandLineParserPrivate::aliases(const QString &optionName) const
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
@@ -491,6 +482,41 @@ QString QCommandLineParser::errorText() const
return QString();
}
+enum MessageType { UsageMessage, ErrorMessage };
+
+#if defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)
+// Return whether to use a message box. Use handles if a console can be obtained
+// or we are run with redirected handles (for example, by QProcess).
+static inline bool displayMessageBox()
+{
+ if (GetConsoleWindow())
+ return false;
+ STARTUPINFO startupInfo;
+ startupInfo.cb = sizeof(STARTUPINFO);
+ GetStartupInfo(&startupInfo);
+ return !(startupInfo.dwFlags & STARTF_USESTDHANDLES);
+}
+#endif // Q_OS_WIN && !QT_BOOTSTRAPPED && !Q_OS_WIN && !Q_OS_WINRT
+
+static void showParserMessage(const QString &message, MessageType type)
+{
+#if defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)
+ if (displayMessageBox()) {
+ const UINT flags = MB_OK | MB_TOPMOST | MB_SETFOREGROUND
+ | (type == UsageMessage ? MB_ICONINFORMATION : MB_ICONERROR);
+ QString title;
+ if (QCoreApplication::instance())
+ title = QCoreApplication::instance()->property("applicationDisplayName").toString();
+ if (title.isEmpty())
+ title = QCoreApplication::applicationName();
+ MessageBoxW(0, reinterpret_cast<const wchar_t *>(message.utf16()),
+ reinterpret_cast<const wchar_t *>(title.utf16()), flags);
+ return;
+ }
+#endif // Q_OS_WIN && !QT_BOOTSTRAPPED && !Q_OS_WIN && !Q_OS_WINRT
+ fputs(qPrintable(message), type == UsageMessage ? stdout : stderr);
+}
+
/*!
Processes the command line \a arguments.
@@ -507,7 +533,7 @@ QString QCommandLineParser::errorText() const
void QCommandLineParser::process(const QStringList &arguments)
{
if (!d->parse(arguments)) {
- fprintf(stderr, "%s\n", qPrintable(errorText()));
+ showParserMessage(errorText() + QLatin1Char('\n'), ErrorMessage);
::exit(EXIT_FAILURE);
}
@@ -913,7 +939,9 @@ QStringList QCommandLineParser::unknownOptionNames() const
*/
Q_NORETURN void QCommandLineParser::showVersion()
{
- fprintf(stdout, "%s %s\n", qPrintable(QCoreApplication::applicationName()), qPrintable(QCoreApplication::applicationVersion()));
+ showParserMessage(QCoreApplication::applicationName() + QLatin1Char(' ')
+ + QCoreApplication::applicationVersion() + QLatin1Char('\n'),
+ UsageMessage);
::exit(EXIT_SUCCESS);
}
@@ -930,7 +958,7 @@ Q_NORETURN void QCommandLineParser::showVersion()
*/
Q_NORETURN void QCommandLineParser::showHelp(int exitCode)
{
- fprintf(stdout, "%s", qPrintable(d->helpText()));
+ showParserMessage(d->helpText(), UsageMessage);
::exit(exitCode);
}
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index f0f6a56755..69d4bd7d99 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -249,7 +249,7 @@ static QString toOffsetString(Qt::DateFormat format, int offset)
}
// Parse offset in [+-]HH[:]MM format
-static int fromOffsetString(const QString &offsetString, bool *valid)
+static int fromOffsetString(const QStringRef &offsetString, bool *valid)
{
*valid = false;
@@ -270,15 +270,15 @@ static int fromOffsetString(const QString &offsetString, bool *valid)
return 0;
// Split the hour and minute parts
- QStringList parts = offsetString.mid(1).split(QLatin1Char(':'));
+ QVector<QStringRef> parts = offsetString.mid(1).split(QLatin1Char(':'));
if (parts.count() == 1) {
// [+-]HHMM format
- parts.append(parts.at(0).mid(2));
- parts[0] = parts.at(0).left(2);
+ parts.append(parts.first().mid(2));
+ parts[0] = parts.first().left(2);
}
bool ok = false;
- const int hour = parts.at(0).toInt(&ok);
+ const int hour = parts.first().toInt(&ok);
if (!ok)
return 0;
@@ -898,18 +898,18 @@ QString QDate::toString(Qt::DateFormat format) const
#ifndef QT_NO_TEXTDATE
case Qt::TextDate:
getDateFromJulianDay(jd, &y, &m, &d);
- return QString::fromUtf8("%1 %2 %3 %4").arg(shortDayName(dayOfWeek()))
- .arg(shortMonthName(m))
- .arg(d)
- .arg(y);
+ return QString::fromLatin1("%1 %2 %3 %4").arg(shortDayName(dayOfWeek()))
+ .arg(shortMonthName(m))
+ .arg(d)
+ .arg(y);
#endif
case Qt::ISODate:
getDateFromJulianDay(jd, &y, &m, &d);
if (y < 0 || y > 9999)
return QString();
- return QString::fromUtf8("%1-%2-%3").arg(y, 4, 10, QLatin1Char('0'))
- .arg(m, 2, 10, QLatin1Char('0'))
- .arg(d, 2, 10, QLatin1Char('0'));
+ return QString::fromLatin1("%1-%2-%3").arg(y, 4, 10, QLatin1Char('0'))
+ .arg(m, 2, 10, QLatin1Char('0'))
+ .arg(d, 2, 10, QLatin1Char('0'));
}
}
@@ -1247,12 +1247,12 @@ QDate QDate::fromString(const QString& string, Qt::DateFormat format)
default:
#ifndef QT_NO_TEXTDATE
case Qt::TextDate: {
- QStringList parts = string.split(QLatin1Char(' '), QString::SkipEmptyParts);
+ QVector<QStringRef> parts = string.splitRef(QLatin1Char(' '), QString::SkipEmptyParts);
if (parts.count() != 4)
return QDate();
- QString monthName = parts.at(1);
+ QStringRef monthName = parts.at(1);
int month = -1;
// Assume that English monthnames are the default
for (int i = 0; i < 12; ++i) {
@@ -1288,10 +1288,10 @@ QDate QDate::fromString(const QString& string, Qt::DateFormat format)
|| (string.size() > 10 && string.at(10).isDigit())) {
return QDate();
}
- const int year = string.mid(0, 4).toInt();
+ const int year = string.midRef(0, 4).toInt();
if (year <= 0 || year > 9999)
return QDate();
- return QDate(year, string.mid(5, 2).toInt(), string.mid(8, 2).toInt());
+ return QDate(year, string.midRef(5, 2).toInt(), string.midRef(8, 2).toInt());
}
}
return QDate();
@@ -1649,9 +1649,9 @@ QString QTime::toString(Qt::DateFormat format) const
case Qt::ISODate:
case Qt::TextDate:
default:
- return QString::fromUtf8("%1:%2:%3").arg(hour(), 2, 10, QLatin1Char('0'))
- .arg(minute(), 2, 10, QLatin1Char('0'))
- .arg(second(), 2, 10, QLatin1Char('0'));
+ return QString::fromLatin1("%1:%2:%3").arg(hour(), 2, 10, QLatin1Char('0'))
+ .arg(minute(), 2, 10, QLatin1Char('0'))
+ .arg(second(), 2, 10, QLatin1Char('0'));
}
}
@@ -3596,11 +3596,11 @@ QString QDateTime::toString(Qt::DateFormat format) const
QTime tm;
d->getDateTime(&dt, &tm);
//We cant use date.toString(Qt::TextDate) as we need to insert the time before the year
- buf = QString::fromUtf8("%1 %2 %3 %4 %5").arg(dt.shortDayName(dt.dayOfWeek()))
- .arg(dt.shortMonthName(dt.month()))
- .arg(dt.day())
- .arg(tm.toString(Qt::TextDate))
- .arg(dt.year());
+ buf = QString::fromLatin1("%1 %2 %3 %4 %5").arg(dt.shortDayName(dt.dayOfWeek()))
+ .arg(dt.shortMonthName(dt.month()))
+ .arg(dt.day())
+ .arg(tm.toString(Qt::TextDate))
+ .arg(dt.year());
if (timeSpec() != Qt::LocalTime) {
buf += QStringLiteral(" GMT");
if (d->m_spec == Qt::OffsetFromUTC)
@@ -4197,6 +4197,39 @@ qint64 QDateTime::currentMSecsSinceEpoch() Q_DECL_NOTHROW
#error "What system is this?"
#endif
+/*! \fn QDateTime QDateTime::fromCFDate(CFDateRef date)
+ \since 5.5
+
+ Constructs a new QDateTime containing a copy of the CFDate \a date.
+
+ \sa toCFDate()
+*/
+
+/*! \fn CFDateRef QDateTime::toCFDate() const
+ \since 5.5
+
+ Creates a CFDate from a QDateTime. The caller owns the CFDate object
+ and is responsible for releasing it.
+
+ \sa fromCFDate()
+*/
+
+/*! \fn QDateTime QDateTime::fromNSDate(const NSDate *date)
+ \since 5.5
+
+ Constructs a new QDateTime containing a copy of the NSDate \a date.
+
+ \sa toNSDate()
+*/
+
+/*! \fn NSDate QDateTime::toNSDate() const
+ \since 5.5
+
+ Creates an NSDate from a QDateTime. The NSDate object is autoreleased.
+
+ \sa fromNSDate()
+*/
+
/*!
\since 4.2
@@ -4351,7 +4384,7 @@ int QDateTime::utcOffset() const
#ifndef QT_NO_DATESTRING
-static int fromShortMonthName(const QString &monthName)
+static int fromShortMonthName(const QStringRef &monthName)
{
// Assume that English monthnames are the default
for (int i = 0; i < 12; ++i) {
@@ -4443,7 +4476,7 @@ QDateTime QDateTime::fromString(const QString& string, Qt::DateFormat format)
if (found) {
bool ok;
- offset = fromOffsetString(isoString.mid(signIndex).toString(), &ok);
+ offset = fromOffsetString(isoString.mid(signIndex), &ok);
if (!ok)
return QDateTime();
isoString = isoString.left(signIndex);
@@ -4463,7 +4496,7 @@ QDateTime QDateTime::fromString(const QString& string, Qt::DateFormat format)
}
#if !defined(QT_NO_TEXTDATE)
case Qt::TextDate: {
- QStringList parts = string.split(QLatin1Char(' '), QString::SkipEmptyParts);
+ QVector<QStringRef> parts = string.splitRef(QLatin1Char(' '), QString::SkipEmptyParts);
if ((parts.count() < 5) || (parts.count() > 6))
return QDateTime();
@@ -4482,9 +4515,9 @@ QDateTime QDateTime::fromString(const QString& string, Qt::DateFormat format)
if (!month || !day) {
month = fromShortMonthName(parts.at(2));
if (month) {
- QString dayStr = parts.at(1);
+ QStringRef dayStr = parts.at(1);
if (dayStr.endsWith(QLatin1Char('.'))) {
- dayStr.chop(1);
+ dayStr = dayStr.left(dayStr.size() - 1);
day = dayStr.toInt();
}
}
@@ -4517,7 +4550,7 @@ QDateTime QDateTime::fromString(const QString& string, Qt::DateFormat format)
if (!date.isValid())
return QDateTime();
- QStringList timeParts = parts.at(timePart).split(QLatin1Char(':'));
+ QVector<QStringRef> timeParts = parts.at(timePart).split(QLatin1Char(':'));
if (timeParts.count() < 2 || timeParts.count() > 3)
return QDateTime();
@@ -4532,7 +4565,7 @@ QDateTime QDateTime::fromString(const QString& string, Qt::DateFormat format)
int second = 0;
int millisecond = 0;
if (timeParts.count() > 2) {
- QStringList secondParts = timeParts.at(2).split(QLatin1Char('.'));
+ QVector<QStringRef> secondParts = timeParts.at(2).split(QLatin1Char('.'));
if (secondParts.size() > 2) {
return QDateTime();
}
@@ -4557,10 +4590,10 @@ QDateTime QDateTime::fromString(const QString& string, Qt::DateFormat format)
if (parts.count() == 5)
return QDateTime(date, time, Qt::LocalTime);
- QString tz = parts.at(5);
+ QStringRef tz = parts.at(5);
if (!tz.startsWith(QLatin1String("GMT"), Qt::CaseInsensitive))
return QDateTime();
- tz.remove(0, 3);
+ tz = tz.mid(3);
if (!tz.isEmpty()) {
int offset = fromOffsetString(tz, &ok);
if (!ok)
@@ -4987,7 +5020,7 @@ QDebug operator<<(QDebug dbg, const QDateTime &date)
spec = QStringLiteral(" Qt::UTC");
break;
case Qt::OffsetFromUTC:
- spec = QString::fromUtf8(" Qt::OffsetFromUTC %1s").arg(date.offsetFromUtc());
+ spec = QString::fromLatin1(" Qt::OffsetFromUTC %1s").arg(date.offsetFromUtc());
break;
case Qt::TimeZone:
#ifndef QT_BOOTSTRAPPED
diff --git a/src/corelib/tools/qdatetime.h b/src/corelib/tools/qdatetime.h
index a75d7d9bc8..5bcd01a587 100644
--- a/src/corelib/tools/qdatetime.h
+++ b/src/corelib/tools/qdatetime.h
@@ -40,6 +40,13 @@
#include <limits>
+#ifdef Q_OS_MAC
+Q_FORWARD_DECLARE_CF_TYPE(CFDate);
+# ifdef __OBJC__
+Q_FORWARD_DECLARE_OBJC_CLASS(NSDate);
+# endif
+#endif
+
QT_BEGIN_NAMESPACE
class QTimeZone;
@@ -296,6 +303,15 @@ public:
#endif
static qint64 currentMSecsSinceEpoch() Q_DECL_NOTHROW;
+#if defined(Q_OS_MAC) || defined(Q_QDOC)
+ static QDateTime fromCFDate(CFDateRef date);
+ CFDateRef toCFDate() const Q_DECL_CF_RETURNS_RETAINED;
+# if defined(__OBJC__) || defined(Q_QDOC)
+ static QDateTime fromNSDate(const NSDate *date);
+ NSDate *toNSDate() const Q_DECL_NS_RETURNS_AUTORELEASED;
+# endif
+#endif
+
private:
friend class QDateTimePrivate;
void detach();
diff --git a/src/corelib/tools/qdatetime_mac.mm b/src/corelib/tools/qdatetime_mac.mm
new file mode 100644
index 0000000000..c8a1d22928
--- /dev/null
+++ b/src/corelib/tools/qdatetime_mac.mm
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Petroules Corporation.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdatetime.h"
+
+#import <Foundation/Foundation.h>
+
+QT_BEGIN_NAMESPACE
+
+QDateTime QDateTime::fromCFDate(CFDateRef date)
+{
+ if (!date)
+ return QDateTime();
+ return QDateTime::fromMSecsSinceEpoch(static_cast<qint64>((CFDateGetAbsoluteTime(date)
+ + kCFAbsoluteTimeIntervalSince1970) * 1000));
+}
+
+CFDateRef QDateTime::toCFDate() const
+{
+ return CFDateCreate(kCFAllocatorDefault, (static_cast<CFAbsoluteTime>(toMSecsSinceEpoch())
+ / 1000) - kCFAbsoluteTimeIntervalSince1970);
+}
+
+QDateTime QDateTime::fromNSDate(const NSDate *date)
+{
+ if (!date)
+ return QDateTime();
+ return QDateTime::fromMSecsSinceEpoch(static_cast<qint64>([date timeIntervalSince1970] * 1000));
+}
+
+NSDate *QDateTime::toNSDate() const
+{
+ return [NSDate
+ dateWithTimeIntervalSince1970:static_cast<NSTimeInterval>(toMSecsSinceEpoch()) / 1000];
+}
+
+QT_END_NAMESPACE
diff --git a/src/corelib/tools/qdatetime_p.h b/src/corelib/tools/qdatetime_p.h
index 78484f30ed..7c7f7f2a6a 100644
--- a/src/corelib/tools/qdatetime_p.h
+++ b/src/corelib/tools/qdatetime_p.h
@@ -111,6 +111,9 @@ public:
m_status(other.m_status)
{}
+ // ### XXX: when the tooling situation improves, look at fixing the padding.
+ // 4 bytes padding
+
qint64 m_msecs;
Qt::TimeSpec m_spec;
int m_offsetFromUtc;
diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp
index a3dd4d9a60..e6fb531d7d 100644
--- a/src/corelib/tools/qeasingcurve.cpp
+++ b/src/corelib/tools/qeasingcurve.cpp
@@ -347,9 +347,7 @@ typedef QVector<TCBPoint> TCBPoints;
class QEasingCurveFunction
{
public:
- enum Type { In, Out, InOut, OutIn };
-
- QEasingCurveFunction(QEasingCurveFunction::Type type = In, qreal period = 0.3, qreal amplitude = 1.0,
+ QEasingCurveFunction(QEasingCurve::Type type, qreal period = 0.3, qreal amplitude = 1.0,
qreal overshoot = 1.70158)
: _t(type), _p(period), _a(amplitude), _o(overshoot)
{ }
@@ -358,7 +356,7 @@ public:
virtual QEasingCurveFunction *copy() const;
bool operator==(const QEasingCurveFunction &other) const;
- Type _t;
+ QEasingCurve::Type _t;
qreal _p;
qreal _a;
qreal _o;
@@ -367,9 +365,12 @@ public:
};
+static QEasingCurve::EasingFunction curveToFunc(QEasingCurve::Type curve);
+
qreal QEasingCurveFunction::value(qreal t)
{
- return t;
+ QEasingCurve::EasingFunction func = curveToFunc(_t);
+ return func(t);
}
QEasingCurveFunction *QEasingCurveFunction::copy() const
@@ -430,8 +431,8 @@ struct BezierEase : public QEasingCurveFunction
bool _init;
bool _valid;
- BezierEase()
- : QEasingCurveFunction(InOut), _curves(10), _intervals(10), _init(false), _valid(false)
+ BezierEase(QEasingCurve::Type type = QEasingCurve::BezierSpline)
+ : QEasingCurveFunction(type), _curves(10), _intervals(10), _init(false), _valid(false)
{ }
void init()
@@ -488,7 +489,7 @@ struct BezierEase : public QEasingCurveFunction
}
}
- QEasingCurveFunction *copy() const
+ QEasingCurveFunction *copy() const Q_DECL_OVERRIDE
{
BezierEase *rv = new BezierEase();
rv->_t = _t;
@@ -524,7 +525,7 @@ struct BezierEase : public QEasingCurveFunction
return newT;
}
- qreal value(qreal x)
+ qreal value(qreal x) Q_DECL_OVERRIDE
{
Q_ASSERT(_bezierCurves.count() % 3 == 0);
@@ -814,7 +815,11 @@ struct BezierEase : public QEasingCurveFunction
struct TCBEase : public BezierEase
{
- qreal value(qreal x)
+ TCBEase()
+ : BezierEase(QEasingCurve::TCBSpline)
+ { }
+
+ qreal value(qreal x) Q_DECL_OVERRIDE
{
Q_ASSERT(_bezierCurves.count() % 3 == 0);
@@ -830,11 +835,11 @@ struct TCBEase : public BezierEase
struct ElasticEase : public QEasingCurveFunction
{
- ElasticEase(Type type)
+ ElasticEase(QEasingCurve::Type type)
: QEasingCurveFunction(type, qreal(0.3), qreal(1.0))
{ }
- QEasingCurveFunction *copy() const
+ QEasingCurveFunction *copy() const Q_DECL_OVERRIDE
{
ElasticEase *rv = new ElasticEase(_t);
rv->_p = _p;
@@ -844,18 +849,18 @@ struct ElasticEase : public QEasingCurveFunction
return rv;
}
- qreal value(qreal t)
+ qreal value(qreal t) Q_DECL_OVERRIDE
{
qreal p = (_p < 0) ? qreal(0.3) : _p;
qreal a = (_a < 0) ? qreal(1.0) : _a;
switch(_t) {
- case In:
+ case QEasingCurve::InElastic:
return easeInElastic(t, a, p);
- case Out:
+ case QEasingCurve::OutElastic:
return easeOutElastic(t, a, p);
- case InOut:
+ case QEasingCurve::InOutElastic:
return easeInOutElastic(t, a, p);
- case OutIn:
+ case QEasingCurve::OutInElastic:
return easeOutInElastic(t, a, p);
default:
return t;
@@ -865,11 +870,11 @@ struct ElasticEase : public QEasingCurveFunction
struct BounceEase : public QEasingCurveFunction
{
- BounceEase(Type type)
+ BounceEase(QEasingCurve::Type type)
: QEasingCurveFunction(type, qreal(0.3), qreal(1.0))
{ }
- QEasingCurveFunction *copy() const
+ QEasingCurveFunction *copy() const Q_DECL_OVERRIDE
{
BounceEase *rv = new BounceEase(_t);
rv->_a = _a;
@@ -878,17 +883,17 @@ struct BounceEase : public QEasingCurveFunction
return rv;
}
- qreal value(qreal t)
+ qreal value(qreal t) Q_DECL_OVERRIDE
{
qreal a = (_a < 0) ? qreal(1.0) : _a;
switch(_t) {
- case In:
+ case QEasingCurve::InBounce:
return easeInBounce(t, a);
- case Out:
+ case QEasingCurve::OutBounce:
return easeOutBounce(t, a);
- case InOut:
+ case QEasingCurve::InOutBounce:
return easeInOutBounce(t, a);
- case OutIn:
+ case QEasingCurve::OutInBounce:
return easeOutInBounce(t, a);
default:
return t;
@@ -898,11 +903,11 @@ struct BounceEase : public QEasingCurveFunction
struct BackEase : public QEasingCurveFunction
{
- BackEase(Type type)
+ BackEase(QEasingCurve::Type type)
: QEasingCurveFunction(type, qreal(0.3), qreal(1.0), qreal(1.70158))
{ }
- QEasingCurveFunction *copy() const
+ QEasingCurveFunction *copy() const Q_DECL_OVERRIDE
{
BackEase *rv = new BackEase(_t);
rv->_o = _o;
@@ -911,17 +916,17 @@ struct BackEase : public QEasingCurveFunction
return rv;
}
- qreal value(qreal t)
+ qreal value(qreal t) Q_DECL_OVERRIDE
{
qreal o = (_o < 0) ? qreal(1.70158) : _o;
switch(_t) {
- case In:
+ case QEasingCurve::InBack:
return easeInBack(t, o);
- case Out:
+ case QEasingCurve::OutBack:
return easeOutBack(t, o);
- case InOut:
+ case QEasingCurve::InOutBack:
return easeInOutBack(t, o);
- case OutIn:
+ case QEasingCurve::OutInBack:
return easeOutInBack(t, o);
default:
return t;
@@ -1006,55 +1011,31 @@ static QEasingCurve::EasingFunction curveToFunc(QEasingCurve::Type curve)
static QEasingCurveFunction *curveToFunctionObject(QEasingCurve::Type type)
{
- QEasingCurveFunction *curveFunc = 0;
switch(type) {
case QEasingCurve::InElastic:
- curveFunc = new ElasticEase(ElasticEase::In);
- break;
case QEasingCurve::OutElastic:
- curveFunc = new ElasticEase(ElasticEase::Out);
- break;
case QEasingCurve::InOutElastic:
- curveFunc = new ElasticEase(ElasticEase::InOut);
- break;
case QEasingCurve::OutInElastic:
- curveFunc = new ElasticEase(ElasticEase::OutIn);
- break;
+ return new ElasticEase(type);
case QEasingCurve::OutBounce:
- curveFunc = new BounceEase(BounceEase::Out);
- break;
case QEasingCurve::InBounce:
- curveFunc = new BounceEase(BounceEase::In);
- break;
case QEasingCurve::OutInBounce:
- curveFunc = new BounceEase(BounceEase::OutIn);
- break;
case QEasingCurve::InOutBounce:
- curveFunc = new BounceEase(BounceEase::InOut);
- break;
+ return new BounceEase(type);
case QEasingCurve::InBack:
- curveFunc = new BackEase(BackEase::In);
- break;
case QEasingCurve::OutBack:
- curveFunc = new BackEase(BackEase::Out);
- break;
case QEasingCurve::InOutBack:
- curveFunc = new BackEase(BackEase::InOut);
- break;
case QEasingCurve::OutInBack:
- curveFunc = new BackEase(BackEase::OutIn);
- break;
+ return new BackEase(type);
case QEasingCurve::BezierSpline:
- curveFunc = new BezierEase();
- break;
+ return new BezierEase;
case QEasingCurve::TCBSpline:
- curveFunc = new TCBEase();
- break;
+ return new TCBEase;
default:
- curveFunc = new QEasingCurveFunction(QEasingCurveFunction::In, qreal(0.3), qreal(1.0), qreal(1.70158));
+ return new QEasingCurveFunction(type, qreal(0.3), qreal(1.0), qreal(1.70158));
}
- return curveFunc;
+ return 0;
}
/*!
diff --git a/src/corelib/tools/qelapsedtimer_generic.cpp b/src/corelib/tools/qelapsedtimer_generic.cpp
index f1f17b7fe5..734f693072 100644
--- a/src/corelib/tools/qelapsedtimer_generic.cpp
+++ b/src/corelib/tools/qelapsedtimer_generic.cpp
@@ -134,6 +134,10 @@ qint64 QElapsedTimer::elapsed() const Q_DECL_NOTHROW
number of milliseconds since January 1st, 1970 at 0:00 UTC (that is, it
is the Unix time expressed in milliseconds).
+ On Linux, Windows and OS X/iOS systems, this value is usually the time
+ since the system boot, though it usually does not include the time the
+ system has spent in sleep states.
+
\sa clockType(), elapsed()
*/
qint64 QElapsedTimer::msecsSinceReference() const Q_DECL_NOTHROW
diff --git a/src/corelib/tools/qelapsedtimer_unix.cpp b/src/corelib/tools/qelapsedtimer_unix.cpp
index d29447fa03..922aa487d7 100644
--- a/src/corelib/tools/qelapsedtimer_unix.cpp
+++ b/src/corelib/tools/qelapsedtimer_unix.cpp
@@ -140,11 +140,6 @@ static int unixCheckClockType()
#endif
}
-static inline qint64 fractionAdjustment()
-{
- return 1000*1000ull;
-}
-
bool QElapsedTimer::isMonotonic() Q_DECL_NOTHROW
{
return clockType() == MonotonicClock;
@@ -196,7 +191,7 @@ static qint64 elapsedAndRestart(qint64 sec, qint64 frac,
do_gettime(nowsec, nowfrac);
sec = *nowsec - sec;
frac = *nowfrac - frac;
- return sec * Q_INT64_C(1000) + frac / fractionAdjustment();
+ return (sec * Q_INT64_C(1000000000) + frac) / Q_INT64_C(1000000);
}
void QElapsedTimer::start() Q_DECL_NOTHROW
@@ -220,20 +215,19 @@ qint64 QElapsedTimer::nsecsElapsed() const Q_DECL_NOTHROW
qint64 QElapsedTimer::elapsed() const Q_DECL_NOTHROW
{
- qint64 sec, frac;
- return elapsedAndRestart(t1, t2, &sec, &frac);
+ return nsecsElapsed() / Q_INT64_C(1000000);
}
qint64 QElapsedTimer::msecsSinceReference() const Q_DECL_NOTHROW
{
- return t1 * Q_INT64_C(1000) + t2 / fractionAdjustment();
+ return t1 * Q_INT64_C(1000) + t2 / Q_INT64_C(1000000);
}
qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW
{
qint64 secs = other.t1 - t1;
qint64 fraction = other.t2 - t2;
- return secs * Q_INT64_C(1000) + fraction / fractionAdjustment();
+ return (secs * Q_INT64_C(1000000000) + fraction) / Q_INT64_C(1000000);
}
qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index fe8c52d103..6a08576f7e 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -259,9 +259,7 @@ static uint qt_create_qhash_seed()
quintptr seedPtr = reinterpret_cast<quintptr>(&seed);
seed ^= seedPtr;
-#if QT_POINTER_SIZE == 8
- seed ^= (seedPtr >> 32);
-#endif
+ seed ^= (qulonglong(seedPtr) >> 32); // no-op on 32-bit platforms
#endif // QT_BOOTSTRAPPED
return seed;
@@ -2227,12 +2225,6 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
*/
/*!
- \fn bool QMultiHash::contains(const Key &key) const
- \overload
- \sa QHash::contains()
-*/
-
-/*!
\fn int QMultiHash::remove(const Key &key, const T &value)
\since 4.3
@@ -2243,12 +2235,6 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
*/
/*!
- \fn int QMultiHash::remove(const Key &key)
- \overload
- \sa QHash::remove()
-*/
-
-/*!
\fn int QMultiHash::count(const Key &key, const T &value) const
\since 4.3
@@ -2258,18 +2244,6 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
*/
/*!
- \fn int QMultiHash::count(const Key &key) const
- \overload
- \sa QHash::count()
-*/
-
-/*!
- \fn int QMultiHash::count() const
- \overload
- \sa QHash::count()
-*/
-
-/*!
\fn typename QHash<Key, T>::iterator QMultiHash::find(const Key &key, const T &value)
\since 4.3
@@ -2283,24 +2257,12 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
*/
/*!
- \fn typename QHash<Key, T>::iterator QMultiHash::find(const Key &key)
- \overload
- \sa QHash::find()
-*/
-
-/*!
\fn typename QHash<Key, T>::const_iterator QMultiHash::find(const Key &key, const T &value) const
\since 4.3
\overload
*/
/*!
- \fn typename QHash<Key, T>::const_iterator QMultiHash::find(const Key &key) const
- \overload
- \sa QHash::find()
-*/
-
-/*!
\fn typename QHash<Key, T>::const_iterator QMultiHash::constFind(const Key &key, const T &value) const
\since 4.3
@@ -2313,10 +2275,4 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
\sa QHash::constFind()
*/
-/*!
- \fn typename QHash<Key, T>::const_iterator QMultiHash::constFind(const Key &key) const
- \overload
- \sa QHash::constFind()
-*/
-
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 59a5251c50..771e81c8f4 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -977,7 +977,7 @@ public:
inline QMultiHash operator+(const QMultiHash &other) const
{ QMultiHash result = *this; result += other; return result; }
-#if !defined(Q_NO_USING_KEYWORD) && !defined(Q_CC_RVCT)
+#if !defined(Q_CC_RVCT)
// RVCT compiler doesn't handle using-keyword right when used functions are overloaded in child class
using QHash<Key, T>::contains;
using QHash<Key, T>::remove;
diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp
index fe5e0f33b4..b91fd38a5f 100644
--- a/src/corelib/tools/qlist.cpp
+++ b/src/corelib/tools/qlist.cpp
@@ -55,6 +55,8 @@ const QListData::Data QListData::shared_null = { Q_REFCOUNT_INITIALIZE_STATIC, 0
static int grow(int size)
{
+ if (size_t(size) > (MaxAllocSize - QListData::DataHeaderSize) / sizeof(void *))
+ qBadAlloc();
// dear compiler: don't optimize me out.
volatile int x = qAllocMore(size * sizeof(void *), QListData::DataHeaderSize) / sizeof(void *);
return x;
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index e33be9a2f1..533f1d6dbc 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -628,9 +628,7 @@ inline void QList<T>::swap(int i, int j)
Q_ASSERT_X(i >= 0 && i < p.size() && j >= 0 && j < p.size(),
"QList<T>::swap", "index out of range");
detach();
- void *t = d->array[d->begin + i];
- d->array[d->begin + i] = d->array[d->begin + j];
- d->array[d->begin + j] = t;
+ std::swap(d->array[d->begin + i], d->array[d->begin + j]);
}
template <typename T>
@@ -773,11 +771,10 @@ Q_OUTOFLINE_TEMPLATE bool QList<T>::operator==(const QList<T> &l) const
return true;
if (p.size() != l.p.size())
return false;
- Node *i = reinterpret_cast<Node *>(p.end());
- Node *b = reinterpret_cast<Node *>(p.begin());
- Node *li = reinterpret_cast<Node *>(l.p.end());
- while (i != b) {
- --i; --li;
+ Node *i = reinterpret_cast<Node *>(p.begin());
+ Node *e = reinterpret_cast<Node *>(p.end());
+ Node *li = reinterpret_cast<Node *>(l.p.begin());
+ for (; i != e; ++i, ++li) {
if (!(i->t() == li->t()))
return false;
}
@@ -925,9 +922,9 @@ Q_OUTOFLINE_TEMPLATE int QList<T>::lastIndexOf(const T &t, int from) const
template <typename T>
Q_OUTOFLINE_TEMPLATE bool QList<T>::contains(const T &t) const
{
- Node *b = reinterpret_cast<Node *>(p.begin());
- Node *i = reinterpret_cast<Node *>(p.end());
- while (i-- != b)
+ Node *e = reinterpret_cast<Node *>(p.end());
+ Node *i = reinterpret_cast<Node *>(p.begin());
+ for (; i != e; ++i)
if (i->t() == t)
return true;
return false;
@@ -937,9 +934,9 @@ template <typename T>
Q_OUTOFLINE_TEMPLATE int QList<T>::count(const T &t) const
{
int c = 0;
- Node *b = reinterpret_cast<Node *>(p.begin());
- Node *i = reinterpret_cast<Node *>(p.end());
- while (i-- != b)
+ Node *e = reinterpret_cast<Node *>(p.end());
+ Node *i = reinterpret_cast<Node *>(p.begin());
+ for (; i != e; ++i)
if (i->t() == t)
++c;
return c;
diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp
index 38b4c0ad7e..ef5fbac377 100644
--- a/src/corelib/tools/qmap.cpp
+++ b/src/corelib/tools/qmap.cpp
@@ -1798,12 +1798,6 @@ void QMapDataBase::freeData(QMapDataBase *d)
*/
/*!
- \fn bool QMultiMap::contains(const Key &key) const
- \overload
- \sa QMap::contains()
-*/
-
-/*!
\fn int QMultiMap::remove(const Key &key, const T &value)
\since 4.3
@@ -1814,12 +1808,6 @@ void QMapDataBase::freeData(QMapDataBase *d)
*/
/*!
- \fn int QMultiMap::remove(const Key &key)
- \overload
- \sa QMap::remove()
-*/
-
-/*!
\fn int QMultiMap::count(const Key &key, const T &value) const
\since 4.3
@@ -1829,18 +1817,6 @@ void QMapDataBase::freeData(QMapDataBase *d)
*/
/*!
- \fn int QMultiMap::count(const Key &key) const
- \overload
- \sa QMap::count()
-*/
-
-/*!
- \fn int QMultiMap::count() const
- \overload
- \sa QMap::count()
-*/
-
-/*!
\fn typename QMap<Key, T>::iterator QMultiMap::find(const Key &key, const T &value)
\since 4.3
@@ -1857,12 +1833,6 @@ void QMapDataBase::freeData(QMapDataBase *d)
*/
/*!
- \fn typename QMap<Key, T>::iterator QMultiMap::find(const Key &key)
- \overload
- \sa QMap::find()
-*/
-
-/*!
\fn typename QMap<Key, T>::const_iterator QMultiMap::find(const Key &key, const T &value) const
\since 4.3
\overload
@@ -1880,13 +1850,6 @@ void QMapDataBase::freeData(QMapDataBase *d)
*/
/*!
- \fn typename QMap<Key, T>::const_iterator QMultiMap::find(const Key &key) const
- \since 4.3
- \overload
- \sa QMap::find()
-*/
-
-/*!
\fn typename QMap<Key, T>::const_iterator QMultiMap::constFind(const Key &key, const T &value) const
\since 4.3
@@ -1899,10 +1862,4 @@ void QMapDataBase::freeData(QMapDataBase *d)
\sa QMap::constFind()
*/
-/*!
- \fn typename QMap<Key, T>::const_iterator QMultiMap::constFind(const Key &key) const
- \overload
- \sa QMap::constFind()
-*/
-
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h
index a776e2eb4d..ce550c540b 100644
--- a/src/corelib/tools/qmap.h
+++ b/src/corelib/tools/qmap.h
@@ -1157,7 +1157,7 @@ public:
inline QMultiMap operator+(const QMultiMap &other) const
{ QMultiMap result = *this; result += other; return result; }
-#if !defined(Q_NO_USING_KEYWORD) && !defined(Q_CC_RVCT)
+#if !defined(Q_CC_RVCT)
// RVCT compiler doesn't handle using-keyword right when used functions are overloaded in child class
using QMap<Key, T>::contains;
using QMap<Key, T>::remove;
diff --git a/src/corelib/tools/qmargins.h b/src/corelib/tools/qmargins.h
index 33a2766345..400f0f76df 100644
--- a/src/corelib/tools/qmargins.h
+++ b/src/corelib/tools/qmargins.h
@@ -55,19 +55,19 @@ public:
Q_DECL_CONSTEXPR int right() const;
Q_DECL_CONSTEXPR int bottom() const;
- void setLeft(int left);
- void setTop(int top);
- void setRight(int right);
- void setBottom(int bottom);
-
- QMargins &operator+=(const QMargins &margins);
- QMargins &operator-=(const QMargins &margins);
- QMargins &operator+=(int);
- QMargins &operator-=(int);
- QMargins &operator*=(int);
- QMargins &operator/=(int);
- QMargins &operator*=(qreal);
- QMargins &operator/=(qreal);
+ Q_DECL_RELAXED_CONSTEXPR void setLeft(int left);
+ Q_DECL_RELAXED_CONSTEXPR void setTop(int top);
+ Q_DECL_RELAXED_CONSTEXPR void setRight(int right);
+ Q_DECL_RELAXED_CONSTEXPR void setBottom(int bottom);
+
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator+=(const QMargins &margins);
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator-=(const QMargins &margins);
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator+=(int);
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator-=(int);
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator*=(int);
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator/=(int);
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator*=(qreal);
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator/=(qreal);
private:
int m_left;
@@ -114,16 +114,16 @@ Q_DECL_CONSTEXPR inline int QMargins::bottom() const
{ return m_bottom; }
-inline void QMargins::setLeft(int aleft)
+Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setLeft(int aleft)
{ m_left = aleft; }
-inline void QMargins::setTop(int atop)
+Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setTop(int atop)
{ m_top = atop; }
-inline void QMargins::setRight(int aright)
+Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setRight(int aright)
{ m_right = aright; }
-inline void QMargins::setBottom(int abottom)
+Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setBottom(int abottom)
{ m_bottom = abottom; }
Q_DECL_CONSTEXPR inline bool operator==(const QMargins &m1, const QMargins &m2)
@@ -210,17 +210,17 @@ Q_DECL_CONSTEXPR inline QMargins operator/(const QMargins &margins, qreal diviso
qRound(margins.right() / divisor), qRound(margins.bottom() / divisor));
}
-inline QMargins &QMargins::operator+=(const QMargins &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator+=(const QMargins &margins)
{
return *this = *this + margins;
}
-inline QMargins &QMargins::operator-=(const QMargins &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator-=(const QMargins &margins)
{
return *this = *this - margins;
}
-inline QMargins &QMargins::operator+=(int margin)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator+=(int margin)
{
m_left += margin;
m_top += margin;
@@ -229,7 +229,7 @@ inline QMargins &QMargins::operator+=(int margin)
return *this;
}
-inline QMargins &QMargins::operator-=(int margin)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator-=(int margin)
{
m_left -= margin;
m_top -= margin;
@@ -238,22 +238,22 @@ inline QMargins &QMargins::operator-=(int margin)
return *this;
}
-inline QMargins &QMargins::operator*=(int factor)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator*=(int factor)
{
return *this = *this * factor;
}
-inline QMargins &QMargins::operator/=(int divisor)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator/=(int divisor)
{
return *this = *this / divisor;
}
-inline QMargins &QMargins::operator*=(qreal factor)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator*=(qreal factor)
{
return *this = *this * factor;
}
-inline QMargins &QMargins::operator/=(qreal divisor)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator/=(qreal divisor)
{
return *this = *this / divisor;
}
@@ -290,17 +290,17 @@ public:
Q_DECL_CONSTEXPR qreal right() const;
Q_DECL_CONSTEXPR qreal bottom() const;
- void setLeft(qreal left);
- void setTop(qreal top);
- void setRight(qreal right);
- void setBottom(qreal bottom);
+ Q_DECL_RELAXED_CONSTEXPR void setLeft(qreal left);
+ Q_DECL_RELAXED_CONSTEXPR void setTop(qreal top);
+ Q_DECL_RELAXED_CONSTEXPR void setRight(qreal right);
+ Q_DECL_RELAXED_CONSTEXPR void setBottom(qreal bottom);
- QMarginsF &operator+=(const QMarginsF &margins);
- QMarginsF &operator-=(const QMarginsF &margins);
- QMarginsF &operator+=(qreal addend);
- QMarginsF &operator-=(qreal subtrahend);
- QMarginsF &operator*=(qreal factor);
- QMarginsF &operator/=(qreal divisor);
+ Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator+=(const QMarginsF &margins);
+ Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator-=(const QMarginsF &margins);
+ Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator+=(qreal addend);
+ Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator-=(qreal subtrahend);
+ Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator*=(qreal factor);
+ Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator/=(qreal divisor);
Q_DECL_CONSTEXPR inline QMargins toMargins() const;
@@ -350,16 +350,16 @@ Q_DECL_CONSTEXPR inline qreal QMarginsF::bottom() const
{ return m_bottom; }
-inline void QMarginsF::setLeft(qreal aleft)
+Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setLeft(qreal aleft)
{ m_left = aleft; }
-inline void QMarginsF::setTop(qreal atop)
+Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setTop(qreal atop)
{ m_top = atop; }
-inline void QMarginsF::setRight(qreal aright)
+Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setRight(qreal aright)
{ m_right = aright; }
-inline void QMarginsF::setBottom(qreal abottom)
+Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setBottom(qreal abottom)
{ m_bottom = abottom; }
Q_DECL_CONSTEXPR inline bool operator==(const QMarginsF &lhs, const QMarginsF &rhs)
@@ -423,17 +423,17 @@ Q_DECL_CONSTEXPR inline QMarginsF operator/(const QMarginsF &lhs, qreal divisor)
lhs.right() / divisor, lhs.bottom() / divisor);
}
-inline QMarginsF &QMarginsF::operator+=(const QMarginsF &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator+=(const QMarginsF &margins)
{
return *this = *this + margins;
}
-inline QMarginsF &QMarginsF::operator-=(const QMarginsF &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator-=(const QMarginsF &margins)
{
return *this = *this - margins;
}
-inline QMarginsF &QMarginsF::operator+=(qreal addend)
+Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator+=(qreal addend)
{
m_left += addend;
m_top += addend;
@@ -442,7 +442,7 @@ inline QMarginsF &QMarginsF::operator+=(qreal addend)
return *this;
}
-inline QMarginsF &QMarginsF::operator-=(qreal subtrahend)
+Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator-=(qreal subtrahend)
{
m_left -= subtrahend;
m_top -= subtrahend;
@@ -451,12 +451,12 @@ inline QMarginsF &QMarginsF::operator-=(qreal subtrahend)
return *this;
}
-inline QMarginsF &QMarginsF::operator*=(qreal factor)
+Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator*=(qreal factor)
{
return *this = *this * factor;
}
-inline QMarginsF &QMarginsF::operator/=(qreal divisor)
+Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator/=(qreal divisor)
{
return *this = *this / divisor;
}
diff --git a/src/corelib/tools/qpair.h b/src/corelib/tools/qpair.h
index b2217e4dd0..ae33d598d4 100644
--- a/src/corelib/tools/qpair.h
+++ b/src/corelib/tools/qpair.h
@@ -52,13 +52,13 @@ struct QPair
template <typename TT1, typename TT2>
Q_DECL_CONSTEXPR QPair(const QPair<TT1, TT2> &p) : first(p.first), second(p.second) {}
template <typename TT1, typename TT2>
- QPair &operator=(const QPair<TT1, TT2> &p)
+ Q_DECL_RELAXED_CONSTEXPR QPair &operator=(const QPair<TT1, TT2> &p)
{ first = p.first; second = p.second; return *this; }
#ifdef Q_COMPILER_RVALUE_REFS
template <typename TT1, typename TT2>
Q_DECL_CONSTEXPR QPair(QPair<TT1, TT2> &&p) : first(std::move(p.first)), second(std::move(p.second)) {}
template <typename TT1, typename TT2>
- QPair &operator=(QPair<TT1, TT2> &&p)
+ Q_DECL_RELAXED_CONSTEXPR QPair &operator=(QPair<TT1, TT2> &&p)
{ first = std::move(p.first); second = std::move(p.second); return *this; }
#endif
diff --git a/src/corelib/tools/qpoint.h b/src/corelib/tools/qpoint.h
index 5cf97b9052..70474b6d59 100644
--- a/src/corelib/tools/qpoint.h
+++ b/src/corelib/tools/qpoint.h
@@ -49,22 +49,22 @@ public:
Q_DECL_CONSTEXPR inline int x() const;
Q_DECL_CONSTEXPR inline int y() const;
- inline void setX(int x);
- inline void setY(int y);
+ Q_DECL_RELAXED_CONSTEXPR inline void setX(int x);
+ Q_DECL_RELAXED_CONSTEXPR inline void setY(int y);
Q_DECL_CONSTEXPR inline int manhattanLength() const;
- inline int &rx();
- inline int &ry();
+ Q_DECL_RELAXED_CONSTEXPR inline int &rx();
+ Q_DECL_RELAXED_CONSTEXPR inline int &ry();
- inline QPoint &operator+=(const QPoint &p);
- inline QPoint &operator-=(const QPoint &p);
+ Q_DECL_RELAXED_CONSTEXPR inline QPoint &operator+=(const QPoint &p);
+ Q_DECL_RELAXED_CONSTEXPR inline QPoint &operator-=(const QPoint &p);
- inline QPoint &operator*=(float factor);
- inline QPoint &operator*=(double factor);
- inline QPoint &operator*=(int factor);
+ Q_DECL_RELAXED_CONSTEXPR inline QPoint &operator*=(float factor);
+ Q_DECL_RELAXED_CONSTEXPR inline QPoint &operator*=(double factor);
+ Q_DECL_RELAXED_CONSTEXPR inline QPoint &operator*=(int factor);
- inline QPoint &operator/=(qreal divisor);
+ Q_DECL_RELAXED_CONSTEXPR inline QPoint &operator/=(qreal divisor);
Q_DECL_CONSTEXPR static inline int dotProduct(const QPoint &p1, const QPoint &p2)
{ return p1.xp * p2.xp + p1.yp * p2.yp; }
@@ -116,34 +116,34 @@ Q_DECL_CONSTEXPR inline int QPoint::x() const
Q_DECL_CONSTEXPR inline int QPoint::y() const
{ return yp; }
-inline void QPoint::setX(int xpos)
+Q_DECL_RELAXED_CONSTEXPR inline void QPoint::setX(int xpos)
{ xp = xpos; }
-inline void QPoint::setY(int ypos)
+Q_DECL_RELAXED_CONSTEXPR inline void QPoint::setY(int ypos)
{ yp = ypos; }
inline int Q_DECL_CONSTEXPR QPoint::manhattanLength() const
{ return qAbs(x())+qAbs(y()); }
-inline int &QPoint::rx()
+Q_DECL_RELAXED_CONSTEXPR inline int &QPoint::rx()
{ return xp; }
-inline int &QPoint::ry()
+Q_DECL_RELAXED_CONSTEXPR inline int &QPoint::ry()
{ return yp; }
-inline QPoint &QPoint::operator+=(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline QPoint &QPoint::operator+=(const QPoint &p)
{ xp+=p.xp; yp+=p.yp; return *this; }
-inline QPoint &QPoint::operator-=(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline QPoint &QPoint::operator-=(const QPoint &p)
{ xp-=p.xp; yp-=p.yp; return *this; }
-inline QPoint &QPoint::operator*=(float factor)
+Q_DECL_RELAXED_CONSTEXPR inline QPoint &QPoint::operator*=(float factor)
{ xp = qRound(xp*factor); yp = qRound(yp*factor); return *this; }
-inline QPoint &QPoint::operator*=(double factor)
+Q_DECL_RELAXED_CONSTEXPR inline QPoint &QPoint::operator*=(double factor)
{ xp = qRound(xp*factor); yp = qRound(yp*factor); return *this; }
-inline QPoint &QPoint::operator*=(int factor)
+Q_DECL_RELAXED_CONSTEXPR inline QPoint &QPoint::operator*=(int factor)
{ xp = xp*factor; yp = yp*factor; return *this; }
Q_DECL_CONSTEXPR inline bool operator==(const QPoint &p1, const QPoint &p2)
@@ -182,7 +182,7 @@ Q_DECL_CONSTEXPR inline const QPoint operator+(const QPoint &p)
Q_DECL_CONSTEXPR inline const QPoint operator-(const QPoint &p)
{ return QPoint(-p.xp, -p.yp); }
-inline QPoint &QPoint::operator/=(qreal c)
+Q_DECL_RELAXED_CONSTEXPR inline QPoint &QPoint::operator/=(qreal c)
{
xp = qRound(xp/c);
yp = qRound(yp/c);
@@ -215,16 +215,16 @@ public:
Q_DECL_CONSTEXPR inline qreal x() const;
Q_DECL_CONSTEXPR inline qreal y() const;
- inline void setX(qreal x);
- inline void setY(qreal y);
+ Q_DECL_RELAXED_CONSTEXPR inline void setX(qreal x);
+ Q_DECL_RELAXED_CONSTEXPR inline void setY(qreal y);
- inline qreal &rx();
- inline qreal &ry();
+ Q_DECL_RELAXED_CONSTEXPR inline qreal &rx();
+ Q_DECL_RELAXED_CONSTEXPR inline qreal &ry();
- inline QPointF &operator+=(const QPointF &p);
- inline QPointF &operator-=(const QPointF &p);
- inline QPointF &operator*=(qreal c);
- inline QPointF &operator/=(qreal c);
+ Q_DECL_RELAXED_CONSTEXPR inline QPointF &operator+=(const QPointF &p);
+ Q_DECL_RELAXED_CONSTEXPR inline QPointF &operator-=(const QPointF &p);
+ Q_DECL_RELAXED_CONSTEXPR inline QPointF &operator*=(qreal c);
+ Q_DECL_RELAXED_CONSTEXPR inline QPointF &operator/=(qreal c);
Q_DECL_CONSTEXPR static inline qreal dotProduct(const QPointF &p1, const QPointF &p2)
{ return p1.xp * p2.xp + p1.yp * p2.yp; }
@@ -289,39 +289,39 @@ Q_DECL_CONSTEXPR inline qreal QPointF::y() const
return yp;
}
-inline void QPointF::setX(qreal xpos)
+Q_DECL_RELAXED_CONSTEXPR inline void QPointF::setX(qreal xpos)
{
xp = xpos;
}
-inline void QPointF::setY(qreal ypos)
+Q_DECL_RELAXED_CONSTEXPR inline void QPointF::setY(qreal ypos)
{
yp = ypos;
}
-inline qreal &QPointF::rx()
+Q_DECL_RELAXED_CONSTEXPR inline qreal &QPointF::rx()
{
return xp;
}
-inline qreal &QPointF::ry()
+Q_DECL_RELAXED_CONSTEXPR inline qreal &QPointF::ry()
{
return yp;
}
-inline QPointF &QPointF::operator+=(const QPointF &p)
+Q_DECL_RELAXED_CONSTEXPR inline QPointF &QPointF::operator+=(const QPointF &p)
{
xp+=p.xp;
yp+=p.yp;
return *this;
}
-inline QPointF &QPointF::operator-=(const QPointF &p)
+Q_DECL_RELAXED_CONSTEXPR inline QPointF &QPointF::operator-=(const QPointF &p)
{
xp-=p.xp; yp-=p.yp; return *this;
}
-inline QPointF &QPointF::operator*=(qreal c)
+Q_DECL_RELAXED_CONSTEXPR inline QPointF &QPointF::operator*=(qreal c)
{
xp*=c; yp*=c; return *this;
}
@@ -366,7 +366,7 @@ Q_DECL_CONSTEXPR inline const QPointF operator-(const QPointF &p)
return QPointF(-p.xp, -p.yp);
}
-inline QPointF &QPointF::operator/=(qreal divisor)
+Q_DECL_RELAXED_CONSTEXPR inline QPointF &QPointF::operator/=(qreal divisor)
{
xp/=divisor;
yp/=divisor;
diff --git a/src/corelib/tools/qrect.h b/src/corelib/tools/qrect.h
index b5be5724af..9b86a9f8fc 100644
--- a/src/corelib/tools/qrect.h
+++ b/src/corelib/tools/qrect.h
@@ -64,17 +64,17 @@ public:
Q_DECL_CONSTEXPR inline int x() const;
Q_DECL_CONSTEXPR inline int y() const;
- inline void setLeft(int pos);
- inline void setTop(int pos);
- inline void setRight(int pos);
- inline void setBottom(int pos);
- inline void setX(int x);
- inline void setY(int y);
-
- inline void setTopLeft(const QPoint &p);
- inline void setBottomRight(const QPoint &p);
- inline void setTopRight(const QPoint &p);
- inline void setBottomLeft(const QPoint &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void setLeft(int pos);
+ Q_DECL_RELAXED_CONSTEXPR inline void setTop(int pos);
+ Q_DECL_RELAXED_CONSTEXPR inline void setRight(int pos);
+ Q_DECL_RELAXED_CONSTEXPR inline void setBottom(int pos);
+ Q_DECL_RELAXED_CONSTEXPR inline void setX(int x);
+ Q_DECL_RELAXED_CONSTEXPR inline void setY(int y);
+
+ Q_DECL_RELAXED_CONSTEXPR inline void setTopLeft(const QPoint &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void setBottomRight(const QPoint &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void setTopRight(const QPoint &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void setBottomLeft(const QPoint &p);
Q_DECL_CONSTEXPR inline QPoint topLeft() const;
Q_DECL_CONSTEXPR inline QPoint bottomRight() const;
@@ -82,39 +82,39 @@ public:
Q_DECL_CONSTEXPR inline QPoint bottomLeft() const;
Q_DECL_CONSTEXPR inline QPoint center() const;
- inline void moveLeft(int pos);
- inline void moveTop(int pos);
- inline void moveRight(int pos);
- inline void moveBottom(int pos);
- inline void moveTopLeft(const QPoint &p);
- inline void moveBottomRight(const QPoint &p);
- inline void moveTopRight(const QPoint &p);
- inline void moveBottomLeft(const QPoint &p);
- inline void moveCenter(const QPoint &p);
-
- inline void translate(int dx, int dy);
- inline void translate(const QPoint &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveLeft(int pos);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTop(int pos);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveRight(int pos);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveBottom(int pos);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTopLeft(const QPoint &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveBottomRight(const QPoint &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTopRight(const QPoint &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveBottomLeft(const QPoint &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveCenter(const QPoint &p);
+
+ Q_DECL_RELAXED_CONSTEXPR inline void translate(int dx, int dy);
+ Q_DECL_RELAXED_CONSTEXPR inline void translate(const QPoint &p);
Q_DECL_CONSTEXPR inline QRect translated(int dx, int dy) const Q_REQUIRED_RESULT;
Q_DECL_CONSTEXPR inline QRect translated(const QPoint &p) const Q_REQUIRED_RESULT;
- inline void moveTo(int x, int t);
- inline void moveTo(const QPoint &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTo(int x, int t);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTo(const QPoint &p);
- inline void setRect(int x, int y, int w, int h);
- inline void getRect(int *x, int *y, int *w, int *h) const;
+ Q_DECL_RELAXED_CONSTEXPR inline void setRect(int x, int y, int w, int h);
+ Q_DECL_RELAXED_CONSTEXPR inline void getRect(int *x, int *y, int *w, int *h) const;
- inline void setCoords(int x1, int y1, int x2, int y2);
- inline void getCoords(int *x1, int *y1, int *x2, int *y2) const;
+ Q_DECL_RELAXED_CONSTEXPR inline void setCoords(int x1, int y1, int x2, int y2);
+ Q_DECL_RELAXED_CONSTEXPR inline void getCoords(int *x1, int *y1, int *x2, int *y2) const;
- inline void adjust(int x1, int y1, int x2, int y2);
+ Q_DECL_RELAXED_CONSTEXPR inline void adjust(int x1, int y1, int x2, int y2);
Q_DECL_CONSTEXPR inline QRect adjusted(int x1, int y1, int x2, int y2) const Q_REQUIRED_RESULT;
Q_DECL_CONSTEXPR inline QSize size() const;
Q_DECL_CONSTEXPR inline int width() const;
Q_DECL_CONSTEXPR inline int height() const;
- inline void setWidth(int w);
- inline void setHeight(int h);
- inline void setSize(const QSize &s);
+ Q_DECL_RELAXED_CONSTEXPR inline void setWidth(int w);
+ Q_DECL_RELAXED_CONSTEXPR inline void setHeight(int h);
+ Q_DECL_RELAXED_CONSTEXPR inline void setSize(const QSize &s);
QRect operator|(const QRect &r) const;
QRect operator&(const QRect &r) const;
@@ -131,8 +131,8 @@ public:
Q_DECL_CONSTEXPR inline QRect marginsAdded(const QMargins &margins) const;
Q_DECL_CONSTEXPR inline QRect marginsRemoved(const QMargins &margins) const;
- inline QRect &operator+=(const QMargins &margins);
- inline QRect &operator-=(const QMargins &margins);
+ Q_DECL_RELAXED_CONSTEXPR inline QRect &operator+=(const QMargins &margins);
+ Q_DECL_RELAXED_CONSTEXPR inline QRect &operator-=(const QMargins &margins);
#if QT_DEPRECATED_SINCE(5, 0)
QT_DEPRECATED QRect unite(const QRect &r) const Q_REQUIRED_RESULT { return united(r); }
@@ -202,34 +202,34 @@ Q_DECL_CONSTEXPR inline int QRect::x() const
Q_DECL_CONSTEXPR inline int QRect::y() const
{ return y1; }
-inline void QRect::setLeft(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setLeft(int pos)
{ x1 = pos; }
-inline void QRect::setTop(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setTop(int pos)
{ y1 = pos; }
-inline void QRect::setRight(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setRight(int pos)
{ x2 = pos; }
-inline void QRect::setBottom(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setBottom(int pos)
{ y2 = pos; }
-inline void QRect::setTopLeft(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setTopLeft(const QPoint &p)
{ x1 = p.x(); y1 = p.y(); }
-inline void QRect::setBottomRight(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setBottomRight(const QPoint &p)
{ x2 = p.x(); y2 = p.y(); }
-inline void QRect::setTopRight(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setTopRight(const QPoint &p)
{ x2 = p.x(); y1 = p.y(); }
-inline void QRect::setBottomLeft(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setBottomLeft(const QPoint &p)
{ x1 = p.x(); y2 = p.y(); }
-inline void QRect::setX(int ax)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setX(int ax)
{ x1 = ax; }
-inline void QRect::setY(int ay)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setY(int ay)
{ y1 = ay; }
Q_DECL_CONSTEXPR inline QPoint QRect::topLeft() const
@@ -256,7 +256,7 @@ Q_DECL_CONSTEXPR inline int QRect::height() const
Q_DECL_CONSTEXPR inline QSize QRect::size() const
{ return QSize(width(), height()); }
-inline void QRect::translate(int dx, int dy)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::translate(int dx, int dy)
{
x1 += dx;
y1 += dy;
@@ -264,7 +264,7 @@ inline void QRect::translate(int dx, int dy)
y2 += dy;
}
-inline void QRect::translate(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::translate(const QPoint &p)
{
x1 += p.x();
y1 += p.y();
@@ -278,7 +278,7 @@ Q_DECL_CONSTEXPR inline QRect QRect::translated(int dx, int dy) const
Q_DECL_CONSTEXPR inline QRect QRect::translated(const QPoint &p) const
{ return QRect(QPoint(x1 + p.x(), y1 + p.y()), QPoint(x2 + p.x(), y2 + p.y())); }
-inline void QRect::moveTo(int ax, int ay)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTo(int ax, int ay)
{
x2 += ax - x1;
y2 += ay - y1;
@@ -286,7 +286,7 @@ inline void QRect::moveTo(int ax, int ay)
y1 = ay;
}
-inline void QRect::moveTo(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTo(const QPoint &p)
{
x2 += p.x() - x1;
y2 += p.y() - y1;
@@ -294,49 +294,49 @@ inline void QRect::moveTo(const QPoint &p)
y1 = p.y();
}
-inline void QRect::moveLeft(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveLeft(int pos)
{ x2 += (pos - x1); x1 = pos; }
-inline void QRect::moveTop(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTop(int pos)
{ y2 += (pos - y1); y1 = pos; }
-inline void QRect::moveRight(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveRight(int pos)
{
x1 += (pos - x2);
x2 = pos;
}
-inline void QRect::moveBottom(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveBottom(int pos)
{
y1 += (pos - y2);
y2 = pos;
}
-inline void QRect::moveTopLeft(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTopLeft(const QPoint &p)
{
moveLeft(p.x());
moveTop(p.y());
}
-inline void QRect::moveBottomRight(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveBottomRight(const QPoint &p)
{
moveRight(p.x());
moveBottom(p.y());
}
-inline void QRect::moveTopRight(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTopRight(const QPoint &p)
{
moveRight(p.x());
moveTop(p.y());
}
-inline void QRect::moveBottomLeft(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveBottomLeft(const QPoint &p)
{
moveLeft(p.x());
moveBottom(p.y());
}
-inline void QRect::moveCenter(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveCenter(const QPoint &p)
{
int w = x2 - x1;
int h = y2 - y1;
@@ -346,7 +346,7 @@ inline void QRect::moveCenter(const QPoint &p)
y2 = y1 + h;
}
-inline void QRect::getRect(int *ax, int *ay, int *aw, int *ah) const
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::getRect(int *ax, int *ay, int *aw, int *ah) const
{
*ax = x1;
*ay = y1;
@@ -354,7 +354,7 @@ inline void QRect::getRect(int *ax, int *ay, int *aw, int *ah) const
*ah = y2 - y1 + 1;
}
-inline void QRect::setRect(int ax, int ay, int aw, int ah)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setRect(int ax, int ay, int aw, int ah)
{
x1 = ax;
y1 = ay;
@@ -362,7 +362,7 @@ inline void QRect::setRect(int ax, int ay, int aw, int ah)
y2 = (ay + ah - 1);
}
-inline void QRect::getCoords(int *xp1, int *yp1, int *xp2, int *yp2) const
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::getCoords(int *xp1, int *yp1, int *xp2, int *yp2) const
{
*xp1 = x1;
*yp1 = y1;
@@ -370,7 +370,7 @@ inline void QRect::getCoords(int *xp1, int *yp1, int *xp2, int *yp2) const
*yp2 = y2;
}
-inline void QRect::setCoords(int xp1, int yp1, int xp2, int yp2)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setCoords(int xp1, int yp1, int xp2, int yp2)
{
x1 = xp1;
y1 = yp1;
@@ -381,7 +381,7 @@ inline void QRect::setCoords(int xp1, int yp1, int xp2, int yp2)
Q_DECL_CONSTEXPR inline QRect QRect::adjusted(int xp1, int yp1, int xp2, int yp2) const
{ return QRect(QPoint(x1 + xp1, y1 + yp1), QPoint(x2 + xp2, y2 + yp2)); }
-inline void QRect::adjust(int dx1, int dy1, int dx2, int dy2)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::adjust(int dx1, int dy1, int dx2, int dy2)
{
x1 += dx1;
y1 += dy1;
@@ -389,13 +389,13 @@ inline void QRect::adjust(int dx1, int dy1, int dx2, int dy2)
y2 += dy2;
}
-inline void QRect::setWidth(int w)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setWidth(int w)
{ x2 = (x1 + w - 1); }
-inline void QRect::setHeight(int h)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setHeight(int h)
{ y2 = (y1 + h - 1); }
-inline void QRect::setSize(const QSize &s)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setSize(const QSize &s)
{
x2 = (s.width() + x1 - 1);
y2 = (s.height() + y1 - 1);
@@ -473,13 +473,13 @@ Q_DECL_CONSTEXPR inline QRect QRect::marginsRemoved(const QMargins &margins) con
QPoint(x2 - margins.right(), y2 - margins.bottom()));
}
-inline QRect &QRect::operator+=(const QMargins &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QRect &QRect::operator+=(const QMargins &margins)
{
*this = marginsAdded(margins);
return *this;
}
-inline QRect &QRect::operator-=(const QMargins &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QRect &QRect::operator-=(const QMargins &margins)
{
*this = marginsRemoved(margins);
return *this;
@@ -511,12 +511,12 @@ public:
Q_DECL_CONSTEXPR inline qreal x() const;
Q_DECL_CONSTEXPR inline qreal y() const;
- inline void setLeft(qreal pos);
- inline void setTop(qreal pos);
- inline void setRight(qreal pos);
- inline void setBottom(qreal pos);
- inline void setX(qreal pos) { setLeft(pos); }
- inline void setY(qreal pos) { setTop(pos); }
+ Q_DECL_RELAXED_CONSTEXPR inline void setLeft(qreal pos);
+ Q_DECL_RELAXED_CONSTEXPR inline void setTop(qreal pos);
+ Q_DECL_RELAXED_CONSTEXPR inline void setRight(qreal pos);
+ Q_DECL_RELAXED_CONSTEXPR inline void setBottom(qreal pos);
+ Q_DECL_RELAXED_CONSTEXPR inline void setX(qreal pos) { setLeft(pos); }
+ Q_DECL_RELAXED_CONSTEXPR inline void setY(qreal pos) { setTop(pos); }
Q_DECL_CONSTEXPR inline QPointF topLeft() const { return QPointF(xp, yp); }
Q_DECL_CONSTEXPR inline QPointF bottomRight() const { return QPointF(xp+w, yp+h); }
@@ -524,45 +524,45 @@ public:
Q_DECL_CONSTEXPR inline QPointF bottomLeft() const { return QPointF(xp, yp+h); }
Q_DECL_CONSTEXPR inline QPointF center() const;
- inline void setTopLeft(const QPointF &p);
- inline void setBottomRight(const QPointF &p);
- inline void setTopRight(const QPointF &p);
- inline void setBottomLeft(const QPointF &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void setTopLeft(const QPointF &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void setBottomRight(const QPointF &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void setTopRight(const QPointF &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void setBottomLeft(const QPointF &p);
- inline void moveLeft(qreal pos);
- inline void moveTop(qreal pos);
- inline void moveRight(qreal pos);
- inline void moveBottom(qreal pos);
- inline void moveTopLeft(const QPointF &p);
- inline void moveBottomRight(const QPointF &p);
- inline void moveTopRight(const QPointF &p);
- inline void moveBottomLeft(const QPointF &p);
- inline void moveCenter(const QPointF &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveLeft(qreal pos);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTop(qreal pos);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveRight(qreal pos);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveBottom(qreal pos);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTopLeft(const QPointF &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveBottomRight(const QPointF &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTopRight(const QPointF &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveBottomLeft(const QPointF &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveCenter(const QPointF &p);
- inline void translate(qreal dx, qreal dy);
- inline void translate(const QPointF &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void translate(qreal dx, qreal dy);
+ Q_DECL_RELAXED_CONSTEXPR inline void translate(const QPointF &p);
Q_DECL_CONSTEXPR inline QRectF translated(qreal dx, qreal dy) const Q_REQUIRED_RESULT;
Q_DECL_CONSTEXPR inline QRectF translated(const QPointF &p) const Q_REQUIRED_RESULT;
- inline void moveTo(qreal x, qreal y);
- inline void moveTo(const QPointF &p);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTo(qreal x, qreal y);
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTo(const QPointF &p);
- inline void setRect(qreal x, qreal y, qreal w, qreal h);
- inline void getRect(qreal *x, qreal *y, qreal *w, qreal *h) const;
+ Q_DECL_RELAXED_CONSTEXPR inline void setRect(qreal x, qreal y, qreal w, qreal h);
+ Q_DECL_RELAXED_CONSTEXPR inline void getRect(qreal *x, qreal *y, qreal *w, qreal *h) const;
- inline void setCoords(qreal x1, qreal y1, qreal x2, qreal y2);
- inline void getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const;
+ Q_DECL_RELAXED_CONSTEXPR inline void setCoords(qreal x1, qreal y1, qreal x2, qreal y2);
+ Q_DECL_RELAXED_CONSTEXPR inline void getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const;
- inline void adjust(qreal x1, qreal y1, qreal x2, qreal y2);
+ Q_DECL_RELAXED_CONSTEXPR inline void adjust(qreal x1, qreal y1, qreal x2, qreal y2);
Q_DECL_CONSTEXPR inline QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const Q_REQUIRED_RESULT;
Q_DECL_CONSTEXPR inline QSizeF size() const;
Q_DECL_CONSTEXPR inline qreal width() const;
Q_DECL_CONSTEXPR inline qreal height() const;
- inline void setWidth(qreal w);
- inline void setHeight(qreal h);
- inline void setSize(const QSizeF &s);
+ Q_DECL_RELAXED_CONSTEXPR inline void setWidth(qreal w);
+ Q_DECL_RELAXED_CONSTEXPR inline void setHeight(qreal h);
+ Q_DECL_RELAXED_CONSTEXPR inline void setSize(const QSizeF &s);
QRectF operator|(const QRectF &r) const;
QRectF operator&(const QRectF &r) const;
@@ -578,8 +578,8 @@ public:
Q_DECL_CONSTEXPR inline QRectF marginsAdded(const QMarginsF &margins) const;
Q_DECL_CONSTEXPR inline QRectF marginsRemoved(const QMarginsF &margins) const;
- inline QRectF &operator+=(const QMarginsF &margins);
- inline QRectF &operator-=(const QMarginsF &margins);
+ Q_DECL_RELAXED_CONSTEXPR inline QRectF &operator+=(const QMarginsF &margins);
+ Q_DECL_RELAXED_CONSTEXPR inline QRectF &operator-=(const QMarginsF &margins);
#if QT_DEPRECATED_SINCE(5, 0)
QT_DEPRECATED QRectF unite(const QRectF &r) const Q_REQUIRED_RESULT { return united(r); }
@@ -652,42 +652,42 @@ Q_DECL_CONSTEXPR inline qreal QRectF::x() const
Q_DECL_CONSTEXPR inline qreal QRectF::y() const
{ return yp; }
-inline void QRectF::setLeft(qreal pos) { qreal diff = pos - xp; xp += diff; w -= diff; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setLeft(qreal pos) { qreal diff = pos - xp; xp += diff; w -= diff; }
-inline void QRectF::setRight(qreal pos) { w = pos - xp; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setRight(qreal pos) { w = pos - xp; }
-inline void QRectF::setTop(qreal pos) { qreal diff = pos - yp; yp += diff; h -= diff; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setTop(qreal pos) { qreal diff = pos - yp; yp += diff; h -= diff; }
-inline void QRectF::setBottom(qreal pos) { h = pos - yp; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setBottom(qreal pos) { h = pos - yp; }
-inline void QRectF::setTopLeft(const QPointF &p) { setLeft(p.x()); setTop(p.y()); }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setTopLeft(const QPointF &p) { setLeft(p.x()); setTop(p.y()); }
-inline void QRectF::setTopRight(const QPointF &p) { setRight(p.x()); setTop(p.y()); }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setTopRight(const QPointF &p) { setRight(p.x()); setTop(p.y()); }
-inline void QRectF::setBottomLeft(const QPointF &p) { setLeft(p.x()); setBottom(p.y()); }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setBottomLeft(const QPointF &p) { setLeft(p.x()); setBottom(p.y()); }
-inline void QRectF::setBottomRight(const QPointF &p) { setRight(p.x()); setBottom(p.y()); }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setBottomRight(const QPointF &p) { setRight(p.x()); setBottom(p.y()); }
Q_DECL_CONSTEXPR inline QPointF QRectF::center() const
{ return QPointF(xp + w/2, yp + h/2); }
-inline void QRectF::moveLeft(qreal pos) { xp = pos; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveLeft(qreal pos) { xp = pos; }
-inline void QRectF::moveTop(qreal pos) { yp = pos; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTop(qreal pos) { yp = pos; }
-inline void QRectF::moveRight(qreal pos) { xp = pos - w; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveRight(qreal pos) { xp = pos - w; }
-inline void QRectF::moveBottom(qreal pos) { yp = pos - h; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveBottom(qreal pos) { yp = pos - h; }
-inline void QRectF::moveTopLeft(const QPointF &p) { moveLeft(p.x()); moveTop(p.y()); }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTopLeft(const QPointF &p) { moveLeft(p.x()); moveTop(p.y()); }
-inline void QRectF::moveTopRight(const QPointF &p) { moveRight(p.x()); moveTop(p.y()); }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTopRight(const QPointF &p) { moveRight(p.x()); moveTop(p.y()); }
-inline void QRectF::moveBottomLeft(const QPointF &p) { moveLeft(p.x()); moveBottom(p.y()); }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveBottomLeft(const QPointF &p) { moveLeft(p.x()); moveBottom(p.y()); }
-inline void QRectF::moveBottomRight(const QPointF &p) { moveRight(p.x()); moveBottom(p.y()); }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveBottomRight(const QPointF &p) { moveRight(p.x()); moveBottom(p.y()); }
-inline void QRectF::moveCenter(const QPointF &p) { xp = p.x() - w/2; yp = p.y() - h/2; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveCenter(const QPointF &p) { xp = p.x() - w/2; yp = p.y() - h/2; }
Q_DECL_CONSTEXPR inline qreal QRectF::width() const
{ return w; }
@@ -698,25 +698,25 @@ Q_DECL_CONSTEXPR inline qreal QRectF::height() const
Q_DECL_CONSTEXPR inline QSizeF QRectF::size() const
{ return QSizeF(w, h); }
-inline void QRectF::translate(qreal dx, qreal dy)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::translate(qreal dx, qreal dy)
{
xp += dx;
yp += dy;
}
-inline void QRectF::translate(const QPointF &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::translate(const QPointF &p)
{
xp += p.x();
yp += p.y();
}
-inline void QRectF::moveTo(qreal ax, qreal ay)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTo(qreal ax, qreal ay)
{
xp = ax;
yp = ay;
}
-inline void QRectF::moveTo(const QPointF &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTo(const QPointF &p)
{
xp = p.x();
yp = p.y();
@@ -728,7 +728,7 @@ Q_DECL_CONSTEXPR inline QRectF QRectF::translated(qreal dx, qreal dy) const
Q_DECL_CONSTEXPR inline QRectF QRectF::translated(const QPointF &p) const
{ return QRectF(xp + p.x(), yp + p.y(), w, h); }
-inline void QRectF::getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) const
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) const
{
*ax = this->xp;
*ay = this->yp;
@@ -736,7 +736,7 @@ inline void QRectF::getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) const
*aah = this->h;
}
-inline void QRectF::setRect(qreal ax, qreal ay, qreal aaw, qreal aah)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setRect(qreal ax, qreal ay, qreal aaw, qreal aah)
{
this->xp = ax;
this->yp = ay;
@@ -744,7 +744,7 @@ inline void QRectF::setRect(qreal ax, qreal ay, qreal aaw, qreal aah)
this->h = aah;
}
-inline void QRectF::getCoords(qreal *xp1, qreal *yp1, qreal *xp2, qreal *yp2) const
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::getCoords(qreal *xp1, qreal *yp1, qreal *xp2, qreal *yp2) const
{
*xp1 = xp;
*yp1 = yp;
@@ -752,7 +752,7 @@ inline void QRectF::getCoords(qreal *xp1, qreal *yp1, qreal *xp2, qreal *yp2) co
*yp2 = yp + h;
}
-inline void QRectF::setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2)
{
xp = xp1;
yp = yp1;
@@ -760,19 +760,19 @@ inline void QRectF::setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2)
h = yp2 - yp1;
}
-inline void QRectF::adjust(qreal xp1, qreal yp1, qreal xp2, qreal yp2)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::adjust(qreal xp1, qreal yp1, qreal xp2, qreal yp2)
{ xp += xp1; yp += yp1; w += xp2 - xp1; h += yp2 - yp1; }
Q_DECL_CONSTEXPR inline QRectF QRectF::adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) const
{ return QRectF(xp + xp1, yp + yp1, w + xp2 - xp1, h + yp2 - yp1); }
-inline void QRectF::setWidth(qreal aw)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setWidth(qreal aw)
{ this->w = aw; }
-inline void QRectF::setHeight(qreal ah)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setHeight(qreal ah)
{ this->h = ah; }
-inline void QRectF::setSize(const QSizeF &s)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setSize(const QSizeF &s)
{
w = s.width();
h = s.height();
@@ -852,13 +852,13 @@ Q_DECL_CONSTEXPR inline QRectF QRectF::marginsRemoved(const QMarginsF &margins)
QSizeF(w - margins.left() - margins.right(), h - margins.top() - margins.bottom()));
}
-inline QRectF &QRectF::operator+=(const QMarginsF &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QRectF &QRectF::operator+=(const QMarginsF &margins)
{
*this = marginsAdded(margins);
return *this;
}
-inline QRectF &QRectF::operator-=(const QMarginsF &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QRectF &QRectF::operator-=(const QMarginsF &margins)
{
*this = marginsRemoved(margins);
return *this;
diff --git a/src/corelib/tools/qregularexpression.cpp b/src/corelib/tools/qregularexpression.cpp
index 33894927fe..228ee5b842 100644
--- a/src/corelib/tools/qregularexpression.cpp
+++ b/src/corelib/tools/qregularexpression.cpp
@@ -835,6 +835,8 @@ struct QRegularExpressionPrivate : QSharedData
};
QRegularExpressionMatchPrivate *doMatch(const QString &subject,
+ int subjectStartPos,
+ int subjectLength,
int offset,
QRegularExpression::MatchType matchType,
QRegularExpression::MatchOptions matchOptions,
@@ -872,6 +874,8 @@ struct QRegularExpressionMatchPrivate : QSharedData
{
QRegularExpressionMatchPrivate(const QRegularExpression &re,
const QString &subject,
+ int subjectStart,
+ int subjectLength,
QRegularExpression::MatchType matchType,
QRegularExpression::MatchOptions matchOptions,
int capturingCount = 0);
@@ -884,6 +888,9 @@ struct QRegularExpressionMatchPrivate : QSharedData
// for each captured substring
QVector<int> capturedOffsets;
+ const int subjectStart;
+ const int subjectLength;
+
const QRegularExpression::MatchType matchType;
const QRegularExpression::MatchOptions matchOptions;
@@ -1219,14 +1226,21 @@ static int pcre16SafeExec(const pcre16 *code, const pcre16_extra *extra,
/*!
\internal
- Performs a match of type \a matchType on the given \a subject string with
- options \a matchOptions and returns the QRegularExpressionMatchPrivate of
- the result. It also advances a match if a previous result is given as \a
+ Performs a match on the substring of the given \a subject string,
+ substring which starts from \a subjectStart and up to
+ (but not including) \a subjectStart + \a subjectLength. The match
+ will be of type \a matchType and using the options \a matchOptions;
+ the matching \a offset is relative the substring,
+ and if negative, it's taken as an offset from the end of the substring.
+
+ It also advances a match if a previous result is given as \a
previous. The \a subject string goes a Unicode validity check if
\a checkSubjectString is CheckSubjectString and the match options don't
include DontCheckSubjectStringMatchOption (PCRE doesn't like illegal
UTF-16 sequences).
+ Returns the QRegularExpressionMatchPrivate of the result.
+
Advancing a match is a tricky algorithm. If the previous match matched a
non-empty string, we just do an ordinary match at the offset position.
@@ -1239,6 +1253,8 @@ static int pcre16SafeExec(const pcre16 *code, const pcre16_extra *extra,
must advance over it.
*/
QRegularExpressionMatchPrivate *QRegularExpressionPrivate::doMatch(const QString &subject,
+ int subjectStart,
+ int subjectLength,
int offset,
QRegularExpression::MatchType matchType,
QRegularExpression::MatchOptions matchOptions,
@@ -1246,21 +1262,22 @@ QRegularExpressionMatchPrivate *QRegularExpressionPrivate::doMatch(const QString
const QRegularExpressionMatchPrivate *previous) const
{
if (offset < 0)
- offset += subject.length();
+ offset += subjectLength;
QRegularExpression re(*const_cast<QRegularExpressionPrivate *>(this));
- if (offset < 0 || offset > subject.length())
- return new QRegularExpressionMatchPrivate(re, subject, matchType, matchOptions);
+ if (offset < 0 || offset > subjectLength)
+ return new QRegularExpressionMatchPrivate(re, subject, subjectStart, subjectLength, matchType, matchOptions);
if (!compiledPattern) {
qWarning("QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object");
- return new QRegularExpressionMatchPrivate(re, subject, matchType, matchOptions);
+ return new QRegularExpressionMatchPrivate(re, subject, subjectStart, subjectLength, matchType, matchOptions);
}
// skip optimizing and doing the actual matching if NoMatch type was requested
if (matchType == QRegularExpression::NoMatch) {
QRegularExpressionMatchPrivate *priv = new QRegularExpressionMatchPrivate(re, subject,
+ subjectStart, subjectLength,
matchType, matchOptions);
priv->isValid = true;
return priv;
@@ -1268,6 +1285,7 @@ QRegularExpressionMatchPrivate *QRegularExpressionPrivate::doMatch(const QString
// capturingCount doesn't include the implicit "0" capturing group
QRegularExpressionMatchPrivate *priv = new QRegularExpressionMatchPrivate(re, subject,
+ subjectStart, subjectLength,
matchType, matchOptions,
capturingCount + 1);
@@ -1307,45 +1325,49 @@ QRegularExpressionMatchPrivate *QRegularExpressionPrivate::doMatch(const QString
int * const captureOffsets = priv->capturedOffsets.data();
const int captureOffsetsCount = priv->capturedOffsets.size();
+ int realOffset = offset + subjectStart;
+ const int realSubjectLength = subjectLength + subjectStart;
+
const unsigned short * const subjectUtf16 = subject.utf16();
- const int subjectLength = subject.length();
int result;
if (!previousMatchWasEmpty) {
result = pcre16SafeExec(compiledPattern, currentStudyData,
- subjectUtf16, subjectLength,
- offset, pcreOptions,
+ subjectUtf16, realSubjectLength,
+ realOffset, pcreOptions,
captureOffsets, captureOffsetsCount);
} else {
result = pcre16SafeExec(compiledPattern, currentStudyData,
- subjectUtf16, subjectLength,
- offset, pcreOptions | PCRE_NOTEMPTY_ATSTART | PCRE_ANCHORED,
+ subjectUtf16, realSubjectLength,
+ realOffset, pcreOptions | PCRE_NOTEMPTY_ATSTART | PCRE_ANCHORED,
captureOffsets, captureOffsetsCount);
if (result == PCRE_ERROR_NOMATCH) {
- ++offset;
+ ++realOffset;
if (usingCrLfNewlines
- && offset < subjectLength
- && subjectUtf16[offset - 1] == QLatin1Char('\r')
- && subjectUtf16[offset] == QLatin1Char('\n')) {
- ++offset;
- } else if (offset < subjectLength
- && QChar::isLowSurrogate(subjectUtf16[offset])) {
- ++offset;
+ && realOffset < realSubjectLength
+ && subjectUtf16[realOffset - 1] == QLatin1Char('\r')
+ && subjectUtf16[realOffset] == QLatin1Char('\n')) {
+ ++realOffset;
+ } else if (realOffset < realSubjectLength
+ && QChar::isLowSurrogate(subjectUtf16[realOffset])) {
+ ++realOffset;
}
result = pcre16SafeExec(compiledPattern, currentStudyData,
- subjectUtf16, subjectLength,
- offset, pcreOptions,
+ subjectUtf16, realSubjectLength,
+ realOffset, pcreOptions,
captureOffsets, captureOffsetsCount);
}
}
#ifdef QREGULAREXPRESSION_DEBUG
qDebug() << "Matching" << pattern << "against" << subject
- << offset << matchType << matchOptions << previousMatchWasEmpty
+ << "starting at" << subjectStart << "len" << subjectLength << "real len" << realSubjectLength
+ << "offset" << offset << "real offset" << realOffset
+ << matchType << matchOptions << previousMatchWasEmpty
<< "result" << result;
#endif
@@ -1383,10 +1405,13 @@ QRegularExpressionMatchPrivate *QRegularExpressionPrivate::doMatch(const QString
*/
QRegularExpressionMatchPrivate::QRegularExpressionMatchPrivate(const QRegularExpression &re,
const QString &subject,
+ int subjectStart,
+ int subjectLength,
QRegularExpression::MatchType matchType,
QRegularExpression::MatchOptions matchOptions,
int capturingCount)
: regularExpression(re), subject(subject),
+ subjectStart(subjectStart), subjectLength(subjectLength),
matchType(matchType), matchOptions(matchOptions),
capturedCount(0),
hasMatch(false), hasPartialMatch(false), isValid(false)
@@ -1412,6 +1437,8 @@ QRegularExpressionMatch QRegularExpressionMatchPrivate::nextMatch() const
// then that subject was already checked at least once (when this object
// was created, or when the object that created this one was created, etc.)
QRegularExpressionMatchPrivate *nextPrivate = regularExpression.d->doMatch(subject,
+ subjectStart,
+ subjectLength,
capturedOffsets.at(1),
matchType,
matchOptions,
@@ -1684,7 +1711,33 @@ QRegularExpressionMatch QRegularExpression::match(const QString &subject,
{
d.data()->compilePattern();
- QRegularExpressionMatchPrivate *priv = d->doMatch(subject, offset, matchType, matchOptions);
+ QRegularExpressionMatchPrivate *priv = d->doMatch(subject, 0, subject.length(), offset, matchType, matchOptions);
+ return QRegularExpressionMatch(*priv);
+}
+
+/*!
+ \since 5.5
+ \overload
+
+ Attempts to match the regular expression against the given \a subjectRef
+ string reference, starting at the position \a offset inside the subject, using a
+ match of type \a matchType and honoring the given \a matchOptions.
+
+ The returned QRegularExpressionMatch object contains the results of the
+ match.
+
+ \sa QRegularExpressionMatch, {normal matching}
+*/
+QRegularExpressionMatch QRegularExpression::match(const QStringRef &subjectRef,
+ int offset,
+ MatchType matchType,
+ MatchOptions matchOptions) const
+{
+ d.data()->compilePattern();
+
+ const QString subject = subjectRef.string() ? *subjectRef.string() : QString();
+
+ QRegularExpressionMatchPrivate *priv = d->doMatch(subject, subjectRef.position(), subjectRef.length(), offset, matchType, matchOptions);
return QRegularExpressionMatch(*priv);
}
@@ -1714,6 +1767,34 @@ QRegularExpressionMatchIterator QRegularExpression::globalMatch(const QString &s
}
/*!
+ \since 5.5
+ \overload
+
+ Attempts to perform a global match of the regular expression against the
+ given \a subjectRef string reference, starting at the position \a offset inside the
+ subject, using a match of type \a matchType and honoring the given \a
+ matchOptions.
+
+ The returned QRegularExpressionMatchIterator is positioned before the
+ first match result (if any).
+
+ \sa QRegularExpressionMatchIterator, {global matching}
+*/
+QRegularExpressionMatchIterator QRegularExpression::globalMatch(const QStringRef &subjectRef,
+ int offset,
+ MatchType matchType,
+ MatchOptions matchOptions) const
+{
+ QRegularExpressionMatchIteratorPrivate *priv =
+ new QRegularExpressionMatchIteratorPrivate(*this,
+ matchType,
+ matchOptions,
+ match(subjectRef, offset, matchType, matchOptions));
+
+ return QRegularExpressionMatchIterator(*priv);
+}
+
+/*!
\since 5.4
Forces an immediate optimization of the pattern, including
@@ -1823,6 +1904,8 @@ QString QRegularExpression::escape(const QString &str)
QRegularExpressionMatch::QRegularExpressionMatch()
: d(new QRegularExpressionMatchPrivate(QRegularExpression(),
QString(),
+ 0,
+ 0,
QRegularExpression::NoMatch,
QRegularExpression::NoMatchOption))
{
diff --git a/src/corelib/tools/qregularexpression.h b/src/corelib/tools/qregularexpression.h
index 66538f22b3..f332227094 100644
--- a/src/corelib/tools/qregularexpression.h
+++ b/src/corelib/tools/qregularexpression.h
@@ -112,11 +112,21 @@ public:
MatchType matchType = NormalMatch,
MatchOptions matchOptions = NoMatchOption) const;
+ QRegularExpressionMatch match(const QStringRef &subjectRef,
+ int offset = 0,
+ MatchType matchType = NormalMatch,
+ MatchOptions matchOptions = NoMatchOption) const;
+
QRegularExpressionMatchIterator globalMatch(const QString &subject,
int offset = 0,
MatchType matchType = NormalMatch,
MatchOptions matchOptions = NoMatchOption) const;
+ QRegularExpressionMatchIterator globalMatch(const QStringRef &subjectRef,
+ int offset = 0,
+ MatchType matchType = NormalMatch,
+ MatchOptions matchOptions = NoMatchOption) const;
+
void optimize() const;
static QString escape(const QString &str);
diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h
index 2279f1bc2a..58227d6755 100644
--- a/src/corelib/tools/qringbuffer_p.h
+++ b/src/corelib/tools/qringbuffer_p.h
@@ -91,11 +91,20 @@ public:
int blockSize = buffers.first().size() - head;
if (tailBuffer == 0 || blockSize > bytes) {
- bufferSize -= bytes;
- if (bufferSize <= 0)
- clear(); // try to minify/squeeze us
- else
+ // keep a single block around if it does not exceed
+ // the basic block size, to avoid repeated allocations
+ // between uses of the buffer
+ if (bufferSize <= bytes) {
+ if (buffers.first().size() <= basicBlockSize) {
+ bufferSize = 0;
+ head = tail = 0;
+ } else {
+ clear(); // try to minify/squeeze us
+ }
+ } else {
head += bytes;
+ bufferSize -= bytes;
+ }
return;
}
@@ -113,7 +122,7 @@ public:
// if need buffer reallocation
if (tail + bytes > buffers.last().size()) {
- if (tail >= basicBlockSize) {
+ if (tail + bytes > buffers.last().capacity() && tail >= basicBlockSize) {
// shrink this buffer to its current size
buffers.last().resize(tail);
@@ -139,11 +148,20 @@ public:
inline void chop(int bytes) {
while (bytes > 0) {
if (tailBuffer == 0 || tail > bytes) {
- bufferSize -= bytes;
- if (bufferSize <= 0)
- clear(); // try to minify/squeeze us
- else
+ // keep a single block around if it does not exceed
+ // the basic block size, to avoid repeated allocations
+ // between uses of the buffer
+ if (bufferSize <= bytes) {
+ if (buffers.first().size() <= basicBlockSize) {
+ bufferSize = 0;
+ head = tail = 0;
+ } else {
+ clear(); // try to minify/squeeze us
+ }
+ } else {
tail -= bytes;
+ bufferSize -= bytes;
+ }
return;
}
@@ -156,7 +174,7 @@ public:
}
inline bool isEmpty() const {
- return tailBuffer == 0 && tail == 0;
+ return bufferSize == 0;
}
inline int getChar() {
@@ -175,10 +193,14 @@ public:
inline void ungetChar(char c) {
--head;
if (head < 0) {
- buffers.prepend(QByteArray());
+ if (bufferSize != 0) {
+ buffers.prepend(QByteArray());
+ ++tailBuffer;
+ } else {
+ tail = basicBlockSize;
+ }
buffers.first().resize(basicBlockSize);
head = basicBlockSize - 1;
- ++tailBuffer;
}
buffers.first()[head] = c;
++bufferSize;
diff --git a/src/corelib/tools/qsize.h b/src/corelib/tools/qsize.h
index 6b5cf2dd7d..90222ba822 100644
--- a/src/corelib/tools/qsize.h
+++ b/src/corelib/tools/qsize.h
@@ -51,8 +51,8 @@ public:
Q_DECL_CONSTEXPR inline int width() const;
Q_DECL_CONSTEXPR inline int height() const;
- inline void setWidth(int w);
- inline void setHeight(int h);
+ Q_DECL_RELAXED_CONSTEXPR inline void setWidth(int w);
+ Q_DECL_RELAXED_CONSTEXPR inline void setHeight(int h);
void transpose();
Q_DECL_CONSTEXPR inline QSize transposed() const;
@@ -64,12 +64,12 @@ public:
Q_DECL_CONSTEXPR inline QSize expandedTo(const QSize &) const;
Q_DECL_CONSTEXPR inline QSize boundedTo(const QSize &) const;
- inline int &rwidth();
- inline int &rheight();
+ Q_DECL_RELAXED_CONSTEXPR inline int &rwidth();
+ Q_DECL_RELAXED_CONSTEXPR inline int &rheight();
- inline QSize &operator+=(const QSize &);
- inline QSize &operator-=(const QSize &);
- inline QSize &operator*=(qreal c);
+ Q_DECL_RELAXED_CONSTEXPR inline QSize &operator+=(const QSize &);
+ Q_DECL_RELAXED_CONSTEXPR inline QSize &operator-=(const QSize &);
+ Q_DECL_RELAXED_CONSTEXPR inline QSize &operator*=(qreal c);
inline QSize &operator/=(qreal c);
friend inline Q_DECL_CONSTEXPR bool operator==(const QSize &, const QSize &);
@@ -119,10 +119,10 @@ Q_DECL_CONSTEXPR inline int QSize::width() const
Q_DECL_CONSTEXPR inline int QSize::height() const
{ return ht; }
-inline void QSize::setWidth(int w)
+Q_DECL_RELAXED_CONSTEXPR inline void QSize::setWidth(int w)
{ wd = w; }
-inline void QSize::setHeight(int h)
+Q_DECL_RELAXED_CONSTEXPR inline void QSize::setHeight(int h)
{ ht = h; }
Q_DECL_CONSTEXPR inline QSize QSize::transposed() const
@@ -137,19 +137,19 @@ inline void QSize::scale(const QSize &s, Qt::AspectRatioMode mode)
inline QSize QSize::scaled(int w, int h, Qt::AspectRatioMode mode) const
{ return scaled(QSize(w, h), mode); }
-inline int &QSize::rwidth()
+Q_DECL_RELAXED_CONSTEXPR inline int &QSize::rwidth()
{ return wd; }
-inline int &QSize::rheight()
+Q_DECL_RELAXED_CONSTEXPR inline int &QSize::rheight()
{ return ht; }
-inline QSize &QSize::operator+=(const QSize &s)
+Q_DECL_RELAXED_CONSTEXPR inline QSize &QSize::operator+=(const QSize &s)
{ wd+=s.wd; ht+=s.ht; return *this; }
-inline QSize &QSize::operator-=(const QSize &s)
+Q_DECL_RELAXED_CONSTEXPR inline QSize &QSize::operator-=(const QSize &s)
{ wd-=s.wd; ht-=s.ht; return *this; }
-inline QSize &QSize::operator*=(qreal c)
+Q_DECL_RELAXED_CONSTEXPR inline QSize &QSize::operator*=(qreal c)
{ wd = qRound(wd*c); ht = qRound(ht*c); return *this; }
Q_DECL_CONSTEXPR inline bool operator==(const QSize &s1, const QSize &s2)
@@ -211,8 +211,8 @@ public:
Q_DECL_CONSTEXPR inline qreal width() const;
Q_DECL_CONSTEXPR inline qreal height() const;
- inline void setWidth(qreal w);
- inline void setHeight(qreal h);
+ Q_DECL_RELAXED_CONSTEXPR inline void setWidth(qreal w);
+ Q_DECL_RELAXED_CONSTEXPR inline void setHeight(qreal h);
void transpose();
Q_DECL_CONSTEXPR inline QSizeF transposed() const;
@@ -224,12 +224,12 @@ public:
Q_DECL_CONSTEXPR inline QSizeF expandedTo(const QSizeF &) const;
Q_DECL_CONSTEXPR inline QSizeF boundedTo(const QSizeF &) const;
- inline qreal &rwidth();
- inline qreal &rheight();
+ Q_DECL_RELAXED_CONSTEXPR inline qreal &rwidth();
+ Q_DECL_RELAXED_CONSTEXPR inline qreal &rheight();
- inline QSizeF &operator+=(const QSizeF &);
- inline QSizeF &operator-=(const QSizeF &);
- inline QSizeF &operator*=(qreal c);
+ Q_DECL_RELAXED_CONSTEXPR inline QSizeF &operator+=(const QSizeF &);
+ Q_DECL_RELAXED_CONSTEXPR inline QSizeF &operator-=(const QSizeF &);
+ Q_DECL_RELAXED_CONSTEXPR inline QSizeF &operator*=(qreal c);
inline QSizeF &operator/=(qreal c);
friend Q_DECL_CONSTEXPR inline bool operator==(const QSizeF &, const QSizeF &);
@@ -284,10 +284,10 @@ Q_DECL_CONSTEXPR inline qreal QSizeF::width() const
Q_DECL_CONSTEXPR inline qreal QSizeF::height() const
{ return ht; }
-inline void QSizeF::setWidth(qreal w)
+Q_DECL_RELAXED_CONSTEXPR inline void QSizeF::setWidth(qreal w)
{ wd = w; }
-inline void QSizeF::setHeight(qreal h)
+Q_DECL_RELAXED_CONSTEXPR inline void QSizeF::setHeight(qreal h)
{ ht = h; }
Q_DECL_CONSTEXPR inline QSizeF QSizeF::transposed() const
@@ -302,19 +302,19 @@ inline void QSizeF::scale(const QSizeF &s, Qt::AspectRatioMode mode)
inline QSizeF QSizeF::scaled(qreal w, qreal h, Qt::AspectRatioMode mode) const
{ return scaled(QSizeF(w, h), mode); }
-inline qreal &QSizeF::rwidth()
+Q_DECL_RELAXED_CONSTEXPR inline qreal &QSizeF::rwidth()
{ return wd; }
-inline qreal &QSizeF::rheight()
+Q_DECL_RELAXED_CONSTEXPR inline qreal &QSizeF::rheight()
{ return ht; }
-inline QSizeF &QSizeF::operator+=(const QSizeF &s)
+Q_DECL_RELAXED_CONSTEXPR inline QSizeF &QSizeF::operator+=(const QSizeF &s)
{ wd += s.wd; ht += s.ht; return *this; }
-inline QSizeF &QSizeF::operator-=(const QSizeF &s)
+Q_DECL_RELAXED_CONSTEXPR inline QSizeF &QSizeF::operator-=(const QSizeF &s)
{ wd -= s.wd; ht -= s.ht; return *this; }
-inline QSizeF &QSizeF::operator*=(qreal c)
+Q_DECL_RELAXED_CONSTEXPR inline QSizeF &QSizeF::operator*=(qreal c)
{ wd *= c; ht *= c; return *this; }
Q_DECL_CONSTEXPR inline bool operator==(const QSizeF &s1, const QSizeF &s2)
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 9921d5cfbb..e830ed36e5 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -70,6 +70,7 @@
#include "qchar.cpp"
#include "qstringmatcher.cpp"
#include "qstringiterator_p.h"
+#include "qstringalgorithms_p.h"
#include "qthreadstorage.h"
#ifdef Q_OS_WIN
@@ -731,12 +732,30 @@ inline char qToLower(char ch)
const QString::Null QString::null = { };
/*!
+ \macro QT_RESTRICTED_CAST_FROM_ASCII
+ \relates QString
+
+ Defining this macro disables most automatic conversions from source
+ literals and 8-bit data to unicode QStrings, but allows the use of
+ the \c{QChar(char)} and \c{QString(const char (&ch)[N]} constructors,
+ and the \c{QString::operator=(const char (&ch)[N])} assignment operator
+ giving most of the type-safety benefits of QT_NO_CAST_FROM_ASCII
+ but does not require user code to wrap character and string literals
+ with QLatin1Char, QLatin1String or similar.
+
+ Using this macro together with source strings outside the 7-bit range,
+ non-literals, or literals with embedded NUL characters is undefined.
+
+ \sa QT_NO_CAST_FROM_ASCII, QT_NO_CAST_TO_ASCII
+*/
+
+/*!
\macro QT_NO_CAST_FROM_ASCII
\relates QString
Disables automatic conversions from 8-bit strings (char *) to unicode QStrings
- \sa QT_NO_CAST_TO_ASCII, QT_NO_CAST_FROM_BYTEARRAY
+ \sa QT_NO_CAST_TO_ASCII, QT_RESTRICTED_CAST_FROM_ASCII, QT_NO_CAST_FROM_BYTEARRAY
*/
/*!
@@ -745,7 +764,7 @@ const QString::Null QString::null = { };
disables automatic conversion from QString to 8-bit strings (char *)
- \sa QT_NO_CAST_FROM_ASCII, QT_NO_CAST_FROM_BYTEARRAY
+ \sa QT_NO_CAST_FROM_ASCII, QT_RESTRICTED_CAST_FROM_ASCII, QT_NO_CAST_FROM_BYTEARRAY
*/
/*!
@@ -759,7 +778,7 @@ const QString::Null QString::null = { };
Note: This only works for compilers that support warnings for
deprecated API.
- \sa QT_NO_CAST_TO_ASCII, QT_NO_CAST_FROM_ASCII
+ \sa QT_NO_CAST_TO_ASCII, QT_NO_CAST_FROM_ASCII, QT_RESTRICTED_CAST_FROM_ASCII
*/
/*!
@@ -993,6 +1012,9 @@ const QString::Null QString::null = { };
\list
\li \c QT_NO_CAST_FROM_ASCII disables automatic conversions from
C string literals and pointers to Unicode.
+ \li \c QT_RESTRICTED_CAST_FROM_ASCII allows automatic conversions
+ from C characters and character arrays, but disables automatic
+ conversions from character pointers to Unicode.
\li \c QT_NO_CAST_TO_ASCII disables automatic conversion from QString
to C strings.
\endlist
@@ -1310,6 +1332,12 @@ const QString::Null QString::null = { };
can be useful if you want to ensure that all user-visible strings
go through QObject::tr(), for example.
+ \note Defining QT_RESTRICTED_CAST_FROM_ASCII also disables
+ this constructor, but enables a \c{QString(const char (&ch)[N])}
+ constructor instead. Using non-literal input, or input with
+ embedded NUL characters, or non-7-bit characters is undefined
+ in this case.
+
\sa fromLatin1(), fromLocal8Bit(), fromUtf8()
*/
@@ -1656,8 +1684,11 @@ void QString::resize(int size)
void QString::reallocData(uint alloc, bool grow)
{
- if (grow)
+ if (grow) {
+ if (alloc > (uint(MaxAllocSize) - sizeof(Data)) / sizeof(QChar))
+ qBadAlloc();
alloc = qAllocMore(alloc * sizeof(QChar), sizeof(Data)) / sizeof(QChar);
+ }
if (d->ref.isShared() || IS_RAW_DATA(d)) {
Data::AllocationOptions allocOptions(d->capacityReserved ? Data::CapacityReserved : 0);
@@ -1748,10 +1779,11 @@ QString &QString::operator=(const QString &other)
Assigns \a str to this string. The const char pointer is converted
to Unicode using the fromUtf8() function.
- You can disable this operator by defining \c
- QT_NO_CAST_FROM_ASCII when you compile your applications. This
- can be useful if you want to ensure that all user-visible strings
+ You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII
+ or \c QT_RESTRICTED_CAST_FROM_ASCII when you compile your applications.
+ This can be useful if you want to ensure that all user-visible strings
go through QObject::tr(), for example.
+
*/
/*! \fn QString &QString::operator=(char ch)
@@ -3664,14 +3696,39 @@ int QString::count(const QRegExp& rx) const
*/
int QString::indexOf(const QRegularExpression& re, int from) const
{
+ return indexOf(re, from, Q_NULLPTR);
+}
+
+/*!
+ \overload
+ \since 5.5
+
+ Returns the index position of the first match of the regular
+ expression \a re in the string, searching forward from index
+ position \a from. Returns -1 if \a re didn't match anywhere.
+
+ If the match is successful and \a rmatch is not a null pointer, it also
+ writes the results of the match into the QRegularExpressionMatch object
+ pointed to by \a rmatch.
+
+ Example:
+
+ \snippet qstring/main.cpp 97
+*/
+int QString::indexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const
+{
if (!re.isValid()) {
qWarning("QString::indexOf: invalid QRegularExpression object");
return -1;
}
QRegularExpressionMatch match = re.match(*this, from);
- if (match.hasMatch())
- return match.capturedStart();
+ if (match.hasMatch()) {
+ const int ret = match.capturedStart();
+ if (rmatch)
+ *rmatch = qMove(match);
+ return ret;
+ }
return -1;
}
@@ -3690,22 +3747,45 @@ int QString::indexOf(const QRegularExpression& re, int from) const
*/
int QString::lastIndexOf(const QRegularExpression &re, int from) const
{
+ return lastIndexOf(re, from, Q_NULLPTR);
+}
+
+/*!
+ \overload
+ \since 5.5
+
+ Returns the index position of the last match of the regular
+ expression \a re in the string, which starts before the index
+ position \a from. Returns -1 if \a re didn't match anywhere.
+
+ If the match is successful and \a rmatch is not a null pointer, it also
+ writes the results of the match into the QRegularExpressionMatch object
+ pointed to by \a rmatch.
+
+ Example:
+
+ \snippet qstring/main.cpp 98
+*/
+int QString::lastIndexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const
+{
if (!re.isValid()) {
qWarning("QString::lastIndexOf: invalid QRegularExpression object");
return -1;
}
int endpos = (from < 0) ? (size() + from + 1) : (from + 1);
-
QRegularExpressionMatchIterator iterator = re.globalMatch(*this);
int lastIndex = -1;
while (iterator.hasNext()) {
QRegularExpressionMatch match = iterator.next();
int start = match.capturedStart();
- if (start < endpos)
+ if (start < endpos) {
lastIndex = start;
- else
+ if (rmatch)
+ *rmatch = qMove(match);
+ } else {
break;
+ }
}
return lastIndex;
@@ -3719,12 +3799,7 @@ int QString::lastIndexOf(const QRegularExpression &re, int from) const
*/
bool QString::contains(const QRegularExpression &re) const
{
- if (!re.isValid()) {
- qWarning("QString::contains: invalid QRegularExpression object");
- return false;
- }
- QRegularExpressionMatch match = re.match(*this);
- return match.hasMatch();
+ return contains(re, Q_NULLPTR);
}
/*!
@@ -3744,13 +3819,13 @@ bool QString::contains(const QRegularExpression &re) const
bool QString::contains(const QRegularExpression &re, QRegularExpressionMatch *match) const
{
if (!re.isValid()) {
- qWarning("QString::contains: invalid QRegularExpresssion object");
+ qWarning("QString::contains: invalid QRegularExpression object");
return false;
}
QRegularExpressionMatch m = re.match(*this);
bool hasMatch = m.hasMatch();
if (hasMatch && match)
- *match = m;
+ *match = qMove(m);
return hasMatch;
}
@@ -3912,12 +3987,14 @@ QString QString::section(const QString &sep, int start, int end, SectionFlags fl
#if !(defined(QT_NO_REGEXP) && defined(QT_NO_REGULAREXPRESSION))
class qt_section_chunk {
public:
- qt_section_chunk(int l, QString s) { length = l; string = s; }
+ qt_section_chunk() {}
+ qt_section_chunk(int l, QString s) : length(l), string(qMove(s)) {}
int length;
QString string;
};
+Q_DECLARE_TYPEINFO(qt_section_chunk, Q_MOVABLE_TYPE);
-static QString extractSections(const QList<qt_section_chunk> &sections,
+static QString extractSections(const QVector<qt_section_chunk> &sections,
int start,
int end,
QString::SectionFlags flags)
@@ -4003,7 +4080,7 @@ QString QString::section(const QRegExp &reg, int start, int end, SectionFlags fl
sep.setCaseSensitivity((flags & SectionCaseInsensitiveSeps) ? Qt::CaseInsensitive
: Qt::CaseSensitive);
- QList<qt_section_chunk> sections;
+ QVector<qt_section_chunk> sections;
int n = length(), m = 0, last_m = 0, last_len = 0;
while ((m = sep.indexIn(*this, m)) != -1) {
sections.append(qt_section_chunk(last_len, QString(uc + last_m, m - last_m)));
@@ -4048,7 +4125,7 @@ QString QString::section(const QRegularExpression &re, int start, int end, Secti
if (flags & SectionCaseInsensitiveSeps)
sep.setPatternOptions(sep.patternOptions() | QRegularExpression::CaseInsensitiveOption);
- QList<qt_section_chunk> sections;
+ QVector<qt_section_chunk> sections;
int n = length(), m = 0, last_m = 0, last_len = 0;
QRegularExpressionMatchIterator iterator = sep.globalMatch(*this);
while (iterator.hasNext()) {
@@ -4626,6 +4703,8 @@ QString& QString::setUnicode(const QChar *unicode, int size)
*/
/*!
+ \fn QString QString::simplified() const
+
Returns a string that has whitespace removed from the start
and the end, and that has each sequence of internal whitespace
replaced with a single space.
@@ -4640,83 +4719,19 @@ QString& QString::setUnicode(const QChar *unicode, int size)
\sa trimmed()
*/
-QString QString::simplified() const
+QString QString::simplified_helper(const QString &str)
{
- if (d->size == 0)
- return *this;
-
- const QChar * const start = reinterpret_cast<QChar *>(d->data());
- const QChar *from = start;
- const QChar *fromEnd = start + d->size;
- forever {
- QChar ch = *from;
- if (!ch.isSpace())
- break;
- if (++from == fromEnd) {
- // All-whitespace string
- QStringDataPtr empty = { Data::allocate(0) };
- return QString(empty);
- }
- }
- // This loop needs no underflow check, as we already determined that
- // the string contains non-whitespace. If the string has exactly one
- // non-whitespace, it will be checked twice - we can live with that.
- while (fromEnd[-1].isSpace())
- fromEnd--;
- // The rest of the function depends on the fact that we already know
- // that the last character in the source is no whitespace.
- const QChar *copyFrom = from;
- int copyCount;
- forever {
- if (++from == fromEnd) {
- // Only leading and/or trailing whitespace, if any at all
- return mid(copyFrom - start, from - copyFrom);
- }
- QChar ch = *from;
- if (!ch.isSpace())
- continue;
- if (ch != QLatin1Char(' ')) {
- copyCount = from - copyFrom;
- break;
- }
- ch = *++from;
- if (ch.isSpace()) {
- copyCount = from - copyFrom - 1;
- break;
- }
- }
- // 'from' now points at the non-trailing whitespace which made the
- // string not simplified in the first place. 'copyCount' is the number
- // of already simplified characters - at least one, obviously -
- // without a trailing space.
- QString result((fromEnd - from) + copyCount, Qt::Uninitialized);
- QChar *to = reinterpret_cast<QChar *>(result.d->data());
- ::memcpy(to, copyFrom, copyCount * 2);
- to += copyCount;
- fromEnd--;
- QChar ch;
- forever {
- *to++ = QLatin1Char(' ');
- do {
- ch = *++from;
- } while (ch.isSpace());
- if (from == fromEnd)
- break;
- do {
- *to++ = ch;
- ch = *++from;
- if (from == fromEnd)
- goto done;
- } while (!ch.isSpace());
+ return QStringAlgorithms<const QString>::simplified_helper(str);
+}
- }
- done:
- *to++ = ch;
- result.truncate(to - reinterpret_cast<QChar *>(result.d->data()));
- return result;
+QString QString::simplified_helper(QString &str)
+{
+ return QStringAlgorithms<QString>::simplified_helper(str);
}
/*!
+ \fn QString QString::trimmed() const
+
Returns a string that has whitespace removed from the start and
the end.
@@ -4732,27 +4747,14 @@ QString QString::simplified() const
\sa simplified()
*/
-QString QString::trimmed() const
+QString QString::trimmed_helper(const QString &str)
{
- if (d->size == 0)
- return *this;
- const QChar *s = (const QChar*)d->data();
- if (!s->isSpace() && !s[d->size-1].isSpace())
- return *this;
- int start = 0;
- int end = d->size - 1;
- while (start<=end && s[start].isSpace()) // skip white space from start
- start++;
- if (start <= end) { // only white space
- while (end && s[end].isSpace()) // skip white space from end
- end--;
- }
- int l = end - start + 1;
- if (l <= 0) {
- QStringDataPtr empty = { Data::allocate(0) };
- return QString(empty);
- }
- return QString(s + start, l);
+ return QStringAlgorithms<const QString>::trimmed_helper(str);
+}
+
+QString QString::trimmed_helper(QString &str)
+{
+ return QStringAlgorithms<QString>::trimmed_helper(str);
}
/*! \fn const QChar QString::at(int position) const
@@ -5519,6 +5521,8 @@ QString QString::rightJustified(int width, QChar fill, bool truncate) const
}
/*!
+ \fn QString QString::toLower() const
+
Returns a lowercase copy of the string.
\snippet qstring/main.cpp 75
@@ -5529,132 +5533,118 @@ QString QString::rightJustified(int width, QChar fill, bool truncate) const
\sa toUpper(), QLocale::toLower()
*/
-QString QString::toLower() const
+namespace QUnicodeTables {
+struct LowercaseTraits
{
- const ushort *p = d->data();
- if (!p)
- return *this;
+ static signed short caseDiff(const Properties *prop)
+ { return prop->lowerCaseDiff; }
+ static bool caseSpecial(const Properties *prop)
+ { return prop->lowerCaseSpecial; }
+};
- const ushort *e = p + d->size;
- // this avoids out of bounds check in the loop
- while (e != p && QChar::isHighSurrogate(*(e - 1)))
- --e;
+struct UppercaseTraits
+{
+ static signed short caseDiff(const Properties *prop)
+ { return prop->upperCaseDiff; }
+ static bool caseSpecial(const Properties *prop)
+ { return prop->upperCaseSpecial; }
+};
- const QUnicodeTables::Properties *prop;
- while (p != e) {
- if (QChar::isHighSurrogate(*p) && QChar::isLowSurrogate(p[1])) {
- ushort high = *p++;
- prop = qGetProp(QChar::surrogateToUcs4(high, *p));
+struct CasefoldTraits
+{
+ static signed short caseDiff(const Properties *prop)
+ { return prop->caseFoldDiff; }
+ static bool caseSpecial(const Properties *prop)
+ { return prop->caseFoldSpecial; }
+};
+
+template <typename Traits, typename T>
+#ifdef Q_CC_MSVC
+__declspec(noinline)
+#elif defined(Q_CC_GNU)
+__attribute__((noinline))
+#endif
+static QString detachAndConvertCase(T &str, QStringIterator it)
+{
+ QString s = qMove(str); // will copy if T is const QString
+ QChar *pp = s.begin() + it.index(); // will detach if necessary
+ uint uc = it.nextUnchecked();
+ forever {
+ const QUnicodeTables::Properties *prop = qGetProp(uc);
+ signed short caseDiff = Traits::caseDiff(prop);
+
+ if (Q_UNLIKELY(Traits::caseSpecial(prop))) {
+ // slow path
+ const ushort *specialCase = specialCaseMap + caseDiff;
+ ushort length = *specialCase++;
+ int pos = pp - s.constBegin();
+ s.replace(pos, 1, reinterpret_cast<const QChar *>(specialCase), length);
+ pp = const_cast<QChar *>(s.constBegin()) + pos + length;
+ } else if (QChar::requiresSurrogates(uc)) {
+ *pp++ = QChar::highSurrogate(uc + caseDiff);
+ *pp++ = QChar::lowSurrogate(uc + caseDiff);
} else {
- prop = qGetProp(*p);
+ *pp++ = QChar(uc + caseDiff);
}
- if (prop->lowerCaseDiff) {
- if (QChar::isLowSurrogate(*p))
- --p; // safe; diff is 0 for surrogates
- QString s(d->size, Qt::Uninitialized);
- memcpy(s.d->data(), d->data(), (p - d->data())*sizeof(ushort));
- ushort *pp = s.d->data() + (p - d->data());
- while (p != e) {
- if (QChar::isHighSurrogate(*p) && QChar::isLowSurrogate(p[1])) {
- *pp = *p++;
- prop = qGetProp(QChar::surrogateToUcs4(*pp++, *p));
- } else {
- prop = qGetProp(*p);
- }
- if (prop->lowerCaseSpecial) {
- const ushort *specialCase = specialCaseMap + prop->lowerCaseDiff;
- ushort length = *specialCase++;
- int pos = pp - s.d->data();
- s.resize(s.d->size + length - 1);
- pp = s.d->data() + pos;
- while (length--)
- *pp++ = *specialCase++;
- } else {
- *pp++ = *p + prop->lowerCaseDiff;
- }
- ++p;
- }
-
- // this restores high surrogate parts eaten above, if any
- while (e != d->data() + d->size)
- *pp++ = *e++;
+ if (!it.hasNext())
return s;
- }
- ++p;
+
+ uc = it.nextUnchecked();
}
- return *this;
}
-/*!
- Returns the case folded equivalent of the string. For most Unicode
- characters this is the same as toLower().
-*/
-QString QString::toCaseFolded() const
+template <typename Traits, typename T>
+static QString convertCase(T &str)
{
- const ushort *p = d->data();
- if (!p)
- return *this;
+ const QChar *p = str.constBegin();
+ const QChar *e = p + str.size();
- const ushort *e = p + d->size;
// this avoids out of bounds check in the loop
- while (e != p && QChar::isHighSurrogate(*(e - 1)))
+ while (e != p && e[-1].isHighSurrogate())
--e;
const QUnicodeTables::Properties *prop;
- while (p != e) {
- if (QChar::isHighSurrogate(*p) && QChar::isLowSurrogate(p[1])) {
- ushort high = *p++;
- prop = qGetProp(QChar::surrogateToUcs4(high, *p));
- } else {
- prop = qGetProp(*p);
- }
- if (prop->caseFoldDiff) {
- if (QChar::isLowSurrogate(*p))
- --p; // safe; diff is 0 for surrogates
- QString s(d->size, Qt::Uninitialized);
- memcpy(s.d->data(), d->data(), (p - d->data())*sizeof(ushort));
- ushort *pp = s.d->data() + (p - d->data());
- while (p != e) {
- if (QChar::isHighSurrogate(*p) && QChar::isLowSurrogate(p[1])) {
- *pp = *p++;
- prop = qGetProp(QChar::surrogateToUcs4(*pp++, *p));
- } else {
- prop = qGetProp(*p);
- }
- if (prop->caseFoldSpecial) {
- const ushort *specialCase = specialCaseMap + prop->caseFoldDiff;
- ushort length = *specialCase++;
-#if 0
- int pos = pp - s.d->data;
- s.resize(s.d->size + length - 1);
- pp = s.d->data + pos;
- while (length--)
- *pp++ = *specialCase++;
-#else
- //### we currently don't support full case foldings
- Q_ASSERT(length == 1);
- Q_UNUSED(length)
- *pp++ = *specialCase;
-#endif
- } else {
- *pp++ = *p + prop->caseFoldDiff;
- }
- ++p;
- }
+ QStringIterator it(p, e);
+ for ( ; it.hasNext(); it.advanceUnchecked()) {
+ prop = qGetProp(it.peekNextUnchecked());
+ if (Traits::caseDiff(prop))
+ return detachAndConvertCase<Traits>(str, it);
+ }
+ return qMove(str);
+}
+} // namespace QUnicodeTables
- // this restores high surrogate parts eaten above, if any
- while (e != d->data() + d->size)
- *pp++ = *e++;
+QString QString::toLower_helper(const QString &str)
+{
+ return QUnicodeTables::convertCase<QUnicodeTables::LowercaseTraits>(str);
+}
- return s;
- }
- ++p;
- }
- return *this;
+QString QString::toLower_helper(QString &str)
+{
+ return QUnicodeTables::convertCase<QUnicodeTables::LowercaseTraits>(str);
}
/*!
+ \fn QString QString::toCaseFolded() const
+
+ Returns the case folded equivalent of the string. For most Unicode
+ characters this is the same as toLower().
+*/
+
+QString QString::toCaseFolded_helper(const QString &str)
+{
+ return QUnicodeTables::convertCase<QUnicodeTables::CasefoldTraits>(str);
+}
+
+QString QString::toCaseFolded_helper(QString &str)
+{
+ return QUnicodeTables::convertCase<QUnicodeTables::CasefoldTraits>(str);
+}
+
+/*!
+ \fn QString QString::toUpper() const
+
Returns an uppercase copy of the string.
\snippet qstring/main.cpp 81
@@ -5664,63 +5654,18 @@ QString QString::toCaseFolded() const
\sa toLower(), QLocale::toLower()
*/
-QString QString::toUpper() const
-{
- const ushort *p = d->data();
- if (!p)
- return *this;
- const ushort *e = p + d->size;
- // this avoids out of bounds check in the loop
- while (e != p && QChar::isHighSurrogate(*(e - 1)))
- --e;
-
- const QUnicodeTables::Properties *prop;
- while (p != e) {
- if (QChar::isHighSurrogate(*p) && QChar::isLowSurrogate(p[1])) {
- ushort high = *p++;
- prop = qGetProp(QChar::surrogateToUcs4(high, *p));
- } else {
- prop = qGetProp(*p);
- }
- if (prop->upperCaseDiff) {
- if (QChar::isLowSurrogate(*p))
- --p; // safe; diff is 0 for surrogates
- QString s(d->size, Qt::Uninitialized);
- memcpy(s.d->data(), d->data(), (p - d->data())*sizeof(ushort));
- ushort *pp = s.d->data() + (p - d->data());
- while (p != e) {
- if (QChar::isHighSurrogate(*p) && QChar::isLowSurrogate(p[1])) {
- *pp = *p++;
- prop = qGetProp(QChar::surrogateToUcs4(*pp++, *p));
- } else {
- prop = qGetProp(*p);
- }
- if (prop->upperCaseSpecial) {
- const ushort *specialCase = specialCaseMap + prop->upperCaseDiff;
- ushort length = *specialCase++;
- int pos = pp - s.d->data();
- s.resize(s.d->size + length - 1);
- pp = s.d->data() + pos;
- while (length--)
- *pp++ = *specialCase++;
- } else {
- *pp++ = *p + prop->upperCaseDiff;
- }
- ++p;
- }
-
- // this restores high surrogate parts eaten above, if any
- while (e != d->data() + d->size)
- *pp++ = *e++;
+QString QString::toUpper_helper(const QString &str)
+{
+ return QUnicodeTables::convertCase<QUnicodeTables::UppercaseTraits>(str);
+}
- return s;
- }
- ++p;
- }
- return *this;
+QString QString::toUpper_helper(QString &str)
+{
+ return QUnicodeTables::convertCase<QUnicodeTables::UppercaseTraits>(str);
}
+
// ### Qt 6: Consider whether this function shouldn't be removed See task 202871.
/*!
Safely builds a formatted string from the format string \a cformat
@@ -9843,20 +9788,15 @@ QVector<uint> QStringRef::toUcs4() const
*/
QStringRef QStringRef::trimmed() const
{
- if (m_size == 0 || m_string == 0)
+ const QChar *begin = cbegin();
+ const QChar *end = cend();
+ QStringAlgorithms<const QStringRef>::trimmed_helper_positions(begin, end);
+ if (begin == cbegin() && end == cend())
return *this;
- const QChar *s = m_string->constData() + m_position;
- int start = 0;
- int end = m_size - 1;
- while (start <= end && s[start].isSpace()) // skip white space from start
- start++;
- if (start <= end) { // only white space
- while (end && s[end].isSpace()) // skip white space from end
- end--;
- }
- int l = end - start + 1;
- Q_ASSERT(l >= 0);
- return QStringRef(m_string, m_position + start, l);
+ if (begin == end)
+ return QStringRef();
+ int position = m_position + (begin - cbegin());
+ return QStringRef(m_string, position, end - begin);
}
/*!
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index a12946e23c..4d51521b12 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -34,6 +34,10 @@
#ifndef QSTRING_H
#define QSTRING_H
+#if defined(QT_NO_CAST_FROM_ASCII) && defined(QT_RESTRICTED_CAST_FROM_ASCII)
+#error QT_NO_CAST_FROM_ASCII and QT_RESTRICTED_CAST_FROM_ASCII must not be defined at the same time
+#endif
+
#include <QtCore/qchar.h>
#include <QtCore/qbytearray.h>
#include <QtCore/qrefcount.h>
@@ -93,7 +97,7 @@ public:
inline bool operator>=(const QString &s) const;
inline bool operator<=(const QString &s) const;
-#ifndef QT_NO_CAST_FROM_ASCII
+#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
inline QT_ASCII_CAST_WARN bool operator==(const char *s) const;
inline QT_ASCII_CAST_WARN bool operator!=(const char *s) const;
inline QT_ASCII_CAST_WARN bool operator<(const char *s) const;
@@ -107,7 +111,7 @@ public:
inline QT_ASCII_CAST_WARN bool operator>(const QByteArray &s) const;
inline QT_ASCII_CAST_WARN bool operator<=(const QByteArray &s) const;
inline QT_ASCII_CAST_WARN bool operator>=(const QByteArray &s) const;
-#endif // QT_NO_CAST_FROM_ASCII
+#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
private:
int m_size;
@@ -327,7 +331,9 @@ public:
#ifndef QT_NO_REGULAREXPRESSION
int indexOf(const QRegularExpression &re, int from = 0) const;
+ int indexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const; // ### Qt 6: merge overloads
int lastIndexOf(const QRegularExpression &re, int from = -1) const;
+ int lastIndexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const; // ### Qt 6: merge overloads
bool contains(const QRegularExpression &re) const;
bool contains(const QRegularExpression &re, QRegularExpressionMatch *match) const; // ### Qt 6: merge overloads
int count(const QRegularExpression &re) const;
@@ -369,12 +375,44 @@ public:
QString leftJustified(int width, QChar fill = QLatin1Char(' '), bool trunc = false) const Q_REQUIRED_RESULT;
QString rightJustified(int width, QChar fill = QLatin1Char(' '), bool trunc = false) const Q_REQUIRED_RESULT;
+#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QSTRING_COMPAT_CPP)
+# if defined(Q_CC_GNU)
+ // required due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61941
+# pragma push_macro("Q_REQUIRED_RESULT")
+# undef Q_REQUIRED_RESULT
+# define Q_REQUIRED_RESULT
+# define Q_REQUIRED_RESULT_pushed
+# endif
+ QString toLower() const & Q_REQUIRED_RESULT
+ { return toLower_helper(*this); }
+ QString toLower() && Q_REQUIRED_RESULT
+ { return toLower_helper(*this); }
+ QString toUpper() const & Q_REQUIRED_RESULT
+ { return toUpper_helper(*this); }
+ QString toUpper() && Q_REQUIRED_RESULT
+ { return toUpper_helper(*this); }
+ QString toCaseFolded() const & Q_REQUIRED_RESULT
+ { return toCaseFolded_helper(*this); }
+ QString toCaseFolded() && Q_REQUIRED_RESULT
+ { return toCaseFolded_helper(*this); }
+ QString trimmed() const & Q_REQUIRED_RESULT
+ { return trimmed_helper(*this); }
+ QString trimmed() && Q_REQUIRED_RESULT
+ { return trimmed_helper(*this); }
+ QString simplified() const & Q_REQUIRED_RESULT
+ { return simplified_helper(*this); }
+ QString simplified() && Q_REQUIRED_RESULT
+ { return simplified_helper(*this); }
+# ifdef Q_REQUIRED_RESULT_pushed
+# pragma pop_macro("Q_REQUIRED_RESULT")
+# endif
+#else
QString toLower() const Q_REQUIRED_RESULT;
QString toUpper() const Q_REQUIRED_RESULT;
QString toCaseFolded() const Q_REQUIRED_RESULT;
-
QString trimmed() const Q_REQUIRED_RESULT;
QString simplified() const Q_REQUIRED_RESULT;
+#endif
QString toHtmlEscaped() const Q_REQUIRED_RESULT;
QString &insert(int i, QChar c);
@@ -596,7 +634,16 @@ public:
inline bool operator>=(QLatin1String s) const { return !operator<(s); }
// ASCII compatibility
-#ifndef QT_NO_CAST_FROM_ASCII
+#if defined(QT_RESTRICTED_CAST_FROM_ASCII)
+ template <int N>
+ inline QString(const char (&ch)[N])
+ : d(fromAscii_helper(ch, N - 1))
+ {}
+ template <int N>
+ inline QString &operator=(const char (&ch)[N])
+ { return (*this = fromLatin1(ch, N - 1)); }
+#endif
+#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
inline QT_ASCII_CAST_WARN QString(const char *ch)
: d(fromAscii_helper(ch, ch ? int(strlen(ch)) : -1))
{}
@@ -734,6 +781,16 @@ private:
Qt::CaseSensitivity cs = Qt::CaseSensitive);
static int localeAwareCompare_helper(const QChar *data1, int length1,
const QChar *data2, int length2);
+ static QString toLower_helper(const QString &str);
+ static QString toLower_helper(QString &str);
+ static QString toUpper_helper(const QString &str);
+ static QString toUpper_helper(QString &str);
+ static QString toCaseFolded_helper(const QString &str);
+ static QString toCaseFolded_helper(QString &str);
+ static QString trimmed_helper(const QString &str);
+ static QString trimmed_helper(QString &str);
+ static QString simplified_helper(const QString &str);
+ static QString simplified_helper(QString &str);
static Data *fromLatin1_helper(const char *str, int size = -1);
static Data *fromAscii_helper(const char *str, int size = -1);
static QString fromUtf8_helper(const char *str, int size);
@@ -867,11 +924,8 @@ 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
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_MSVC(4127) // "conditional expression is constant"
inline int QString::toWCharArray(wchar_t *array) const
{
@@ -882,9 +936,7 @@ 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
+QT_WARNING_POP
inline QString QString::fromWCharArray(const wchar_t *string, int size)
{
@@ -1083,7 +1135,7 @@ inline bool QLatin1String::operator>=(const QString &s) const
inline bool QLatin1String::operator<=(const QString &s) const
{ return s >= *this; }
-#ifndef QT_NO_CAST_FROM_ASCII
+#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
inline bool QString::operator==(const char *s) const
{ return QString::compare_helper(constData(), size(), s, -1) == 0; }
inline bool QString::operator!=(const char *s) const
@@ -1174,7 +1226,7 @@ inline bool QByteArray::operator<=(const QString &s) const
{ return QString::compare_helper(s.constData(), s.size(), constData(), qstrnlen(constData(), size())) <= 0; }
inline bool QByteArray::operator>=(const QString &s) const
{ return QString::compare_helper(s.constData(), s.size(), constData(), qstrnlen(constData(), size())) >= 0; }
-#endif // QT_NO_CAST_FROM_ASCII
+#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
#ifndef QT_NO_CAST_TO_ASCII
inline QByteArray &QByteArray::append(const QString &s)
@@ -1202,7 +1254,7 @@ inline const QString operator+(const QString &s1, QChar s2)
{ QString t(s1); t += s2; return t; }
inline const QString operator+(QChar s1, const QString &s2)
{ QString t(s1); t += s2; return t; }
-# ifndef QT_NO_CAST_FROM_ASCII
+# if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
inline QT_ASCII_CAST_WARN const QString operator+(const QString &s1, const char *s2)
{ QString t(s1); t += QString::fromUtf8(s2); return t; }
inline QT_ASCII_CAST_WARN const QString operator+(const char *s1, const QString &s2)
@@ -1355,7 +1407,7 @@ public:
inline const QChar at(int i) const
{ Q_ASSERT(uint(i) < uint(size())); return m_string->at(i + m_position); }
-#ifndef QT_NO_CAST_FROM_ASCII
+#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
// ASCII compatibility
inline QT_ASCII_CAST_WARN bool operator==(const char *s) const;
inline QT_ASCII_CAST_WARN bool operator!=(const char *s) const;
@@ -1429,7 +1481,7 @@ inline bool operator<=(const QStringRef &s1, const QStringRef &s2)
inline bool operator>=(const QStringRef &s1, const QStringRef &s2)
{ return !(s1 < s2); }
-#ifndef QT_NO_CAST_FROM_ASCII
+#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
inline QT_ASCII_CAST_WARN bool QStringRef::operator==(const char *s) const
{ return QString::compare_helper(constData(), size(), s, -1) == 0; }
inline QT_ASCII_CAST_WARN bool QStringRef::operator!=(const char *s) const
@@ -1455,7 +1507,7 @@ inline QT_ASCII_CAST_WARN bool operator>(const char *s1, const QStringRef &s2)
{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) <= 0; }
inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QStringRef &s2)
{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) >= 0; }
-#endif // QT_NO_CAST_FROM_ASCII
+#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
inline int QString::compare(const QStringRef &s, Qt::CaseSensitivity cs) const
{ return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); }
diff --git a/src/corelib/tools/qstring_compat.cpp b/src/corelib/tools/qstring_compat.cpp
index c776092569..d4f21e483a 100644
--- a/src/corelib/tools/qstring_compat.cpp
+++ b/src/corelib/tools/qstring_compat.cpp
@@ -31,16 +31,42 @@
**
****************************************************************************/
-#if defined(QSTRING_H)
+#if defined(QSTRING_H) || defined(QBYTEARRAY_H)
# error "This file cannot be compiled with pre-compiled headers"
#endif
#define QT_COMPILING_QSTRING_COMPAT_CPP
+#include "qbytearray.h"
#include "qstring.h"
QT_BEGIN_NAMESPACE
// all these implementations must be the same as the inline versions in qstring.h
+QString QString::trimmed() const
+{
+ return trimmed_helper(*this);
+}
+
+QString QString::simplified() const
+{
+ return simplified_helper(*this);
+}
+
+QString QString::toLower() const
+{
+ return toLower_helper(*this);
+}
+
+QString QString::toCaseFolded() const
+{
+ return toCaseFolded_helper(*this);
+}
+
+QString QString::toUpper() const
+{
+ return toUpper_helper(*this);
+}
+
QByteArray QString::toLatin1() const
{
return toLatin1_helper(*this);
@@ -56,4 +82,25 @@ QByteArray QString::toUtf8() const
return toUtf8_helper(*this);
}
+// ditto, for qbytearray.h (because we're lazy)
+QByteArray QByteArray::toLower() const
+{
+ return toLower_helper(*this);
+}
+
+QByteArray QByteArray::toUpper() const
+{
+ return toUpper_helper(*this);
+}
+
+QByteArray QByteArray::trimmed() const
+{
+ return trimmed_helper(*this);
+}
+
+QByteArray QByteArray::simplified() const
+{
+ return simplified_helper(*this);
+}
+
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qstringalgorithms_p.h b/src/corelib/tools/qstringalgorithms_p.h
new file mode 100644
index 0000000000..2911055f6a
--- /dev/null
+++ b/src/corelib/tools/qstringalgorithms_p.h
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Intel Corporation.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSTRINGALGORITHMS_P_H
+#define QSTRINGALGORITHMS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of internal files. This header file may change from version to version
+// without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qstring.h"
+#include "qlocale_p.h" // for ascii_isspace
+
+QT_BEGIN_NAMESPACE
+
+template <typename StringType> struct QStringAlgorithms
+{
+ typedef typename StringType::value_type Char;
+ typedef typename StringType::size_type size_type;
+ typedef typename QtPrivate::remove_cv<StringType>::type NakedStringType;
+ static const bool isConst = QtPrivate::is_const<StringType>::value;
+
+ static inline bool isSpace(char ch) { return ascii_isspace(ch); }
+ static inline bool isSpace(QChar ch) { return ch.isSpace(); }
+
+ // Surrogate pairs are not handled in either of the functions below. That is
+ // not a problem because there are no space characters (Zs, Zl, Zp) outside the
+ // Basic Multilingual Plane.
+
+ static inline StringType trimmed_helper_inplace(NakedStringType &str, const Char *begin, const Char *end)
+ {
+ // in-place trimming:
+ Char *data = const_cast<Char *>(str.cbegin());
+ if (begin != data)
+ memmove(data, begin, (end - begin) * sizeof(Char));
+ str.resize(end - begin);
+ return qMove(str);
+ }
+
+ static inline StringType trimmed_helper_inplace(const NakedStringType &, const Char *, const Char *)
+ {
+ // can't happen
+ Q_UNREACHABLE();
+ return StringType();
+ }
+
+ static inline void trimmed_helper_positions(const Char *&begin, const Char *&end)
+ {
+ // skip white space from start
+ while (begin < end && isSpace(*begin))
+ begin++;
+ // skip white space from end
+ if (begin < end) {
+ while (begin < end && isSpace(end[-1]))
+ end--;
+ }
+ }
+
+ static inline StringType trimmed_helper(StringType &str)
+ {
+ const Char *begin = str.cbegin();
+ const Char *end = str.cend();
+ trimmed_helper_positions(begin, end);
+
+ if (begin == str.cbegin() && end == str.cend())
+ return str;
+ if (begin == end)
+ return StringType();
+ if (!isConst && str.isDetached())
+ return trimmed_helper_inplace(str, begin, end);
+ return StringType(begin, end - begin);
+ }
+
+ static inline StringType simplified_helper(StringType &str)
+ {
+ if (str.isEmpty())
+ return str;
+ const Char *src = str.cbegin();
+ const Char *end = str.cend();
+ NakedStringType result = isConst ?
+ StringType(str.size(), Qt::Uninitialized) :
+ qMove(str);
+
+ Char *dst = const_cast<Char *>(result.cbegin());
+ Char *ptr = dst;
+ forever {
+ while (src != end && isSpace(*src))
+ ++src;
+ while (src != end && !isSpace(*src))
+ *ptr++ = *src++;
+ if (src != end)
+ *ptr++ = QChar::Space;
+ else
+ break;
+ }
+ if (ptr != dst && ptr[-1] == QChar::Space)
+ --ptr;
+
+ int newlen = ptr - dst;
+ if (isConst && newlen == str.size()) {
+ // nothing happened, return the original
+ return str;
+ }
+ result.resize(newlen);
+ return result;
+ }
+};
+
+QT_END_NAMESPACE
+
+#endif // QSTRINGALGORITHMS_P_H
diff --git a/src/corelib/tools/qstringiterator_p.h b/src/corelib/tools/qstringiterator_p.h
index b80193b790..3f431daf6f 100644
--- a/src/corelib/tools/qstringiterator_p.h
+++ b/src/corelib/tools/qstringiterator_p.h
@@ -74,6 +74,11 @@ public:
return pos;
}
+ inline int index() const
+ {
+ return pos - i;
+ }
+
inline void setPosition(QString::const_iterator position)
{
Q_ASSERT_X(i <= position && position <= e, Q_FUNC_INFO, "position out of bounds");
diff --git a/src/corelib/tools/qstringlist.cpp b/src/corelib/tools/qstringlist.cpp
index 4e5393e0b0..192306c059 100644
--- a/src/corelib/tools/qstringlist.cpp
+++ b/src/corelib/tools/qstringlist.cpp
@@ -516,28 +516,6 @@ QString QtPrivate::QStringList_join(const QStringList *that, const QChar *sep, i
the latter string list.
*/
-#ifndef QT_NO_DATASTREAM
-/*!
- \fn QDataStream &operator>>(QDataStream &in, QStringList &list)
- \relates QStringList
-
- Reads a string list from the given \a in stream into the specified
- \a list.
-
- \sa {Serializing Qt Data Types}
-*/
-
-/*!
- \fn QDataStream &operator<<(QDataStream &out, const QStringList &list)
- \relates QStringList
-
- Writes the given string \a list to the specified \a out stream.
-
- \sa {Serializing Qt Data Types}
-*/
-#endif // QT_NO_DATASTREAM
-
-
#ifndef QT_NO_REGEXP
static int indexOfMutating(const QStringList *that, QRegExp &rx, int from)
{
@@ -704,29 +682,6 @@ int QtPrivate::QStringList_lastIndexOf(const QStringList *that, const QRegularEx
#endif // QT_BOOTSTRAPPED
/*!
- \fn int QStringList::indexOf(const QString &value, int from = 0) const
-
- Returns the index position of the first occurrence of \a value in
- the list, searching forward from index position \a from. Returns
- -1 if no item matched.
-
- \sa lastIndexOf(), contains(), QList::indexOf()
-*/
-
-/*!
- \fn int QStringList::lastIndexOf(const QString &value, int from = -1) const
-
- Returns the index position of the last occurrence of \a value in
- the list, searching backward from index position \a from. If \a
- from is -1 (the default), the search starts at the last item.
- Returns -1 if no item matched.
-
- By default, this function is case sensitive.
-
- \sa indexOf(), QList::lastIndexOf()
-*/
-
-/*!
\fn int QStringList::removeDuplicates()
\since 4.5
diff --git a/src/corelib/tools/qstringlist.h b/src/corelib/tools/qstringlist.h
index b24a261a7c..cce67820f8 100644
--- a/src/corelib/tools/qstringlist.h
+++ b/src/corelib/tools/qstringlist.h
@@ -108,15 +108,8 @@ public:
#endif // QT_NO_REGULAREXPRESSION
#endif // QT_BOOTSTRAPPED
-#if !defined(Q_NO_USING_KEYWORD)
using QList<QString>::indexOf;
using QList<QString>::lastIndexOf;
-#else
- inline int indexOf(const QString &str, int from = 0) const
- { return QList<QString>::indexOf(str, from); }
- inline int lastIndexOf(const QString &str, int from = -1) const
- { return QList<QString>::lastIndexOf(str, from); }
-#endif
};
Q_DECLARE_TYPEINFO(QStringList, Q_MOVABLE_TYPE);
@@ -245,17 +238,6 @@ inline int QStringList::lastIndexOf(const QRegularExpression &rx, int from) cons
#endif // QT_NO_REGULAREXPRESSION
#endif // QT_BOOTSTRAPPED
-#ifndef QT_NO_DATASTREAM
-inline QDataStream &operator>>(QDataStream &in, QStringList &list)
-{
- return operator>>(in, static_cast<QList<QString> &>(list));
-}
-inline QDataStream &operator<<(QDataStream &out, const QStringList &list)
-{
- return operator<<(out, static_cast<const QList<QString> &>(list));
-}
-#endif // QT_NO_DATASTREAM
-
QT_END_NAMESPACE
#endif // QSTRINGLIST_H
diff --git a/src/corelib/tools/qtimeline.h b/src/corelib/tools/qtimeline.h
index 8e577c2651..c0b245ed8d 100644
--- a/src/corelib/tools/qtimeline.h
+++ b/src/corelib/tools/qtimeline.h
@@ -137,7 +137,7 @@ Q_SIGNALS:
);
protected:
- void timerEvent(QTimerEvent *event);
+ void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(QTimeLine)
diff --git a/src/corelib/tools/qtimezone.cpp b/src/corelib/tools/qtimezone.cpp
index 8f3db74131..fb5af2bf4a 100644
--- a/src/corelib/tools/qtimezone.cpp
+++ b/src/corelib/tools/qtimezone.cpp
@@ -56,6 +56,8 @@ static QTimeZonePrivate *newBackendTimeZone()
#else
#if defined Q_OS_MAC
return new QMacTimeZonePrivate();
+#elif defined Q_OS_ANDROID
+ return new QAndroidTimeZonePrivate();
#elif defined Q_OS_UNIX
return new QTzTimeZonePrivate();
// Registry based timezone backend not available on WinRT
@@ -81,6 +83,8 @@ static QTimeZonePrivate *newBackendTimeZone(const QByteArray &ianaId)
#else
#if defined Q_OS_MAC
return new QMacTimeZonePrivate(ianaId);
+#elif defined Q_OS_ANDROID
+ return new QAndroidTimeZonePrivate(ianaId);
#elif defined Q_OS_UNIX
return new QTzTimeZonePrivate(ianaId);
// Registry based timezone backend not available on WinRT
diff --git a/src/corelib/tools/qtimezoneprivate_android.cpp b/src/corelib/tools/qtimezoneprivate_android.cpp
new file mode 100644
index 0000000000..9d9bfc612d
--- /dev/null
+++ b/src/corelib/tools/qtimezoneprivate_android.cpp
@@ -0,0 +1,287 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Drew Parsons <dparsons@emerall.com>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QSet>
+#include "qtimezone.h"
+#include "qtimezoneprivate_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*
+ Private
+
+ Android implementation
+*/
+
+// Create the system default time zone
+QAndroidTimeZonePrivate::QAndroidTimeZonePrivate()
+ : QTimeZonePrivate()
+{
+ // start with system time zone
+ androidTimeZone = QJNIObjectPrivate::callStaticObjectMethod("java.util.TimeZone", "getDefault", "()Ljava/util/TimeZone;");
+ init("UTC");
+}
+
+// Create a named time zone
+QAndroidTimeZonePrivate::QAndroidTimeZonePrivate(const QByteArray &ianaId)
+ : QTimeZonePrivate()
+{
+ init(ianaId);
+}
+
+QAndroidTimeZonePrivate::QAndroidTimeZonePrivate(const QAndroidTimeZonePrivate &other)
+ : QTimeZonePrivate(other)
+{
+ androidTimeZone = other.androidTimeZone;
+ m_id = other.id();
+}
+
+QAndroidTimeZonePrivate::~QAndroidTimeZonePrivate()
+{
+}
+
+
+void QAndroidTimeZonePrivate::init(const QByteArray &ianaId)
+{
+ QJNIObjectPrivate jo_ianaId = QJNIObjectPrivate::fromString( QString::fromUtf8(ianaId) );
+ androidTimeZone = QJNIObjectPrivate::callStaticObjectMethod( "java.util.TimeZone", "getTimeZone", "(Ljava/lang/String;)Ljava/util/TimeZone;", static_cast<jstring>(jo_ianaId.object()) );
+
+ if (ianaId.isEmpty())
+ m_id = systemTimeZoneId();
+ else
+ m_id = ianaId;
+}
+
+QTimeZonePrivate *QAndroidTimeZonePrivate::clone()
+{
+ return new QAndroidTimeZonePrivate(*this);
+}
+
+
+QString QAndroidTimeZonePrivate::displayName(QTimeZone::TimeType timeType, QTimeZone::NameType nameType,
+ const QLocale &locale) const
+{
+ QString name;
+
+ if (androidTimeZone.isValid()) {
+ jboolean daylightTime = (timeType == QTimeZone::DaylightTime); // treat QTimeZone::GenericTime as QTimeZone::StandardTime
+
+ // treat all NameTypes as java TimeZone style LONG (value 1), except of course QTimeZone::ShortName which is style SHORT (value 0);
+ jint style = (nameType == QTimeZone::ShortName ? 0 : 1);
+
+ QJNIObjectPrivate jlanguage = QJNIObjectPrivate::fromString(QLocale::languageToString(locale.language()));
+ QJNIObjectPrivate jcountry = QJNIObjectPrivate::fromString(QLocale::countryToString(locale.country()));
+ QJNIObjectPrivate jvariant = QJNIObjectPrivate::fromString(QLocale::scriptToString(locale.script()));
+ QJNIObjectPrivate jlocale("java.util.Locale", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", static_cast<jstring>(jlanguage.object()), static_cast<jstring>(jcountry.object()), static_cast<jstring>(jvariant.object()));
+
+ QJNIObjectPrivate jname = androidTimeZone.callObjectMethod("getDisplayName", "(ZILjava/util/Locale;)Ljava/lang/String;", daylightTime, style, jlocale.object());
+
+ name = jname.toString();
+ }
+
+ return name;
+}
+
+QString QAndroidTimeZonePrivate::abbreviation(qint64 atMSecsSinceEpoch) const
+{
+ if ( isDaylightTime( atMSecsSinceEpoch ) )
+ return displayName(QTimeZone::DaylightTime, QTimeZone::ShortName, QLocale() );
+ else
+ return displayName(QTimeZone::StandardTime, QTimeZone::ShortName, QLocale() );
+}
+
+int QAndroidTimeZonePrivate::offsetFromUtc(qint64 atMSecsSinceEpoch) const
+{
+ // offsetFromUtc( ) is invoked when androidTimeZone may not yet be set at startup,
+ // so a validity test is needed here
+ if ( androidTimeZone.isValid() )
+ // the java method getOffset() returns milliseconds, but QTimeZone returns seconds
+ return androidTimeZone.callMethod<jint>( "getOffset", "(J)I", static_cast<jlong>(atMSecsSinceEpoch) ) / 1000;
+ else
+ return 0;
+}
+
+int QAndroidTimeZonePrivate::standardTimeOffset(qint64 atMSecsSinceEpoch) const
+{
+ // the java method does not use a reference time
+ Q_UNUSED( atMSecsSinceEpoch );
+ if ( androidTimeZone.isValid() )
+ // the java method getRawOffset() returns milliseconds, but QTimeZone returns seconds
+ return androidTimeZone.callMethod<jint>( "getRawOffset" ) / 1000;
+ else
+ return 0;
+}
+
+int QAndroidTimeZonePrivate::daylightTimeOffset(qint64 atMSecsSinceEpoch) const
+{
+ return ( offsetFromUtc(atMSecsSinceEpoch) - standardTimeOffset(atMSecsSinceEpoch) );
+}
+
+bool QAndroidTimeZonePrivate::hasDaylightTime() const
+{
+ if ( androidTimeZone.isValid() )
+ /* note: the Java function only tests for future daylight transtions, not past */
+ return androidTimeZone.callMethod<jboolean>("useDaylightTime" );
+ else
+ return false;
+}
+
+bool QAndroidTimeZonePrivate::isDaylightTime(qint64 atMSecsSinceEpoch) const
+{
+ if ( androidTimeZone.isValid() ) {
+ QJNIObjectPrivate jDate( "java/util/Date", "(J)V", static_cast<jlong>(atMSecsSinceEpoch) );
+ return androidTimeZone.callMethod<jboolean>("inDaylightTime", "(Ljava/util/Date;)Z", jDate.object() );
+ }
+ else
+ return false;
+}
+
+QTimeZonePrivate::Data QAndroidTimeZonePrivate::data(qint64 forMSecsSinceEpoch) const
+{
+ if (androidTimeZone.isValid()) {
+ Data data;
+ data.atMSecsSinceEpoch = forMSecsSinceEpoch;
+ data.standardTimeOffset = standardTimeOffset(forMSecsSinceEpoch);
+ data.offsetFromUtc = offsetFromUtc(forMSecsSinceEpoch);
+ data.daylightTimeOffset = data.offsetFromUtc - data.standardTimeOffset;
+ data.abbreviation = abbreviation(forMSecsSinceEpoch);
+ return data;
+ } else {
+ return invalidData();
+ }
+}
+
+bool QAndroidTimeZonePrivate::hasTransitions() const
+{
+ // java.util.TimeZone does not directly provide transitions
+ return false;
+}
+
+QTimeZonePrivate::Data QAndroidTimeZonePrivate::nextTransition(qint64 afterMSecsSinceEpoch) const
+{
+ // transitions not available on Android, so return an invalid data object
+ Q_UNUSED( afterMSecsSinceEpoch );
+ return invalidData();
+}
+
+QTimeZonePrivate::Data QAndroidTimeZonePrivate::previousTransition(qint64 beforeMSecsSinceEpoch) const
+{
+ // transitions not available on Android, so return an invalid data object
+ Q_UNUSED( beforeMSecsSinceEpoch );
+ return invalidData();
+}
+
+// Since Android does not provide an API to access transitions,
+// dataForLocalTime needs to be reimplemented without direct use of transitions
+QTimeZonePrivate::Data QAndroidTimeZonePrivate::dataForLocalTime(qint64 forLocalMSecs) const
+{
+ if (!androidTimeZone.isValid()) {
+ return invalidData();
+ } else {
+ qint64 UTCepochMSecs;
+
+ // compare the UTC time with standard offset against normal daylight offset of one hour
+ qint64 standardUTCMSecs(forLocalMSecs - (standardTimeOffset(forLocalMSecs) * 1000));
+ qint64 daylightUTCMsecs;
+
+ // Check if daylight time does apply,
+ // checking also for daylight time boundaries
+ if (isDaylightTime(standardUTCMSecs)) {
+ // If daylight does apply, then standardUTCMSecs will be an hour or so ahead of the real epoch time
+ // so check that time
+ daylightUTCMsecs = standardUTCMSecs - daylightTimeOffset(standardUTCMSecs)*1000;
+ if (isDaylightTime(daylightUTCMsecs)) {
+ // daylight time confirmed
+ UTCepochMSecs = daylightUTCMsecs;
+ } else {
+ // daylight time has just finished
+ UTCepochMSecs = standardUTCMSecs;
+ }
+ } else {
+ // Standard time indicated, but check for a false negative.
+ // Would a standard one-hour daylight offset indicate daylight time?
+ daylightUTCMsecs = standardUTCMSecs - 3600000; // 3600000 MSECS_PER_HOUR
+ if (isDaylightTime(daylightUTCMsecs)) {
+ // daylight time may have just started,
+ // but double check against timezone's own daylight offset
+ // (don't necessarily assume a one-hour offset)
+ daylightUTCMsecs = standardUTCMSecs - daylightTimeOffset(daylightUTCMsecs)*1000;
+ if (isDaylightTime(daylightUTCMsecs)) {
+ // daylight time confirmed
+ UTCepochMSecs = daylightUTCMsecs;
+ } else {
+ // false positive, apply standard time after all
+ UTCepochMSecs = standardUTCMSecs;
+ }
+ } else {
+ // confirmed standard time
+ UTCepochMSecs = standardUTCMSecs;
+ }
+ }
+
+ return data(UTCepochMSecs);
+ }
+}
+
+QByteArray QAndroidTimeZonePrivate::systemTimeZoneId() const
+{
+ QJNIObjectPrivate androidSystemTimeZone = QJNIObjectPrivate::callStaticObjectMethod("java.util.TimeZone", "getDefault", "()Ljava/util/TimeZone;");
+ QJNIObjectPrivate systemTZIdAndroid = androidSystemTimeZone.callObjectMethod<jstring>("getID");
+ QByteArray systemTZid = systemTZIdAndroid.toString().toUtf8();
+
+ return systemTZid;
+}
+
+QSet<QByteArray> QAndroidTimeZonePrivate::availableTimeZoneIds() const
+{
+ QSet<QByteArray> availableTimeZoneIdList;
+ QJNIObjectPrivate androidAvailableIdList = QJNIObjectPrivate::callStaticObjectMethod("java.util.TimeZone", "getAvailableIDs", "()[Ljava/lang/String;");
+
+ QJNIEnvironmentPrivate jniEnv;
+ int androidTZcount = jniEnv->GetArrayLength( static_cast<jarray>(androidAvailableIdList.object()) );
+
+ // need separate jobject and QAndroidJniObject here so that we can delete (DeleteLocalRef) the reference to the jobject
+ // (or else the JNI reference table fills after 512 entries from GetObjectArrayElement)
+ jobject androidTZobject;
+ QJNIObjectPrivate androidTZ;
+ for (int i=0; i<androidTZcount; i++ ) {
+ androidTZobject = jniEnv->GetObjectArrayElement( static_cast<jobjectArray>( androidAvailableIdList.object() ), i );
+ androidTZ = androidTZobject;
+ availableTimeZoneIdList.insert( androidTZ.toString().toUtf8() );
+ jniEnv->DeleteLocalRef(androidTZobject);
+ }
+
+ return availableTimeZoneIdList;
+}
+
+QT_END_NAMESPACE
diff --git a/src/corelib/tools/qtimezoneprivate_p.h b/src/corelib/tools/qtimezoneprivate_p.h
index 5ba42de560..6494ffe148 100644
--- a/src/corelib/tools/qtimezoneprivate_p.h
+++ b/src/corelib/tools/qtimezoneprivate_p.h
@@ -65,6 +65,10 @@ class NSTimeZone;
#include <qt_windows.h>
#endif // Q_OS_WIN
+#ifdef Q_OS_ANDROID
+#include <QtCore/private/qjni_p.h>
+#endif
+
QT_BEGIN_NAMESPACE
class Q_CORE_EXPORT QTimeZonePrivate : public QSharedData
@@ -256,7 +260,7 @@ private:
};
#endif // QT_USE_ICU
-#if defined Q_OS_UNIX && !defined Q_OS_MAC
+#if defined Q_OS_UNIX && !defined Q_OS_MAC && !defined Q_OS_ANDROID
class Q_AUTOTEST_EXPORT QTzTimeZonePrivate Q_DECL_FINAL : public QTimeZonePrivate
{
public:
@@ -424,6 +428,50 @@ private:
};
#endif // Q_OS_WIN
+#ifdef Q_OS_ANDROID
+class QAndroidTimeZonePrivate Q_DECL_FINAL : public QTimeZonePrivate
+{
+public:
+ // Create default time zone
+ QAndroidTimeZonePrivate();
+ // Create named time zone
+ QAndroidTimeZonePrivate(const QByteArray &ianaId);
+ QAndroidTimeZonePrivate(const QAndroidTimeZonePrivate &other);
+ ~QAndroidTimeZonePrivate();
+
+ QTimeZonePrivate *clone();
+
+ QString displayName(QTimeZone::TimeType timeType, QTimeZone::NameType nameType,
+ const QLocale &locale) const Q_DECL_OVERRIDE;
+ QString abbreviation(qint64 atMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+
+ int offsetFromUtc(qint64 atMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+ int standardTimeOffset(qint64 atMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+ int daylightTimeOffset(qint64 atMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+
+ bool hasDaylightTime() const Q_DECL_OVERRIDE;
+ bool isDaylightTime(qint64 atMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+
+ Data data(qint64 forMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+
+ bool hasTransitions() const Q_DECL_OVERRIDE;
+ Data nextTransition(qint64 afterMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+ Data previousTransition(qint64 beforeMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+
+ Data dataForLocalTime(qint64 forLocalMSecs) const Q_DECL_OVERRIDE;
+
+ QByteArray systemTimeZoneId() const Q_DECL_OVERRIDE;
+
+ QSet<QByteArray> availableTimeZoneIds() const Q_DECL_OVERRIDE;
+
+private:
+ void init(const QByteArray &zoneId);
+
+ QJNIObjectPrivate androidTimeZone;
+
+};
+#endif // Q_OS_ANDROID
+
QT_END_NAMESPACE
#endif // QTIMEZONEPRIVATE_P_H
diff --git a/src/corelib/tools/qtools_p.h b/src/corelib/tools/qtools_p.h
index 3876d3822c..53d5228c3b 100644
--- a/src/corelib/tools/qtools_p.h
+++ b/src/corelib/tools/qtools_p.h
@@ -46,9 +46,40 @@
//
#include "QtCore/qglobal.h"
+#include <limits>
QT_BEGIN_NAMESPACE
+namespace QtMiscUtils {
+inline char toHexUpper(uint value)
+{
+ static const char hexdigits[] = "0123456789ABCDEF";
+ return hexdigits[value & 0xF];
+}
+
+inline char toHexLower(uint value)
+{
+ static const char hexdigits[] = "0123456789abcdef";
+ return hexdigits[value & 0xF];
+}
+
+inline int fromHex(uint c)
+{
+ if ((c >= '0') && (c <= '9'))
+ return c - '0';
+ if ((c >= 'A') && (c <= 'F'))
+ return c - 'A' + 10;
+ if ((c >= 'a') && (c <= 'f'))
+ return c - 'a' + 10;
+ return -1;
+}
+}
+
+// We typically need an extra bit for qNextPowerOfTwo when determining the next allocation size.
+enum {
+ MaxAllocSize = (1 << (std::numeric_limits<int>::digits - 1)) - 1
+};
+
// implemented in qbytearray.cpp
int Q_CORE_EXPORT qAllocMore(int alloc, int extra) Q_DECL_NOTHROW;
diff --git a/src/corelib/tools/qvector.cpp b/src/corelib/tools/qvector.cpp
index 99e1db1cab..50c90ad746 100644
--- a/src/corelib/tools/qvector.cpp
+++ b/src/corelib/tools/qvector.cpp
@@ -463,6 +463,18 @@
\sa operator<<(), prepend(), insert()
*/
+/*! \fn void QVector::append(const QVector<T> &value)
+
+ \overload
+
+ \since 5.5
+
+ Appends the items of the \a value vector to this vector.
+
+ \sa operator<<(), operator+=()
+*/
+
+
/*! \fn void QVector::prepend(const T &value)
Inserts \a value at the beginning of the vector.
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h
index 07c66bc393..c00bd07a72 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -128,6 +128,7 @@ public:
T &operator[](int i);
const T &operator[](int i) const;
void append(const T &t);
+ inline void append(const QVector<T> &l) { *this += l; }
void prepend(const T &t);
void insert(int i, const T &t);
void insert(int i, int n, const T &t);
@@ -327,9 +328,11 @@ inline QVector<T>::QVector(const QVector<T> &v)
} else {
if (v.d->capacityReserved) {
d = Data::allocate(v.d->alloc);
+ Q_CHECK_PTR(d);
d->capacityReserved = true;
} else {
d = Data::allocate(v.d->size);
+ Q_CHECK_PTR(d);
}
if (d->alloc) {
copyConstruct(v.d->begin(), v.d->end(), d->begin());
@@ -439,6 +442,7 @@ QVector<T>::QVector(int asize)
Q_ASSERT_X(asize >= 0, "QVector::QVector", "Size must be greater than or equal to 0.");
if (Q_LIKELY(asize > 0)) {
d = Data::allocate(asize);
+ Q_CHECK_PTR(d);
d->size = asize;
defaultConstruct(d->begin(), d->end());
} else {
@@ -452,6 +456,7 @@ QVector<T>::QVector(int asize, const T &t)
Q_ASSERT_X(asize >= 0, "QVector::QVector", "Size must be greater than or equal to 0.");
if (asize > 0) {
d = Data::allocate(asize);
+ Q_CHECK_PTR(d);
d->size = asize;
T* i = d->end();
while (i != d->begin())
@@ -467,6 +472,7 @@ QVector<T>::QVector(std::initializer_list<T> args)
{
if (args.size() > 0) {
d = Data::allocate(args.size());
+ Q_CHECK_PTR(d);
// std::initializer_list<T>::iterator is guaranteed to be
// const T* ([support.initlist]/1), so can be memcpy'ed away from by copyConstruct
copyConstruct(args.begin(), args.end(), d->begin());
@@ -707,13 +713,10 @@ bool QVector<T>::operator==(const QVector<T> &v) const
return true;
if (d->size != v.d->size)
return false;
- T* b = d->begin();
- T* i = b + d->size;
- T* j = v.d->end();
- while (i != b)
- if (!(*--i == *--j))
- return false;
- return true;
+ const T *vb = v.d->begin();
+ const T *b = d->begin();
+ const T *e = d->end();
+ return std::equal(b, e, vb);
}
template <typename T>
@@ -791,12 +794,9 @@ int QVector<T>::lastIndexOf(const T &t, int from) const
template <typename T>
bool QVector<T>::contains(const T &t) const
{
- T* b = d->begin();
- T* i = d->end();
- while (i != b)
- if (*--i == t)
- return true;
- return false;
+ const T *b = d->begin();
+ const T *e = d->end();
+ return std::find(b, e, t) != e;
}
template <typename T>
diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri
index cef802fa76..01b514d329 100644
--- a/src/corelib/tools/tools.pri
+++ b/src/corelib/tools/tools.pri
@@ -57,6 +57,7 @@ HEADERS += \
tools/qsize.h \
tools/qstack.h \
tools/qstring.h \
+ tools/qstringalgorithms_p.h \
tools/qstringbuilder.h \
tools/qstringiterator_p.h \
tools/qstringlist.h \
@@ -128,13 +129,19 @@ false: SOURCES += $$NO_PCH_SOURCES # Hack for QtCreator
OBJECTIVE_SOURCES += tools/qlocale_mac.mm \
tools/qtimezoneprivate_mac.mm \
tools/qstring_mac.mm \
- tools/qbytearray_mac.mm
+ tools/qbytearray_mac.mm \
+ tools/qdatetime_mac.mm
}
else:blackberry {
SOURCES += tools/qelapsedtimer_unix.cpp tools/qlocale_blackberry.cpp tools/qtimezoneprivate_tz.cpp
HEADERS += tools/qlocale_blackberry.h
}
-else:unix:SOURCES += tools/qelapsedtimer_unix.cpp tools/qlocale_unix.cpp tools/qtimezoneprivate_tz.cpp
+else:android {
+ SOURCES += tools/qelapsedtimer_unix.cpp tools/qlocale_unix.cpp tools/qtimezoneprivate_android.cpp
+}
+else:unix {
+ SOURCES += tools/qelapsedtimer_unix.cpp tools/qlocale_unix.cpp tools/qtimezoneprivate_tz.cpp
+}
else:win32 {
SOURCES += tools/qelapsedtimer_win.cpp tools/qlocale_win.cpp
!winrt: SOURCES += tools/qtimezoneprivate_win.cpp
diff --git a/src/corelib/xml/qxmlstream.cpp b/src/corelib/xml/qxmlstream.cpp
index 94f6a8bcde..9928098a33 100644
--- a/src/corelib/xml/qxmlstream.cpp
+++ b/src/corelib/xml/qxmlstream.cpp
@@ -2393,15 +2393,6 @@ QXmlStreamAttribute& QXmlStreamAttribute::operator=(const QXmlStreamAttribute &o
*/
/*!
- \fn void QXmlStreamAttributes::append(const QXmlStreamAttribute &attribute)
-
- Appends the given \a attribute to the end of the vector.
-
- \sa QVector::append()
-*/
-
-
-/*!
\typedef QXmlStreamNotationDeclarations
\relates QXmlStreamNotationDeclaration
diff --git a/src/corelib/xml/qxmlstream.h b/src/corelib/xml/qxmlstream.h
index 77f99c5d16..9a5756a431 100644
--- a/src/corelib/xml/qxmlstream.h
+++ b/src/corelib/xml/qxmlstream.h
@@ -125,12 +125,7 @@ public:
return !value(namespaceUri, name).isNull();
}
-#if !defined(Q_NO_USING_KEYWORD)
using QVector<QXmlStreamAttribute>::append;
-#else
- inline void append(const QXmlStreamAttribute &attribute)
- { QVector<QXmlStreamAttribute>::append(attribute); }
-#endif
};
class Q_CORE_EXPORT QXmlStreamNamespaceDeclaration {