summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/animation/qabstractanimation.h7
-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/arch/qatomic_mips.h5
-rw-r--r--src/corelib/codecs/qicucodec_p.h10
-rw-r--r--src/corelib/codecs/qisciicodec.cpp1
-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_global_qglobal.cpp13
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qmimedata.cpp6
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp14
-rw-r--r--src/corelib/doc/snippets/qloggingcategory/main.cpp14
-rw-r--r--src/corelib/doc/snippets/qstring/main.cpp14
-rw-r--r--src/corelib/global/global.pri2
-rw-r--r--src/corelib/global/qcompilerdetection.h106
-rw-r--r--src/corelib/global/qendian.h254
-rw-r--r--src/corelib/global/qflags.h73
-rw-r--r--src/corelib/global/qglobal.cpp191
-rw-r--r--src/corelib/global/qglobal.h73
-rw-r--r--src/corelib/global/qhooks.cpp2
-rw-r--r--src/corelib/global/qlibraryinfo.cpp110
-rw-r--r--src/corelib/global/qlibraryinfo.h10
-rw-r--r--src/corelib/global/qlogging.cpp212
-rw-r--r--src/corelib/global/qlogging.h18
-rw-r--r--src/corelib/global/qnamespace.h150
-rw-r--r--src/corelib/global/qnamespace.qdoc22
-rw-r--r--src/corelib/global/qsysinfo.h20
-rw-r--r--src/corelib/global/qsystemdetection.h3
-rw-r--r--src/corelib/global/qtypeinfo.h13
-rw-r--r--src/corelib/io/forkfd_qt.cpp82
-rw-r--r--src/corelib/io/io.pri9
-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.cpp168
-rw-r--r--src/corelib/io/qdebug.h101
-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.cpp37
-rw-r--r--src/corelib/io/qfilesystemengine_unix.cpp57
-rw-r--r--src/corelib/io/qfilesystementry.cpp8
-rw-r--r--src/corelib/io/qfilesystemwatcher.cpp20
-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.cpp210
-rw-r--r--src/corelib/io/qiodevice_p.h4
-rw-r--r--src/corelib/io/qipaddress.cpp3
-rw-r--r--src/corelib/io/qloggingcategory.cpp75
-rw-r--r--src/corelib/io/qloggingcategory.h19
-rw-r--r--src/corelib/io/qloggingregistry.cpp11
-rw-r--r--src/corelib/io/qnoncontiguousbytedevice.cpp29
-rw-r--r--src/corelib/io/qnoncontiguousbytedevice_p.h55
-rw-r--r--src/corelib/io/qprocess.cpp31
-rw-r--r--src/corelib/io/qprocess.h20
-rw-r--r--src/corelib/io/qprocess_p.h20
-rw-r--r--src/corelib/io/qprocess_unix.cpp533
-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.cpp5
-rw-r--r--src/corelib/io/qsettings.h2
-rw-r--r--src/corelib/io/qsettings_p.h18
-rw-r--r--src/corelib/io/qstandardpaths.cpp16
-rw-r--r--src/corelib/io/qstandardpaths.h1
-rw-r--r--src/corelib/io/qstandardpaths_android.cpp1
-rw-r--r--src/corelib/io/qstandardpaths_blackberry.cpp1
-rw-r--r--src/corelib/io/qstandardpaths_haiku.cpp222
-rw-r--r--src/corelib/io/qstandardpaths_ios.mm1
-rw-r--r--src/corelib/io/qstandardpaths_mac.mm10
-rw-r--r--src/corelib/io/qstandardpaths_unix.cpp31
-rw-r--r--src/corelib/io/qstandardpaths_win.cpp2
-rw-r--r--src/corelib/io/qstandardpaths_winrt.cpp1
-rw-r--r--src/corelib/io/qstorageinfo_p.h6
-rw-r--r--src/corelib/io/qstorageinfo_unix.cpp7
-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.cpp155
-rw-r--r--src/corelib/io/qtextstream.h2
-rw-r--r--src/corelib/io/qtextstream_p.h8
-rw-r--r--src/corelib/io/qtldurl.cpp2
-rw-r--r--src/corelib/io/qurl.h8
-rw-r--r--src/corelib/io/qurlrecode.cpp4
-rw-r--r--src/corelib/itemmodels/qabstractitemmodel.cpp33
-rw-r--r--src/corelib/itemmodels/qabstractitemmodel.h80
-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/qitemselectionmodel.cpp144
-rw-r--r--src/corelib/itemmodels/qitemselectionmodel.h34
-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.pri30
-rw-r--r--src/corelib/kernel/qcore_mac_objc.mm97
-rw-r--r--src/corelib/kernel/qcore_mac_p.h8
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp83
-rw-r--r--src/corelib/kernel/qcoreapplication.h2
-rw-r--r--src/corelib/kernel/qcoreapplication_p.h5
-rw-r--r--src/corelib/kernel/qcoreevent.cpp1
-rw-r--r--src/corelib/kernel/qcoreevent.h4
-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_p.h9
-rw-r--r--src/corelib/kernel/qfunctions_wince.h2
-rw-r--r--src/corelib/kernel/qjnihelpers.cpp33
-rw-r--r--src/corelib/kernel/qjnihelpers_p.h11
-rw-r--r--src/corelib/kernel/qmetaobject.cpp216
-rw-r--r--src/corelib/kernel/qmetaobject.h44
-rw-r--r--src/corelib/kernel/qmetaobject_p.h4
-rw-r--r--src/corelib/kernel/qmetatype.cpp297
-rw-r--r--src/corelib/kernel/qmetatype.h126
-rw-r--r--src/corelib/kernel/qmetatype_p.h6
-rw-r--r--src/corelib/kernel/qmimedata.cpp5
-rw-r--r--src/corelib/kernel/qobject.cpp25
-rw-r--r--src/corelib/kernel/qobject.h12
-rw-r--r--src/corelib/kernel/qobject_p.h5
-rw-r--r--src/corelib/kernel/qobjectdefs.h21
-rw-r--r--src/corelib/kernel/qsharedmemory.cpp2
-rw-r--r--src/corelib/kernel/qsharedmemory_p.h4
-rw-r--r--src/corelib/kernel/qsharedmemory_posix.cpp231
-rw-r--r--src/corelib/kernel/qsharedmemory_systemv.cpp254
-rw-r--r--src/corelib/kernel/qsharedmemory_unix.cpp199
-rw-r--r--src/corelib/kernel/qsocketnotifier.h2
-rw-r--r--src/corelib/kernel/qsystemsemaphore.cpp2
-rw-r--r--src/corelib/kernel/qsystemsemaphore_android.cpp4
-rw-r--r--src/corelib/kernel/qsystemsemaphore_p.h11
-rw-r--r--src/corelib/kernel/qsystemsemaphore_posix.cpp182
-rw-r--r--src/corelib/kernel/qsystemsemaphore_systemv.cpp198
-rw-r--r--src/corelib/kernel/qsystemsemaphore_unix.cpp150
-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.cpp233
-rw-r--r--src/corelib/kernel/qvariant.h24
-rw-r--r--src/corelib/kernel/qvariant_p.h4
-rw-r--r--src/corelib/mimetypes/qmimedatabase_p.h1
-rw-r--r--src/corelib/mimetypes/qmimeprovider_p.h38
-rw-r--r--src/corelib/plugin/qfactoryloader.cpp28
-rw-r--r--src/corelib/plugin/qlibrary.cpp12
-rw-r--r--src/corelib/plugin/qlibrary.h6
-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.h8
-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.h23
-rw-r--r--src/corelib/statemachine/qstatemachine.cpp20
-rw-r--r--src/corelib/statemachine/qstatemachine.h8
-rw-r--r--src/corelib/statemachine/qstatemachine_p.h19
-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/qmutex.h20
-rw-r--r--src/corelib/thread/qreadwritelock.h36
-rw-r--r--src/corelib/thread/qthread.h2
-rw-r--r--src/corelib/thread/qthread_p.h2
-rw-r--r--src/corelib/thread/qthread_unix.cpp6
-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/thread/qwaitcondition_unix.cpp2
-rw-r--r--src/corelib/tools/qalgorithms.h6
-rw-r--r--src/corelib/tools/qarraydata.cpp19
-rw-r--r--src/corelib/tools/qarraydata.h4
-rw-r--r--src/corelib/tools/qarraydatapointer.h6
-rw-r--r--src/corelib/tools/qbitarray.h6
-rw-r--r--src/corelib/tools/qbytearray.cpp235
-rw-r--r--src/corelib/tools/qbytearray.h57
-rw-r--r--src/corelib/tools/qbytearraymatcher.h8
-rw-r--r--src/corelib/tools/qcache.h4
-rw-r--r--src/corelib/tools/qchar.h125
-rw-r--r--src/corelib/tools/qcollator.h10
-rw-r--r--src/corelib/tools/qcommandlineparser.cpp68
-rw-r--r--src/corelib/tools/qdatetime.cpp115
-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/qeasingcurve.h2
-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.cpp159
-rw-r--r--src/corelib/tools/qhash.h92
-rw-r--r--src/corelib/tools/qlist.cpp8
-rw-r--r--src/corelib/tools/qlist.h28
-rw-r--r--src/corelib/tools/qlocale.cpp25
-rw-r--r--src/corelib/tools/qlocale.h7
-rw-r--r--src/corelib/tools/qlocale_tools.cpp53
-rw-r--r--src/corelib/tools/qmap.cpp43
-rw-r--r--src/corelib/tools/qmap.h18
-rw-r--r--src/corelib/tools/qmargins.h213
-rw-r--r--src/corelib/tools/qpair.h23
-rw-r--r--src/corelib/tools/qpair.qdoc25
-rw-r--r--src/corelib/tools/qpoint.h72
-rw-r--r--src/corelib/tools/qrect.cpp28
-rw-r--r--src/corelib/tools/qrect.h649
-rw-r--r--src/corelib/tools/qregexp.cpp3
-rw-r--r--src/corelib/tools/qregularexpression.cpp131
-rw-r--r--src/corelib/tools/qregularexpression.h22
-rw-r--r--src/corelib/tools/qringbuffer_p.h48
-rw-r--r--src/corelib/tools/qset.h9
-rw-r--r--src/corelib/tools/qset.qdoc11
-rw-r--r--src/corelib/tools/qshareddata.h26
-rw-r--r--src/corelib/tools/qsize.cpp8
-rw-r--r--src/corelib/tools/qsize.h248
-rw-r--r--src/corelib/tools/qstring.cpp649
-rw-r--r--src/corelib/tools/qstring.h130
-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.h138
-rw-r--r--src/corelib/tools/qstringmatcher.h8
-rw-r--r--src/corelib/tools/qtimeline.h2
-rw-r--r--src/corelib/tools/qtimezone.cpp27
-rw-r--r--src/corelib/tools/qtimezone.h6
-rw-r--r--src/corelib/tools/qtimezoneprivate_android.cpp287
-rw-r--r--src/corelib/tools/qtimezoneprivate_p.h60
-rw-r--r--src/corelib/tools/qtools_p.h31
-rw-r--r--src/corelib/tools/qunicodetables.cpp16
-rw-r--r--src/corelib/tools/qunicodetables_p.h20
-rw-r--r--src/corelib/tools/qvector.cpp12
-rw-r--r--src/corelib/tools/qvector.h28
-rw-r--r--src/corelib/tools/qversionnumber.cpp8
-rw-r--r--src/corelib/tools/qversionnumber_p.h14
-rw-r--r--src/corelib/tools/tools.pri14
-rw-r--r--src/corelib/xml/qxmlstream.cpp9
-rw-r--r--src/corelib/xml/qxmlstream.h5
255 files changed, 7551 insertions, 4259 deletions
diff --git a/src/corelib/animation/qabstractanimation.h b/src/corelib/animation/qabstractanimation.h
index 2c325e7c02..152a914475 100644
--- a/src/corelib/animation/qabstractanimation.h
+++ b/src/corelib/animation/qabstractanimation.h
@@ -49,8 +49,7 @@ class QAbstractAnimationPrivate;
class Q_CORE_EXPORT QAbstractAnimation : public QObject
{
Q_OBJECT
- Q_ENUMS(State)
- Q_ENUMS(Direction)
+
Q_PROPERTY(State state READ state NOTIFY stateChanged)
Q_PROPERTY(int loopCount READ loopCount WRITE setLoopCount)
Q_PROPERTY(int currentTime READ currentTime WRITE setCurrentTime)
@@ -63,12 +62,14 @@ public:
Forward,
Backward
};
+ Q_ENUM(Direction)
enum State {
Stopped,
Paused,
Running
};
+ Q_ENUM(State)
enum DeletionPolicy {
KeepWhenStopped = 0,
@@ -111,7 +112,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/arch/qatomic_mips.h b/src/corelib/arch/qatomic_mips.h
index b8a9665f86..b99c70f0c8 100644
--- a/src/corelib/arch/qatomic_mips.h
+++ b/src/corelib/arch/qatomic_mips.h
@@ -120,7 +120,10 @@ void QBasicAtomicOps<size>::releaseMemoryFence(const T &) Q_DECL_NOTHROW
template <int size> template <typename T> inline
void QBasicAtomicOps<size>::orderedMemoryFence(const T &) Q_DECL_NOTHROW
{
- asm volatile ("sync 0" ::: "memory");
+ asm volatile (".set push\n"
+ ".set mips32\n"
+ "sync 0\n"
+ ".set pop\n" ::: "memory");
}
template<> template<typename T> inline
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.cpp b/src/corelib/codecs/qisciicodec.cpp
index e0c33aaa50..bd3b31667c 100644
--- a/src/corelib/codecs/qisciicodec.cpp
+++ b/src/corelib/codecs/qisciicodec.cpp
@@ -212,6 +212,7 @@ QByteArray QIsciiCodec::convertFromUnicode(const QChar *uc, int len, ConverterSt
if (iscii > 0x80) {
*ch++ = iscii;
} else if (iscii) {
+ Q_ASSERT((2 * iscii) < (sizeof(uni_to_iscii_pairs) / sizeof(uni_to_iscii_pairs[0])));
const uchar *pair = uni_to_iscii_pairs + 2*iscii;
*ch++ = *pair++;
*ch++ = *pair++;
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_global_qglobal.cpp b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
index d804514584..0ddd433d71 100644
--- a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
@@ -253,6 +253,9 @@ void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QS
case QtDebugMsg:
fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
+ case QtInfoMsg:
+ fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
+ break;
case QtWarningMsg:
fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
@@ -285,6 +288,14 @@ qDebug() << "Brush:" << myQBrush << "Other value:" << i;
//! [25]
+//! [qInfo_printf]
+qInfo("Items in list: %d", myList.size());
+//! [qInfo_printf]
+
+//! [qInfo_stream]
+qInfo() << "Brush:" << myQBrush << "Other value:" << i;
+//! [qInfo_stream]
+
//! [26]
void f(int c)
{
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/code/src_corelib_tools_qhash.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp
index aa0473964c..0195b07b54 100644
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp
@@ -307,3 +307,17 @@ inline uint qHash(const std::vector<int> &key, uint seed = 0)
return qHashBits(&key.front(), key.size() * sizeof(int), seed);
}
//! [qhashbits]
+
+//! [qhashrange]
+inline uint qHash(const std::vector<int> &key, uint seed = 0)
+{
+ return qHashRange(key.begin(), key.end(), seed);
+}
+//! [qhashrange]
+
+//! [qhashrangecommutative]
+inline uint qHash(const std::unordered_set<int> &key, uint seed = 0)
+{
+ return qHashRangeCommutative(key.begin(), key.end(), seed);
+}
+//! [qhashrangecommutative]
diff --git a/src/corelib/doc/snippets/qloggingcategory/main.cpp b/src/corelib/doc/snippets/qloggingcategory/main.cpp
index 3c6424921e..504a88b1a8 100644
--- a/src/corelib/doc/snippets/qloggingcategory/main.cpp
+++ b/src/corelib/doc/snippets/qloggingcategory/main.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -117,6 +117,11 @@ oldCategoryFilter = QLoggingCategory::installFilter(myCategoryFilter);
//![10]
}
+//![qcinfo_stream]
+ QLoggingCategory category("driver.usb");
+ qCInfo(category) << "an informational message";
+//![qcinfo_stream]
+
{
//![11]
QLoggingCategory category("driver.usb");
@@ -139,6 +144,13 @@ oldCategoryFilter = QLoggingCategory::installFilter(myCategoryFilter);
}
{
+//![qcinfo_printf]
+ QLoggingCategory category("driver.usb");
+ qCInfo(category, "an informational message logged into category %s", category.categoryName());
+//![qcinfo_printf]
+ }
+
+ {
//![14]
QLoggingCategory category("driver.usb");
qCWarning(category, "a warning message logged into category %s", category.categoryName());
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/global.pri b/src/corelib/global/global.pri
index e0dd9e4f36..bc11c77d88 100644
--- a/src/corelib/global/global.pri
+++ b/src/corelib/global/global.pri
@@ -38,7 +38,7 @@ PRECOMPILED_HEADER = global/qt_pch.h
# qlogging.cpp uses backtrace(3), which is in a separate library on the BSDs.
LIBS_PRIVATE += $$QMAKE_LIBS_EXECINFO
-linux*:!cross_compile:!static:!*-armcc* {
+if(linux*|hurd*):!cross_compile:!static:!*-armcc* {
QMAKE_LFLAGS += -Wl,-e,qt_core_boilerplate
prog=$$quote(if (/program interpreter: (.*)]/) { print $1; })
DEFINES += ELF_INTERPRETER=\\\"$$system(readelf -l /bin/ls | perl -n -e \'$$prog\')\\\"
diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h
index 7effb24130..2881a0fcbd 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
@@ -138,7 +136,6 @@
#elif defined(__GNUC__)
# define Q_CC_GNU (__GNUC__ * 100 + __GNUC_MINOR__)
-# define Q_C_CALLBACKS
# if defined(__MINGW32__)
# define Q_CC_MINGW
# endif
@@ -282,7 +279,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
@@ -319,7 +315,6 @@
/* The Comeau compiler is based on EDG and does define __EDG__ */
# if defined(__COMO__)
# define Q_CC_COMEAU
-# define Q_C_CALLBACKS
/* The `using' keyword was introduced to avoid KAI C++ warnings
but it's now causing KAI C++ errors instead. The standard is
@@ -327,7 +322,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)
@@ -350,23 +344,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
@@ -408,10 +398,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
# error "Compiler not supported"
@@ -449,7 +435,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/"
@@ -515,7 +500,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
@@ -533,6 +518,9 @@
# define Q_COMPILER_AUTO_FUNCTION
# define Q_COMPILER_NULLPTR
# define Q_COMPILER_TEMPLATE_ALIAS
+# ifndef _CHAR16T // MSVC headers
+# define Q_COMPILER_UNICODE_STRINGS
+# endif
# define Q_COMPILER_VARIADIC_TEMPLATES
# endif
# if __INTEL_COMPILER >= 1300
@@ -879,7 +867,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 */
@@ -949,12 +954,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
@@ -1057,6 +1071,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/qendian.h b/src/corelib/global/qendian.h
index 0e383c18d2..957ba2ad63 100644
--- a/src/corelib/global/qendian.h
+++ b/src/corelib/global/qendian.h
@@ -63,7 +63,7 @@ template <typename T> inline void qbswap(const T src, uchar *dest)
}
// Used to implement a type-safe and alignment-safe copy operation
-// If you want to avoid the memcopy, you must write specializations for this function
+// If you want to avoid the memcpy, you must write specializations for these functions
template <typename T> inline void qToUnaligned(const T src, uchar *dest)
{
// Using sizeof(T) inside memcpy function produces internal compiler error with
@@ -71,199 +71,14 @@ template <typename T> inline void qToUnaligned(const T src, uchar *dest)
const size_t size = sizeof(T);
memcpy(dest, &src, size);
}
-
-/* T qFromLittleEndian(const uchar *src)
- * This function will read a little-endian encoded value from \a src
- * and return the value in host-endian encoding.
- * There is no requirement that \a src must be aligned.
-*/
-#if defined Q_CC_SUN
-inline quint64 qFromLittleEndian_helper(const uchar *src, quint64 *dest)
-{
- return 0
- | src[0]
- | src[1] * Q_UINT64_C(0x0000000000000100)
- | src[2] * Q_UINT64_C(0x0000000000010000)
- | src[3] * Q_UINT64_C(0x0000000001000000)
- | src[4] * Q_UINT64_C(0x0000000100000000)
- | src[5] * Q_UINT64_C(0x0000010000000000)
- | src[6] * Q_UINT64_C(0x0001000000000000)
- | src[7] * Q_UINT64_C(0x0100000000000000);
-}
-
-inline quint32 qFromLittleEndian_helper(const uchar *src, quint32 *dest)
-{
- return 0
- | src[0]
- | src[1] * quint32(0x00000100)
- | src[2] * quint32(0x00010000)
- | src[3] * quint32(0x01000000);
-}
-
-inline quint16 qFromLittleEndian_helper(const uchar *src, quint16 *dest)
-{
- return 0
- | src[0]
- | src[1] * 0x0100;
-}
-
-inline qint64 qFromLittleEndian_helper(const uchar *src, qint64 * dest)
-{ return static_cast<qint64>(qFromLittleEndian_helper(src, reinterpret_cast<quint64*>(0))); }
-inline qint32 qFromLittleEndian_helper(const uchar *src, qint32 * dest)
-{ return static_cast<qint32>(qFromLittleEndian_helper(src, reinterpret_cast<quint32*>(0))); }
-inline qint16 qFromLittleEndian_helper(const uchar *src, qint16 * dest)
-{ return static_cast<qint16>(qFromLittleEndian_helper(src, reinterpret_cast<quint16*>(0))); }
-
-template <class T> inline T qFromLittleEndian(const uchar *src)
-{
- return qFromLittleEndian_helper(src, reinterpret_cast<T*>(0));
-}
-
-#else
-template <typename T> inline T qFromLittleEndian(const uchar *src);
-template <> inline quint64 qFromLittleEndian<quint64>(const uchar *src)
-{
- return 0
- | src[0]
- | src[1] * Q_UINT64_C(0x0000000000000100)
- | src[2] * Q_UINT64_C(0x0000000000010000)
- | src[3] * Q_UINT64_C(0x0000000001000000)
- | src[4] * Q_UINT64_C(0x0000000100000000)
- | src[5] * Q_UINT64_C(0x0000010000000000)
- | src[6] * Q_UINT64_C(0x0001000000000000)
- | src[7] * Q_UINT64_C(0x0100000000000000);
-}
-
-template <> inline quint32 qFromLittleEndian<quint32>(const uchar *src)
-{
- return 0
- | src[0]
- | src[1] * quint32(0x00000100)
- | src[2] * quint32(0x00010000)
- | src[3] * quint32(0x01000000);
-}
-
-template <> inline quint16 qFromLittleEndian<quint16>(const uchar *src)
-{
- return quint16(0
- | src[0]
- | src[1] * 0x0100);
-}
-
-// signed specializations
-template <> inline qint64 qFromLittleEndian<qint64>(const uchar *src)
-{ return static_cast<qint64>(qFromLittleEndian<quint64>(src)); }
-
-template <> inline qint32 qFromLittleEndian<qint32>(const uchar *src)
-{ return static_cast<qint32>(qFromLittleEndian<quint32>(src)); }
-
-template <> inline qint16 qFromLittleEndian<qint16>(const uchar *src)
-{ return static_cast<qint16>(qFromLittleEndian<quint16>(src)); }
-#endif
-
-template <> inline quint8 qFromLittleEndian<quint8>(const uchar *src)
-{ return static_cast<quint8>(src[0]); }
-template <> inline qint8 qFromLittleEndian<qint8>(const uchar *src)
-{ return static_cast<qint8>(src[0]); }
-
-/* This function will read a big-endian (also known as network order) encoded value from \a src
- * and return the value in host-endian encoding.
- * There is no requirement that \a src must be aligned.
-*/
-#if defined Q_CC_SUN
-inline quint64 qFromBigEndian_helper(const uchar *src, quint64 *dest)
-{
- return 0
- | src[7]
- | src[6] * Q_UINT64_C(0x0000000000000100)
- | src[5] * Q_UINT64_C(0x0000000000010000)
- | src[4] * Q_UINT64_C(0x0000000001000000)
- | src[3] * Q_UINT64_C(0x0000000100000000)
- | src[2] * Q_UINT64_C(0x0000010000000000)
- | src[1] * Q_UINT64_C(0x0001000000000000)
- | src[0] * Q_UINT64_C(0x0100000000000000);
-}
-
-inline quint32 qFromBigEndian_helper(const uchar *src, quint32 * dest)
-{
- return 0
- | src[3]
- | src[2] * quint32(0x00000100)
- | src[1] * quint32(0x00010000)
- | src[0] * quint32(0x01000000);
-}
-
-inline quint16 qFromBigEndian_helper(const uchar *src, quint16 * des)
-{
- return 0
- | src[1]
- | src[0] * 0x0100;
-}
-
-
-inline qint64 qFromBigEndian_helper(const uchar *src, qint64 * dest)
-{ return static_cast<qint64>(qFromBigEndian_helper(src, reinterpret_cast<quint64*>(0))); }
-inline qint32 qFromBigEndian_helper(const uchar *src, qint32 * dest)
-{ return static_cast<qint32>(qFromBigEndian_helper(src, reinterpret_cast<quint32*>(0))); }
-inline qint16 qFromBigEndian_helper(const uchar *src, qint16 * dest)
-{ return static_cast<qint16>(qFromBigEndian_helper(src, reinterpret_cast<quint16*>(0))); }
-
-template <class T> inline T qFromBigEndian(const uchar *src)
-{
- return qFromBigEndian_helper(src, reinterpret_cast<T*>(0));
-}
-
-#else
-template <class T> inline T qFromBigEndian(const uchar *src);
-template<>
-inline quint64 qFromBigEndian<quint64>(const uchar *src)
+template <typename T> inline T qFromUnaligned(const uchar *src)
{
- return 0
- | src[7]
- | src[6] * Q_UINT64_C(0x0000000000000100)
- | src[5] * Q_UINT64_C(0x0000000000010000)
- | src[4] * Q_UINT64_C(0x0000000001000000)
- | src[3] * Q_UINT64_C(0x0000000100000000)
- | src[2] * Q_UINT64_C(0x0000010000000000)
- | src[1] * Q_UINT64_C(0x0001000000000000)
- | src[0] * Q_UINT64_C(0x0100000000000000);
-}
-
-template<>
-inline quint32 qFromBigEndian<quint32>(const uchar *src)
-{
- return 0
- | src[3]
- | src[2] * quint32(0x00000100)
- | src[1] * quint32(0x00010000)
- | src[0] * quint32(0x01000000);
-}
-
-template<>
-inline quint16 qFromBigEndian<quint16>(const uchar *src)
-{
- return quint16( 0
- | src[1]
- | src[0] * quint16(0x0100));
+ T dest;
+ const size_t size = sizeof(T);
+ memcpy(&dest, src, size);
+ return dest;
}
-
-// signed specializations
-template <> inline qint64 qFromBigEndian<qint64>(const uchar *src)
-{ return static_cast<qint64>(qFromBigEndian<quint64>(src)); }
-
-template <> inline qint32 qFromBigEndian<qint32>(const uchar *src)
-{ return static_cast<qint32>(qFromBigEndian<quint32>(src)); }
-
-template <> inline qint16 qFromBigEndian<qint16>(const uchar *src)
-{ return static_cast<qint16>(qFromBigEndian<quint16>(src)); }
-#endif
-
-template <> inline quint8 qFromBigEndian<quint8>(const uchar *src)
-{ return static_cast<quint8>(src[0]); }
-template <> inline qint8 qFromBigEndian<qint8>(const uchar *src)
-{ return static_cast<qint8>(src[0]); }
-
/*
* T qbswap(T source).
* Changes the byte order of a value from big endian to little endian or vice versa.
@@ -289,6 +104,15 @@ template <> inline quint32 qbswap<quint32>(quint32 source)
{
return __builtin_bswap32(source);
}
+
+template <> inline void qbswap<quint64>(quint64 source, uchar *dest)
+{
+ qToUnaligned<quint64>(__builtin_bswap64(source), dest);
+}
+template <> inline void qbswap<quint32>(quint32 source, uchar *dest)
+{
+ qToUnaligned<quint32>(__builtin_bswap32(source), dest);
+}
#else
template <> inline quint64 qbswap<quint64>(quint64 source)
{
@@ -317,6 +141,10 @@ template <> inline quint16 qbswap<quint16>(quint16 source)
{
return __builtin_bswap16(source);
}
+template <> inline void qbswap<quint16>(quint16 source, uchar *dest)
+{
+ qToUnaligned<quint16>(__builtin_bswap16(source), dest);
+}
#else
template <> inline quint16 qbswap<quint16>(quint16 source)
{
@@ -344,6 +172,21 @@ template <> inline qint16 qbswap<qint16>(qint16 source)
return qbswap<quint16>(quint16(source));
}
+template <> inline void qbswap<qint64>(qint64 source, uchar *dest)
+{
+ qbswap<quint64>(quint64(source), dest);
+}
+
+template <> inline void qbswap<qint32>(qint32 source, uchar *dest)
+{
+ qbswap<quint32>(quint32(source), dest);
+}
+
+template <> inline void qbswap<qint16>(qint16 source, uchar *dest)
+{
+ qbswap<quint16>(quint16(source), dest);
+}
+
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
template <typename T> inline T qToBigEndian(T source)
@@ -385,6 +228,35 @@ template <> inline qint8 qbswap<qint8>(qint8 source)
return source;
}
+/* T qFromLittleEndian(const uchar *src)
+ * This function will read a little-endian encoded value from \a src
+ * and return the value in host-endian encoding.
+ * There is no requirement that \a src must be aligned.
+*/
+template <typename T> inline T qFromLittleEndian(const uchar *src)
+{
+ return qFromLittleEndian(qFromUnaligned<T>(src));
+}
+
+template <> inline quint8 qFromLittleEndian<quint8>(const uchar *src)
+{ return static_cast<quint8>(src[0]); }
+template <> inline qint8 qFromLittleEndian<qint8>(const uchar *src)
+{ return static_cast<qint8>(src[0]); }
+
+/* This function will read a big-endian (also known as network order) encoded value from \a src
+ * and return the value in host-endian encoding.
+ * There is no requirement that \a src must be aligned.
+*/
+template <class T> inline T qFromBigEndian(const uchar *src)
+{
+ return qFromBigEndian(qFromUnaligned<T>(src));
+}
+
+template <> inline quint8 qFromBigEndian<quint8>(const uchar *src)
+{ return static_cast<quint8>(src[0]); }
+template <> inline qint8 qFromBigEndian<qint8>(const uchar *src)
+{ return static_cast<qint8>(src[0]); }
+
QT_END_NAMESPACE
#endif // QENDIAN_H
diff --git a/src/corelib/global/qflags.h b/src/corelib/global/qflags.h
index 275ab12800..0b7b23e039 100644
--- a/src/corelib/global/qflags.h
+++ b/src/corelib/global/qflags.h
@@ -49,21 +49,21 @@ class QFlag
{
int i;
public:
- Q_DECL_CONSTEXPR inline QFlag(int ai) : i(ai) {}
- Q_DECL_CONSTEXPR inline operator int() const { return i; }
+ Q_DECL_CONSTEXPR inline QFlag(int ai) Q_DECL_NOTHROW : i(ai) {}
+ Q_DECL_CONSTEXPR inline operator int() const Q_DECL_NOTHROW { return i; }
#if !defined(Q_CC_MSVC)
// Microsoft Visual Studio has buggy behavior when it comes to
// unsigned enums: even if the enum is unsigned, the enum tags are
// always signed
# if !defined(__LP64__) && !defined(Q_QDOC)
- Q_DECL_CONSTEXPR inline QFlag(long ai) : i(int(ai)) {}
- Q_DECL_CONSTEXPR inline QFlag(ulong ai) : i(int(long(ai))) {}
+ Q_DECL_CONSTEXPR inline QFlag(long ai) Q_DECL_NOTHROW : i(int(ai)) {}
+ Q_DECL_CONSTEXPR inline QFlag(ulong ai) Q_DECL_NOTHROW : i(int(long(ai))) {}
# endif
- Q_DECL_CONSTEXPR inline QFlag(uint ai) : i(int(ai)) {}
- Q_DECL_CONSTEXPR inline QFlag(short ai) : i(int(ai)) {}
- Q_DECL_CONSTEXPR inline QFlag(ushort ai) : i(int(uint(ai))) {}
- Q_DECL_CONSTEXPR inline operator uint() const { return uint(i); }
+ Q_DECL_CONSTEXPR inline QFlag(uint ai) Q_DECL_NOTHROW : i(int(ai)) {}
+ Q_DECL_CONSTEXPR inline QFlag(short ai) Q_DECL_NOTHROW : i(int(ai)) {}
+ Q_DECL_CONSTEXPR inline QFlag(ushort ai) Q_DECL_NOTHROW : i(int(uint(ai))) {}
+ Q_DECL_CONSTEXPR inline operator uint() const Q_DECL_NOTHROW { return uint(i); }
#endif
};
Q_DECLARE_TYPEINFO(QFlag, Q_PRIMITIVE_TYPE);
@@ -72,12 +72,12 @@ class QIncompatibleFlag
{
int i;
public:
- Q_DECL_CONSTEXPR inline explicit QIncompatibleFlag(int i);
- Q_DECL_CONSTEXPR inline operator int() const { return i; }
+ Q_DECL_CONSTEXPR inline explicit QIncompatibleFlag(int i) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline operator int() const Q_DECL_NOTHROW { return i; }
};
Q_DECLARE_TYPEINFO(QIncompatibleFlag, Q_PRIMITIVE_TYPE);
-Q_DECL_CONSTEXPR inline QIncompatibleFlag::QIncompatibleFlag(int ai) : i(ai) {}
+Q_DECL_CONSTEXPR inline QIncompatibleFlag::QIncompatibleFlag(int ai) Q_DECL_NOTHROW : i(ai) {}
#ifndef Q_NO_TYPESAFE_FLAGS
@@ -108,41 +108,42 @@ public:
inline QFlags(const QFlags &other);
inline QFlags &operator=(const QFlags &other);
#endif
- Q_DECL_CONSTEXPR inline QFlags(Enum f) : i(Int(f)) {}
- Q_DECL_CONSTEXPR inline QFlags(Zero = 0) : i(0) {}
- Q_DECL_CONSTEXPR inline QFlags(QFlag f) : i(f) {}
+ Q_DECL_CONSTEXPR inline QFlags(Enum f) Q_DECL_NOTHROW : i(Int(f)) {}
+ Q_DECL_CONSTEXPR inline QFlags(Zero = 0) Q_DECL_NOTHROW : i(0) {}
+ Q_DECL_CONSTEXPR inline QFlags(QFlag f) Q_DECL_NOTHROW : i(f) {}
#ifdef Q_COMPILER_INITIALIZER_LISTS
- Q_DECL_CONSTEXPR inline QFlags(std::initializer_list<Enum> flags)
+ Q_DECL_CONSTEXPR inline QFlags(std::initializer_list<Enum> flags) Q_DECL_NOTHROW
: 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) Q_DECL_NOTHROW { i &= mask; return *this; }
+ Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator&=(uint mask) Q_DECL_NOTHROW { i &= mask; return *this; }
+ Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator&=(Enum mask) Q_DECL_NOTHROW { i &= Int(mask); return *this; }
+ Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator|=(QFlags f) Q_DECL_NOTHROW { i |= f.i; return *this; }
+ Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator|=(Enum f) Q_DECL_NOTHROW { i |= Int(f); return *this; }
+ Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator^=(QFlags f) Q_DECL_NOTHROW { i ^= f.i; return *this; }
+ Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator^=(Enum f) Q_DECL_NOTHROW { i ^= Int(f); return *this; }
- Q_DECL_CONSTEXPR inline operator Int() const { return i; }
+ Q_DECL_CONSTEXPR inline operator Int() const Q_DECL_NOTHROW { return i; }
- Q_DECL_CONSTEXPR inline QFlags operator|(QFlags f) const { return QFlags(QFlag(i | f.i)); }
- Q_DECL_CONSTEXPR inline QFlags operator|(Enum f) const { return QFlags(QFlag(i | Int(f))); }
- Q_DECL_CONSTEXPR inline QFlags operator^(QFlags f) const { return QFlags(QFlag(i ^ f.i)); }
- Q_DECL_CONSTEXPR inline QFlags operator^(Enum f) const { return QFlags(QFlag(i ^ Int(f))); }
- Q_DECL_CONSTEXPR inline QFlags operator&(int mask) const { return QFlags(QFlag(i & mask)); }
- Q_DECL_CONSTEXPR inline QFlags operator&(uint mask) const { return QFlags(QFlag(i & mask)); }
- Q_DECL_CONSTEXPR inline QFlags operator&(Enum f) const { return QFlags(QFlag(i & Int(f))); }
- Q_DECL_CONSTEXPR inline QFlags operator~() const { return QFlags(QFlag(~i)); }
+ Q_DECL_CONSTEXPR inline QFlags operator|(QFlags f) const Q_DECL_NOTHROW { return QFlags(QFlag(i | f.i)); }
+ Q_DECL_CONSTEXPR inline QFlags operator|(Enum f) const Q_DECL_NOTHROW { return QFlags(QFlag(i | Int(f))); }
+ Q_DECL_CONSTEXPR inline QFlags operator^(QFlags f) const Q_DECL_NOTHROW { return QFlags(QFlag(i ^ f.i)); }
+ Q_DECL_CONSTEXPR inline QFlags operator^(Enum f) const Q_DECL_NOTHROW { return QFlags(QFlag(i ^ Int(f))); }
+ Q_DECL_CONSTEXPR inline QFlags operator&(int mask) const Q_DECL_NOTHROW { return QFlags(QFlag(i & mask)); }
+ Q_DECL_CONSTEXPR inline QFlags operator&(uint mask) const Q_DECL_NOTHROW { return QFlags(QFlag(i & mask)); }
+ Q_DECL_CONSTEXPR inline QFlags operator&(Enum f) const Q_DECL_NOTHROW { return QFlags(QFlag(i & Int(f))); }
+ Q_DECL_CONSTEXPR inline QFlags operator~() const Q_DECL_NOTHROW { return QFlags(QFlag(~i)); }
- Q_DECL_CONSTEXPR inline bool operator!() const { return !i; }
+ Q_DECL_CONSTEXPR inline bool operator!() const Q_DECL_NOTHROW { return !i; }
- Q_DECL_CONSTEXPR inline bool testFlag(Enum f) const { return (i & Int(f)) == Int(f) && (Int(f) != 0 || i == Int(f) ); }
+ Q_DECL_CONSTEXPR inline bool testFlag(Enum f) const Q_DECL_NOTHROW { return (i & Int(f)) == Int(f) && (Int(f) != 0 || i == Int(f) ); }
private:
#ifdef Q_COMPILER_INITIALIZER_LISTS
Q_DECL_CONSTEXPR static inline Int initializer_list_helper(typename std::initializer_list<Enum>::const_iterator it,
typename std::initializer_list<Enum>::const_iterator end)
+ Q_DECL_NOTHROW
{
return (it == end ? Int(0) : (Int(*it) | initializer_list_helper(it + 1, end)));
}
@@ -155,13 +156,13 @@ private:
typedef QFlags<Enum> Flags;
#define Q_DECLARE_INCOMPATIBLE_FLAGS(Flags) \
-Q_DECL_CONSTEXPR inline QIncompatibleFlag operator|(Flags::enum_type f1, int f2) \
+Q_DECL_CONSTEXPR inline QIncompatibleFlag operator|(Flags::enum_type f1, int f2) Q_DECL_NOTHROW \
{ return QIncompatibleFlag(int(f1) | f2); }
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags) \
-Q_DECL_CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) \
+Q_DECL_CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) Q_DECL_NOTHROW \
{ return QFlags<Flags::enum_type>(f1) | f2; } \
-Q_DECL_CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> f2) \
+Q_DECL_CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> f2) Q_DECL_NOTHROW \
{ return f2 | f1; } Q_DECLARE_INCOMPATIBLE_FLAGS(Flags)
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index 997e804579..0a9e2f97db 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
** Copyright (C) 2014 Intel Corporation
** Contact: http://www.qt-project.org/legal
**
@@ -39,6 +39,7 @@
#include "qthreadstorage.h"
#include "qdir.h"
#include "qdatetime.h"
+#include <private/qlocale_tools_p.h>
#include <private/qsystemlibrary_p.h>
@@ -548,9 +549,9 @@ Q_STATIC_ASSERT_X(UCHAR_MAX == 255, "Qt assumes that char is 8 bits");
\snippet code/src_corelib_global_qglobal.cpp 3
<QtGlobal> also contains functions that generate messages from the
- given string argument: qCritical(), qDebug(), qFatal() and
- qWarning(). These functions call the message handler with the
- given message.
+ given string argument: qDebug(), qInfo(), qWarning(), qCritical(),
+ and qFatal(). These functions call the message handler
+ with the given message.
Example:
@@ -769,6 +770,8 @@ Q_STATIC_ASSERT_X(UCHAR_MAX == 255, "Qt assumes that char is 8 bits");
\value QtDebugMsg
A message generated by the qDebug() function.
+ \value QtInfoMsg
+ A message generated by the qInfo() function.
\value QtWarningMsg
A message generated by the qWarning() function.
\value QtCriticalMsg
@@ -777,6 +780,7 @@ Q_STATIC_ASSERT_X(UCHAR_MAX == 255, "Qt assumes that char is 8 bits");
A message generated by the qFatal() function.
\value QtSystemMsg
+ \c QtInfoMsg was added in Qt 5.5.
\sa QtMessageHandler, qInstallMessageHandler()
*/
@@ -986,9 +990,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
@@ -1011,7 +1015,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.
*/
/*!
@@ -1019,19 +1023,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.
*/
/*!
@@ -1068,6 +1075,7 @@ bool qSharedBuild() Q_DECL_NOTHROW
\value WV_WINDOWS7 Windows 7, Windows Server 2008 R2 (operating system version 6.1)
\value WV_WINDOWS8 Windows 8 (operating system version 6.2)
\value WV_WINDOWS8_1 Windows 8.1 (operating system version 6.3), introduced in Qt 5.2
+ \value WV_WINDOWS10 Windows 10 (operating system version 10.0), introduced in Qt 5.5
Alternatively, you may use the following macros which correspond directly to the Windows operating system version number:
@@ -1079,6 +1087,7 @@ bool qSharedBuild() Q_DECL_NOTHROW
\value WV_6_1 Operating system version 6.1, corresponds to Windows 7 and Windows Server 2008 R2
\value WV_6_2 Operating system version 6.2, corresponds to Windows 8
\value WV_6_3 Operating system version 6.3, corresponds to Windows 8.1, introduced in Qt 5.2
+ \value WV_10_0 Operating system version 10.0, corresponds to Windows 10, introduced in Qt 5.5
CE-based versions:
@@ -1094,6 +1103,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
*/
@@ -1141,6 +1152,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
*/
@@ -1847,16 +1860,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();
@@ -2024,6 +2035,8 @@ QSysInfo::WinVersion QSysInfo::windowsVersion()
winver = QSysInfo::WV_WINDOWS8;
} else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 3) {
winver = QSysInfo::WV_WINDOWS8_1;
+ } else if (osver.dwMajorVersion == 10 && osver.dwMinorVersion == 0) {
+ winver = QSysInfo::WV_WINDOWS10;
} else {
qWarning("Qt: Untested Windows version %d.%d detected!",
int(osver.dwMajorVersion), int(osver.dwMinorVersion));
@@ -2516,6 +2529,9 @@ QString QSysInfo::productType()
#elif defined(Q_OS_DARWIN)
return QStringLiteral("darwin");
+#elif defined(Q_OS_HAIKU)
+ return QStringLiteral("haiku");
+
#elif defined(USE_ETC_OS_RELEASE) // Q_OS_UNIX
QUnixOSVersion unixOsVersion;
readEtcOsRelease(unixOsVersion);
@@ -2551,25 +2567,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)
@@ -2662,6 +2662,8 @@ QString QSysInfo::prettyProductName()
return QLatin1String("Android ") + productVersion();
#elif defined(Q_OS_BLACKBERRY)
return QLatin1String("BlackBerry ") + productVersion();
+#elif defined(Q_OS_HAIKU)
+ return QLatin1String("Haiku ") + productVersion();
#elif defined(Q_OS_UNIX)
# ifdef USE_ETC_OS_RELEASE
QUnixOSVersion unixOsVersion;
@@ -3065,6 +3067,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.
@@ -3556,8 +3605,8 @@ int qrand()
qPrintable() is used. This is because the array returned by
QString::toLocal8Bit() will fall out of scope.
- \note qDebug(), qWarning(), qCritical(), qFatal() expect %s
- arguments to be UTF-8 encoded, while qPrintable() converts to
+ \note qDebug(), qInfo(), qWarning(), qCritical(), qFatal() expect
+ %s arguments to be UTF-8 encoded, while qPrintable() converts to
local 8-bit encoding. Therefore qUtf8Printable() should be used
for logging strings instead of qPrintable().
@@ -3580,7 +3629,7 @@ int qrand()
\snippet code/src_corelib_global_qglobal.cpp 37
- \sa qPrintable(), qDebug(), qWarning(), qCritical(), qFatal()
+ \sa qPrintable(), qDebug(), qInfo(), qWarning(), qCritical(), qFatal()
*/
/*!
@@ -3968,6 +4017,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
*/
/*!
@@ -3976,8 +4040,8 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
Calls the message handler with the debug message \a message. If no
message handler has been installed, the message is printed to
- stderr. Under Windows, the message is sent to the console, if it is a
- console application; otherwise, it is sent to the debugger. On Blackberry the
+ stderr. Under Windows the message is sent to the console, if it is a
+ console application; otherwise, it is sent to the debugger. On Blackberry, the
message is sent to slogger2. This function does nothing if \c QT_NO_DEBUG_OUTPUT
was defined during compilation.
@@ -4002,7 +4066,44 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
To suppress the output at run-time, install your own message handler
with qInstallMessageHandler().
- \sa qWarning(), qCritical(), qFatal(), qInstallMessageHandler(),
+ \sa qInfo(), qWarning(), qCritical(), qFatal(), qInstallMessageHandler(),
+ {Debugging Techniques}
+*/
+
+/*!
+ \macro qInfo(const char *message, ...)
+ \relates <QtGlobal>
+ \since 5.5
+
+ Calls the message handler with the informational message \a message. If no
+ message handler has been installed, the message is printed to
+ stderr. Under Windows, the message is sent to the console, if it is a
+ console application; otherwise, it is sent to the debugger. On Blackberry the
+ message is sent to slogger2. This function does nothing if \c QT_NO_INFO_OUTPUT
+ was defined during compilation.
+
+ If you pass the function a format string and a list of arguments,
+ it works in similar way to the C printf() function. The format
+ should be a Latin-1 string.
+
+ Example:
+
+ \snippet code/src_corelib_global_qglobal.cpp qInfo_printf
+
+ If you include \c <QtDebug>, a more convenient syntax is also
+ available:
+
+ \snippet code/src_corelib_global_qglobal.cpp qInfo_stream
+
+ With this syntax, the function returns a QDebug object that is
+ configured to use the QtInfoMsg message type. It automatically
+ puts a single space between each item, and outputs a newline at
+ the end. It supports many C++ and Qt types.
+
+ To suppress the output at run-time, install your own message handler
+ with qInstallMessageHandler().
+
+ \sa qDebug(), qWarning(), qCritical(), qFatal(), qInstallMessageHandler(),
{Debugging Techniques}
*/
@@ -4036,7 +4137,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
To suppress the output at runtime, install your own message handler
with qInstallMessageHandler().
- \sa qDebug(), qCritical(), qFatal(), qInstallMessageHandler(),
+ \sa qDebug(), qInfo(), qCritical(), qFatal(), qInstallMessageHandler(),
{Debugging Techniques}
*/
@@ -4069,7 +4170,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
To suppress the output at runtime, install your own message handler
with qInstallMessageHandler().
- \sa qDebug(), qWarning(), qFatal(), qInstallMessageHandler(),
+ \sa qDebug(), qInfo(), qWarning(), qFatal(), qInstallMessageHandler(),
{Debugging Techniques}
*/
@@ -4096,7 +4197,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
To suppress the output at runtime, install your own message handler
with qInstallMessageHandler().
- \sa qDebug(), qCritical(), qWarning(), qInstallMessageHandler(),
+ \sa qDebug(), qInfo(), qWarning(), qCritical(), qInstallMessageHandler(),
{Debugging Techniques}
*/
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index dade7fc6ec..863e499667 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -35,13 +35,17 @@
#ifndef QGLOBAL_H
#define QGLOBAL_H
+#ifdef __cplusplus
+# include <cstddef>
+#endif
+
#include <stddef.h>
-#define QT_VERSION_STR "5.4.2"
+#define QT_VERSION_STR "5.5.0"
/*
QT_VERSION is (major << 16) + (minor << 8) + patch.
*/
-#define QT_VERSION 0x050402
+#define QT_VERSION 0x050500
/*
can be used like #if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0))
*/
@@ -481,6 +485,14 @@ typedef qptrdiff qintptr;
# define Q_ATTRIBUTE_FORMAT_PRINTF(A, B)
#endif
+#ifdef Q_CC_MSVC
+# define Q_NEVER_INLINE __declspec(noinline)
+#elif defined(Q_CC_GNU)
+# define Q_NEVER_INLINE __attribute__((noinline))
+#else
+# define Q_NEVER_INLINE
+#endif
+
//defines the type for the WNDPROC on windows
//the alignment needs to be forced for sse2 to not crash with mingw
#if defined(Q_OS_WIN)
@@ -620,14 +632,7 @@ Q_CORE_EXPORT bool qSharedBuild() Q_DECL_NOTHROW;
/*
Avoid "unused parameter" warnings
*/
-
-#if defined(Q_CC_RVCT)
-template <typename T>
-inline void qUnused(T &x) { (void)x; }
-# define Q_UNUSED(x) qUnused(x);
-#else
-# define Q_UNUSED(x) (void)x;
-#endif
+#define Q_UNUSED(x) (void)x;
/*
Debugging and error handling
@@ -655,7 +660,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
@@ -805,8 +810,20 @@ static inline bool qIsNull(float f)
# define Q_DUMMY_COMPARISON_OPERATOR(C)
#endif
+namespace QtPrivate
+{
+namespace SwapExceptionTester { // insulate users from the "using std::swap" below
+ using std::swap; // import std::swap
+ template <typename T>
+ void checkSwap(T &t)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(swap(t, t)));
+ // declared, but not implemented (only to be used in unevaluated contexts (noexcept operator))
+}
+} // namespace QtPrivate
+
template <typename T>
inline void qSwap(T &value1, T &value2)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(QtPrivate::SwapExceptionTester::checkSwap(value1)))
{
using std::swap;
swap(value1, value2);
@@ -834,22 +851,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
@@ -861,7 +878,7 @@ Q_CORE_EXPORT void qFreeAligned(void *ptr);
# endif
#endif
-#if defined(Q_COMPILER_DECLTYPE) || (defined(Q_CC_GNU) && !defined(Q_CC_RVCT))
+#if defined(Q_COMPILER_DECLTYPE) || defined(Q_CC_GNU)
/* make use of decltype or GCC's __typeof__ extension */
template <typename T>
class QForeachContainer {
@@ -1027,6 +1044,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); }
@@ -1039,13 +1057,6 @@ Q_CORE_EXPORT int qrand();
#define QT_MODULE(x)
-#ifdef Q_OS_QNX
-// QNX doesn't have SYSV style shared memory. Multiprocess QWS apps,
-// shared fonts and QSystemSemaphore + QSharedMemory are not available
-# define QT_NO_SYSTEMSEMAPHORE
-# define QT_NO_SHAREDMEMORY
-#endif
-
#if !defined(QT_BOOTSTRAPPED) && defined(QT_REDUCE_RELOCATIONS) && defined(__ELF__) && !defined(__PIC__) && !defined(__PIE__)
# error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
"Compile your code with -fPIC or -fPIE."
diff --git a/src/corelib/global/qhooks.cpp b/src/corelib/global/qhooks.cpp
index 7638414cf1..39ed87e789 100644
--- a/src/corelib/global/qhooks.cpp
+++ b/src/corelib/global/qhooks.cpp
@@ -37,7 +37,7 @@ QT_BEGIN_NAMESPACE
// Only add to the end, and bump version if you do.
quintptr Q_CORE_EXPORT qtHookData[] = {
- 1, // hook data version
+ 2, // hook data version
QHooks::LastHookIndex, // size of qtHookData
QT_VERSION,
diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp
index d592032c1f..b47015cbc9 100644
--- a/src/corelib/global/qlibraryinfo.cpp
+++ b/src/corelib/global/qlibraryinfo.cpp
@@ -41,16 +41,8 @@
#ifdef QT_BUILD_QMAKE
QT_BEGIN_NAMESPACE
-extern QString qt_libraryInfoFile();
+extern QString qmake_libraryInfoFile();
QT_END_NAMESPACE
-#elif defined(QT_BOOTSTRAPPED)
-QString qt_libraryInfoFile()
-{
- QString qmakeAbsoluteLocation = QLatin1String(QT_QMAKE_LOCATION);
- if (!qmakeAbsoluteLocation.isEmpty())
- return QDir(QFileInfo(qmakeAbsoluteLocation).absolutePath()).filePath(QLatin1String("qt.conf"));
- return QString();
-}
#else
# include "qcoreapplication.h"
#endif
@@ -72,7 +64,8 @@ struct QLibrarySettings
{
QLibrarySettings();
QScopedPointer<QSettings> settings;
-#ifdef QT_BOOTSTRAPPED
+#ifdef QT_BUILD_QMAKE
+ bool haveDevicePaths;
bool haveEffectiveSourcePaths;
bool haveEffectivePaths;
bool havePaths;
@@ -84,14 +77,17 @@ class QLibraryInfoPrivate
{
public:
static QSettings *findConfiguration();
-#ifdef QT_BOOTSTRAPPED
+#ifdef QT_BUILD_QMAKE
static bool haveGroup(QLibraryInfo::PathGroup group)
{
QLibrarySettings *ls = qt_library_settings();
return ls ? (group == QLibraryInfo::EffectiveSourcePaths
? ls->haveEffectiveSourcePaths
: group == QLibraryInfo::EffectivePaths
- ? ls->haveEffectivePaths : ls->havePaths) : false;
+ ? ls->haveEffectivePaths
+ : group == QLibraryInfo::DevicePaths
+ ? ls->haveDevicePaths
+ : ls->havePaths) : false;
}
#endif
static QSettings *configuration()
@@ -106,7 +102,8 @@ static const char platformsSection[] = "Platforms";
QLibrarySettings::QLibrarySettings()
: settings(QLibraryInfoPrivate::findConfiguration())
{
-#ifndef QT_BOOTSTRAPPED
+#ifndef QT_BUILD_QMAKE
+ bool haveDevicePaths;
bool haveEffectivePaths;
bool havePaths;
#endif
@@ -114,7 +111,8 @@ QLibrarySettings::QLibrarySettings()
// This code needs to be in the regular library, as otherwise a qt.conf that
// works for qmake would break things for dynamically built Qt tools.
QStringList children = settings->childGroups();
-#ifdef QT_BOOTSTRAPPED
+ haveDevicePaths = children.contains(QLatin1String("DevicePaths"));
+#ifdef QT_BUILD_QMAKE
haveEffectiveSourcePaths = children.contains(QLatin1String("EffectiveSourcePaths"));
#else
// EffectiveSourcePaths is for the Qt build only, so needs no backwards compat trickery.
@@ -122,13 +120,15 @@ QLibrarySettings::QLibrarySettings()
#endif
haveEffectivePaths = haveEffectiveSourcePaths || children.contains(QLatin1String("EffectivePaths"));
// Backwards compat: an existing but empty file is claimed to contain the Paths section.
- havePaths = (!haveEffectivePaths && !children.contains(QLatin1String(platformsSection)))
+ havePaths = (!haveDevicePaths && !haveEffectivePaths
+ && !children.contains(QLatin1String(platformsSection)))
|| children.contains(QLatin1String("Paths"));
-#ifndef QT_BOOTSTRAPPED
+#ifndef QT_BUILD_QMAKE
if (!havePaths)
settings.reset(0);
#else
} else {
+ haveDevicePaths = false;
haveEffectiveSourcePaths = false;
haveEffectivePaths = false;
havePaths = false;
@@ -139,9 +139,9 @@ QLibrarySettings::QLibrarySettings()
QSettings *QLibraryInfoPrivate::findConfiguration()
{
QString qtconfig = QStringLiteral(":/qt/etc/qt.conf");
-#ifdef QT_BOOTSTRAPPED
+#ifdef QT_BUILD_QMAKE
if(!QFile::exists(qtconfig))
- qtconfig = qt_libraryInfoFile();
+ qtconfig = qmake_libraryInfoFile();
#else
if (!QFile::exists(qtconfig) && QCoreApplication::instance()) {
#ifdef Q_OS_MAC
@@ -189,7 +189,7 @@ QSettings *QLibraryInfoPrivate::findConfiguration()
\sa QSysInfo, {Using qt.conf}
*/
-#ifndef QT_BOOTSTRAPPED
+#ifndef QT_BUILD_QMAKE
/*!
\internal
@@ -287,6 +287,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
@@ -333,7 +335,7 @@ QLibraryInfo::isDebugBuild()
#endif
}
-#endif // QT_BOOTSTRAPPED
+#endif // QT_BUILD_QMAKE
/*
* To add a new entry in QLibrary::LibraryLocation, add it to the enum above the bootstrapped values and:
@@ -365,14 +367,14 @@ static const struct {
{ "Translations", "translations" }, // should be ${Data}/translations
{ "Examples", "examples" },
{ "Tests", "tests" },
-#ifdef QT_BOOTSTRAPPED
+#ifdef QT_BUILD_QMAKE
{ "Sysroot", "" },
- { "HostPrefix", "" },
{ "HostBinaries", "bin" },
{ "HostLibraries", "lib" },
{ "HostData", "." },
{ "TargetSpec", "" },
{ "HostSpec", "" },
+ { "HostPrefix", "" },
#endif
};
@@ -383,11 +385,11 @@ static const struct {
QString
QLibraryInfo::location(LibraryLocation loc)
{
-#ifdef QT_BOOTSTRAPPED
+#ifdef QT_BUILD_QMAKE
QString ret = rawLocation(loc, FinalPaths);
// Automatically prepend the sysroot to target paths
- if ((loc < SysrootPath || loc > LastHostPath) && qt_sysrootify_prefix[12] == 'y') {
+ if ((loc < SysrootPath || loc > LastHostPath) && QT_CONFIGURE_SYSROOTIFY_PREFIX) {
QString sysroot = rawLocation(SysrootPath, FinalPaths);
if (!sysroot.isEmpty() && ret.length() > 2 && ret.at(1) == QLatin1Char(':')
&& (ret.at(2) == QLatin1Char('/') || ret.at(2) == QLatin1Char('\\')))
@@ -402,33 +404,45 @@ QLibraryInfo::location(LibraryLocation loc)
QString
QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group)
{
-#else
-# define rawLocation(loca, group) location(loca)
-# define group dummy
#endif
QString ret;
-#ifdef QT_BOOTSTRAPPED
+#ifdef QT_BUILD_QMAKE
// Logic for choosing the right data source: if EffectivePaths are requested
// and qt.conf with that section is present, use it, otherwise fall back to
// FinalPaths. For FinalPaths, use qt.conf if present and contains not only
// [EffectivePaths], otherwise fall back to builtins.
// EffectiveSourcePaths falls back to EffectivePaths.
+ // DevicePaths falls back to FinalPaths.
+ PathGroup orig_group = group;
if (!QLibraryInfoPrivate::haveGroup(group)
&& !(group == EffectiveSourcePaths
&& (group = EffectivePaths, QLibraryInfoPrivate::haveGroup(group)))
- && !(group == EffectivePaths
- && (group = FinalPaths, QLibraryInfoPrivate::haveGroup(group))))
+ && !((group == EffectivePaths || group == DevicePaths)
+ && (group = FinalPaths, QLibraryInfoPrivate::haveGroup(group)))
+ && (group = orig_group, true))
#elif !defined(QT_NO_SETTINGS)
if (!QLibraryInfoPrivate::configuration())
#endif
{
const char *path = 0;
- if (unsigned(loc) < sizeof(qt_configure_prefix_path_strs)/sizeof(qt_configure_prefix_path_strs[0]))
- path = qt_configure_prefix_path_strs[loc] + 12;
+ if (loc == PrefixPath) {
+ path =
+#ifdef QT_BUILD_QMAKE
+ (group != DevicePaths) ?
+ QT_CONFIGURE_EXT_PREFIX_PATH :
+#endif
+ QT_CONFIGURE_PREFIX_PATH;
+ } else if (unsigned(loc) <= sizeof(qt_configure_str_offsets)/sizeof(qt_configure_str_offsets[0])) {
+ path = qt_configure_strs + qt_configure_str_offsets[loc - 1];
#ifndef Q_OS_WIN // On Windows we use the registry
- else if (loc == SettingsPath)
+ } else if (loc == SettingsPath) {
path = QT_CONFIGURE_SETTINGS_PATH;
#endif
+#ifdef QT_BUILD_QMAKE
+ } else if (loc == HostPrefixPath) {
+ path = QT_CONFIGURE_HOST_PREFIX_PATH;
+#endif
+ }
if (path)
ret = QString::fromLocal8Bit(path);
@@ -448,7 +462,8 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group)
if(!key.isNull()) {
QSettings *config = QLibraryInfoPrivate::configuration();
config->beginGroup(QLatin1String(
-#ifdef QT_BOOTSTRAPPED
+#ifdef QT_BUILD_QMAKE
+ group == DevicePaths ? "DevicePaths" :
group == EffectiveSourcePaths ? "EffectiveSourcePaths" :
group == EffectivePaths ? "EffectivePaths" :
#endif
@@ -456,13 +471,13 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group)
ret = config->value(key, defaultValue).toString();
-#ifdef QT_BOOTSTRAPPED
+#ifdef QT_BUILD_QMAKE
if (ret.isEmpty()) {
if (loc == HostPrefixPath)
ret = config->value(QLatin1String(qtConfEntries[PrefixPath].key),
QLatin1String(qtConfEntries[PrefixPath].value)).toString();
else if (loc == TargetSpecPath || loc == HostSpecPath)
- ret = QString::fromLocal8Bit(qt_configure_prefix_path_strs[loc] + 12);
+ ret = QString::fromLocal8Bit(qt_configure_strs + qt_configure_str_offsets[loc - 1]);
}
#endif
@@ -483,7 +498,7 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group)
#endif // QT_NO_SETTINGS
}
-#ifdef QT_BOOTSTRAPPED
+#ifdef QT_BUILD_QMAKE
// The specs need to be returned verbatim.
if (loc == TargetSpecPath || loc == HostSpecPath)
return ret;
@@ -491,15 +506,18 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group)
if (!ret.isEmpty() && QDir::isRelativePath(ret)) {
QString baseDir;
-#ifdef QT_BOOTSTRAPPED
+#ifdef QT_BUILD_QMAKE
if (loc == HostPrefixPath || loc == PrefixPath || loc == SysrootPath) {
// We make the prefix/sysroot path absolute to the executable's directory.
// loc == PrefixPath while a sysroot is set would make no sense here.
// loc == SysrootPath only makes sense if qmake lives inside the sysroot itself.
- baseDir = QFileInfo(qt_libraryInfoFile()).absolutePath();
+ baseDir = QFileInfo(qmake_libraryInfoFile()).absolutePath();
} else if (loc > SysrootPath && loc <= LastHostPath) {
// We make any other host path absolute to the host prefix directory.
baseDir = rawLocation(HostPrefixPath, group);
+ } else {
+ // we make any other path absolute to the prefix directory
+ baseDir = rawLocation(PrefixPath, group);
#else
if (loc == PrefixPath) {
if (QCoreApplication::instance()) {
@@ -524,10 +542,10 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group)
} else {
baseDir = QDir::currentPath();
}
-#endif
} else {
// we make any other path absolute to the prefix directory
- baseDir = rawLocation(PrefixPath, group);
+ baseDir = location(PrefixPath);
+#endif
}
ret = QDir::cleanPath(baseDir + QLatin1Char('/') + ret);
}
@@ -549,7 +567,7 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group)
QStringList QLibraryInfo::platformPluginArguments(const QString &platformName)
{
-#if !defined(QT_BOOTSTRAPPED) && !defined(QT_NO_SETTINGS)
+#if !defined(QT_BUILD_QMAKE) && !defined(QT_NO_SETTINGS)
QScopedPointer<const QSettings> settings(QLibraryInfoPrivate::findConfiguration());
if (!settings.isNull()) {
QString key = QLatin1String(platformsSection);
@@ -558,7 +576,7 @@ QStringList QLibraryInfo::platformPluginArguments(const QString &platformName)
key += QLatin1String("Arguments");
return settings->value(key).toStringList();
}
-#endif // !QT_BOOTSTRAPPED && !QT_NO_SETTINGS
+#endif // !QT_BUILD_QMAKE && !QT_NO_SETTINGS
return QStringList();
}
@@ -612,9 +630,9 @@ void qt_core_boilerplate()
"Library path: %s\n"
"Include path: %s\n",
qt_configure_installation + 12,
- qt_configure_prefix_path_strs[QT_PREPEND_NAMESPACE(QLibraryInfo)::PrefixPath] + 12,
- qt_configure_prefix_path_strs[QT_PREPEND_NAMESPACE(QLibraryInfo)::LibrariesPath] + 12,
- qt_configure_prefix_path_strs[QT_PREPEND_NAMESPACE(QLibraryInfo)::HeadersPath] + 12);
+ qt_configure_prefix_path_str + 12,
+ qt_configure_strs + qt_configure_str_offsets[QT_PREPEND_NAMESPACE(QLibraryInfo)::LibrariesPath - 1],
+ qt_configure_strs + qt_configure_str_offsets[QT_PREPEND_NAMESPACE(QLibraryInfo)::HeadersPath - 1]);
QT_PREPEND_NAMESPACE(qDumpCPUFeatures)();
diff --git a/src/corelib/global/qlibraryinfo.h b/src/corelib/global/qlibraryinfo.h
index 543c4b3828..4dff8ca494 100644
--- a/src/corelib/global/qlibraryinfo.h
+++ b/src/corelib/global/qlibraryinfo.h
@@ -73,22 +73,22 @@ public:
TestsPath,
// Insert new values above this line
// Please read the comments in qlibraryinfo.cpp before adding
-#ifdef QT_BOOTSTRAPPED
+#ifdef QT_BUILD_QMAKE
// These are not subject to binary compatibility constraints
SysrootPath,
- HostPrefixPath,
HostBinariesPath,
HostLibrariesPath,
HostDataPath,
TargetSpecPath,
HostSpecPath,
- LastHostPath = HostSpecPath,
+ HostPrefixPath,
+ LastHostPath = HostPrefixPath,
#endif
SettingsPath = 100
};
static QString location(LibraryLocation); // ### Qt 6: consider renaming it to path()
-#ifdef QT_BOOTSTRAPPED
- enum PathGroup { FinalPaths, EffectivePaths, EffectiveSourcePaths };
+#ifdef QT_BUILD_QMAKE
+ enum PathGroup { FinalPaths, EffectivePaths, EffectiveSourcePaths, DevicePaths };
static QString rawLocation(LibraryLocation, PathGroup);
#endif
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index 50d35a6d84..2f3b5606f6 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com>
** Copyright (C) 2014 Intel Corporation.
** Contact: http://www.qt-project.org/legal
@@ -76,7 +76,8 @@
# define __has_include(x) 0
#endif
-#if !defined QT_NO_REGULAREXPRESSION && !defined(QT_BOOTSTRAPPED)
+#ifndef QT_BOOTSTRAPPED
+#if !defined QT_NO_REGULAREXPRESSION
# if (defined(__GLIBC__) && defined(__GLIBCXX__)) || (__has_include(<cxxabi.h>) && __has_include(<execinfo.h>))
# define QLOGGING_HAVE_BACKTRACE
# include <qregularexpression.h>
@@ -85,6 +86,38 @@
# endif
#endif
+#if defined(Q_OS_LINUX) && (defined(__GLIBC__) || __has_include(<sys/syscall.h>))
+# include <sys/syscall.h>
+static long qt_gettid()
+{
+ // no error handling
+ // this syscall has existed since Linux 2.4.11 and cannot fail
+ return syscall(SYS_gettid);
+}
+#elif defined(Q_OS_DARWIN)
+# include <pthread.h>
+static int qt_gettid()
+{
+ // no error handling: this call cannot fail
+ __uint64_t tid;
+ pthread_threadid_np(NULL, &tid);
+ return tid;
+}
+#elif defined(Q_OS_FREEBSD_KERNEL) && defined(__FreeBSD_version) && __FreeBSD_version >= 900031
+# include <pthread_np.h>
+static int qt_gettid()
+{
+ return pthread_getthreadid_np();
+}
+#else
+static QT_PREPEND_NAMESPACE(qint64) qt_gettid()
+{
+ QT_USE_NAMESPACE
+ return qintptr(QThread::currentThreadId());
+}
+#endif
+#endif // !QT_BOOTSTRAPPED
+
#include <stdio.h>
QT_BEGIN_NAMESPACE
@@ -168,7 +201,7 @@ Q_CORE_EXPORT bool qt_logging_to_console()
\brief The QMessageLogContext class provides additional information about a log message.
\since 5.0
- The class provides information about the source code location a qDebug(), qWarning(),
+ The class provides information about the source code location a qDebug(), qInfo(), qWarning(),
qCritical() or qFatal() message was generated.
\note By default, this information is recorded only in debug builds. You can overwrite
@@ -184,7 +217,7 @@ Q_CORE_EXPORT bool qt_logging_to_console()
\since 5.0
QMessageLogger is used to generate messages for the Qt logging framework. Usually one uses
- it through qDebug(), qWarning(), qCritical, or qFatal() functions,
+ it through qDebug(), qInfo(), qWarning(), qCritical, or qFatal() functions,
which are actually macros: For example qDebug() expands to
QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).debug()
for debug builds, and QMessageLogger(0, 0, 0).debug() for release builds.
@@ -193,7 +226,7 @@ Q_CORE_EXPORT bool qt_logging_to_console()
\snippet code/qlogging/qlogging.cpp 1
- \sa QMessageLogContext, qDebug(), qWarning(), qCritical(), qFatal()
+ \sa QMessageLogContext, qDebug(), qInfo(), qWarning(), qCritical(), qFatal()
*/
#ifdef Q_OS_WIN
@@ -244,6 +277,28 @@ void QMessageLogger::debug(const char *msg, ...) const
qt_message_fatal(QtDebugMsg, context, message);
}
+
+#undef qInfo
+/*!
+ Logs an informational message specified with format \a msg. Additional
+ parameters, specified by \a msg, may be used.
+
+ \sa qInfo()
+ \since 5.5
+*/
+void QMessageLogger::info(const char *msg, ...) const
+{
+ QString message;
+
+ va_list ap;
+ va_start(ap, msg); // use variable arg list
+ qt_message(QtInfoMsg, context, msg, ap, message);
+ va_end(ap);
+
+ if (isFatal(QtInfoMsg))
+ qt_message_fatal(QtInfoMsg, context, message);
+}
+
/*!
\typedef QMessageLogger::CategoryFunction
@@ -373,6 +428,110 @@ QNoDebug QMessageLogger::noDebug() const Q_DECL_NOTHROW
#endif
+/*!
+ Logs an informational message specified with format \a msg for the context \a cat.
+ Additional parameters, specified by \a msg, may be used.
+
+ \since 5.5
+ \sa qCInfo()
+*/
+void QMessageLogger::info(const QLoggingCategory &cat, const char *msg, ...) const
+{
+ if (!cat.isInfoEnabled())
+ return;
+
+ QMessageLogContext ctxt;
+ ctxt.copy(context);
+ ctxt.category = cat.categoryName();
+
+ QString message;
+
+ va_list ap;
+ va_start(ap, msg); // use variable arg list
+ qt_message(QtInfoMsg, ctxt, msg, ap, message);
+ va_end(ap);
+
+ if (isFatal(QtInfoMsg))
+ qt_message_fatal(QtInfoMsg, ctxt, message);
+}
+
+/*!
+ Logs an informational message specified with format \a msg for the context returned
+ by \a catFunc. Additional parameters, specified by \a msg, may be used.
+
+ \since 5.5
+ \sa qCInfo()
+*/
+void QMessageLogger::info(QMessageLogger::CategoryFunction catFunc,
+ const char *msg, ...) const
+{
+ const QLoggingCategory &cat = (*catFunc)();
+ if (!cat.isInfoEnabled())
+ return;
+
+ QMessageLogContext ctxt;
+ ctxt.copy(context);
+ ctxt.category = cat.categoryName();
+
+ QString message;
+
+ va_list ap;
+ va_start(ap, msg); // use variable arg list
+ qt_message(QtInfoMsg, ctxt, msg, ap, message);
+ va_end(ap);
+
+ if (isFatal(QtInfoMsg))
+ qt_message_fatal(QtInfoMsg, ctxt, message);
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+
+/*!
+ Logs an informational message using a QDebug stream.
+
+ \since 5.5
+ \sa qInfo(), QDebug
+*/
+QDebug QMessageLogger::info() const
+{
+ QDebug dbg = QDebug(QtInfoMsg);
+ QMessageLogContext &ctxt = dbg.stream->context;
+ ctxt.copy(context);
+ return dbg;
+}
+
+/*!
+ Logs an informational message into the category \a cat using a QDebug stream.
+
+ \since 5.5
+ \sa qCInfo(), QDebug
+*/
+QDebug QMessageLogger::info(const QLoggingCategory &cat) const
+{
+ QDebug dbg = QDebug(QtInfoMsg);
+ if (!cat.isInfoEnabled())
+ dbg.stream->message_output = false;
+
+ QMessageLogContext &ctxt = dbg.stream->context;
+ ctxt.copy(context);
+ ctxt.category = cat.categoryName();
+
+ return dbg;
+}
+
+/*!
+ Logs an informational message into category returned by \a catFunc using a QDebug stream.
+
+ \since 5.5
+ \sa qCInfo(), QDebug
+*/
+QDebug QMessageLogger::info(QMessageLogger::CategoryFunction catFunc) const
+{
+ return info((*catFunc)());
+}
+
+#endif
+
#undef qWarning
/*!
Logs a warning message specified with format \a msg. Additional
@@ -802,10 +961,12 @@ static const char functionTokenC[] = "%{function}";
static const char pidTokenC[] = "%{pid}";
static const char appnameTokenC[] = "%{appname}";
static const char threadidTokenC[] = "%{threadid}";
+static const char qthreadptrTokenC[] = "%{qthreadptr}";
static const char timeTokenC[] = "%{time"; //not a typo: this command has arguments
static const char backtraceTokenC[] = "%{backtrace"; //ditto
static const char ifCategoryTokenC[] = "%{if-category}";
static const char ifDebugTokenC[] = "%{if-debug}";
+static const char ifInfoTokenC[] = "%{if-info}";
static const char ifWarningTokenC[] = "%{if-warning}";
static const char ifCriticalTokenC[] = "%{if-critical}";
static const char ifFatalTokenC[] = "%{if-fatal}";
@@ -825,6 +986,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 +996,6 @@ struct QMessagePattern {
bool fromEnvironment;
static QBasicMutex mutex;
-#ifndef QT_BOOTSTRAPPED
- QElapsedTimer timer;
- QDateTime startTime;
-#endif
};
QBasicMutex QMessagePattern::mutex;
@@ -848,9 +1008,6 @@ QMessagePattern::QMessagePattern()
, backtraceSeparator(QLatin1Char('|'))
#endif
, fromEnvironment(false)
-#ifndef QT_BOOTSTRAPPED
- , startTime(QDateTime::currentDateTime())
-#endif
{
#ifndef QT_BOOTSTRAPPED
timer.start();
@@ -942,6 +1099,8 @@ void QMessagePattern::setPattern(const QString &pattern)
tokens[i] = appnameTokenC;
else if (lexeme == QLatin1String(threadidTokenC))
tokens[i] = threadidTokenC;
+ else if (lexeme == QLatin1String(qthreadptrTokenC))
+ tokens[i] = qthreadptrTokenC;
else if (lexeme.startsWith(QLatin1String(timeTokenC))) {
tokens[i] = timeTokenC;
int spaceIdx = lexeme.indexOf(QChar::fromLatin1(' '));
@@ -977,6 +1136,7 @@ void QMessagePattern::setPattern(const QString &pattern)
}
IF_TOKEN(ifCategoryTokenC)
IF_TOKEN(ifDebugTokenC)
+ IF_TOKEN(ifInfoTokenC)
IF_TOKEN(ifWarningTokenC)
IF_TOKEN(ifCriticalTokenC)
IF_TOKEN(ifFatalTokenC)
@@ -1055,6 +1215,9 @@ static void slog2_default_handler(QtMsgType msgType, const char *message)
//Determines the severity level
switch (msgType) {
case QtDebugMsg:
+ severity = SLOG2_DEBUG1;
+ break;
+ case QtInfoMsg:
severity = SLOG2_INFO;
break;
case QtWarningMsg:
@@ -1117,6 +1280,7 @@ QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context, con
} else if (token == typeTokenC) {
switch (type) {
case QtDebugMsg: message.append(QLatin1String("debug")); break;
+ case QtInfoMsg: message.append(QLatin1String("info")); break;
case QtWarningMsg: message.append(QLatin1String("warning")); break;
case QtCriticalMsg:message.append(QLatin1String("critical")); break;
case QtFatalMsg: message.append(QLatin1String("fatal")); break;
@@ -1139,6 +1303,9 @@ QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context, con
} else if (token == appnameTokenC) {
message.append(QCoreApplication::applicationName());
} else if (token == threadidTokenC) {
+ // print the TID as decimal
+ message.append(QString::number(qt_gettid()));
+ } else if (token == qthreadptrTokenC) {
message.append(QLatin1String("0x"));
message.append(QString::number(qlonglong(QThread::currentThread()->currentThread()), 16));
#ifdef QLOGGING_HAVE_BACKTRACE
@@ -1201,6 +1368,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 {
@@ -1214,6 +1387,7 @@ QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context, con
} else if (token == if##LEVEL##TokenC) { \
skip = type != Qt##LEVEL##Msg;
HANDLE_IF_TOKEN(Debug)
+ HANDLE_IF_TOKEN(Info)
HANDLE_IF_TOKEN(Warning)
HANDLE_IF_TOKEN(Critical)
HANDLE_IF_TOKEN(Fatal)
@@ -1249,6 +1423,9 @@ static void systemd_default_message_handler(QtMsgType type,
case QtDebugMsg:
priority = LOG_DEBUG; // Debug-level messages
break;
+ case QtInfoMsg:
+ priority = LOG_INFO; // Informational conditions
+ break;
case QtWarningMsg:
priority = LOG_WARNING; // Warning conditions
break;
@@ -1278,6 +1455,7 @@ static void android_default_message_handler(QtMsgType type,
android_LogPriority priority = ANDROID_LOG_DEBUG;
switch (type) {
case QtDebugMsg: priority = ANDROID_LOG_DEBUG; break;
+ case QtInfoMsg: priority = ANDROID_LOG_INFO; break;
case QtWarningMsg: priority = ANDROID_LOG_WARN; break;
case QtCriticalMsg: priority = ANDROID_LOG_ERROR; break;
case QtFatalMsg: priority = ANDROID_LOG_FATAL; break;
@@ -1548,9 +1726,13 @@ void qErrnoWarning(int code, const char *msg, ...)
\row \li \c %{line} \li Line in source file
\row \li \c %{message} \li The actual message
\row \li \c %{pid} \li QCoreApplication::applicationPid()
- \row \li \c %{threadid} \li ID of current thread
+ \row \li \c %{threadid} \li The system-wide ID of current thread (if it can be obtained)
+ \row \li \c %{qthreadptr} \li A pointer to the current QThread (result of QThread::currentThread())
\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.
@@ -1564,7 +1746,7 @@ void qErrnoWarning(int code, const char *msg, ...)
tail call optimization.
\endtable
- You can also use conditionals on the type of the message using \c %{if-debug},
+ You can also use conditionals on the type of the message using \c %{if-debug}, \c %{if-info}
\c %{if-warning}, \c %{if-critical} or \c %{if-fatal} followed by an \c %{endif}.
What is inside the \c %{if-*} and \c %{endif} will only be printed if the type matches.
@@ -1573,7 +1755,7 @@ void qErrnoWarning(int code, const char *msg, ...)
Example:
\code
- QT_MESSAGE_PATTERN="[%{time yyyyMMdd h:mm:ss.zzz t} %{if-debug}D%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] %{file}:%{line} - %{message}"
+ QT_MESSAGE_PATTERN="[%{time yyyyMMdd h:mm:ss.zzz t} %{if-debug}D{%endif}%{if-info}I%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] %{file}:%{line} - %{message}"
\endcode
The default \a pattern is "%{if-category}%{category}: %{endif}%{message}".
diff --git a/src/corelib/global/qlogging.h b/src/corelib/global/qlogging.h
index f9bbf7fcce..0cbb678e17 100644
--- a/src/corelib/global/qlogging.h
+++ b/src/corelib/global/qlogging.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE
class QDebug;
class QNoDebug;
-enum QtMsgType { QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg, QtSystemMsg = QtCriticalMsg };
+enum QtMsgType { QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg, QtInfoMsg, QtSystemMsg = QtCriticalMsg };
class QMessageLogContext
{
@@ -89,6 +89,7 @@ public:
void debug(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
void noDebug(const char *, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3)
{}
+ void info(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
void warning(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
void critical(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
@@ -96,6 +97,8 @@ public:
void debug(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
void debug(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
+ void info(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
+ void info(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
void warning(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
void warning(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
void critical(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
@@ -110,6 +113,9 @@ public:
QDebug debug() const;
QDebug debug(const QLoggingCategory &cat) const;
QDebug debug(CategoryFunction catFunc) const;
+ QDebug info() const;
+ QDebug info(const QLoggingCategory &cat) const;
+ QDebug info(CategoryFunction catFunc) const;
QDebug warning() const;
QDebug warning(const QLoggingCategory &cat) const;
QDebug warning(CategoryFunction catFunc) const;
@@ -143,20 +149,24 @@ private:
#endif
#define qDebug QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).debug
+#define qInfo QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).info
#define qWarning QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).warning
#define qCritical QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).critical
#define qFatal QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).fatal
#define QT_NO_QDEBUG_MACRO while (false) QMessageLogger().noDebug
-#define QT_NO_QWARNING_MACRO while (false) QMessageLogger().noDebug
#if defined(QT_NO_DEBUG_OUTPUT)
# undef qDebug
# define qDebug QT_NO_QDEBUG_MACRO
#endif
+#if defined(QT_NO_INFO_OUTPUT)
+# undef qInfo
+# define qInfo QT_NO_QDEBUG_MACRO
+#endif
#if defined(QT_NO_WARNING_OUTPUT)
# undef qWarning
-# define qWarning QT_NO_QWARNING_MACRO
+# define qWarning QT_NO_QDEBUG_MACRO
#endif
Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context,
diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h
index e239a11cda..5c7c435db8 100644
--- a/src/corelib/global/qnamespace.h
+++ b/src/corelib/global/qnamespace.h
@@ -42,6 +42,17 @@
QT_BEGIN_NAMESPACE
+#if !defined(Q_QDOC) && !defined(Q_MOC_RUN)
+struct QMetaObject;
+const QMetaObject *qt_getQtMetaObject() Q_DECL_NOEXCEPT; // defined in qobject.h (which can't be included here)
+#define QT_Q_ENUM(ENUM) \
+ inline const QMetaObject *qt_getEnumMetaObject(ENUM) Q_DECL_NOEXCEPT { return qt_getQtMetaObject(); } \
+ inline Q_DECL_CONSTEXPR const char *qt_getEnumName(ENUM) Q_DECL_NOEXCEPT { return #ENUM; }
+#define QT_Q_FLAG(ENUM) QT_Q_ENUM(ENUM)
+#else
+#define QT_Q_ENUM Q_ENUM
+#define QT_Q_FLAG Q_FLAG
+#endif
#ifndef Q_MOC_RUN
namespace
@@ -52,53 +63,6 @@ Qt {
#if defined(Q_MOC_RUN)
Q_OBJECT
-#endif
-
-#if defined(Q_MOC_RUN)
- // NOTE: Generally, do not add Q_ENUMS if a corresponding Q_FLAGS exists.
- Q_ENUMS(ScrollBarPolicy FocusPolicy ContextMenuPolicy)
- Q_ENUMS(ArrowType ToolButtonStyle PenStyle PenCapStyle PenJoinStyle BrushStyle)
- Q_ENUMS(FillRule MaskMode BGMode ClipOperation SizeMode)
- Q_ENUMS(Axis Corner Edge LayoutDirection SizeHint Orientation DropAction)
- Q_FLAGS(Alignment Orientations DropActions Edges)
- Q_FLAGS(DockWidgetAreas ToolBarAreas)
- Q_ENUMS(DockWidgetArea ToolBarArea)
- Q_ENUMS(TextFormat)
- Q_ENUMS(TextElideMode)
- Q_ENUMS(DateFormat TimeSpec DayOfWeek)
- Q_ENUMS(CursorShape GlobalColor)
- Q_ENUMS(AspectRatioMode TransformationMode)
- Q_FLAGS(ImageConversionFlags)
- Q_ENUMS(Key ShortcutContext)
- Q_ENUMS(TextInteractionFlag)
- Q_FLAGS(TextInteractionFlags)
- Q_ENUMS(ItemSelectionMode)
- Q_FLAGS(ItemFlags)
- Q_ENUMS(CheckState)
- Q_ENUMS(SortOrder CaseSensitivity)
- Q_FLAGS(MatchFlags)
- Q_FLAGS(KeyboardModifiers MouseButtons)
- Q_ENUMS(WindowType WindowState WindowModality WidgetAttribute ApplicationAttribute)
- Q_FLAGS(WindowFlags WindowStates)
- Q_ENUMS(FocusReason)
- Q_ENUMS(InputMethodHint InputMethodQuery)
- Q_FLAGS(InputMethodHints InputMethodQueries)
- Q_ENUMS(ScreenOrientation)
- Q_FLAGS(ScreenOrientations)
- Q_ENUMS(ConnectionType)
- Q_ENUMS(ApplicationState)
-#ifndef QT_NO_GESTURES
- Q_ENUMS(GestureState)
- Q_ENUMS(GestureType)
- Q_ENUMS(NativeGestureType)
-#endif
- Q_ENUMS(CursorMoveStyle)
- Q_ENUMS(TimerType)
- Q_ENUMS(ScrollPhase)
- Q_ENUMS(MouseEventSource)
-#endif // defined(Q_MOC_RUN)
-
-#if defined(Q_MOC_RUN)
public:
#endif
@@ -1298,6 +1262,11 @@ public:
IntersectsItemBoundingRect = 0x3
};
+ enum ItemSelectionOperation {
+ ReplaceSelection,
+ AddToSelection
+ };
+
enum TransformationMode {
FastTransformation,
SmoothTransformation
@@ -1469,7 +1438,8 @@ public:
ItemIsUserCheckable = 16,
ItemIsEnabled = 32,
ItemIsTristate = 64,
- ItemNeverHasChildren = 128
+ ItemNeverHasChildren = 128,
+ ItemIsUserTristate = 256
};
Q_DECLARE_FLAGS(ItemFlags, ItemFlag)
@@ -1637,11 +1607,95 @@ public:
};
Q_DECLARE_FLAGS(MouseEventFlags, MouseEventFlag)
+#ifndef Q_QDOC
+ // NOTE: Generally, do not add QT_Q_ENUM if a corresponding Q_Q_FLAG exists.
+ QT_Q_ENUM(ScrollBarPolicy)
+ QT_Q_ENUM(FocusPolicy)
+ QT_Q_ENUM(ContextMenuPolicy)
+ QT_Q_ENUM(ArrowType)
+ QT_Q_ENUM(ToolButtonStyle)
+ QT_Q_ENUM(PenStyle)
+ QT_Q_ENUM(PenCapStyle)
+ QT_Q_ENUM(PenJoinStyle)
+ QT_Q_ENUM(BrushStyle)
+ QT_Q_ENUM(FillRule)
+ QT_Q_ENUM(MaskMode)
+ QT_Q_ENUM(BGMode)
+ QT_Q_ENUM(ClipOperation)
+ QT_Q_ENUM(SizeMode)
+ QT_Q_ENUM(Axis)
+ QT_Q_ENUM(Corner)
+ QT_Q_ENUM(Edge)
+ QT_Q_ENUM(LayoutDirection)
+ QT_Q_ENUM(SizeHint)
+ QT_Q_ENUM(Orientation)
+ QT_Q_ENUM(DropAction)
+ QT_Q_FLAG(Alignment)
+ QT_Q_FLAG(Orientations)
+ QT_Q_FLAG(DropActions)
+ QT_Q_FLAG(Edges)
+ QT_Q_FLAG(DockWidgetAreas)
+ QT_Q_FLAG(ToolBarAreas)
+ QT_Q_ENUM(DockWidgetArea)
+ QT_Q_ENUM(ToolBarArea)
+ QT_Q_ENUM(TextFormat)
+ QT_Q_ENUM(TextElideMode)
+ QT_Q_ENUM(DateFormat)
+ QT_Q_ENUM(TimeSpec)
+ QT_Q_ENUM(DayOfWeek)
+ QT_Q_ENUM(CursorShape)
+ QT_Q_ENUM(GlobalColor)
+ QT_Q_ENUM(AspectRatioMode)
+ QT_Q_ENUM(TransformationMode)
+ QT_Q_FLAG(ImageConversionFlags)
+ QT_Q_ENUM(Key)
+ QT_Q_ENUM(ShortcutContext)
+ QT_Q_ENUM(TextInteractionFlag)
+ QT_Q_FLAG(TextInteractionFlags)
+ QT_Q_ENUM(ItemSelectionMode)
+ QT_Q_ENUM(ItemSelectionOperation)
+ QT_Q_FLAG(ItemFlags)
+ QT_Q_ENUM(CheckState)
+ QT_Q_ENUM(SortOrder)
+ QT_Q_ENUM(CaseSensitivity)
+ QT_Q_FLAG(MatchFlags)
+ QT_Q_FLAG(KeyboardModifiers)
+ QT_Q_FLAG(MouseButtons)
+ QT_Q_ENUM(WindowType)
+ QT_Q_ENUM(WindowState)
+ QT_Q_ENUM(WindowModality)
+ QT_Q_ENUM(WidgetAttribute)
+ QT_Q_ENUM(ApplicationAttribute)
+ QT_Q_FLAG(WindowFlags)
+ QT_Q_FLAG(WindowStates)
+ QT_Q_ENUM(FocusReason)
+ QT_Q_ENUM(InputMethodHint)
+ QT_Q_ENUM(InputMethodQuery)
+ QT_Q_FLAG(InputMethodHints)
+ QT_Q_FLAG(InputMethodQueries)
+ QT_Q_ENUM(ScreenOrientation)
+ QT_Q_FLAG(ScreenOrientations)
+ QT_Q_ENUM(ConnectionType)
+ QT_Q_ENUM(ApplicationState)
+#ifndef QT_NO_GESTURES
+ QT_Q_ENUM(GestureState)
+ QT_Q_ENUM(GestureType)
+ QT_Q_ENUM(NativeGestureType)
+#endif
+ QT_Q_ENUM(CursorMoveStyle)
+ QT_Q_ENUM(TimerType)
+ QT_Q_ENUM(ScrollPhase)
+ QT_Q_ENUM(MouseEventSource)
+#endif // Q_DOC
+
}
#ifdef Q_MOC_RUN
;
#endif
+#undef QT_Q_ENUM
+#undef QT_Q_FLAG
+
Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::MouseButtons)
Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::Orientations)
Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::KeyboardModifiers)
diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc
index 9e9a357272..e49bc1565f 100644
--- a/src/corelib/global/qnamespace.qdoc
+++ b/src/corelib/global/qnamespace.qdoc
@@ -2234,6 +2234,21 @@
*/
/*!
+ \enum Qt::ItemSelectionOperation
+
+ This enum is used in QGraphicsScene to specify what to do with currently selected
+ items when setting a selection area.
+
+ \value ReplaceSelection The currently selected items are replaced by items
+ in the selection area.
+
+ \value AddToSelection The items in the selection area are added to the currently
+ selected items.
+
+ \sa QGraphicsScene::setSelectionArea()
+*/
+
+/*!
\enum Qt::FillRule
Specifies which method should be used to fill the paths and polygons.
@@ -2559,8 +2574,13 @@
\value ItemIsDropEnabled It can be used as a drop target.
\value ItemIsUserCheckable It can be checked or unchecked by the user.
\value ItemIsEnabled The user can interact with the item.
- \value ItemIsTristate The item is checkable with three separate states.
+ \value ItemIsTristate The item can show three separate states.
+ This enables automatic management of the state of parent items in QTreeWidget
+ (checked if all children are checked, unchecked if all children are unchecked,
+ or partially checked if only some children are checked).
\value ItemNeverHasChildren The item never has child items.
+ \value ItemIsUserTristate The user can cycle through three separate states.
+ This value has been added in Qt 5.5.
Note that checkable items need to be given both a suitable set of flags
and an initial state, indicating whether the item is checked or not.
diff --git a/src/corelib/global/qsysinfo.h b/src/corelib/global/qsysinfo.h
index 277caa8db6..e80720ae67 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,
@@ -89,6 +90,7 @@ public:
WV_WINDOWS7 = 0x0090,
WV_WINDOWS8 = 0x00a0,
WV_WINDOWS8_1 = 0x00b0,
+ WV_WINDOWS10 = 0x00c0,
WV_NT_based = 0x00f0,
/* version numbers */
@@ -100,6 +102,7 @@ public:
WV_6_1 = WV_WINDOWS7,
WV_6_2 = WV_WINDOWS8,
WV_6_3 = WV_WINDOWS8_1,
+ WV_10_0 = WV_WINDOWS10,
WV_CE = 0x0100,
WV_CENET = 0x0200,
@@ -107,13 +110,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 +162,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/global/qsystemdetection.h b/src/corelib/global/qsystemdetection.h
index 08a5daa5f4..37d571e228 100644
--- a/src/corelib/global/qsystemdetection.h
+++ b/src/corelib/global/qsystemdetection.h
@@ -75,6 +75,7 @@
BSD4 - Any BSD 4.4 system
UNIX - Any UNIX BSD/SYSV system
ANDROID - Android platform
+ HAIKU - Haiku
The following operating systems have variants:
LINUX - both Q_OS_LINUX and Q_OS_ANDROID are defined when building for Android
@@ -169,6 +170,8 @@
# define Q_OS_INTEGRITY
#elif defined(VXWORKS) /* there is no "real" VxWorks define - this has to be set in the mkspec! */
# define Q_OS_VXWORKS
+#elif defined(__HAIKU__)
+# define Q_OS_HAIKU
#elif defined(__MAKEDEPEND__)
#else
# error "Qt has not been ported to this OS - see http://www.qt-project.org/"
diff --git a/src/corelib/global/qtypeinfo.h b/src/corelib/global/qtypeinfo.h
index e5abb8138b..e2b165ccbc 100644
--- a/src/corelib/global/qtypeinfo.h
+++ b/src/corelib/global/qtypeinfo.h
@@ -202,19 +202,12 @@ Q_DECLARE_TYPEINFO_BODY(QFlags<T>, Q_PRIMITIVE_TYPE);
types must define a member-swap, and be defined in the same
namespace as Qt for this to work.
*/
-#define Q_DECLARE_SHARED_STL(TYPE) \
-QT_END_NAMESPACE \
-namespace std { \
- template<> inline void swap< QT_PREPEND_NAMESPACE(TYPE) >(QT_PREPEND_NAMESPACE(TYPE) &value1, QT_PREPEND_NAMESPACE(TYPE) &value2) \
- { value1.swap(value2); } \
-} \
-QT_BEGIN_NAMESPACE
#define Q_DECLARE_SHARED(TYPE) \
Q_DECLARE_TYPEINFO(TYPE, Q_MOVABLE_TYPE); \
-template <> inline void qSwap<TYPE>(TYPE &value1, TYPE &value2) \
-{ value1.swap(value2); } \
-Q_DECLARE_SHARED_STL(TYPE)
+inline void swap(TYPE &value1, TYPE &value2) \
+ Q_DECL_NOEXCEPT_EXPR(noexcept(value1.swap(value2))) \
+{ value1.swap(value2); }
/*
QTypeInfo primitive specializations
diff --git a/src/corelib/io/forkfd_qt.cpp b/src/corelib/io/forkfd_qt.cpp
new file mode 100644
index 0000000000..dbfeda7895
--- /dev/null
+++ b/src/corelib/io/forkfd_qt.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+// these might be defined via precompiled headers
+#ifndef _POSIX_C_SOURCE
+# define _POSIX_C_SOURCE 200809L
+#endif
+#if !defined(_XOPEN_SOURCE) && !defined(__QNXNTO__)
+# define _XOPEN_SOURCE 500
+#endif
+
+#include <QtCore/qatomic.h>
+
+#if defined(QT_NO_DEBUG) && !defined(NDEBUG)
+# define NDEBUG
+#endif
+
+typedef QT_PREPEND_NAMESPACE(QBasicAtomicInt) ffd_atomic_int;
+#define ffd_atomic_pointer(type) QT_PREPEND_NAMESPACE(QBasicAtomicPointer<type>)
+
+QT_BEGIN_NAMESPACE
+
+#define FFD_ATOMIC_INIT(val) Q_BASIC_ATOMIC_INITIALIZER(val)
+
+#define FFD_ATOMIC_RELAXED Relaxed
+#define FFD_ATOMIC_ACQUIRE Acquire
+#define FFD_ATOMIC_RELEASE Release
+#define loadRelaxed load
+#define storeRelaxed store
+
+#define FFD_CONCAT(x, y) x ## y
+
+#define ffd_atomic_load(ptr,order) (ptr)->FFD_CONCAT(load, order)()
+#define ffd_atomic_store(ptr,val,order) (ptr)->FFD_CONCAT(store, order)(val)
+#define ffd_atomic_exchange(ptr,val,order) (ptr)->FFD_CONCAT(fetchAndStore, order)(val)
+#define ffd_atomic_compare_exchange(ptr,expected,desired,order1,order2) \
+ (ptr)->FFD_CONCAT(testAndSet, order1)(*expected, desired, *expected)
+#define ffd_atomic_add_fetch(ptr,val,order) ((ptr)->FFD_CONCAT(fetchAndAdd, order)(val) + val)
+
+QT_END_NAMESPACE
+
+extern "C" {
+#include "../../3rdparty/forkfd/forkfd.c"
+}
diff --git a/src/corelib/io/io.pri b/src/corelib/io/io.pri
index 77788e3cca..78349fbc49 100644
--- a/src/corelib/io/io.pri
+++ b/src/corelib/io/io.pri
@@ -137,6 +137,10 @@ win32 {
io/qlockfile_unix.cpp \
io/qprocess_unix.cpp \
io/qfilesystemiterator_unix.cpp \
+ io/forkfd_qt.cpp
+ HEADERS += \
+ ../3rdparty/forkfd/forkfd.h
+ INCLUDEPATH += ../3rdparty/forkfd
!nacl:mac: {
SOURCES += io/qsettings_mac.cpp
@@ -165,6 +169,11 @@ win32 {
SOURCES += \
io/qstandardpaths_android.cpp \
io/qstorageinfo_unix.cpp
+ } else:haiku {
+ SOURCES += \
+ io/qstandardpaths_haiku.cpp \
+ io/qstorageinfo_unix.cpp
+ LIBS += -lbe
} else {
SOURCES += \
io/qstandardpaths_unix.cpp \
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..ad61621a93 100644
--- a/src/corelib/io/qdebug.cpp
+++ b/src/corelib/io/qdebug.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2015 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.
@@ -40,9 +41,13 @@
#include "qdebug.h"
#include <private/qtextstream_p.h>
+#include <private/qtools_p.h>
QT_BEGIN_NAMESPACE
+using QtMiscUtils::toHexUpper;
+using QtMiscUtils::fromHex;
+
// This file is needed to force compilation of QDebug into the kernel library.
/*!
@@ -148,6 +153,167 @@ 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('\'');
+}
+
+template <typename Char>
+static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, int length, bool isUnicode = true)
+{
+ QChar quote(QLatin1Char('"'));
+ d->write(&quote, 1);
+
+ bool lastWasHexEscape = false;
+ const Char *end = begin + length;
+ for (const Char *p = begin; p != end; ++p) {
+ // check if we need to insert "" to break an hex escape sequence
+ if (Q_UNLIKELY(lastWasHexEscape)) {
+ if (fromHex(*p) != -1) {
+ // yes, insert it
+ QChar quotes[] = { QLatin1Char('"'), QLatin1Char('"') };
+ d->write(quotes, 2);
+ }
+ lastWasHexEscape = false;
+ }
+
+ if (sizeof(Char) == sizeof(QChar)) {
+ int runLength = 0;
+ while (p + runLength != end &&
+ p[runLength] < 0x7f && p[runLength] >= 0x20 && p[runLength] != '\\' && p[runLength] != '"')
+ ++runLength;
+ if (runLength) {
+ d->write(reinterpret_cast<const QChar *>(p), runLength);
+ p += runLength - 1;
+ continue;
+ }
+ } else if (*p < 0x7f && *p >= 0x20 && *p != '\\' && *p != '"') {
+ QChar c = QLatin1Char(*p);
+ d->write(&c, 1);
+ continue;
+ }
+
+ // print as an escape sequence
+ int buflen = 2;
+ ushort buf[sizeof "\\U12345678" - 1];
+ buf[0] = '\\';
+
+ switch (*p) {
+ case '"':
+ case '\\':
+ buf[1] = *p;
+ break;
+ case '\b':
+ buf[1] = 'b';
+ break;
+ case '\f':
+ buf[1] = 'f';
+ break;
+ case '\n':
+ buf[1] = 'n';
+ break;
+ case '\r':
+ buf[1] = 'r';
+ break;
+ case '\t':
+ buf[1] = 't';
+ break;
+ default:
+ if (!isUnicode) {
+ // print as hex escape
+ buf[1] = 'x';
+ buf[2] = toHexUpper(uchar(*p) >> 4);
+ buf[3] = toHexUpper(uchar(*p));
+ buflen = 4;
+ lastWasHexEscape = true;
+ break;
+ }
+ if (QChar::isHighSurrogate(*p)) {
+ if ((p + 1) != end && QChar::isLowSurrogate(p[1])) {
+ // properly-paired surrogates
+ uint ucs4 = QChar::surrogateToUcs4(*p, p[1]);
+ ++p;
+ buf[1] = 'U';
+ buf[2] = '0'; // toHexUpper(ucs4 >> 32);
+ buf[3] = '0'; // toHexUpper(ucs4 >> 28);
+ buf[4] = toHexUpper(ucs4 >> 20);
+ buf[5] = toHexUpper(ucs4 >> 16);
+ buf[6] = toHexUpper(ucs4 >> 12);
+ buf[7] = toHexUpper(ucs4 >> 8);
+ buf[8] = toHexUpper(ucs4 >> 4);
+ buf[9] = toHexUpper(ucs4);
+ buflen = 10;
+ break;
+ }
+ // improperly-paired surrogates, fall through
+ }
+ buf[1] = 'u';
+ buf[2] = toHexUpper(ushort(*p) >> 12);
+ buf[3] = toHexUpper(ushort(*p) >> 8);
+ buf[4] = toHexUpper(*p >> 4);
+ buf[5] = toHexUpper(*p);
+ buflen = 6;
+ }
+ d->write(reinterpret_cast<QChar *>(buf), buflen);
+ }
+
+ d->write(&quote, 1);
+}
+
+/*!
+ \internal
+ Duplicated from QtTest::toPrettyUnicode().
+*/
+void QDebug::putString(const QChar *begin, size_t length)
+{
+ if (stream->testFlag(Stream::NoQuotes)) {
+ // no quotes, write the string directly too (no pretty-printing)
+ // this respects the QTextStream state, though
+ stream->ts.d_ptr->putString(begin, length);
+ } else {
+ // we'll reset the QTextStream formatting mechanisms, so save the state
+ QDebugStateSaver saver(*this);
+ stream->ts.d_ptr->params.reset();
+ putEscapedString(stream->ts.d_ptr.data(), reinterpret_cast<const ushort *>(begin), length);
+ }
+}
+
+/*!
+ \internal
+ Duplicated from QtTest::toPrettyCString().
+*/
+void QDebug::putByteArray(const char *begin, size_t length, Latin1Content content)
+{
+ if (stream->testFlag(Stream::NoQuotes)) {
+ // no quotes, write the string directly too (no pretty-printing)
+ // this respects the QTextStream state, though
+ QString string = content == ContainsLatin1 ? QString::fromLatin1(begin, length) : QString::fromUtf8(begin, length);
+ stream->ts.d_ptr->putString(string);
+ } else {
+ // we'll reset the QTextStream formatting mechanisms, so save the state
+ QDebugStateSaver saver(*this);
+ stream->ts.d_ptr->params.reset();
+ putEscapedString(stream->ts.d_ptr.data(), reinterpret_cast<const uchar *>(begin),
+ length, content == ContainsLatin1);
+ }
+}
+
+/*!
\fn QDebug::swap(QDebug &other)
\since 5.0
diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h
index 4edb3057fb..27abf2a740 100644
--- a/src/corelib/io/qdebug.h
+++ b/src/corelib/io/qdebug.h
@@ -76,6 +76,12 @@ class Q_CORE_EXPORT QDebug
// added in 5.4
int flags;
} *stream;
+
+ enum Latin1Content { ContainsBinary = 0, ContainsLatin1 };
+
+ void putUcs4(uint ucs4);
+ void putString(const QChar *begin, size_t length);
+ void putByteArray(const char *begin, size_t length, Latin1Content content);
public:
inline QDebug(QIODevice *device) : stream(new Stream(device)) {}
inline QDebug(QString *string) : stream(new Stream(string)) {}
@@ -83,7 +89,7 @@ public:
inline QDebug(const QDebug &o):stream(o.stream) { ++stream->ref; }
inline QDebug &operator=(const QDebug &other);
~QDebug();
- inline void swap(QDebug &other) { qSwap(stream, other.stream); }
+ inline void swap(QDebug &other) Q_DECL_NOTHROW { qSwap(stream, other.stream); }
QDebug &resetFormat();
@@ -98,11 +104,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(); }
@@ -112,11 +122,14 @@ public:
inline QDebug &operator<<(float t) { stream->ts << t; return maybeSpace(); }
inline QDebug &operator<<(double t) { stream->ts << t; return maybeSpace(); }
inline QDebug &operator<<(const char* t) { stream->ts << QString::fromUtf8(t); return maybeSpace(); }
- inline QDebug &operator<<(const QString & t) { maybeQuote(); stream->ts << t; maybeQuote(); return maybeSpace(); }
- inline QDebug &operator<<(const QStringRef & t) { return operator<<(t.toString()); }
- 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 QString & t) { putString(t.constData(), uint(t.length())); return maybeSpace(); }
+ inline QDebug &operator<<(const QStringRef & t) { putString(t.constData(), uint(t.length())); return maybeSpace(); }
+ inline QDebug &operator<<(QLatin1String t) { putByteArray(t.latin1(), t.size(), ContainsLatin1); return maybeSpace(); }
+ inline QDebug &operator<<(const QByteArray & t) { putByteArray(t.constData(), t.size(), ContainsBinary); 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;
@@ -268,6 +281,82 @@ inline QDebug operator<<(QDebug debug, const QFlags<T> &flags)
return debug;
}
+#ifdef Q_OS_MAC
+
+// We provide QDebug stream operators for commonly used Core Foundation
+// and Core Graphics types, as well as NSObject. Additional CF/CG types
+// may be added by the user, using Q_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE.
+
+#define QT_FOR_EACH_CORE_FOUNDATION_TYPE(F) \
+ F(CFArray) \
+ F(CFURL) \
+ F(CFData) \
+ F(CFNumber) \
+ F(CFDictionary) \
+ F(CFLocale) \
+ F(CFDate) \
+ F(CFBoolean) \
+ F(CFTimeZone) \
+
+#define QT_FOR_EACH_MUTABLE_CORE_FOUNDATION_TYPE(F) \
+ F(CFError) \
+ F(CFBundle) \
+
+#define QT_FOR_EACH_CORE_GRAPHICS_TYPE(F) \
+ F(CGPath) \
+
+#define QT_FOR_EACH_MUTABLE_CORE_GRAPHICS_TYPE(F) \
+ F(CGColorSpace) \
+ F(CGImage) \
+ F(CGFont) \
+ F(CGColor) \
+
+#define QT_FORWARD_DECLARE_CF_TYPE(type) Q_FORWARD_DECLARE_CF_TYPE(type);
+#define QT_FORWARD_DECLARE_MUTABLE_CF_TYPE(type) Q_FORWARD_DECLARE_MUTABLE_CF_TYPE(type);
+#define QT_FORWARD_DECLARE_CG_TYPE(type) typedef const struct type *type ## Ref;
+#define QT_FORWARD_DECLARE_MUTABLE_CG_TYPE(type) typedef struct type *type ## Ref;
+
+QT_END_NAMESPACE
+Q_FORWARD_DECLARE_CF_TYPE(CFString);
+Q_FORWARD_DECLARE_OBJC_CLASS(NSObject);
+QT_FOR_EACH_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_CF_TYPE);
+QT_FOR_EACH_MUTABLE_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_MUTABLE_CF_TYPE);
+QT_FOR_EACH_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_CG_TYPE);
+QT_FOR_EACH_MUTABLE_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_MUTABLE_CG_TYPE);
+QT_BEGIN_NAMESPACE
+
+#define QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE(CFType) \
+ Q_CORE_EXPORT QDebug operator<<(QDebug, CFType##Ref);
+
+#define Q_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE(CFType) \
+ QDebug operator<<(QDebug debug, CFType##Ref ref) \
+ { \
+ if (!ref) \
+ return debug << QT_STRINGIFY(CFType) "Ref(0x0)"; \
+ if (CFStringRef description = CFCopyDescription(ref)) { \
+ QDebugStateSaver saver(debug); \
+ debug.noquote() << description; \
+ CFRelease(description); \
+ } \
+ return debug; \
+ }
+
+// Defined in qcore_mac_objc.mm
+Q_CORE_EXPORT QDebug operator<<(QDebug, const NSObject *);
+Q_CORE_EXPORT QDebug operator<<(QDebug, CFStringRef);
+
+QT_FOR_EACH_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE);
+QT_FOR_EACH_MUTABLE_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE);
+QT_FOR_EACH_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE);
+QT_FOR_EACH_MUTABLE_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE);
+
+#undef QT_FORWARD_DECLARE_CF_TYPE
+#undef QT_FORWARD_DECLARE_MUTABLE_CF_TYPE
+#undef QT_FORWARD_DECLARE_CG_TYPE
+#undef QT_FORWARD_DECLARE_MUTABLE_CG_TYPE
+
+#endif // Q_OS_MAC
+
QT_END_NAMESPACE
#endif // QDEBUG_H
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..b95e628b0f 100644
--- a/src/corelib/io/qfileselector.cpp
+++ b/src/corelib/io/qfileselector.cpp
@@ -145,7 +145,9 @@ QFileSelectorPrivate::QFileSelectorPrivate()
Selectors normally available are
\list
\li platform, any of the following strings which match the platform the application is running
- on: android, blackberry, ios, osx, darwin, mac, linux, wince, unix, windows.
+ on (list not exhaustive): android, blackberry, ios, osx, darwin, mac, linux, wince, unix,
+ windows. On Linux, if it can be determined, the name of the distribution too, like debian,
+ fedora or opensuse.
\li locale, same as QLocale::system().name().
\endlist
@@ -335,7 +337,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
@@ -351,10 +353,10 @@ QStringList QFileSelectorPrivate::platformSelectors()
// similar, but not identical to QSysInfo::osType
QStringList ret;
#if defined(Q_OS_WIN)
+ // can't fall back to QSysInfo because we need both "winphone" and "winrt" for the Windows Phone case
ret << QStringLiteral("windows");
-# if defined(Q_OS_WINCE)
- ret << QStringLiteral("wince");
-# elif defined(Q_OS_WINRT)
+ ret << QSysInfo::kernelType(); // "wince" and "winnt"
+# if defined(Q_OS_WINRT)
ret << QStringLiteral("winrt");
# if defined(Q_OS_WINPHONE)
ret << QStringLiteral("winphone");
@@ -362,25 +364,16 @@ QStringList QFileSelectorPrivate::platformSelectors()
# endif
#elif defined(Q_OS_UNIX)
ret << QStringLiteral("unix");
-# if defined(Q_OS_ANDROID)
- ret << QStringLiteral("android");
-# elif defined(Q_OS_BLACKBERRY)
- ret << QStringLiteral("blackberry");
-# elif defined(Q_OS_QNX)
- ret << QStringLiteral("qnx");
-# elif defined(Q_OS_LINUX)
- ret << QStringLiteral("linux");
-# elif defined(Q_OS_DARWIN)
- ret << QStringLiteral("darwin");
- ret << QStringLiteral("mac"); // compatibility synonym
-# if defined(Q_OS_IOS)
- ret << QStringLiteral("ios");
-# elif defined(Q_OS_OSX)
- ret << QStringLiteral("osx");
-# endif
-# else
+# if !defined(Q_OS_ANDROID) && !defined(Q_OS_BLACKBERRY)
+ // we don't want "linux" for Android or "qnx" for Blackberry here
ret << QSysInfo::kernelType();
+# ifdef Q_OS_MAC
+ ret << QStringLiteral("mac"); // compatibility, since kernelType() is "darwin"
+# endif
# endif
+ QString productName = QSysInfo::productType();
+ if (productName != QLatin1String("unknown"))
+ ret << productName; // "opensuse", "fedora", "osx", "ios", "blackberry", "android"
#endif
return ret;
}
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp
index bfa4483ca7..10326dea06 100644
--- a/src/corelib/io/qfilesystemengine_unix.cpp
+++ b/src/corelib/io/qfilesystemengine_unix.cpp
@@ -250,6 +250,26 @@ QFileSystemEntry QFileSystemEngine::canonicalName(const QFileSystemEntry &entry,
return QFileSystemEntry(ret);
}
}
+
+# elif defined(Q_OS_ANDROID)
+ // On some Android versions, realpath() will return a path even if it does not exist
+ // To work around this, we check existence in advance.
+ if (!data.hasFlags(QFileSystemMetaData::ExistsAttribute))
+ fillMetaData(entry, data, QFileSystemMetaData::ExistsAttribute);
+
+ if (!data.exists()) {
+ ret = 0;
+ errno = ENOENT;
+ } else {
+ ret = (char*)malloc(PATH_MAX + 1);
+ if (realpath(entry.nativeFilePath().constData(), (char*)ret) == 0) {
+ const int savedErrno = errno; // errno is checked below, and free() might change it
+ free(ret);
+ errno = savedErrno;
+ ret = 0;
+ }
+ }
+
# else
# if _POSIX_VERSION >= 200801L
ret = realpath(entry.nativeFilePath().constData(), (char*)0);
@@ -723,36 +743,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/qfilesystementry.cpp b/src/corelib/io/qfilesystementry.cpp
index 8e48dd1630..69c0e08763 100644
--- a/src/corelib/io/qfilesystementry.cpp
+++ b/src/corelib/io/qfilesystementry.cpp
@@ -315,13 +315,7 @@ void QFileSystemEntry::findLastSeparator() const
{
if (m_lastSeparator == -2) {
resolveFilePath();
- m_lastSeparator = -1;
- for (int i = m_filePath.size() - 1; i >= 0; --i) {
- if (m_filePath[i].unicode() == '/') {
- m_lastSeparator = i;
- break;
- }
- }
+ m_lastSeparator = m_filePath.lastIndexOf(QLatin1Char('/'));
}
}
diff --git a/src/corelib/io/qfilesystemwatcher.cpp b/src/corelib/io/qfilesystemwatcher.cpp
index 4bca8d90a0..416dd29d23 100644
--- a/src/corelib/io/qfilesystemwatcher.cpp
+++ b/src/corelib/io/qfilesystemwatcher.cpp
@@ -52,9 +52,9 @@
# include "qfilesystemwatcher_win_p.h"
#elif defined(USE_INOTIFY)
# include "qfilesystemwatcher_inotify_p.h"
-#elif defined(Q_OS_FREEBSD) || defined(Q_OS_IOS) || (defined(Q_OS_OSX) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7)
+#elif defined(Q_OS_FREEBSD) || defined(Q_OS_IOS)
# include "qfilesystemwatcher_kqueue_p.h"
-#elif defined(Q_OS_OSX) && MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_6
+#elif defined(Q_OS_OSX)
# include "qfilesystemwatcher_fsevents_p.h"
#endif
@@ -68,9 +68,9 @@ QFileSystemWatcherEngine *QFileSystemWatcherPrivate::createNativeEngine(QObject
// there is a chance that inotify may fail on Linux pre-2.6.13 (August
// 2005), so we can't just new inotify directly.
return QInotifyFileSystemWatcherEngine::create(parent);
-#elif defined(Q_OS_FREEBSD) || defined(Q_OS_IOS) || (defined(Q_OS_OSX) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7)
+#elif defined(Q_OS_FREEBSD) || defined(Q_OS_IOS)
return QKqueueFileSystemWatcherEngine::create(parent);
-#elif defined(Q_OS_OSX) && MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_6
+#elif defined(Q_OS_OSX)
return QFseventsFileSystemWatcherEngine::create(parent);
#else
Q_UNUSED(parent);
@@ -394,12 +394,12 @@ QStringList QFileSystemWatcher::removePaths(const QStringList &paths)
/*!
\fn void QFileSystemWatcher::directoryChanged(const QString &path)
- This signal is emitted when the directory at a specified \a path,
- is modified (e.g., when a file is added, modified or deleted) or
- removed from disk. Note that if there are several changes during a
- short period of time, some of the changes might not emit this
- signal. However, the last change in the sequence of changes will
- always generate this signal.
+ This signal is emitted when the directory at a specified \a path
+ is modified (e.g., when a file is added or deleted) or removed
+ from disk. Note that if there are several changes during a short
+ period of time, some of the changes might not emit this signal.
+ However, the last change in the sequence of changes will always
+ generate this signal.
\sa fileChanged()
*/
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..388c623bcb 100644
--- a/src/corelib/io/qiodevice.cpp
+++ b/src/corelib/io/qiodevice.cpp
@@ -117,8 +117,7 @@ void debugBinaryString(const char *data, qint64 maxlen)
*/
QIODevicePrivate::QIODevicePrivate()
: openMode(QIODevice::NotOpen), buffer(QIODEVICE_BUFFERSIZE),
- pos(0), devicePos(0), seqDumpPos(0)
- , pPos(&pos), pDevicePos(&devicePos)
+ pos(0), devicePos(0)
, baseReadLineDataCalled(false)
, firstRead(true)
, accessMode(Unset)
@@ -566,7 +565,6 @@ void QIODevice::close()
d->openMode = NotOpen;
d->errorString.clear();
d->pos = 0;
- d->seqDumpPos = 0;
d->buffer.clear();
d->firstRead = true;
}
@@ -733,12 +731,6 @@ qint64 QIODevice::bytesToWrite() const
return qint64(0);
}
-#ifdef Q_CC_RVCT
-// arm mode makes the 64-bit integer operations much faster in RVCT 2.2
-#pragma push
-#pragma arm
-#endif
-
/*!
Reads at most \a maxSize bytes from the device into \a data, and
returns the number of bytes read. If an error occurs, such as when
@@ -761,11 +753,14 @@ qint64 QIODevice::read(char *data, qint64 maxSize)
this, data, int(maxSize), int(d->pos), int(d->buffer.size()));
#endif
+ const bool sequential = d->isSequential();
+
// Short circuit for getChar()
if (maxSize == 1) {
int chint;
while ((chint = d->buffer.getChar()) != -1) {
- ++(*d->pPos);
+ if (!sequential)
+ ++d->pos;
char c = char(uchar(chint));
if (c == '\r' && (d->openMode & Text))
@@ -783,27 +778,21 @@ 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) {
+ if (!sequential)
+ d->pos += 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) {
@@ -811,105 +800,88 @@ qint64 QIODevice::read(char *data, qint64 maxSize)
// for fast pos updates.
CHECK_READABLE(read, qint64(-1));
d->firstRead = false;
- if (d->isSequential()) {
- d->pPos = &d->seqDumpPos;
- 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 (sequential || d->pos == d->devicePos || 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;
+ if (!sequential) {
+ d->pos += readFromDevice;
+ d->devicePos += 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) {
+ if (!sequential)
+ d->devicePos += 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,16 +889,14 @@ 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;
}
-#ifdef Q_CC_RVCT
-#pragma pop
-#endif
-
/*!
\overload
@@ -1039,12 +1009,6 @@ QByteArray QIODevice::readAll()
return result;
}
-#ifdef Q_CC_RVCT
-// arm mode makes the 64-bit integer operations much faster in RVCT 2.2
-#pragma push
-#pragma arm
-#endif
-
/*!
This function reads a line of ASCII characters from the device, up
to a maximum of \a maxSize - 1 bytes, stores the characters in \a
@@ -1264,10 +1228,6 @@ qint64 QIODevice::readLineData(char *data, qint64 maxSize)
return readSoFar;
}
-#ifdef Q_CC_RVCT
-#pragma pop
-#endif
-
/*!
Returns \c true if a complete line of data can be read from the device;
otherwise returns \c false.
@@ -1455,7 +1415,8 @@ qint64 QIODevicePrivate::peek(char *data, qint64 maxSize)
return readBytes;
buffer.ungetBlock(data, readBytes);
- *pPos -= readBytes;
+ if (!isSequential())
+ pos -= readBytes;
return readBytes;
}
@@ -1470,7 +1431,8 @@ QByteArray QIODevicePrivate::peek(qint64 maxSize)
return result;
buffer.ungetBlock(result.constData(), result.size());
- *pPos -= result.size();
+ if (!isSequential())
+ pos -= result.size();
return result;
}
diff --git a/src/corelib/io/qiodevice_p.h b/src/corelib/io/qiodevice_p.h
index d764cb0fbb..ac76f8ded8 100644
--- a/src/corelib/io/qiodevice_p.h
+++ b/src/corelib/io/qiodevice_p.h
@@ -209,10 +209,6 @@ public:
QIODevicePrivateLinearBuffer buffer;
qint64 pos;
qint64 devicePos;
- // these three are for fast position updates during read, avoiding isSequential test
- qint64 seqDumpPos;
- qint64 *pPos;
- qint64 *pDevicePos;
bool baseReadLineDataCalled;
bool firstRead;
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/qloggingcategory.cpp b/src/corelib/io/qloggingcategory.cpp
index 79d20601a6..a032fe3d1b 100644
--- a/src/corelib/io/qloggingcategory.cpp
+++ b/src/corelib/io/qloggingcategory.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -64,8 +64,8 @@ static void setBoolLane(QBasicAtomicInt *atomic, bool enable, int shift)
QLoggingCategory represents a certain logging category - identified by a
string - at runtime. A category can be configured to enable or disable
logging of messages per message type. Whether a message type is enabled or
- not can be checked with the \l isDebugEnabled(), \l isWarningEnabled(), and
- \l isCriticalEnabled() methods.
+ not can be checked with the \l isDebugEnabled(), \l isInfoEnabled(),
+ \l isWarningEnabled(), and \l isCriticalEnabled() methods.
All objects are meant to be configured by a common registry (see also
\l{Configuring Categories}). Different objects can also represent the same
@@ -82,8 +82,8 @@ static void setBoolLane(QBasicAtomicInt *atomic, bool enable, int shift)
\section1 Checking Category Configuration
- QLoggingCategory provides \l isDebugEnabled(), \l isWarningEnabled(),
- \l isCriticalEnabled(), as well as \l isEnabled()
+ QLoggingCategory provides \l isDebugEnabled(), \l isInfoEnabled(),
+ \l isWarningEnabled(), \l isCriticalEnabled(), as well as \l isEnabled()
to check whether messages for the given message type should be logged.
\note The qCDebug(), qCWarning(), qCCritical() macros prevent arguments
@@ -101,7 +101,7 @@ static void setBoolLane(QBasicAtomicInt *atomic, bool enable, int shift)
\snippet qloggingcategory/main.cpp 5
will log messages of type \c QtWarningMsg, \c QtCriticalMsg, \c QtFatalMsg, but will
- ignore messages of type \c QtDebugMsg.
+ ignore messages of type \c QtDebugMsg and \c QtInfoMsg.
If no argument is passed, all messages will be logged.
@@ -122,7 +122,7 @@ static void setBoolLane(QBasicAtomicInt *atomic, bool enable, int shift)
\c <category> is the name of the category, potentially with \c{*} as a
wildcard symbol as the first or last character (or at both positions).
- The optional \c <type> must be either \c debug, \c warning, or \c critical.
+ The optional \c <type> must be either \c debug, \c info, \c warning, or \c critical.
Lines that do not fit this scheme are ignored.
Rules are evaluated in text order, from first to last. That is, if two rules
@@ -250,6 +250,21 @@ QLoggingCategory::~QLoggingCategory()
expensive generation of data that is only used for debug output.
*/
+
+/*!
+ \fn bool QLoggingCategory::isInfoEnabled() const
+
+ Returns \c true if informational messages should be shown for this category.
+ Returns \c false otherwise.
+
+ \note The \l qCInfo() macro already does this check before executing any
+ code. However, calling this method may be useful to avoid
+ expensive generation of data that is only used for debug output.
+
+ \since 5.5
+*/
+
+
/*!
\fn bool QLoggingCategory::isWarningEnabled() const
@@ -280,6 +295,7 @@ bool QLoggingCategory::isEnabled(QtMsgType msgtype) const
{
switch (msgtype) {
case QtDebugMsg: return isDebugEnabled();
+ case QtInfoMsg: return isInfoEnabled();
case QtWarningMsg: return isWarningEnabled();
case QtCriticalMsg: return isCriticalEnabled();
case QtFatalMsg: return true;
@@ -302,10 +318,12 @@ void QLoggingCategory::setEnabled(QtMsgType type, bool enable)
switch (type) {
#ifdef Q_ATOMIC_INT8_IS_SUPPORTED
case QtDebugMsg: bools.enabledDebug.store(enable); break;
+ case QtInfoMsg: bools.enabledInfo.store(enable); break;
case QtWarningMsg: bools.enabledWarning.store(enable); break;
case QtCriticalMsg: bools.enabledCritical.store(enable); break;
#else
case QtDebugMsg: setBoolLane(&enabled, enable, DebugShift); break;
+ case QtInfoMsg: setBoolLane(&enabled, enable, InfoShift); break;
case QtWarningMsg: setBoolLane(&enabled, enable, WarningShift); break;
case QtCriticalMsg: setBoolLane(&enabled, enable, CriticalShift); break;
#endif
@@ -331,7 +349,7 @@ void QLoggingCategory::setEnabled(QtMsgType type, bool enable)
/*!
Returns a pointer to the global category \c "default" that
- is used e.g. by qDebug(), qWarning(), qCritical(), qFatal().
+ is used e.g. by qDebug(), qInfo(), qWarning(), qCritical(), qFatal().
\note The returned pointer may be null during destruction of
static objects.
@@ -439,6 +457,47 @@ void QLoggingCategory::setFilterRules(const QString &rules)
*/
/*!
+ \macro qCInfo(category)
+ \relates QLoggingCategory
+ \since 5.5
+
+ Returns an output stream for informational messages in the logging category
+ \a category.
+
+ The macro expands to code that checks whether
+ \l QLoggingCategory::isInfoEnabled() evaluates to \c true.
+ If so, the stream arguments are processed and sent to the message handler.
+
+ Example:
+
+ \snippet qloggingcategory/main.cpp qcinfo_stream
+
+ \note Arguments are not processed if debug output for the category is not
+ enabled, so do not rely on any side effects.
+
+ \sa qInfo()
+*/
+
+/*!
+ \macro qCInfo(category, const char *message, ...)
+ \relates QLoggingCategory
+ \since 5.5
+
+ Logs an informational message \a message in the logging category \a category.
+ \a message might contain place holders that are replaced by additional
+ arguments, similar to the C printf() function.
+
+ Example:
+
+ \snippet qloggingcategory/main.cpp qcinfo_printf
+
+ \note Arguments might not be processed if debug output for the category is
+ not enabled, so do not rely on any side effects.
+
+ \sa qInfo()
+*/
+
+/*!
\macro qCWarning(category)
\relates QLoggingCategory
\since 5.2
diff --git a/src/corelib/io/qloggingcategory.h b/src/corelib/io/qloggingcategory.h
index c7e242af08..5504ebab3b 100644
--- a/src/corelib/io/qloggingcategory.h
+++ b/src/corelib/io/qloggingcategory.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -53,10 +53,12 @@ public:
#ifdef Q_ATOMIC_INT8_IS_SUPPORTED
bool isDebugEnabled() const { return bools.enabledDebug.load(); }
+ bool isInfoEnabled() const { return bools.enabledInfo.load(); }
bool isWarningEnabled() const { return bools.enabledWarning.load(); }
bool isCriticalEnabled() const { return bools.enabledCritical.load(); }
#else
bool isDebugEnabled() const { return enabled.load() >> DebugShift & 1; }
+ bool isInfoEnabled() const { return enabled.load() >> InfoShift & 1; }
bool isWarningEnabled() const { return enabled.load() >> WarningShift & 1; }
bool isCriticalEnabled() const { return enabled.load() >> CriticalShift & 1; }
#endif
@@ -80,9 +82,9 @@ private:
const char *name;
#ifdef Q_BIG_ENDIAN
- enum { DebugShift = 0, WarningShift = 8, CriticalShift = 16 };
+ enum { DebugShift = 0, WarningShift = 8, CriticalShift = 16, InfoShift = 24 };
#else
- enum { DebugShift = 24, WarningShift = 16, CriticalShift = 8 };
+ enum { DebugShift = 24, WarningShift = 16, CriticalShift = 8, InfoShift = 0};
#endif
struct AtomicBools {
@@ -90,6 +92,7 @@ private:
QBasicAtomicInteger<bool> enabledDebug;
QBasicAtomicInteger<bool> enabledWarning;
QBasicAtomicInteger<bool> enabledCritical;
+ QBasicAtomicInteger<bool> enabledInfo;
#endif
};
union {
@@ -114,6 +117,9 @@ private:
#define qCDebug(category, ...) \
for (bool qt_category_enabled = category().isDebugEnabled(); qt_category_enabled; qt_category_enabled = false) \
QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC, category().categoryName()).debug(__VA_ARGS__)
+#define qCInfo(category, ...) \
+ for (bool qt_category_enabled = category().isInfoEnabled(); qt_category_enabled; qt_category_enabled = false) \
+ QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC, category().categoryName()).info(__VA_ARGS__)
#define qCWarning(category, ...) \
for (bool qt_category_enabled = category().isWarningEnabled(); qt_category_enabled; qt_category_enabled = false) \
QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC, category().categoryName()).warning(__VA_ARGS__)
@@ -133,6 +139,7 @@ private:
// check for enabled category inside QMessageLogger.
#define qCDebug qDebug
+#define qCInfo qInfo
#define qCWarning qWarning
#define qCCritical qCritical
@@ -142,9 +149,13 @@ private:
# undef qCDebug
# define qCDebug(category) QT_NO_QDEBUG_MACRO()
#endif
+#if defined(QT_NO_INFO_OUTPUT)
+# undef qCInfo
+# define qCInfo(category) QT_NO_QDEBUG_MACRO()
+#endif
#if defined(QT_NO_WARNING_OUTPUT)
# undef qCWarning
-# define qCWarning(category) QT_NO_QWARNING_MACRO()
+# define qCWarning(category) QT_NO_QDEBUG_MACRO()
#endif
QT_END_NAMESPACE
diff --git a/src/corelib/io/qloggingregistry.cpp b/src/corelib/io/qloggingregistry.cpp
index 8af1487834..0c916df910 100644
--- a/src/corelib/io/qloggingregistry.cpp
+++ b/src/corelib/io/qloggingregistry.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -124,6 +124,10 @@ void QLoggingRule::parse(const QStringRef &pattern)
p = QStringRef(pattern.string(), pattern.position(),
pattern.length() - 6); // strlen(".debug")
messageType = QtDebugMsg;
+ } else if (pattern.endsWith(QLatin1String(".info"))) {
+ p = QStringRef(pattern.string(), pattern.position(),
+ pattern.length() - 5); // strlen(".info")
+ messageType = QtInfoMsg;
} else if (pattern.endsWith(QLatin1String(".warning"))) {
p = QStringRef(pattern.string(), pattern.position(),
pattern.length() - 8); // strlen(".warning")
@@ -392,6 +396,7 @@ void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat)
QtMsgType enableForLevel = reg->categories.value(cat);
bool debug = (enableForLevel == QtDebugMsg);
+ bool info = (enableForLevel <= QtInfoMsg);
bool warning = (enableForLevel <= QtWarningMsg);
bool critical = (enableForLevel <= QtCriticalMsg);
@@ -409,6 +414,9 @@ void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat)
int filterpass = item.pass(categoryName, QtDebugMsg);
if (filterpass != 0)
debug = (filterpass > 0);
+ filterpass = item.pass(categoryName, QtInfoMsg);
+ if (filterpass != 0)
+ info = (filterpass > 0);
filterpass = item.pass(categoryName, QtWarningMsg);
if (filterpass != 0)
warning = (filterpass > 0);
@@ -418,6 +426,7 @@ void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat)
}
cat->setEnabled(QtDebugMsg, debug);
+ cat->setEnabled(QtInfoMsg, info);
cat->setEnabled(QtWarningMsg, warning);
cat->setEnabled(QtCriticalMsg, critical);
}
diff --git a/src/corelib/io/qnoncontiguousbytedevice.cpp b/src/corelib/io/qnoncontiguousbytedevice.cpp
index 11510a8397..1c10ef9f83 100644
--- a/src/corelib/io/qnoncontiguousbytedevice.cpp
+++ b/src/corelib/io/qnoncontiguousbytedevice.cpp
@@ -94,17 +94,7 @@ QT_BEGIN_NAMESPACE
Moves the internal read pointer back to the beginning.
Returns \c false if this was not possible.
- \sa atEnd(), disableReset()
-
- \internal
-*/
-/*!
- \fn void QNonContiguousByteDevice::disableReset()
-
- Disable the reset() call, e.g. it will always
- do nothing and return false.
-
- \sa reset()
+ \sa atEnd()
\internal
*/
@@ -131,7 +121,7 @@ QT_BEGIN_NAMESPACE
\internal
*/
-QNonContiguousByteDevice::QNonContiguousByteDevice() : QObject((QObject*)0), resetDisabled(false)
+QNonContiguousByteDevice::QNonContiguousByteDevice() : QObject((QObject*)0)
{
}
@@ -139,11 +129,6 @@ QNonContiguousByteDevice::~QNonContiguousByteDevice()
{
}
-void QNonContiguousByteDevice::disableReset()
-{
- resetDisabled = true;
-}
-
// FIXME we should scrap this whole implementation and instead change the ByteArrayImpl to be able to cope with sub-arrays?
QNonContiguousByteDeviceBufferImpl::QNonContiguousByteDeviceBufferImpl(QBuffer *b) : QNonContiguousByteDevice()
{
@@ -176,8 +161,6 @@ bool QNonContiguousByteDeviceBufferImpl::atEnd()
bool QNonContiguousByteDeviceBufferImpl::reset()
{
- if (resetDisabled)
- return false;
return arrayImpl->reset();
}
@@ -224,9 +207,6 @@ bool QNonContiguousByteDeviceByteArrayImpl::atEnd()
bool QNonContiguousByteDeviceByteArrayImpl::reset()
{
- if (resetDisabled)
- return false;
-
currentPosition = 0;
return true;
}
@@ -275,9 +255,6 @@ bool QNonContiguousByteDeviceRingBufferImpl::atEnd()
bool QNonContiguousByteDeviceRingBufferImpl::reset()
{
- if (resetDisabled)
- return false;
-
currentPosition = 0;
return true;
}
@@ -378,8 +355,6 @@ bool QNonContiguousByteDeviceIoDeviceImpl::atEnd()
bool QNonContiguousByteDeviceIoDeviceImpl::reset()
{
- if (resetDisabled)
- return false;
bool reset = (initialPosition == 0) ? device->reset() : device->seek(initialPosition);
if (reset) {
eof = false; // assume eof is false, it will be true after a read has been attempted
diff --git a/src/corelib/io/qnoncontiguousbytedevice_p.h b/src/corelib/io/qnoncontiguousbytedevice_p.h
index c05ae11b0f..d36422e82c 100644
--- a/src/corelib/io/qnoncontiguousbytedevice_p.h
+++ b/src/corelib/io/qnoncontiguousbytedevice_p.h
@@ -62,8 +62,6 @@ public:
virtual bool advanceReadPointer(qint64 amount) = 0;
virtual bool atEnd() = 0;
virtual bool reset() = 0;
- void disableReset();
- bool isResetDisabled() { return resetDisabled; }
virtual qint64 size() = 0;
virtual ~QNonContiguousByteDevice();
@@ -72,7 +70,6 @@ protected:
QNonContiguousByteDevice();
- bool resetDisabled;
Q_SIGNALS:
void readyRead();
void readProgress(qint64 current, qint64 total);
@@ -101,11 +98,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 +113,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 +130,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 +152,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 +169,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.cpp b/src/corelib/io/qprocess.cpp
index 939cecfb44..408f07f00e 100644
--- a/src/corelib/io/qprocess.cpp
+++ b/src/corelib/io/qprocess.cpp
@@ -89,6 +89,8 @@ QT_END_NAMESPACE
#ifdef Q_OS_WIN
#include <qwineventnotifier.h>
+#else
+#include <private/qcore_unix_p.h>
#endif
#ifndef QT_NO_PROCESS
@@ -810,8 +812,7 @@ QProcessPrivate::QProcessPrivate()
deathNotifier = 0;
childStartedPipe[0] = INVALID_Q_PIPE;
childStartedPipe[1] = INVALID_Q_PIPE;
- deathPipe[0] = INVALID_Q_PIPE;
- deathPipe[1] = INVALID_Q_PIPE;
+ forkfd = -1;
exitCode = 0;
crashed = false;
dying = false;
@@ -821,9 +822,6 @@ QProcessPrivate::QProcessPrivate()
notifier = 0;
processFinishedNotifier = 0;
#endif // Q_OS_WIN
-#ifdef Q_OS_UNIX
- serial = 0;
-#endif
}
/*!
@@ -890,9 +888,10 @@ void QProcessPrivate::cleanup()
closeChannel(&stderrChannel);
closeChannel(&stdinChannel);
destroyPipe(childStartedPipe);
- destroyPipe(deathPipe);
#ifdef Q_OS_UNIX
- serial = 0;
+ if (forkfd != -1)
+ qt_safe_close(forkfd);
+ forkfd = -1;
#endif
}
@@ -1079,6 +1078,17 @@ bool QProcessPrivate::_q_processDied()
processError = QProcess::Crashed;
q->setErrorString(QProcess::tr("Process crashed"));
emit q->error(processError);
+ } else {
+#ifdef QPROCESS_USE_SPAWN
+ // if we're using posix_spawn, waitForStarted always succeeds.
+ // POSIX documents that the sub-process launched by posix_spawn will exit with code
+ // 127 if anything prevents the target program from starting.
+ // http://pubs.opengroup.org/onlinepubs/009695399/functions/posix_spawn.html
+ if (exitStatus == QProcess::NormalExit && exitCode == 127) {
+ processError = QProcess::FailedToStart;
+ q->setErrorString(QProcess::tr("Process failed to start (spawned process exited with code 127)"));
+ }
+#endif
}
bool wasRunning = (processState == QProcess::Running);
@@ -1754,6 +1764,9 @@ QProcessEnvironment QProcess::processEnvironment() const
If msecs is -1, this function will not time out.
+ \note On some UNIX operating systems, this function may return true but
+ the process may later report a QProcess::FailedToStart error.
+
\sa started(), waitForReadyRead(), waitForBytesWritten(), waitForFinished()
*/
bool QProcess::waitForStarted(int msecs)
@@ -2348,7 +2361,7 @@ int QProcess::execute(const QString &program, const QStringList &arguments)
QProcess process;
process.setReadChannelMode(ForwardedChannels);
process.start(program, arguments);
- if (!process.waitForFinished(-1))
+ if (!process.waitForFinished(-1) || process.error() == FailedToStart)
return -2;
return process.exitStatus() == QProcess::NormalExit ? process.exitCode() : -1;
}
@@ -2371,7 +2384,7 @@ int QProcess::execute(const QString &command)
QProcess process;
process.setReadChannelMode(ForwardedChannels);
process.start(command);
- if (!process.waitForFinished(-1))
+ if (!process.waitForFinished(-1) || process.error() == FailedToStart)
return -2;
return process.exitStatus() == QProcess::NormalExit ? process.exitCode() : -1;
}
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_p.h b/src/corelib/io/qprocess_p.h
index 35626ddc38..3f86960c74 100644
--- a/src/corelib/io/qprocess_p.h
+++ b/src/corelib/io/qprocess_p.h
@@ -62,6 +62,9 @@ typedef HANDLE Q_PIPE;
#else
typedef int Q_PIPE;
#define INVALID_Q_PIPE -1
+# ifdef Q_OS_QNX
+# define QPROCESS_USE_SPAWN
+# endif
#endif
#ifndef QT_NO_PROCESS
@@ -98,7 +101,7 @@ public:
QByteArray key;
uint hash;
};
-inline uint qHash(const QProcEnvKey &key) { return key.hash; }
+inline uint qHash(const QProcEnvKey &key) Q_DECL_NOTHROW { return key.hash; }
class QProcEnvValue
{
@@ -331,12 +334,13 @@ public:
QProcessEnvironment environment;
Q_PIPE childStartedPipe[2];
- Q_PIPE deathPipe[2];
void destroyPipe(Q_PIPE pipe[2]);
QSocketNotifier *startupSocketNotifier;
QSocketNotifier *deathNotifier;
+ int forkfd;
+
#ifdef Q_OS_WIN
// the wonderful windows notifier
QTimer *notifier;
@@ -345,10 +349,10 @@ public:
void start(QIODevice::OpenMode mode);
void startProcess();
-#if defined(Q_OS_UNIX) && !defined(Q_OS_QNX)
+#if defined(Q_OS_UNIX) && !defined(QPROCESS_USE_SPAWN)
void execChild(const char *workingDirectory, char **path, char **argv, char **envp);
-#elif defined(Q_OS_QNX)
- pid_t spawnChild(const char *workingDirectory, char **argv, char **envp);
+#elif defined(QPROCESS_USE_SPAWN)
+ pid_t spawnChild(pid_t *ppid, const char *workingDirectory, char **argv, char **envp);
#endif
bool processStarted();
void terminateProcess();
@@ -369,9 +373,6 @@ public:
int exitCode;
QProcess::ExitStatus exitStatus;
bool crashed;
-#ifdef Q_OS_UNIX
- int serial;
-#endif
bool waitForStarted(int msecs = 30000);
bool waitForReadyRead(int msecs = 30000);
@@ -389,9 +390,6 @@ public:
QList<QSocketNotifier *> defaultNotifiers() const;
#endif // Q_OS_BLACKBERRY
-#ifdef Q_OS_UNIX
- static void initializeProcessManager();
-#endif
};
QT_END_NAMESPACE
diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp
index cc154cfbc5..014ff12313 100644
--- a/src/corelib/io/qprocess_unix.cpp
+++ b/src/corelib/io/qprocess_unix.cpp
@@ -95,15 +95,14 @@ QT_END_NAMESPACE
#include <qthread.h>
#include <qelapsedtimer.h>
+#ifdef Q_OS_QNX
+# include <sys/neutrino.h>
+#endif
+
#include <errno.h>
#include <stdlib.h>
#include <string.h>
-#ifdef Q_OS_QNX
-#include "qvarlengtharray.h"
-
-#include <spawn.h>
-#include <sys/neutrino.h>
-#endif
+#include <forkfd.h>
QT_BEGIN_NAMESPACE
@@ -111,38 +110,6 @@ QT_BEGIN_NAMESPACE
// so we will use 512
static const int errorBufferMax = 512;
-static int qt_qprocess_deadChild_pipe[2];
-static struct sigaction qt_sa_old_sigchld_handler;
-static void qt_sa_sigchld_sigaction(int signum, siginfo_t *info, void *context)
-{
- // *Never* use the info or contect variables in this function
- // (except for passing them to the next signal in the chain).
- // We cannot be sure if another library or if the application
- // installed a signal handler for SIGCHLD without SA_SIGINFO
- // and fails to pass the arguments to us. If they do that,
- // these arguments contain garbage and we'd most likely crash.
-
- qt_safe_write(qt_qprocess_deadChild_pipe[1], "", 1);
-#if defined (QPROCESS_DEBUG)
- fprintf(stderr, "*** SIGCHLD\n");
-#endif
-
- // load as volatile
- volatile struct sigaction *vsa = &qt_sa_old_sigchld_handler;
-
- if (qt_sa_old_sigchld_handler.sa_flags & SA_SIGINFO) {
- void (*oldAction)(int, siginfo_t *, void *) = vsa->sa_sigaction;
-
- if (oldAction)
- oldAction(signum, info, context);
- } else {
- void (*oldAction)(int) = vsa->sa_handler;
-
- if (oldAction && oldAction != SIG_IGN)
- oldAction(signum);
- }
-}
-
static inline void add_fd(int &nfds, int fd, fd_set *fdset)
{
FD_SET(fd, fdset);
@@ -150,199 +117,6 @@ static inline void add_fd(int &nfds, int fd, fd_set *fdset)
nfds = fd;
}
-struct QProcessInfo {
- QProcess *process;
- int deathPipe;
- int exitResult;
- pid_t pid;
- int serialNumber;
-};
-
-class QProcessManager : public QThread
-{
- Q_OBJECT
-public:
- QProcessManager();
- ~QProcessManager();
-
- void run();
- void catchDeadChildren();
- void add(pid_t pid, QProcess *process);
- void remove(QProcess *process);
- void lock();
- void unlock();
-
-private:
- QMutex mutex;
- QHash<int, QProcessInfo *> children;
-};
-
-
-static QProcessManager *processManagerInstance = 0;
-
-static QProcessManager *processManager()
-{
- // The constructor of QProcessManager should be called only once
- // so we cannot use Q_GLOBAL_STATIC directly for QProcessManager
- static QBasicMutex processManagerGlobalMutex;
- QMutexLocker locker(&processManagerGlobalMutex);
-
- if (!processManagerInstance)
- new QProcessManager;
-
- Q_ASSERT(processManagerInstance);
- return processManagerInstance;
-}
-
-QProcessManager::QProcessManager()
-{
-#if defined (QPROCESS_DEBUG)
- qDebug() << "QProcessManager::QProcessManager()";
-#endif
- // initialize the dead child pipe and make it non-blocking. in the
- // extremely unlikely event that the pipe fills up, we do not under any
- // circumstances want to block.
- qt_safe_pipe(qt_qprocess_deadChild_pipe, O_NONBLOCK);
-
- // set up the SIGCHLD handler, which writes a single byte to the dead
- // child pipe every time a child dies.
-
- struct sigaction action;
- // use the old handler as template, i.e., preserve the signal mask
- // otherwise the original signal handler might be interrupted although it
- // was marked to never be interrupted
- ::sigaction(SIGCHLD, NULL, &action);
- action.sa_sigaction = qt_sa_sigchld_sigaction;
- // set the SA_SIGINFO flag such that we can use the three argument handler
- // function
- action.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
- ::sigaction(SIGCHLD, &action, &qt_sa_old_sigchld_handler);
-
- processManagerInstance = this;
-}
-
-QProcessManager::~QProcessManager()
-{
- // notify the thread that we're shutting down.
- qt_safe_write(qt_qprocess_deadChild_pipe[1], "@", 1);
- qt_safe_close(qt_qprocess_deadChild_pipe[1]);
- wait();
-
- // on certain unixes, closing the reading end of the pipe will cause
- // select in run() to block forever, rather than return with EBADF.
- qt_safe_close(qt_qprocess_deadChild_pipe[0]);
-
- qt_qprocess_deadChild_pipe[0] = -1;
- qt_qprocess_deadChild_pipe[1] = -1;
-
- qDeleteAll(children.values());
- children.clear();
-
- struct sigaction currentAction;
- ::sigaction(SIGCHLD, 0, &currentAction);
- if (currentAction.sa_sigaction == qt_sa_sigchld_sigaction) {
- ::sigaction(SIGCHLD, &qt_sa_old_sigchld_handler, 0);
- }
-
- processManagerInstance = 0;
-}
-
-void QProcessManager::run()
-{
- forever {
- fd_set readset;
- FD_ZERO(&readset);
- FD_SET(qt_qprocess_deadChild_pipe[0], &readset);
-
-#if defined (QPROCESS_DEBUG)
- qDebug() << "QProcessManager::run() waiting for children to die";
-#endif
-
- // block forever, or until activity is detected on the dead child
- // pipe. the only other peers are the SIGCHLD signal handler, and the
- // QProcessManager destructor.
- int nselect = select(qt_qprocess_deadChild_pipe[0] + 1, &readset, 0, 0, 0);
- if (nselect < 0) {
- if (errno == EINTR)
- continue;
- break;
- }
-
- // empty only one byte from the pipe, even though several SIGCHLD
- // signals may have been delivered in the meantime, to avoid race
- // conditions.
- char c;
- if (qt_safe_read(qt_qprocess_deadChild_pipe[0], &c, 1) < 0 || c == '@')
- break;
-
- // catch any and all children that we can.
- catchDeadChildren();
- }
-}
-
-void QProcessManager::catchDeadChildren()
-{
- QMutexLocker locker(&mutex);
-
- // try to catch all children whose pid we have registered, and whose
- // deathPipe is still valid (i.e, we have not already notified it).
- QHash<int, QProcessInfo *>::Iterator it = children.begin();
- while (it != children.end()) {
- // notify all children that they may have died. they need to run
- // waitpid() in their own thread.
- QProcessInfo *info = it.value();
- qt_safe_write(info->deathPipe, "", 1);
-
-#if defined (QPROCESS_DEBUG)
- qDebug() << "QProcessManager::run() sending death notice to" << info->process;
-#endif
- ++it;
- }
-}
-
-static QBasicAtomicInt idCounter = Q_BASIC_ATOMIC_INITIALIZER(1);
-
-void QProcessManager::add(pid_t pid, QProcess *process)
-{
-#if defined (QPROCESS_DEBUG)
- qDebug() << "QProcessManager::add() adding pid" << pid << "process" << process;
-#endif
-
- // insert a new info structure for this process
- QProcessInfo *info = new QProcessInfo;
- info->process = process;
- info->deathPipe = process->d_func()->deathPipe[1];
- info->exitResult = 0;
- info->pid = pid;
-
- int serial = idCounter.fetchAndAddRelaxed(1);
- process->d_func()->serial = serial;
- children.insert(serial, info);
-}
-
-void QProcessManager::remove(QProcess *process)
-{
- QMutexLocker locker(&mutex);
-
- int serial = process->d_func()->serial;
- QProcessInfo *info = children.take(serial);
-#if defined (QPROCESS_DEBUG)
- if (info)
- qDebug() << "QProcessManager::remove() removing pid" << info->pid << "process" << info->process;
-#endif
- delete info;
-}
-
-void QProcessManager::lock()
-{
- mutex.lock();
-}
-
-void QProcessManager::unlock()
-{
- mutex.unlock();
-}
-
static int qt_create_pipe(int *pipe)
{
if (pipe[0] != -1)
@@ -562,14 +336,11 @@ void QProcessPrivate::startProcess()
qDebug("QProcessPrivate::startProcess()");
#endif
- processManager()->start();
-
// Initialize pipes
if (!openChannel(stdinChannel) ||
!openChannel(stdoutChannel) ||
!openChannel(stderrChannel) ||
- qt_create_pipe(childStartedPipe) != 0 ||
- qt_create_pipe(deathPipe) != 0) {
+ qt_create_pipe(childStartedPipe) != 0) {
processError = QProcess::FailedToStart;
q->setErrorString(qt_error_string(errno));
emit q->error(processError);
@@ -582,11 +353,6 @@ void QProcessPrivate::startProcess()
QSocketNotifier::Read, q);
QObject::connect(startupSocketNotifier, SIGNAL(activated(int)),
q, SLOT(_q_startupNotification()));
-
- deathNotifier = new QSocketNotifier(deathPipe[0],
- QSocketNotifier::Read, q);
- QObject::connect(deathNotifier, SIGNAL(activated(int)),
- q, SLOT(_q_processDied()));
}
// Start the process (platform dependent)
@@ -669,14 +435,17 @@ void QProcessPrivate::startProcess()
}
// Start the process manager, and fork off the child process.
- processManager()->lock();
-#if defined(Q_OS_QNX)
- pid_t childPid = spawnChild(workingDirPtr, argv, envp);
+#if defined(QPROCESS_USE_SPAWN)
+ pid_t childPid;
+ forkfd = spawnChild(&childPid, workingDirPtr, argv, envp);
+ Q_ASSUME(forkfd != FFD_CHILD_PROCESS);
#else
- pid_t childPid = fork();
- int lastForkErrno = errno;
+ pid_t childPid;
+ forkfd = ::forkfd(FFD_CLOEXEC, &childPid);
#endif
- if (childPid != 0) {
+ int lastForkErrno = errno;
+ if (forkfd != FFD_CHILD_PROCESS) {
+ // Parent process.
// Clean up duplicated memory.
free(dupProgramName);
for (int i = 1; i <= arguments.count(); ++i)
@@ -690,23 +459,15 @@ void QProcessPrivate::startProcess()
delete [] path;
}
- // This is not a valid check under QNX, because the semantics are
- // different. While under other platforms where fork() may succeed and exec() can still fail,
- // causing the childPid to hold a valid value (and thus evaluating the
- // following if to false), and then signaling the error via
- // childStartedPipe, under QNX on the other hand, spawn() return value will be assigned
- // to childPid (which will be -1 in case of failure). This will force
- // QProcess to cleanup, instead of signaling the error via
- // childStartedPipe. Since it will invalidade the pipes, functions like
- // QProcess::waitForStarted() will fail, for childStartedPipe will be
- // '-1' and mess with the select() calls.
-#if !defined(Q_OS_QNX)
- if (childPid < 0) {
+ // On QNX, if spawnChild failed, childPid will be -1 but forkfd is still 0.
+ // This is intentional because we only want to handle failure to fork()
+ // here, which is a rare occurrence. Handling of the failure to start is
+ // done elsewhere.
+ if (forkfd == -1) {
// Cleanup, report error and return
#if defined (QPROCESS_DEBUG)
qDebug("fork failed: %s", qPrintable(qt_error_string(lastForkErrno)));
#endif
- processManager()->unlock();
q->setProcessState(QProcess::NotRunning);
processError = QProcess::FailedToStart;
q->setErrorString(QProcess::tr("Resource error (fork failure): %1").arg(qt_error_string(lastForkErrno)));
@@ -716,21 +477,17 @@ void QProcessPrivate::startProcess()
}
// Start the child.
- if (childPid == 0) {
+#if !defined(QPROCESS_USE_SPAWN)
+ if (forkfd == FFD_CHILD_PROCESS) {
execChild(workingDirPtr, path, argv, envp);
::_exit(-1);
}
#endif
- // Register the child. In the mean time, we can get a SIGCHLD, so we need
- // to keep the lock held to avoid a race to catch the child.
- processManager()->add(childPid, q);
pid = Q_PID(childPid);
- processManager()->unlock();
// parent
// close the ends we don't use and make all pipes non-blocking
- ::fcntl(deathPipe[0], F_SETFL, ::fcntl(deathPipe[0], F_GETFL) | O_NONBLOCK);
qt_safe_close(childStartedPipe[1]);
childStartedPipe[1] = -1;
@@ -756,110 +513,151 @@ void QProcessPrivate::startProcess()
}
if (stderrChannel.pipe[0] != -1)
::fcntl(stderrChannel.pipe[0], F_SETFL, ::fcntl(stderrChannel.pipe[0], F_GETFL) | O_NONBLOCK);
+
+ if (threadData->eventDispatcher) {
+ deathNotifier = new QSocketNotifier(forkfd, QSocketNotifier::Read, q);
+ QObject::connect(deathNotifier, SIGNAL(activated(int)),
+ q, SLOT(_q_processDied()));
+ }
}
-#if defined(Q_OS_QNX)
-static pid_t doSpawn(int fd_count, int fd_map[], char **argv, char **envp,
- const char *workingDir, bool spawn_detached)
+#if defined(QPROCESS_USE_SPAWN)
+static int doSpawn(pid_t *ppid, const posix_spawn_file_actions_t *file_actions,
+ char **argv, char **envp, const char *workingDir, bool spawn_detached)
{
- // A multi threaded QNX Process can't fork so we call spawn() instead.
-
- struct inheritance inherit;
- memset(&inherit, 0, sizeof(inherit));
- inherit.flags |= SPAWN_SETSID;
- inherit.flags |= SPAWN_CHECK_SCRIPT;
- if (spawn_detached)
- inherit.flags |= SPAWN_NOZOMBIE;
- inherit.flags |= SPAWN_SETSIGDEF;
- sigaddset(&inherit.sigdefault, SIGPIPE); // reset the signal that we ignored
+ // A multi threaded QNX Process can't fork so we call spawnfd() instead.
+ posix_spawnattr_t attr;
+ posix_spawnattr_init(&attr);
+# ifdef Q_OS_QNX
+ posix_spawnattr_setxflags(&attr, POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETPGROUP
+ | (spawn_detached * POSIX_SPAWN_NOZOMBIE));
+# else
+ posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETPGROUP);
+# endif
+ posix_spawnattr_setpgroup(&attr, 0);
+
+ sigset_t sigdefault;
+ sigemptyset(&sigdefault);
+ sigaddset(&sigdefault, SIGPIPE); // reset the signal that we ignored
+ posix_spawnattr_setsigdefault(&attr, &sigdefault);
// enter the working directory
const char *oldWorkingDir = 0;
char buff[PATH_MAX + 1];
if (workingDir) {
+# ifdef Q_OS_QNX
//we need to freeze everyone in order to avoid race conditions with //chdir().
if (ThreadCtl(_NTO_TCTL_THREADS_HOLD, 0) == -1)
qWarning("ThreadCtl(): cannot hold threads: %s", qPrintable(qt_error_string(errno)));
+# endif
oldWorkingDir = QT_GETCWD(buff, PATH_MAX + 1);
if (QT_CHDIR(workingDir) == -1)
qWarning("ThreadCtl(): failed to chdir to %s", workingDir);
}
- pid_t childPid;
- EINTR_LOOP(childPid, ::spawn(argv[0], fd_count, fd_map, &inherit, argv, envp));
- if (childPid == -1) {
- inherit.flags |= SPAWN_SEARCH_PATH;
- EINTR_LOOP(childPid, ::spawn(argv[0], fd_count, fd_map, &inherit, argv, envp));
+ int fd;
+ if (spawn_detached) {
+ fd = ::posix_spawn(ppid, argv[0], file_actions, &attr, argv, envp);
+ if (fd == -1) {
+ fd = ::posix_spawnp(ppid, argv[0], file_actions, &attr, argv, envp);
+ }
+ } else {
+ // use spawnfd
+ fd = ::spawnfd(FFD_CLOEXEC | FFD_NONBLOCK, ppid, argv[0], file_actions, &attr, argv, envp);
+ if (fd == -1) {
+ fd = ::spawnfd(FFD_CLOEXEC | FFD_NONBLOCK | FFD_SPAWN_SEARCH_PATH, ppid, argv[0], file_actions,
+ &attr, argv, envp);
+ }
}
if (oldWorkingDir) {
if (QT_CHDIR(oldWorkingDir) == -1)
qWarning("ThreadCtl(): failed to chdir to %s", oldWorkingDir);
+# ifdef Q_OS_QNX
if (ThreadCtl(_NTO_TCTL_THREADS_CONT, 0) == -1)
qFatal("ThreadCtl(): cannot resume threads: %s", qPrintable(qt_error_string(errno)));
+# endif
}
- return childPid;
+ posix_spawnattr_destroy(&attr);
+ return fd;
}
-pid_t QProcessPrivate::spawnChild(const char *workingDir, char **argv, char **envp)
+pid_t QProcessPrivate::spawnChild(pid_t *ppid, const char *workingDir, char **argv, char **envp)
{
- // we need to manually fill in fd_map
- // to inherit the file descriptors from
- // the parent
- const int fd_count = sysconf(_SC_OPEN_MAX);
- QVarLengthArray<int, 1024> fd_map(fd_count);
-
- for (int i = 3; i < fd_count; ++i) {
- // here we rely that fcntl returns -1 and
- // sets errno to EBADF
- const int flags = ::fcntl(i, F_GETFD);
-
- fd_map[i] = ((flags >= 0) && !(flags & FD_CLOEXEC))
- ? i : SPAWN_FDCLOSED;
+ // posix_spawn causes all file descriptors with FD_CLOEXEC to be closed automatically;
+ // we only need to add the actions for our own pipes
+ posix_spawn_file_actions_t file_actions;
+ posix_spawn_file_actions_init(&file_actions);
+
+# ifdef Q_OS_QNX
+ static const bool OS_QNX = true;
+# else
+ static const bool OS_QNX = false;
+#endif
+
+ int fdmax = -1;
+
+ if (processChannelMode == QProcess::MergedChannels) {
+ // managed stderr == stdout
+ posix_spawn_file_actions_adddup2(&file_actions, stdoutChannel.pipe[1], STDERR_FILENO);
+
+ if (OS_QNX)
+ fdmax = qMax(fdmax, stdoutChannel.pipe[1]);
+ } else if (processChannelMode != QProcess::ForwardedChannels && processChannelMode != QProcess::ForwardedErrorChannel) {
+ // managed stderr
+ posix_spawn_file_actions_adddup2(&file_actions, stderrChannel.pipe[1], STDERR_FILENO);
+
+ if (OS_QNX)
+ fdmax = qMax(fdmax, stderrChannel.pipe[1]);
+ else
+ posix_spawn_file_actions_addclose(&file_actions, stderrChannel.pipe[1]);
+
}
- if (inputChannelMode == QProcess::ManagedInputChannel)
- fd_map[0] = stdinChannel.pipe[0];
- else
- fd_map[0] = QT_FILENO(stdin);
-
- switch (processChannelMode) {
- case QProcess::ForwardedChannels:
- fd_map[1] = QT_FILENO(stdout);
- fd_map[2] = QT_FILENO(stderr);
- break;
- case QProcess::ForwardedOutputChannel:
- fd_map[1] = QT_FILENO(stdout);
- fd_map[2] = stderrChannel.pipe[1];
- break;
- case QProcess::ForwardedErrorChannel:
- fd_map[1] = stdoutChannel.pipe[1];
- fd_map[2] = QT_FILENO(stderr);
- break;
- case QProcess::MergedChannels:
- fd_map[1] = stdoutChannel.pipe[1];
- fd_map[2] = stdoutChannel.pipe[1];
- break;
- case QProcess::SeparateChannels:
- fd_map[1] = stdoutChannel.pipe[1];
- fd_map[2] = stderrChannel.pipe[1];
- break;
+ if (processChannelMode != QProcess::ForwardedChannels && processChannelMode != QProcess::ForwardedOutputChannel) {
+ // managed stdout
+ posix_spawn_file_actions_adddup2(&file_actions, stdoutChannel.pipe[1], STDOUT_FILENO);
+
+ if (OS_QNX)
+ fdmax = qMax(fdmax, stdoutChannel.pipe[1]);
+ else
+ posix_spawn_file_actions_addclose(&file_actions, stdoutChannel.pipe[1]);
+
}
- pid_t childPid = doSpawn(fd_count, fd_map.data(), argv, envp, workingDir, false);
+ if (inputChannelMode == QProcess::ManagedInputChannel) {
+ posix_spawn_file_actions_adddup2(&file_actions, stdinChannel.pipe[0], STDIN_FILENO);
- if (childPid == -1) {
+ if (OS_QNX)
+ fdmax = qMax(fdmax, stdinChannel.pipe[0]);
+ else
+ posix_spawn_file_actions_addclose(&file_actions, stdinChannel.pipe[0]);
+ }
+
+ // Workaround: QNX's spawn implementation will actually dup all FD values
+ // LESS than fdmax - regardless of the FD_CLOEEXEC flag. So we need to add
+ // those to the list of files to close, otherwise dup will fail when some
+ // other thread closes the FD.
+ for (int i = 3; i <= fdmax; i++) {
+ if (::fcntl(i, F_GETFD) & FD_CLOEXEC)
+ posix_spawn_file_actions_addclose(&file_actions, i);
+ }
+
+ int retval = doSpawn(ppid, &file_actions, argv, envp, workingDir, false);
+
+ if (retval == -1) {
QString error = qt_error_string(errno);
qt_safe_write(childStartedPipe[1], error.data(), error.length() * sizeof(QChar));
qt_safe_close(childStartedPipe[1]);
childStartedPipe[1] = -1;
}
- return childPid;
+ posix_spawn_file_actions_destroy(&file_actions);
+ return retval;
}
#else
@@ -963,7 +761,7 @@ qint64 QProcessPrivate::bytesAvailableInChannel(const Channel *channel) const
if (::ioctl(channel->pipe[0], FIONREAD, (char *) &nbytes) >= 0)
available = (qint64) nbytes;
#if defined (QPROCESS_DEBUG)
- qDebug("QProcessPrivate::bytesAvailableInChannel(%d) == %lld", channel - &stdinChannel, available);
+ qDebug("QProcessPrivate::bytesAvailableInChannel(%d) == %lld", int(channel - &stdinChannel), available);
#endif
return available;
}
@@ -975,7 +773,7 @@ qint64 QProcessPrivate::readFromChannel(const Channel *channel, char *data, qint
#if defined QPROCESS_DEBUG
int save_errno = errno;
qDebug("QProcessPrivate::readFromChannel(%d, %p \"%s\", %lld) == %lld",
- channel - &stdinChannel,
+ int(channel - &stdinChannel),
data, qt_prettyDebug(data, bytesRead, 16).constData(), maxlen, bytesRead);
errno = save_errno;
#endif
@@ -1092,8 +890,8 @@ bool QProcessPrivate::waitForReadyRead(int msecs)
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
- int nfds = deathPipe[0];
- FD_SET(deathPipe[0], &fdread);
+ int nfds = forkfd;
+ FD_SET(forkfd, &fdread);
if (processState == QProcess::Starting)
add_fd(nfds, childStartedPipe[0], &fdread);
@@ -1143,7 +941,7 @@ bool QProcessPrivate::waitForReadyRead(int msecs)
if (stdinChannel.pipe[1] != -1 && FD_ISSET(stdinChannel.pipe[1], &fdwrite))
_q_canWrite();
- if (deathPipe[0] == -1 || FD_ISSET(deathPipe[0], &fdread)) {
+ if (forkfd == -1 || FD_ISSET(forkfd, &fdread)) {
if (_q_processDied())
return false;
}
@@ -1172,8 +970,8 @@ bool QProcessPrivate::waitForBytesWritten(int msecs)
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
- int nfds = deathPipe[0];
- FD_SET(deathPipe[0], &fdread);
+ int nfds = forkfd;
+ FD_SET(forkfd, &fdread);
if (processState == QProcess::Starting)
add_fd(nfds, childStartedPipe[0], &fdread);
@@ -1217,7 +1015,7 @@ bool QProcessPrivate::waitForBytesWritten(int msecs)
if (stderrChannel.pipe[0] != -1 && FD_ISSET(stderrChannel.pipe[0], &fdread))
_q_canReadStandardError();
- if (deathPipe[0] == -1 || FD_ISSET(deathPipe[0], &fdread)) {
+ if (forkfd == -1 || FD_ISSET(forkfd, &fdread)) {
if (_q_processDied())
return false;
}
@@ -1256,8 +1054,8 @@ bool QProcessPrivate::waitForFinished(int msecs)
if (stderrChannel.pipe[0] != -1)
add_fd(nfds, stderrChannel.pipe[0], &fdread);
- if (processState == QProcess::Running)
- add_fd(nfds, deathPipe[0], &fdread);
+ if (processState == QProcess::Running && forkfd != -1)
+ add_fd(nfds, forkfd, &fdread);
if (!stdinChannel.buffer.isEmpty() && stdinChannel.pipe[1] != -1)
add_fd(nfds, stdinChannel.pipe[1], &fdwrite);
@@ -1290,7 +1088,7 @@ bool QProcessPrivate::waitForFinished(int msecs)
if (stderrChannel.pipe[0] != -1 && FD_ISSET(stderrChannel.pipe[0], &fdread))
_q_canReadStandardError();
- if (deathPipe[0] == -1 || FD_ISSET(deathPipe[0], &fdread)) {
+ if (forkfd == -1 || FD_ISSET(forkfd, &fdread)) {
if (_q_processDied())
return true;
}
@@ -1308,46 +1106,41 @@ bool QProcessPrivate::waitForWrite(int msecs)
void QProcessPrivate::findExitCode()
{
- Q_Q(QProcess);
- processManager()->remove(q);
}
bool QProcessPrivate::waitForDeadChild()
{
- Q_Q(QProcess);
+ if (forkfd == -1)
+ return true; // child has already exited
- // read a byte from the death pipe
- char c;
- qt_safe_read(deathPipe[0], &c, 1);
+ // read the process information from our fd
+ siginfo_t info;
+ qint64 ret = qt_safe_read(forkfd, &info, sizeof info);
+ Q_ASSERT(ret == sizeof info);
+ Q_UNUSED(ret);
+
+ Q_ASSERT(info.si_pid == pid_t(pid));
+
+ exitCode = info.si_status;
+ crashed = info.si_code != CLD_EXITED;
+
+ qt_safe_close(forkfd);
+ forkfd = -1; // Child is dead, don't try to kill it anymore
- // check if our process is dead
- int exitStatus;
- if (qt_safe_waitpid(pid_t(pid), &exitStatus, WNOHANG) > 0) {
- processManager()->remove(q);
- crashed = !WIFEXITED(exitStatus);
- exitCode = WEXITSTATUS(exitStatus);
-#if defined QPROCESS_DEBUG
- qDebug() << "QProcessPrivate::waitForDeadChild() dead with exitCode"
- << exitCode << ", crashed?" << crashed;
-#endif
- return true;
- }
#if defined QPROCESS_DEBUG
- qDebug() << "QProcessPrivate::waitForDeadChild() not dead!";
+ qDebug() << "QProcessPrivate::waitForDeadChild() dead with exitCode"
+ << exitCode << ", crashed?" << crashed;
#endif
- return false;
+ return true;
}
void QProcessPrivate::_q_notified()
{
}
-#if defined(Q_OS_QNX)
+#if defined(QPROCESS_USE_SPAWN)
bool QProcessPrivate::startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid)
{
- const int fd_count = 3;
- int fd_map[fd_count] = { QT_FILENO(stdin), QT_FILENO(stdout), QT_FILENO(stderr) };
-
QList<QByteArray> enc_args;
enc_args.append(QFile::encodeName(program));
for (int i = 0; i < arguments.size(); ++i)
@@ -1369,19 +1162,18 @@ bool QProcessPrivate::startDetached(const QString &program, const QStringList &a
workingDirPtr = encodedWorkingDirectory.constData();
}
- pid_t childPid = doSpawn(fd_count, fd_map, raw_argv.data(), envp, workingDirPtr, true);
- if (pid && childPid != -1)
+ pid_t childPid;
+ int retval = doSpawn(&childPid, NULL, raw_argv.data(), envp, workingDirPtr, true);
+ if (pid && retval != -1)
*pid = childPid;
- return childPid != -1;
+ return retval != -1;
}
#else
bool QProcessPrivate::startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid)
{
- processManager()->start();
-
QByteArray encodedWorkingDirectory = QFile::encodeName(workingDirectory);
// To catch the startup of the child
@@ -1496,13 +1288,6 @@ bool QProcessPrivate::startDetached(const QString &program, const QStringList &a
}
#endif
-void QProcessPrivate::initializeProcessManager()
-{
- (void) processManager();
-}
-
QT_END_NAMESPACE
-#include "qprocess_unix.moc"
-
#endif // QT_NO_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.cpp b/src/corelib/io/qsettings.cpp
index ebca7d57ff..baaa0dab53 100644
--- a/src/corelib/io/qsettings.cpp
+++ b/src/corelib/io/qsettings.cpp
@@ -1017,7 +1017,6 @@ static inline int pathHashKey(QSettings::Format format, QSettings::Scope scope)
static void initDefaultPaths(QMutexLocker *locker)
{
PathHash *pathHash = pathHashFunc();
- QString homePath = QDir::homePath();
QString systemPath;
locker->unlock();
@@ -1051,13 +1050,13 @@ static void initDefaultPaths(QMutexLocker *locker)
QString userPath;
char *env = getenv("XDG_CONFIG_HOME");
if (env == 0) {
- userPath = homePath;
+ userPath = QDir::homePath();
userPath += QLatin1Char('/');
userPath += QLatin1String(".config");
} else if (*env == '/') {
userPath = QFile::decodeName(env);
} else {
- userPath = homePath;
+ userPath = QDir::homePath();
userPath += QLatin1Char('/');
userPath += QFile::decodeName(env);
}
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/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp
index b41aee55d2..2e16c6d1ae 100644
--- a/src/corelib/io/qstandardpaths.cpp
+++ b/src/corelib/io/qstandardpaths.cpp
@@ -142,6 +142,10 @@ QT_BEGIN_NAMESPACE
\value AppLocalDataLocation Returns the local settings path on the Windows operating
system. On all other platforms, it returns the same value as AppDataLocation.
This enum value was added in Qt 5.4.
+ \value AppConfigLocation Returns a directory location where user-specific
+ configuration files should be written. This is an application-specific directory,
+ and the returned path is never empty.
+ This enum value was added in Qt 5.5.
The following table gives examples of paths on different operating systems.
The first path is the writable path (unless noted). Other, additional
@@ -206,6 +210,9 @@ QT_BEGIN_NAMESPACE
\row \li AppLocalDataLocation
\li "~/Library/Application Support/<APPNAME>", "/Library/Application Support/<APPNAME>". "<APPDIR>/../Resources"
\li "C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>", "<APPDIR>", "<APPDIR>/data"
+ \row \li AppConfigLocation
+ \li "~/Library/Preferences/<APPNAME>"
+ \li "C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>"
\endtable
\table
@@ -267,6 +274,9 @@ QT_BEGIN_NAMESPACE
\row \li AppLocalDataLocation
\li "<APPROOT>/data", "<APPROOT>/app/native/assets"
\li "~/.local/share/<APPNAME>", "/usr/local/share/<APPNAME>", "/usr/share/<APPNAME>"
+ \row \li AppConfigLocation
+ \li "<APPROOT>/data/Settings"
+ \li "~/.config/<APPNAME>", "/etc/xdg/<APPNAME>"
\endtable
\table
@@ -307,6 +317,8 @@ QT_BEGIN_NAMESPACE
\li "<APPROOT>/cache" (there is no shared cache)
\row \li AppDataLocation
\li "<APPROOT>/files", "<USER>/<APPNAME>/files"
+ \row \li AppConfigLocation
+ \li "<APPROOT>/files/settings"
\endtable
In the table above, \c <APPNAME> is usually the organization name, the
@@ -565,6 +577,8 @@ QString QStandardPaths::displayName(StandardLocation type)
case AppDataLocation:
case AppLocalDataLocation:
return QCoreApplication::translate("QStandardPaths", "Application Data");
+ case AppConfigLocation:
+ return QCoreApplication::translate("QStandardPaths", "Application Configuration");
}
// not reached
return QString();
@@ -585,7 +599,7 @@ QString QStandardPaths::displayName(StandardLocation type)
This affects the locations into which test programs might write files:
GenericDataLocation, DataLocation, ConfigLocation, GenericConfigLocation,
- GenericCacheLocation, CacheLocation.
+ AppConfigLocation, GenericCacheLocation, CacheLocation.
Other locations are not affected.
On Unix, \c XDG_DATA_HOME is set to \e ~/.qttest/share, \c XDG_CONFIG_HOME is
diff --git a/src/corelib/io/qstandardpaths.h b/src/corelib/io/qstandardpaths.h
index e305450240..60e53fe117 100644
--- a/src/corelib/io/qstandardpaths.h
+++ b/src/corelib/io/qstandardpaths.h
@@ -64,6 +64,7 @@ public:
GenericCacheLocation,
GenericConfigLocation,
AppDataLocation,
+ AppConfigLocation,
AppLocalDataLocation = DataLocation
};
diff --git a/src/corelib/io/qstandardpaths_android.cpp b/src/corelib/io/qstandardpaths_android.cpp
index 958b4ea486..b887e107e7 100644
--- a/src/corelib/io/qstandardpaths_android.cpp
+++ b/src/corelib/io/qstandardpaths_android.cpp
@@ -233,6 +233,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
return getExternalStoragePublicDirectory("DIRECTORY_DOWNLOADS");
case QStandardPaths::GenericConfigLocation:
case QStandardPaths::ConfigLocation:
+ case QStandardPaths::AppConfigLocation:
return getFilesDir() + testDir() + QLatin1String("/settings");
case QStandardPaths::GenericDataLocation:
return getExternalStorageDirectory() + testDir();
diff --git a/src/corelib/io/qstandardpaths_blackberry.cpp b/src/corelib/io/qstandardpaths_blackberry.cpp
index 02d7c110ae..473da7542c 100644
--- a/src/corelib/io/qstandardpaths_blackberry.cpp
+++ b/src/corelib/io/qstandardpaths_blackberry.cpp
@@ -69,6 +69,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
return QDir::homePath() + testModeInsert() + QLatin1String("/Cache");
case ConfigLocation:
case GenericConfigLocation:
+ case AppConfigLocation:
return QDir::homePath() + testModeInsert() + QLatin1String("/Settings");
case GenericDataLocation:
return sharedRoot + testModeInsert() + QLatin1String("/misc");
diff --git a/src/corelib/io/qstandardpaths_haiku.cpp b/src/corelib/io/qstandardpaths_haiku.cpp
new file mode 100644
index 0000000000..ac57686126
--- /dev/null
+++ b/src/corelib/io/qstandardpaths_haiku.cpp
@@ -0,0 +1,222 @@
+/***************************************************************************
+**
+** Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Tobias Koenig <tobias.koenig@kdab.com>
+** 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 "qstandardpaths.h"
+
+#ifndef QT_NO_STANDARDPATHS
+
+#ifndef QT_BOOTSTRAPPED
+#include <qcoreapplication.h>
+#endif
+
+#include <qfile.h>
+
+#include <FindDirectory.h>
+#include <Path.h>
+#include <PathFinder.h>
+#include <StringList.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace {
+
+void appendOrganizationAndApp(QString &path)
+{
+#ifndef QT_BOOTSTRAPPED
+ const QString org = QCoreApplication::organizationName();
+ if (!org.isEmpty())
+ path += QLatin1Char('/') + org;
+ const QString appName = QCoreApplication::applicationName();
+ if (!appName.isEmpty())
+ path += QLatin1Char('/') + appName;
+#else
+ Q_UNUSED(path);
+#endif
+}
+
+/*
+ * Returns the generic standard path for given directory type.
+ */
+QString haikuStandardPath(directory_which which)
+{
+ BPath standardPath;
+
+ if (find_directory(which, &standardPath, false) != B_OK)
+ return QString();
+
+ return QFile::decodeName(standardPath.Path());
+}
+
+/*
+ * Returns the generic standard paths for given path type.
+ */
+QStringList haikuStandardPaths(path_base_directory baseDirectory)
+{
+ BStringList paths;
+
+ if (BPathFinder::FindPaths(baseDirectory, paths) != B_OK)
+ return QStringList();
+
+ QStringList standardPaths;
+ for (int i = 0; i < paths.CountStrings(); ++i) {
+ standardPaths << QFile::decodeName(paths.StringAt(i).String());
+ }
+
+ return standardPaths;
+}
+
+/*
+ * Returns the application specific standard path for given directory type.
+ */
+QString haikuAppStandardPath(directory_which which)
+{
+ QString path = haikuStandardPath(which);
+ if (!path.isEmpty())
+ appendOrganizationAndApp(path);
+
+ return path;
+}
+
+/*
+ * Returns the application specific standard paths for given path type.
+ */
+QStringList haikuAppStandardPaths(path_base_directory baseDirectory)
+{
+ QStringList paths = haikuStandardPaths(baseDirectory);
+ for (int i = 0; i < paths.count(); ++i)
+ appendOrganizationAndApp(paths[i]);
+
+ return paths;
+}
+
+} // namespace
+
+QString QStandardPaths::writableLocation(StandardLocation type)
+{
+ switch (type) {
+ case DesktopLocation:
+ return haikuStandardPath(B_DESKTOP_DIRECTORY);
+ case DocumentsLocation: // fall through
+ case PicturesLocation:
+ case MusicLocation:
+ case MoviesLocation:
+ case DownloadLocation:
+ case HomeLocation:
+ return haikuStandardPath(B_USER_DIRECTORY);
+ case FontsLocation:
+ return haikuStandardPath(B_USER_NONPACKAGED_FONTS_DIRECTORY);
+ case ApplicationsLocation:
+ return haikuStandardPath(B_USER_NONPACKAGED_BIN_DIRECTORY);
+ case TempLocation:
+ return haikuStandardPath(B_SYSTEM_TEMP_DIRECTORY);
+ case AppDataLocation: // fall through
+ case AppLocalDataLocation:
+ return haikuAppStandardPath(B_USER_NONPACKAGED_DATA_DIRECTORY);
+ case GenericDataLocation:
+ return haikuStandardPath(B_USER_NONPACKAGED_DATA_DIRECTORY);
+ case CacheLocation:
+ return haikuAppStandardPath(B_USER_CACHE_DIRECTORY);
+ case GenericCacheLocation:
+ return haikuStandardPath(B_USER_CACHE_DIRECTORY);
+ case ConfigLocation: // fall through
+ case AppConfigLocation:
+ return haikuAppStandardPath(B_USER_SETTINGS_DIRECTORY);
+ case GenericConfigLocation:
+ return haikuStandardPath(B_USER_SETTINGS_DIRECTORY);
+ default:
+ return QString();
+ }
+}
+
+QStringList QStandardPaths::standardLocations(StandardLocation type)
+{
+ QStringList paths;
+
+ const QString writablePath = writableLocation(type);
+ if (!writablePath.isEmpty())
+ paths += writablePath;
+
+ switch (type) {
+ case DocumentsLocation: // fall through
+ case PicturesLocation:
+ case MusicLocation:
+ case MoviesLocation:
+ case DownloadLocation:
+ case HomeLocation:
+ paths += haikuStandardPath(B_USER_NONPACKAGED_DIRECTORY);
+ break;
+ case FontsLocation:
+ paths += haikuStandardPaths(B_FIND_PATH_FONTS_DIRECTORY);
+ break;
+ case ApplicationsLocation:
+ paths += haikuStandardPaths(B_FIND_PATH_BIN_DIRECTORY);
+ paths += haikuStandardPaths(B_FIND_PATH_APPS_DIRECTORY);
+ break;
+ case AppDataLocation: // fall through
+ case AppLocalDataLocation:
+ paths += haikuAppStandardPaths(B_FIND_PATH_DATA_DIRECTORY);
+ break;
+ case GenericDataLocation:
+ paths += haikuStandardPaths(B_FIND_PATH_DATA_DIRECTORY);
+ break;
+ case CacheLocation:
+ paths += haikuAppStandardPath(B_SYSTEM_CACHE_DIRECTORY);
+ break;
+ case GenericCacheLocation:
+ paths += haikuStandardPath(B_SYSTEM_CACHE_DIRECTORY);
+ break;
+ case ConfigLocation: // fall through
+ case AppConfigLocation:
+ paths += haikuAppStandardPath(B_SYSTEM_SETTINGS_DIRECTORY);
+ break;
+ case GenericConfigLocation:
+ paths += haikuStandardPath(B_SYSTEM_SETTINGS_DIRECTORY);
+ break;
+ default:
+ break;
+ }
+
+ return paths;
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_STANDARDPATHS
diff --git a/src/corelib/io/qstandardpaths_ios.mm b/src/corelib/io/qstandardpaths_ios.mm
index 9b500f4623..449c66fe0c 100644
--- a/src/corelib/io/qstandardpaths_ios.mm
+++ b/src/corelib/io/qstandardpaths_ios.mm
@@ -103,6 +103,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
break;
case ConfigLocation:
case GenericConfigLocation:
+ case AppConfigLocation:
location = pathForDirectory(NSDocumentDirectory);
break;
case DownloadLocation:
diff --git a/src/corelib/io/qstandardpaths_mac.mm b/src/corelib/io/qstandardpaths_mac.mm
index 13b864600e..9d5d6de6ad 100644
--- a/src/corelib/io/qstandardpaths_mac.mm
+++ b/src/corelib/io/qstandardpaths_mac.mm
@@ -53,6 +53,7 @@ OSType translateLocation(QStandardPaths::StandardLocation type)
switch (type) {
case QStandardPaths::ConfigLocation:
case QStandardPaths::GenericConfigLocation:
+ case QStandardPaths::AppConfigLocation:
return kPreferencesFolderType;
case QStandardPaths::DesktopLocation:
return kDesktopFolderType;
@@ -129,7 +130,8 @@ static QString macLocation(QStandardPaths::StandardLocation type, short domain)
QString path = getFullPath(ref);
- if (type == QStandardPaths::AppDataLocation || type == QStandardPaths::AppLocalDataLocation || type == QStandardPaths::CacheLocation)
+ if (type == QStandardPaths::AppDataLocation || type == QStandardPaths::AppLocalDataLocation ||
+ type == QStandardPaths::CacheLocation || type == QStandardPaths::AppConfigLocation)
appendOrganizationAndApp(path);
return path;
}
@@ -155,7 +157,11 @@ QString QStandardPaths::writableLocation(StandardLocation type)
return path;
case GenericConfigLocation:
case ConfigLocation:
- return qttestDir + QLatin1String("/Preferences");
+ case AppConfigLocation:
+ path = qttestDir + QLatin1String("/Preferences");
+ if (type == AppConfigLocation)
+ appendOrganizationAndApp(path);
+ return path;
default:
break;
}
diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp
index 2ad6dfa121..94dcbaff9a 100644
--- a/src/corelib/io/qstandardpaths_unix.cpp
+++ b/src/corelib/io/qstandardpaths_unix.cpp
@@ -97,6 +97,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
}
case ConfigLocation:
case GenericConfigLocation:
+ case AppConfigLocation:
{
// http://standards.freedesktop.org/basedir-spec/latest/
QString xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
@@ -104,6 +105,8 @@ QString QStandardPaths::writableLocation(StandardLocation type)
xdgConfigHome = QDir::homePath() + QLatin1String("/.qttest/config");
if (xdgConfigHome.isEmpty())
xdgConfigHome = QDir::homePath() + QLatin1String("/.config");
+ if (type == AppConfigLocation)
+ appendOrganizationAndApp(xdgConfigHome);
return xdgConfigHome;
}
case RuntimeLocation:
@@ -278,21 +281,31 @@ static QStringList xdgDataDirs()
return dirs;
}
+static QStringList xdgConfigDirs()
+{
+ QStringList dirs;
+ // http://standards.freedesktop.org/basedir-spec/latest/
+ const QString xdgConfigDirs = QFile::decodeName(qgetenv("XDG_CONFIG_DIRS"));
+ if (xdgConfigDirs.isEmpty())
+ dirs.append(QString::fromLatin1("/etc/xdg"));
+ else
+ dirs = xdgConfigDirs.split(QLatin1Char(':'));
+ return dirs;
+}
+
QStringList QStandardPaths::standardLocations(StandardLocation type)
{
QStringList dirs;
switch (type) {
case ConfigLocation:
case GenericConfigLocation:
- {
- // http://standards.freedesktop.org/basedir-spec/latest/
- const QString xdgConfigDirs = QFile::decodeName(qgetenv("XDG_CONFIG_DIRS"));
- if (xdgConfigDirs.isEmpty())
- dirs.append(QString::fromLatin1("/etc/xdg"));
- else
- dirs = xdgConfigDirs.split(QLatin1Char(':'));
- }
- break;
+ dirs = xdgConfigDirs();
+ break;
+ case AppConfigLocation:
+ dirs = xdgConfigDirs();
+ for (int i = 0; i < dirs.count(); ++i)
+ appendOrganizationAndApp(dirs[i]);
+ break;
case GenericDataLocation:
dirs = xdgDataDirs();
break;
diff --git a/src/corelib/io/qstandardpaths_win.cpp b/src/corelib/io/qstandardpaths_win.cpp
index 5e56db3797..8fe4be0d5c 100644
--- a/src/corelib/io/qstandardpaths_win.cpp
+++ b/src/corelib/io/qstandardpaths_win.cpp
@@ -98,6 +98,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
switch (type) {
case ConfigLocation: // same as AppLocalDataLocation, on Windows
case GenericConfigLocation: // same as GenericDataLocation on Windows
+ case AppConfigLocation:
case AppDataLocation:
case AppLocalDataLocation:
case GenericDataLocation:
@@ -195,6 +196,7 @@ QStringList QStandardPaths::standardLocations(StandardLocation type)
switch (type) {
case ConfigLocation: // same as AppLocalDataLocation, on Windows (oversight, but too late to fix it)
case GenericConfigLocation: // same as GenericDataLocation, on Windows
+ case AppConfigLocation: // same as AppLocalDataLocation, that one on purpose
case AppDataLocation:
case AppLocalDataLocation:
case GenericDataLocation:
diff --git a/src/corelib/io/qstandardpaths_winrt.cpp b/src/corelib/io/qstandardpaths_winrt.cpp
index 5c09b4814d..6aa31bf296 100644
--- a/src/corelib/io/qstandardpaths_winrt.cpp
+++ b/src/corelib/io/qstandardpaths_winrt.cpp
@@ -67,6 +67,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
switch (type) {
case ConfigLocation: // same as AppLocalDataLocation, on Windows
case GenericConfigLocation: // same as GenericDataLocation, on Windows
+ case AppConfigLocation:
case AppDataLocation:
case AppLocalDataLocation:
case GenericDataLocation: {
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..83d94bfe06 100644
--- a/src/corelib/io/qstorageinfo_unix.cpp
+++ b/src/corelib/io/qstorageinfo_unix.cpp
@@ -75,6 +75,9 @@
# if !defined(ST_RDONLY)
# define ST_RDONLY 1 // hack for missing define on Android
# endif
+#elif defined(Q_OS_HAIKU)
+# define QT_STATFSBUF struct statvfs
+# define QT_STATFS ::statvfs
#else
# if defined(QT_LARGEFILE_SUPPORT)
# define QT_STATFSBUF struct statvfs64
@@ -402,11 +405,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 571875c508..fa455c0e8c 100644
--- a/src/corelib/io/qtextstream.cpp
+++ b/src/corelib/io/qtextstream.cpp
@@ -233,6 +233,7 @@ static const int QTEXTSTREAM_BUFFERSIZE = 16384;
#if defined QTEXTSTREAM_DEBUG
#include <ctype.h>
+#include "private/qtools_p.h"
QT_BEGIN_NAMESPACE
@@ -250,10 +251,16 @@ static QByteArray qt_prettyDebug(const char *data, int len, int maxSize)
case '\n': out += "\\n"; break;
case '\r': out += "\\r"; break;
case '\t': out += "\\t"; break;
- default:
- QString tmp;
- tmp.sprintf("\\x%x", (unsigned int)(unsigned char)c);
- out += tmp.toLatin1();
+ default: {
+ const char buf[] = {
+ '\\',
+ 'x',
+ QtMiscUtils::toHexLower(uchar(c) / 16),
+ QtMiscUtils::toHexLower(uchar(c) % 16),
+ 0
+ };
+ out += buf;
+ }
}
}
@@ -460,7 +467,7 @@ bool QTextStreamPrivate::fillReadBuffer(qint64 maxBytes)
#if defined (QTEXTSTREAM_DEBUG)
qDebug("QTextStreamPrivate::fillReadBuffer(), device->read(\"%s\", %d) == %d",
- qt_prettyDebug(buf, qMin(32,int(bytesRead)) , int(bytesRead)).constData(), sizeof(buf), int(bytesRead));
+ qt_prettyDebug(buf, qMin(32,int(bytesRead)) , int(bytesRead)).constData(), int(sizeof(buf)), int(bytesRead));
#endif
if (bytesRead <= 0)
@@ -681,15 +688,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 +813,28 @@ inline void QTextStreamPrivate::restoreToSavedConverterState()
/*!
\internal
*/
-inline void QTextStreamPrivate::write(const QString &data)
+void QTextStreamPrivate::write(const QChar *data, int len)
+{
+ if (string) {
+ // ### What about seek()??
+ string->append(data, len);
+ } else {
+ writeBuffer.append(data, len);
+ if (writeBuffer.size() > QTEXTSTREAM_BUFFERSIZE)
+ flushWriteBuffer();
+ }
+}
+
+/*!
+ \internal
+*/
+inline void QTextStreamPrivate::write(QChar ch)
{
if (string) {
// ### What about seek()??
- string->append(data);
+ string->append(ch);
} else {
- writeBuffer += data;
+ writeBuffer += ch;
if (writeBuffer.size() > QTEXTSTREAM_BUFFERSIZE)
flushWriteBuffer();
}
@@ -865,45 +881,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
+*/
+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);
}
/*!
@@ -1563,17 +1587,60 @@ QString QTextStream::readAll()
*/
QString QTextStream::readLine(qint64 maxlen)
{
+ QString line;
+
+ readLine(&line, maxlen);
+ return line;
+}
+
+/*!
+ \since 5.5
+
+ Reads one line of text from the stream into \a line.
+ If \a line is 0, the read line is not stored.
+
+ The maximum allowed line length is set to \a maxlen. If
+ the stream contains lines longer than this, then the lines will be
+ split after \a maxlen characters and returned in parts.
+
+ If \a maxlen is 0, the lines can be of any length.
+
+ The resulting line has no trailing end-of-line characters ("\\n"
+ or "\\r\\n"), so calling QString::trimmed() can be unnecessary.
+
+ If \a line has sufficient capacity for the data that is about to be
+ read, this function may not need to allocate new memory. Because of
+ this, it can be faster than the other readLine() overload.
+
+ Returns \c false if the stream has read to the end of the file or
+ an error has occurred; otherwise returns \c true. The contents in
+ \a line before the call are discarded in any case.
+
+ \sa readAll(), QIODevice::readLine()
+*/
+bool QTextStream::readLine(QString *line, qint64 maxlen)
+{
Q_D(QTextStream);
- CHECK_VALID_STREAM(QString());
+ // keep in sync with CHECK_VALID_STREAM
+ if (!d->string && !d->device) {
+ qWarning("QTextStream: No device");
+ if (line && !line->isNull())
+ line->resize(0);
+ return false;
+ }
const QChar *readPtr;
int length;
- if (!d->scan(&readPtr, &length, int(maxlen), QTextStreamPrivate::EndOfLine))
- return QString();
+ if (!d->scan(&readPtr, &length, int(maxlen), QTextStreamPrivate::EndOfLine)) {
+ if (line && !line->isNull())
+ line->resize(0);
+ return false;
+ }
- QString tmp = QString(readPtr, length);
+ if (Q_LIKELY(line))
+ line->setUnicode(readPtr, length);
d->consumeLastToken();
- return tmp;
+ return true;
}
/*!
@@ -2231,7 +2298,7 @@ QTextStream &QTextStream::operator<<(QChar c)
{
Q_D(QTextStream);
CHECK_VALID_STREAM(*this);
- d->putString(QString(c));
+ d->putChar(c);
return *this;
}
@@ -2244,7 +2311,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.h b/src/corelib/io/qtextstream.h
index 5c75a006af..6f5e2473e4 100644
--- a/src/corelib/io/qtextstream.h
+++ b/src/corelib/io/qtextstream.h
@@ -124,6 +124,7 @@ public:
void skipWhiteSpace();
QString readLine(qint64 maxlen = 0);
+ bool readLine(QString *line, qint64 maxlen = 0);
QString readAll();
QString read(qint64 maxlen);
@@ -185,6 +186,7 @@ public:
private:
Q_DISABLE_COPY(QTextStream)
friend class QDebugStateSaverPrivate;
+ friend class QDebug;
QScopedPointer<QTextStreamPrivate> d_ptr;
};
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/qtldurl.cpp b/src/corelib/io/qtldurl.cpp
index d0205c3be5..7ccab8abb1 100644
--- a/src/corelib/io/qtldurl.cpp
+++ b/src/corelib/io/qtldurl.cpp
@@ -48,7 +48,7 @@ static bool containsTLDEntry(const QString &entry)
// select the right chunk from the big table
short chunk = 0;
uint chunkIndex = tldIndices[index], offset = 0;
- while (tldIndices[index] >= tldChunks[chunk] && chunk < tldChunkCount) {
+ while (chunk < tldChunkCount && tldIndices[index] >= tldChunks[chunk]) {
chunkIndex -= tldChunks[chunk];
offset += tldChunks[chunk];
chunk++;
diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h
index abf96f5fcd..a1f62925e2 100644
--- a/src/corelib/io/qurl.h
+++ b/src/corelib/io/qurl.h
@@ -173,14 +173,14 @@ public:
QUrl &operator=(const QString &url);
#endif
#ifdef Q_COMPILER_RVALUE_REFS
- QUrl(QUrl &&other) : d(0)
- { qSwap(d, other.d); }
- inline QUrl &operator=(QUrl &&other)
+ QUrl(QUrl &&other) Q_DECL_NOTHROW : d(other.d)
+ { other.d = Q_NULLPTR; }
+ inline QUrl &operator=(QUrl &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
~QUrl();
- inline void swap(QUrl &other) { qSwap(d, other.d); }
+ inline void swap(QUrl &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
void setUrl(const QString &url, ParsingMode mode = TolerantMode);
QString url(FormattingOptions options = FormattingOptions(PrettyDecoded)) const;
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..43b51bcaf5 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
@@ -3350,6 +3345,14 @@ QModelIndex QAbstractTableModel::parent(const QModelIndex &) const
return QModelIndex();
}
+/*!
+ \reimp
+*/
+QModelIndex QAbstractTableModel::sibling(int row, int column, const QModelIndex &) const
+{
+ return index(row, column);
+}
+
bool QAbstractTableModel::hasChildren(const QModelIndex &parent) const
{
if (parent.model() == this || !parent.isValid())
@@ -3493,6 +3496,14 @@ QModelIndex QAbstractListModel::parent(const QModelIndex & /* index */) const
/*!
\reimp
+*/
+QModelIndex QAbstractListModel::sibling(int row, int column, const QModelIndex &) const
+{
+ return index(row, column);
+}
+
+/*!
+ \reimp
*/
Qt::ItemFlags QAbstractListModel::flags(const QModelIndex &index) const
{
diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h
index 32d88e9d96..f1f67c9412 100644
--- a/src/corelib/itemmodels/qabstractitemmodel.h
+++ b/src/corelib/itemmodels/qabstractitemmodel.h
@@ -49,24 +49,24 @@ class Q_CORE_EXPORT QModelIndex
{
friend class QAbstractItemModel;
public:
- Q_DECL_CONSTEXPR inline QModelIndex() : r(-1), c(-1), i(0), m(0) {}
+ Q_DECL_CONSTEXPR inline QModelIndex() Q_DECL_NOTHROW : r(-1), c(-1), i(0), m(0) {}
// compiler-generated copy/move ctors/assignment operators are fine!
- Q_DECL_CONSTEXPR inline int row() const { return r; }
- Q_DECL_CONSTEXPR inline int column() const { return c; }
- Q_DECL_CONSTEXPR inline quintptr internalId() const { return i; }
- inline void *internalPointer() const { return reinterpret_cast<void*>(i); }
+ Q_DECL_CONSTEXPR inline int row() const Q_DECL_NOTHROW { return r; }
+ Q_DECL_CONSTEXPR inline int column() const Q_DECL_NOTHROW { return c; }
+ Q_DECL_CONSTEXPR inline quintptr internalId() const Q_DECL_NOTHROW { return i; }
+ inline void *internalPointer() const Q_DECL_NOTHROW { return reinterpret_cast<void*>(i); }
inline QModelIndex parent() const;
inline QModelIndex sibling(int row, int column) const;
inline QModelIndex child(int row, int column) const;
inline QVariant data(int role = Qt::DisplayRole) const;
inline Qt::ItemFlags flags() const;
- Q_DECL_CONSTEXPR inline const QAbstractItemModel *model() const { return m; }
- Q_DECL_CONSTEXPR inline bool isValid() const { return (r >= 0) && (c >= 0) && (m != 0); }
- Q_DECL_CONSTEXPR inline bool operator==(const QModelIndex &other) const
+ Q_DECL_CONSTEXPR inline const QAbstractItemModel *model() const Q_DECL_NOTHROW { return m; }
+ Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOTHROW { return (r >= 0) && (c >= 0) && (m != 0); }
+ Q_DECL_CONSTEXPR inline bool operator==(const QModelIndex &other) const Q_DECL_NOTHROW
{ return (other.r == r) && (other.i == i) && (other.c == c) && (other.m == m); }
- Q_DECL_CONSTEXPR inline bool operator!=(const QModelIndex &other) const
+ Q_DECL_CONSTEXPR inline bool operator!=(const QModelIndex &other) const Q_DECL_NOTHROW
{ return !(*this == other); }
- Q_DECL_CONSTEXPR inline bool operator<(const QModelIndex &other) const
+ Q_DECL_CONSTEXPR inline bool operator<(const QModelIndex &other) const Q_DECL_NOTHROW
{
return r < other.r
|| (r == other.r && (c < other.c
@@ -74,9 +74,9 @@ public:
|| (i == other.i && m < other.m )))));
}
private:
- inline QModelIndex(int arow, int acolumn, void *ptr, const QAbstractItemModel *amodel)
+ inline QModelIndex(int arow, int acolumn, void *ptr, const QAbstractItemModel *amodel) Q_DECL_NOTHROW
: r(arow), c(acolumn), i(reinterpret_cast<quintptr>(ptr)), m(amodel) {}
- Q_DECL_CONSTEXPR inline QModelIndex(int arow, int acolumn, quintptr id, const QAbstractItemModel *amodel)
+ Q_DECL_CONSTEXPR inline QModelIndex(int arow, int acolumn, quintptr id, const QAbstractItemModel *amodel) Q_DECL_NOTHROW
: r(arow), c(acolumn), i(id), m(amodel) {}
int r, c;
quintptr i;
@@ -91,7 +91,7 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QModelIndex &);
class QPersistentModelIndexData;
// qHash is a friend, but we can't use default arguments for friends (§8.3.6.4)
-uint qHash(const QPersistentModelIndex &index, uint seed = 0);
+uint qHash(const QPersistentModelIndex &index, uint seed = 0) Q_DECL_NOTHROW;
class Q_CORE_EXPORT QPersistentModelIndex
{
@@ -106,11 +106,12 @@ public:
{ return !operator==(other); }
QPersistentModelIndex &operator=(const QPersistentModelIndex &other);
#ifdef Q_COMPILER_RVALUE_REFS
- inline QPersistentModelIndex(QPersistentModelIndex &&other) : d(other.d) { other.d = 0; }
- inline QPersistentModelIndex &operator=(QPersistentModelIndex &&other)
+ inline QPersistentModelIndex(QPersistentModelIndex &&other) Q_DECL_NOTHROW
+ : d(other.d) { other.d = Q_NULLPTR; }
+ inline QPersistentModelIndex &operator=(QPersistentModelIndex &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
- inline void swap(QPersistentModelIndex &other) { qSwap(d, other.d); }
+ inline void swap(QPersistentModelIndex &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
bool operator==(const QModelIndex &other) const;
bool operator!=(const QModelIndex &other) const;
QPersistentModelIndex &operator=(const QModelIndex &other);
@@ -128,14 +129,14 @@ public:
bool isValid() const;
private:
QPersistentModelIndexData *d;
- friend uint qHash(const QPersistentModelIndex &, uint seed);
+ friend uint qHash(const QPersistentModelIndex &, uint seed) Q_DECL_NOTHROW;
#ifndef QT_NO_DEBUG_STREAM
friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QPersistentModelIndex &);
#endif
};
Q_DECLARE_SHARED(QPersistentModelIndex)
-inline uint qHash(const QPersistentModelIndex &index, uint seed)
+inline uint qHash(const QPersistentModelIndex &index, uint seed) Q_DECL_NOTHROW
{ return qHash(index.d, seed); }
@@ -154,7 +155,6 @@ template <class Key, class T> class QMap;
class Q_CORE_EXPORT QAbstractItemModel : public QObject
{
Q_OBJECT
- Q_ENUMS(LayoutChangeHint)
friend class QPersistentModelIndexData;
friend class QAbstractItemViewPrivate;
@@ -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
{
@@ -242,6 +238,7 @@ public:
VerticalSortHint,
HorizontalSortHint
};
+ Q_ENUM(LayoutChangeHint)
Q_SIGNALS:
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>());
@@ -419,27 +416,22 @@ 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;
+ QModelIndex sibling(int row, int column, const QModelIndex &idx) 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 +442,23 @@ 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;
+ QModelIndex sibling(int row, int column, const QModelIndex &idx) 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
@@ -491,9 +478,12 @@ inline QVariant QModelIndex::data(int arole) const
inline Qt::ItemFlags QModelIndex::flags() const
{ return m ? m->flags(*this) : Qt::ItemFlags(0); }
-inline uint qHash(const QModelIndex &index)
+inline uint qHash(const QModelIndex &index) Q_DECL_NOTHROW
{ return uint((index.row() << 4) + index.column() + index.internalId()); }
QT_END_NAMESPACE
+Q_DECLARE_METATYPE(QModelIndexList)
+Q_DECLARE_METATYPE(QPersistentModelIndex)
+
#endif // QABSTRACTITEMMODEL_H
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/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp
index 5395fd5d09..920190e712 100644
--- a/src/corelib/itemmodels/qitemselectionmodel.cpp
+++ b/src/corelib/itemmodels/qitemselectionmodel.cpp
@@ -589,33 +589,51 @@ void QItemSelection::split(const QItemSelectionRange &range,
}
-void QItemSelectionModelPrivate::initModel(QAbstractItemModel *model)
+void QItemSelectionModelPrivate::initModel(QAbstractItemModel *m)
{
- this->model = model;
+ struct Cx {
+ const char *signal;
+ const char *slot;
+ };
+ static const Cx connections[] = {
+ { SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
+ SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int)) },
+ { SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
+ SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int)) },
+ { SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
+ SLOT(_q_rowsAboutToBeInserted(QModelIndex,int,int)) },
+ { SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
+ SLOT(_q_columnsAboutToBeInserted(QModelIndex,int,int)) },
+ { SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
+ SLOT(_q_layoutAboutToBeChanged()) },
+ { SIGNAL(columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
+ SLOT(_q_layoutAboutToBeChanged()) },
+ { SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
+ SLOT(_q_layoutChanged()) },
+ { SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)),
+ SLOT(_q_layoutChanged()) },
+ { SIGNAL(layoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)),
+ SLOT(_q_layoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)) },
+ { SIGNAL(layoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)),
+ SLOT(_q_layoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)) },
+ { SIGNAL(modelReset()),
+ SLOT(reset()) },
+ { 0, 0 }
+ };
+
+ if (model == m)
+ return;
+
+ Q_Q(QItemSelectionModel);
if (model) {
- Q_Q(QItemSelectionModel);
- QObject::connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
- q, SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int)));
- QObject::connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
- q, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int)));
- QObject::connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
- q, SLOT(_q_rowsAboutToBeInserted(QModelIndex,int,int)));
- QObject::connect(model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
- q, SLOT(_q_columnsAboutToBeInserted(QModelIndex,int,int)));
- QObject::connect(model, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
- q, SLOT(_q_layoutAboutToBeChanged()));
- QObject::connect(model, SIGNAL(columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
- q, SLOT(_q_layoutAboutToBeChanged()));
- QObject::connect(model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
- q, SLOT(_q_layoutChanged()));
- QObject::connect(model, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)),
- q, SLOT(_q_layoutChanged()));
- QObject::connect(model, SIGNAL(layoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)),
- q, SLOT(_q_layoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)));
- QObject::connect(model, SIGNAL(layoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)),
- q, SLOT(_q_layoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)));
- QObject::connect(model, SIGNAL(modelReset()),
- q, SLOT(reset()));
+ for (const Cx *cx = &connections[0]; cx->signal; cx++)
+ QObject::disconnect(model, cx->signal, q, cx->slot);
+ q->reset();
+ }
+ model = m;
+ if (model) {
+ for (const Cx *cx = &connections[0]; cx->signal; cx++)
+ QObject::connect(model, cx->signal, q, cx->slot);
}
}
@@ -1078,6 +1096,10 @@ void QItemSelectionModelPrivate::_q_layoutChanged(const QList<QPersistentModelIn
selection. All functions operate on both layers; for example,
\l {QTableWidget::selectedItems()}{selecteditems()} will return items from both layers.
+ \note Since 5.5, \l{QItemSelectionModel::model()}{model},
+ \l{QItemSelectionModel::hasSelection()}{hasSelection}, and
+ \l{QItemSelectionModel::currentIndex()}{currentIndex} are meta-object properties.
+
\sa {Model/View Programming}, QAbstractItemModel, {Chart Example}
*/
@@ -1175,6 +1197,16 @@ void QItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel::
*/
/*!
+ \fn void QItemSelectionModel::modelChanged(QAbstractItemModel *model)
+ \since 5.5
+
+ This signal is emitted when the model is successfully set with setModel().
+
+ \sa model(), setModel()
+*/
+
+
+/*!
\enum QItemSelectionModel::SelectionFlag
This enum describes the way the selection model will be updated.
@@ -1205,6 +1237,10 @@ void QItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel::
void QItemSelectionModel::select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)
{
Q_D(QItemSelectionModel);
+ if (!d->model) {
+ qWarning("QItemSelectionModel: Selecting when no model has been set will result in a no-op.");
+ return;
+ }
if (command == NoUpdate)
return;
@@ -1312,6 +1348,10 @@ void QItemSelectionModel::clearSelection()
void QItemSelectionModel::setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
{
Q_D(QItemSelectionModel);
+ if (!d->model) {
+ qWarning("QItemSelectionModel: Setting the current index when no model has been set will result in a no-op.");
+ return;
+ }
if (index == d->currentIndex) {
if (command != NoUpdate)
select(index, command); // select item
@@ -1387,6 +1427,8 @@ bool QItemSelectionModel::isSelected(const QModelIndex &index) const
bool QItemSelectionModel::isRowSelected(int row, const QModelIndex &parent) const
{
Q_D(const QItemSelectionModel);
+ if (!d->model)
+ return false;
if (parent.isValid() && d->model != parent.model())
return false;
@@ -1447,6 +1489,8 @@ bool QItemSelectionModel::isRowSelected(int row, const QModelIndex &parent) cons
bool QItemSelectionModel::isColumnSelected(int column, const QModelIndex &parent) const
{
Q_D(const QItemSelectionModel);
+ if (!d->model)
+ return false;
if (parent.isValid() && d->model != parent.model())
return false;
@@ -1503,6 +1547,8 @@ bool QItemSelectionModel::isColumnSelected(int column, const QModelIndex &parent
bool QItemSelectionModel::rowIntersectsSelection(int row, const QModelIndex &parent) const
{
Q_D(const QItemSelectionModel);
+ if (!d->model)
+ return false;
if (parent.isValid() && d->model != parent.model())
return false;
@@ -1535,6 +1581,8 @@ bool QItemSelectionModel::rowIntersectsSelection(int row, const QModelIndex &par
bool QItemSelectionModel::columnIntersectsSelection(int column, const QModelIndex &parent) const
{
Q_D(const QItemSelectionModel);
+ if (!d->model)
+ return false;
if (parent.isValid() && d->model != parent.model())
return false;
@@ -1672,6 +1720,35 @@ const QItemSelection QItemSelectionModel::selection() const
}
/*!
+ \since 5.5
+
+ \property QItemSelectionModel::hasSelection
+ \internal
+*/
+/*!
+ \since 5.5
+
+ \property QItemSelectionModel::currentIndex
+ \internal
+*/
+/*!
+ \since 5.5
+
+ \property QItemSelectionModel::model
+ \internal
+*/
+
+/*!
+ \since 5.5
+
+ Returns the item model operated on by the selection model.
+*/
+QAbstractItemModel *QItemSelectionModel::model()
+{
+ return d_func()->model;
+}
+
+/*!
Returns the item model operated on by the selection model.
*/
const QAbstractItemModel *QItemSelectionModel::model() const
@@ -1680,6 +1757,23 @@ const QAbstractItemModel *QItemSelectionModel::model() const
}
/*!
+ \since 5.5
+
+ Sets the model. The modelChanged() signal will be emitted.
+
+ \sa model(), modelChanged()
+*/
+void QItemSelectionModel::setModel(QAbstractItemModel *model)
+{
+ Q_D(QItemSelectionModel);
+ if (d->model == model)
+ return;
+
+ d->initModel(model);
+ emit modelChanged(model);
+}
+
+/*!
Compares the two selections \a newSelection and \a oldSelection
and emits selectionChanged() with the deselected and selected items.
*/
diff --git a/src/corelib/itemmodels/qitemselectionmodel.h b/src/corelib/itemmodels/qitemselectionmodel.h
index 27243a2b99..58b52901cb 100644
--- a/src/corelib/itemmodels/qitemselectionmodel.h
+++ b/src/corelib/itemmodels/qitemselectionmodel.h
@@ -143,8 +143,11 @@ class QItemSelectionModelPrivate;
class Q_CORE_EXPORT QItemSelectionModel : public QObject
{
Q_OBJECT
+ Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelChanged)
+ Q_PROPERTY(bool hasSelection READ hasSelection NOTIFY selectionChanged STORED false DESIGNABLE false)
+ Q_PROPERTY(QModelIndex currentIndex READ currentIndex NOTIFY currentChanged STORED false DESIGNABLE false)
+
Q_DECLARE_PRIVATE(QItemSelectionModel)
- Q_FLAGS(SelectionFlags)
public:
@@ -163,28 +166,33 @@ public:
};
Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag)
+ Q_FLAG(SelectionFlags)
- explicit QItemSelectionModel(QAbstractItemModel *model);
+ explicit QItemSelectionModel(QAbstractItemModel *model = 0);
explicit QItemSelectionModel(QAbstractItemModel *model, QObject *parent);
virtual ~QItemSelectionModel();
QModelIndex currentIndex() const;
- bool isSelected(const QModelIndex &index) const;
- bool isRowSelected(int row, const QModelIndex &parent) const;
- bool isColumnSelected(int column, const QModelIndex &parent) const;
+ Q_INVOKABLE bool isSelected(const QModelIndex &index) const;
+ Q_INVOKABLE bool isRowSelected(int row, const QModelIndex &parent) const;
+ Q_INVOKABLE bool isColumnSelected(int column, const QModelIndex &parent) const;
- bool rowIntersectsSelection(int row, const QModelIndex &parent) const;
- bool columnIntersectsSelection(int column, const QModelIndex &parent) const;
+ Q_INVOKABLE bool rowIntersectsSelection(int row, const QModelIndex &parent) const;
+ Q_INVOKABLE bool columnIntersectsSelection(int column, const QModelIndex &parent) const;
bool hasSelection() const;
- QModelIndexList selectedIndexes() const;
- QModelIndexList selectedRows(int column = 0) const;
- QModelIndexList selectedColumns(int row = 0) const;
- const QItemSelection selection() const;
+ Q_INVOKABLE QModelIndexList selectedIndexes() const;
+ Q_INVOKABLE QModelIndexList selectedRows(int column = 0) const;
+ Q_INVOKABLE QModelIndexList selectedColumns(int row = 0) const;
+ Q_INVOKABLE const QItemSelection selection() const;
+ // ### Qt 6: Merge these two as "QAbstractItemModel *model() const"
const QAbstractItemModel *model() const;
+ QAbstractItemModel *model();
+
+ void setModel(QAbstractItemModel *model);
public Q_SLOTS:
virtual void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
@@ -201,6 +209,7 @@ Q_SIGNALS:
void currentChanged(const QModelIndex &current, const QModelIndex &previous);
void currentRowChanged(const QModelIndex &current, const QModelIndex &previous);
void currentColumnChanged(const QModelIndex &current, const QModelIndex &previous);
+ void modelChanged(QAbstractItemModel *model);
protected:
QItemSelectionModel(QItemSelectionModelPrivate &dd, QAbstractItemModel *model);
@@ -243,4 +252,7 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QItemSelectionRange &);
QT_END_NAMESPACE
+Q_DECLARE_METATYPE(QItemSelectionRange)
+Q_DECLARE_METATYPE(QItemSelection)
+
#endif // QITEMSELECTIONMODEL_H
diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp
index b01c9db418..7af95fe625 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())
@@ -1228,7 +1230,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);
}
}
@@ -1732,8 +1734,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)));
@@ -1785,8 +1787,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)));
@@ -2744,11 +2746,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..87367a9ee7 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 {
@@ -147,7 +149,11 @@ unix|integrity {
contains(QT_CONFIG, clock-gettime):include($$QT_SOURCE_TREE/config.tests/unix/clock-gettime/clock-gettime.pri)
!android {
- SOURCES += kernel/qsharedmemory_unix.cpp \
+ SOURCES += kernel/qsharedmemory_posix.cpp \
+ kernel/qsharedmemory_systemv.cpp \
+ kernel/qsharedmemory_unix.cpp \
+ kernel/qsystemsemaphore_posix.cpp \
+ kernel/qsystemsemaphore_systemv.cpp \
kernel/qsystemsemaphore_unix.cpp
} else {
SOURCES += kernel/qsharedmemory_android.cpp \
diff --git a/src/corelib/kernel/qcore_mac_objc.mm b/src/corelib/kernel/qcore_mac_objc.mm
index 73f8296021..265126dc58 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.
@@ -41,12 +42,16 @@
#include <private/qcore_mac_p.h>
+#include <qdebug.h>
+
#ifdef Q_OS_IOS
#import <UIKit/UIKit.h>
#endif
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 +63,81 @@ QString QCFString::toQString(const NSString *nsstr)
return toQString(reinterpret_cast<CFStringRef>(nsstr));
}
-#ifdef Q_OS_IOS
-QSysInfo::MacVersion qt_ios_version()
+// -------------------------------------------------------------------------
+
+QDebug operator<<(QDebug dbg, const NSObject *nsObject)
{
- 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();
- }
+ return dbg << (nsObject ? nsObject.description.UTF8String : "NSObject(0x0)");
+}
+
+QDebug operator<<(QDebug dbg, CFStringRef stringRef)
+{
+ if (!stringRef)
+ return dbg << "CFStringRef(0x0)";
- [pool release];
+ if (const UniChar *chars = CFStringGetCharactersPtr(stringRef))
+ dbg << QString::fromRawData(reinterpret_cast<const QChar *>(chars), CFStringGetLength(stringRef));
+ else
+ dbg << QString::fromCFString(stringRef);
- return QSysInfo::MacVersion(Q_MV_IOS(major, minor));
+ return dbg;
}
+
+// Prevents breaking the ODR in case we introduce support for more types
+// later on, and lets the user override our default QDebug operators.
+#define QT_DECLARE_WEAK_QDEBUG_OPERATOR_FOR_CF_TYPE(CFType) \
+ __attribute__((weak)) Q_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE(CFType)
+
+QT_FOR_EACH_CORE_FOUNDATION_TYPE(QT_DECLARE_WEAK_QDEBUG_OPERATOR_FOR_CF_TYPE);
+QT_FOR_EACH_MUTABLE_CORE_FOUNDATION_TYPE(QT_DECLARE_WEAK_QDEBUG_OPERATOR_FOR_CF_TYPE);
+QT_FOR_EACH_CORE_GRAPHICS_TYPE(QT_DECLARE_WEAK_QDEBUG_OPERATOR_FOR_CF_TYPE);
+QT_FOR_EACH_MUTABLE_CORE_GRAPHICS_TYPE(QT_DECLARE_WEAK_QDEBUG_OPERATOR_FOR_CF_TYPE);
+
+// -------------------------------------------------------------------------
+
+QAppleOperatingSystemVersion qt_apple_os_version()
+{
+ 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;
+ }
#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.cpp b/src/corelib/kernel/qcoreapplication.cpp
index ca3d92bad1..41ebc95708 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -48,7 +48,6 @@
#include <qhash.h>
#include <qmutex.h>
#include <private/qloggingregistry_p.h>
-#include <private/qprocess_p.h>
#include <qstandardpaths.h>
#include <qtextcodec.h>
#ifndef QT_NO_QOBJECT
@@ -318,7 +317,7 @@ QCoreApplication *QCoreApplication::self = 0;
uint QCoreApplicationPrivate::attribs = (1 << Qt::AA_SynthesizeMouseForUnhandledTouchEvents);
struct QCoreApplicationData {
- QCoreApplicationData() {
+ QCoreApplicationData() Q_DECL_NOTHROW {
#ifndef QT_NO_LIBRARY
app_libpaths = 0;
#endif
@@ -379,6 +378,34 @@ Q_GLOBAL_STATIC(QCoreApplicationData, coreappdata)
static bool quitLockRefEnabled = true;
#endif
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
+// Check whether the command line arguments match those passed to main()
+// by comparing to the global __argv/__argc (MS extension).
+// Deep comparison is required since argv/argc is rebuilt by WinMain for
+// GUI apps or when using MinGW due to its globbing.
+static inline bool isArgvModified(int argc, char **argv)
+{
+ if (__argc != argc)
+ return true;
+ if (__argv == argv)
+ return false;
+ for (int a = 0; a < argc; ++a) {
+ if (argv[a] != __argv[a] && strcmp(argv[a], __argv[a]))
+ return true;
+ }
+ return false;
+}
+
+static inline bool contains(int argc, char **argv, const char *needle)
+{
+ for (int a = 0; a < argc; ++a) {
+ if (!strcmp(argv[a], needle))
+ return true;
+ }
+ return false;
+}
+#endif // Q_OS_WIN && !Q_OS_WINRT
+
QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv, uint flags)
:
#ifndef QT_NO_QOBJECT
@@ -386,9 +413,8 @@ QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv, uint
#endif
argc(aargc)
, argv(aargv)
-#ifdef Q_OS_WIN
- , origArgc(aargc)
- , origArgv(new char *[aargc])
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
+ , modifiedArgv(false)
#endif
, application_type(QCoreApplicationPrivate::Tty)
#ifndef QT_NO_QOBJECT
@@ -405,9 +431,9 @@ QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv, uint
argc = 0;
argv = (char **)&empty;
}
-#ifdef Q_OS_WIN
- std::copy(argv, argv + argc, origArgv);
-#endif
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
+ modifiedArgv = isArgvModified(argc, argv);
+#endif // Q_OS_WIN && !Q_OS_WINRT
#ifndef QT_NO_QOBJECT
QCoreApplicationPrivate::is_app_closing = false;
@@ -432,9 +458,6 @@ QCoreApplicationPrivate::~QCoreApplicationPrivate()
#ifndef QT_NO_QOBJECT
cleanupThreadData();
#endif
-#ifdef Q_OS_WIN
- delete [] origArgv;
-#endif
QCoreApplicationPrivate::clearApplicationFilePath();
}
@@ -739,14 +762,6 @@ void QCoreApplication::init()
d->appendApplicationPathToLibraryPaths();
#endif
-#ifndef QT_NO_QOBJECT
-#if defined(Q_OS_UNIX) && !(defined(QT_NO_PROCESS))
- // Make sure the process manager thread object is created in the main
- // thread.
- QProcessPrivate::initializeProcessManager();
-#endif
-#endif
-
#ifdef QT_EVAL
extern void qt_core_eval_init(QCoreApplicationPrivate::Type);
qt_core_eval_init(d->application_type);
@@ -2140,10 +2155,11 @@ qint64 QCoreApplication::applicationPid()
Latin1 locale. Most modern Unix systems do not have this limitation, as they are
Unicode-based.
- On NT-based Windows, this limitation does not apply either.
- On Windows, the arguments() are not built from the contents of argv/argc, as
- the content does not support Unicode. Instead, the arguments() are constructed
- from the return value of
+ On Windows, the list is built from the argc and argv parameters only if
+ modified argv/argc parameters are passed to the constructor. In that case,
+ encoding problems might occur.
+
+ Otherwise, the arguments() are constructed from the return value of
\l{http://msdn2.microsoft.com/en-us/library/ms683156(VS.85).aspx}{GetCommandLine()}.
As a result of this, the string given by arguments().at(0) might not be
the program name on Windows, depending on how the application was started.
@@ -2178,21 +2194,20 @@ QStringList QCoreApplication::arguments()
}
#endif // Q_OS_WINCE
- char ** const origArgv = self->d_func()->origArgv;
- const int origArgc = self->d_func()->origArgc;
- char ** const avEnd = av + ac;
-
- const QStringList allArguments = qWinCmdArgs(cmdline);
- Q_ASSERT(allArguments.size() == origArgc);
- for (int i = 0; i < origArgc; ++i)
- if (std::find(av, avEnd, origArgv[i]) != avEnd)
- list.push_back(allArguments.at(i));
+ if (!self->d_func()->modifiedArgv) {
+ const QStringList allArguments = qWinCmdArgs(cmdline);
+ Q_ASSERT(allArguments.size() == __argc);
+ for (int i = 0; i < __argc; ++i) {
+ if (contains(ac, av, __argv[i]))
+ list.append(allArguments.at(i));
+ }
+ return list;
+ } // Fall back to rebuilding from argv/argc when a modified argv was passed.
+#endif // defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
-#else
for (int a = 0; a < ac; ++a) {
list << QString::fromLocal8Bit(av[a]);
}
-#endif
return list;
}
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/qcoreapplication_p.h b/src/corelib/kernel/qcoreapplication_p.h
index a3a0eaa68c..2b03fe2382 100644
--- a/src/corelib/kernel/qcoreapplication_p.h
+++ b/src/corelib/kernel/qcoreapplication_p.h
@@ -115,9 +115,8 @@ public:
int &argc;
char **argv;
-#ifdef Q_OS_WIN
- int origArgc;
- char **origArgv; // store unmodified arguments for QCoreApplication::arguments()
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
+ bool modifiedArgv;
#endif
void appendApplicationPathToLibraryPaths(void);
diff --git a/src/corelib/kernel/qcoreevent.cpp b/src/corelib/kernel/qcoreevent.cpp
index 85b7f51bd6..9e8ec250fc 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..b57690198e 100644
--- a/src/corelib/kernel/qcoreevent.h
+++ b/src/corelib/kernel/qcoreevent.h
@@ -46,7 +46,6 @@ class Q_CORE_EXPORT QEvent // event base class
{
Q_GADGET
QDOC_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
- Q_ENUMS(Type)
public:
enum Type {
/*
@@ -275,12 +274,15 @@ 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
User = 1000, // first user event id
MaxUser = 65535 // last user event id
};
+ Q_ENUM(Type)
explicit QEvent(Type type);
QEvent(const QEvent &other);
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_p.h b/src/corelib/kernel/qfunctions_p.h
index b10d92398b..1eb7748364 100644
--- a/src/corelib/kernel/qfunctions_p.h
+++ b/src/corelib/kernel/qfunctions_p.h
@@ -57,14 +57,5 @@
# include "QtCore/qfunctions_winrt.h"
#endif
-#ifdef Q_CC_RVCT
-// rvct doesn't see static operators when using our qalgorithms
-# define Q_STATIC_GLOBAL_OPERATOR inline
-# define Q_STATIC_GLOBAL_INLINE_OPERATOR inline
-#else
-# define Q_STATIC_GLOBAL_OPERATOR static
-# define Q_STATIC_GLOBAL_INLINE_OPERATOR static inline
-#endif
-
#endif
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/qjnihelpers.cpp b/src/corelib/kernel/qjnihelpers.cpp
index d3bbce305a..2ba2645f2c 100644
--- a/src/corelib/kernel/qjnihelpers.cpp
+++ b/src/corelib/kernel/qjnihelpers.cpp
@@ -89,6 +89,39 @@ void QtAndroidPrivate::handleActivityResult(jint requestCode, jint resultCode, j
}
}
+namespace {
+ class NewIntentListeners
+ {
+ public:
+ QMutex mutex;
+ QList<QtAndroidPrivate::NewIntentListener *> listeners;
+ };
+}
+
+Q_GLOBAL_STATIC(NewIntentListeners, g_newIntentListeners)
+
+void QtAndroidPrivate::registerNewIntentListener(NewIntentListener *listener)
+{
+ QMutexLocker locker(&g_newIntentListeners()->mutex);
+ g_newIntentListeners()->listeners.append(listener);
+}
+
+void QtAndroidPrivate::unregisterNewIntentListener(NewIntentListener *listener)
+{
+ QMutexLocker locker(&g_newIntentListeners()->mutex);
+ g_newIntentListeners()->listeners.removeAll(listener);
+}
+
+void QtAndroidPrivate::handleNewIntent(JNIEnv *env, jobject intent)
+{
+ QMutexLocker locker(&g_newIntentListeners()->mutex);
+ const QList<QtAndroidPrivate::NewIntentListener *> &listeners = g_newIntentListeners()->listeners;
+ for (int i=0; i<listeners.size(); ++i) {
+ if (listeners.at(i)->handleNewIntent(env, intent))
+ break;
+ }
+}
+
static inline bool exceptionCheck(JNIEnv *env)
{
if (env->ExceptionCheck()) {
diff --git a/src/corelib/kernel/qjnihelpers_p.h b/src/corelib/kernel/qjnihelpers_p.h
index 6456dce4c4..70783e4bb6 100644
--- a/src/corelib/kernel/qjnihelpers_p.h
+++ b/src/corelib/kernel/qjnihelpers_p.h
@@ -61,6 +61,13 @@ namespace QtAndroidPrivate
virtual bool handleActivityResult(jint requestCode, jint resultCode, jobject data) = 0;
};
+ class Q_CORE_EXPORT NewIntentListener
+ {
+ public:
+ virtual ~NewIntentListener() {}
+ virtual bool handleNewIntent(JNIEnv *env, jobject intent) = 0;
+ };
+
Q_CORE_EXPORT jobject activity();
Q_CORE_EXPORT JavaVM *javaVM();
Q_CORE_EXPORT jint initJNI(JavaVM *vm, JNIEnv *env);
@@ -71,6 +78,10 @@ namespace QtAndroidPrivate
Q_CORE_EXPORT void handleActivityResult(jint requestCode, jint resultCode, jobject data);
Q_CORE_EXPORT void registerActivityResultListener(ActivityResultListener *listener);
Q_CORE_EXPORT void unregisterActivityResultListener(ActivityResultListener *listener);
+
+ Q_CORE_EXPORT void handleNewIntent(JNIEnv *env, jobject intent);
+ Q_CORE_EXPORT void registerNewIntentListener(NewIntentListener *listener);
+ Q_CORE_EXPORT void unregisterNewIntentListener(NewIntentListener *listener);
}
QT_END_NAMESPACE
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp
index b54cb0c344..1af0914ad8 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.
@@ -2570,6 +2677,14 @@ QByteArray QMetaEnum::valueToKeys(int value) const
return keys;
}
+/*!
+ \fn QMetaEnum QMetaEnum::fromType() const
+ \since 5.5
+
+ Returns the QMetaEnum corresponding to the type in the template parameter.
+ The enum needs to be declared with Q_ENUM.
+*/
+
static QByteArray qualifiedName(const QMetaEnum &e)
{
return QByteArray(e.scope()) + "::" + e.name();
@@ -2713,9 +2828,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 +2837,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 +2901,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 +2959,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 +2981,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 +3035,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 +3058,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 +3079,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..eaef05f03d 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
@@ -194,6 +223,15 @@ public:
inline const QMetaObject *enclosingMetaObject() const { return mobj; }
inline bool isValid() const { return name() != 0; }
+
+ template<typename T> static QMetaEnum fromType() {
+ Q_STATIC_ASSERT_X(QtPrivate::IsQEnumHelper<T>::Value,
+ "QMetaEnum::fromType only works with enums declared as Q_ENUM or Q_FLAG");
+ const QMetaObject *metaObject = qt_getEnumMetaObject(T());
+ const char *name = qt_getEnumName(T());
+ return metaObject->enumerator(metaObject->indexOfEnumerator(name));
+ }
+
private:
const QMetaObject *mobj;
uint handle;
@@ -237,11 +275,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..f9092b0a32 100644
--- a/src/corelib/kernel/qmetatype.cpp
+++ b/src/corelib/kernel/qmetatype.cpp
@@ -282,11 +282,12 @@ struct DefinedTypesFilter {
\value NeedsDestruction This type has a non-trivial destructor. If the flag is not set calls to the destructor are not necessary before discarding objects.
\value MovableType An instance of a type having this attribute can be safely moved by memcpy.
\omitvalue SharedPointerToQObject
- \omitvalue IsEnumeration
- \omitvalue PointerToQObject
+ \value IsEnumeration This type is an enumeration
+ \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,23 @@ 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)
+
+ If the type is an enumaration, flags contains QMetaType::IsEnumeration, and this function
+ returns the QMetaObject of the enclosing object if the enum was registered as a Q_ENUM or 0
+ otherwise
+
+ \sa QMetaType::metaObjectForType(), QMetaType::flags()
*/
/*!
@@ -565,11 +581,19 @@ Q_GLOBAL_STATIC(QMetaTypeDebugStreamRegistry, customTypesDebugStreamRegistry)
/*!
\fn bool QMetaType::registerComparators()
\since 5.2
- Registers comparison operetarors for the user-registered type T. This requires T to have
+ Registers comparison operators for the user-registered type T. This requires T to have
both an operator== and an operator<.
Returns \c true if the registration succeeded, otherwise false.
*/
+/*!
+ \fn bool QMetaType::registerEqualsComparator()
+ \since 5.5
+ Registers equals operator for the user-registered type T. This requires T to have
+ an operator==.
+ Returns \c true if the registration succeeded, otherwise false.
+*/
+
#ifndef QT_NO_DEBUG_STREAM
/*!
\fn bool QMetaType::registerDebugStreamOperator()
@@ -675,7 +699,7 @@ bool QMetaType::convert(const void *from, int fromTypeId, void *to, int toTypeId
/*!
Compares the objects at \a lhs and \a rhs. Both objects need to be of type \a typeId.
\a result is set to less than, equal to or greater than zero, if \a lhs is less than, equal to
- or greater than \a rhs. Returns \c true, if the comparison succeeded, otherwiess false.
+ or greater than \a rhs. Returns \c true, if the comparison succeeded, otherwise \c false.
\since 5.2
*/
bool QMetaType::compare(const void *lhs, const void *rhs, int typeId, int* result)
@@ -686,8 +710,29 @@ bool QMetaType::compare(const void *lhs, const void *rhs, int typeId, int* resul
return false;
if (f->equals(f, lhs, rhs))
*result = 0;
- else
+ else if (f->lessThan)
*result = f->lessThan(f, lhs, rhs) ? -1 : 1;
+ else
+ return false;
+ return true;
+}
+
+/*!
+ Compares the objects at \a lhs and \a rhs. Both objects need to be of type \a typeId.
+ \a result is set to zero, if \a lhs equals to rhs. Returns \c true, if the comparison
+ succeeded, otherwise \c false.
+ \since 5.5
+*/
+bool QMetaType::equals(const void *lhs, const void *rhs, int typeId, int *result)
+{
+ const QtPrivate::AbstractComparatorFunction * const f
+ = customTypesComparatorRegistry()->function(typeId);
+ if (!f)
+ return false;
+ if (f->equals(f, lhs, rhs))
+ *result = 0;
+ else
+ *result = -1;
return true;
}
@@ -801,7 +846,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 +866,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 +915,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 +966,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 +1066,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 +1108,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 +1139,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 +1151,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 +1614,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 +1623,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 +1635,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 +1935,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 +1978,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 +2187,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 +2232,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 +2248,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 +2298,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 +2314,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..5ca44f9440 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) 2015 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) \
@@ -289,6 +291,24 @@ struct BuiltInComparatorFunction : public AbstractComparatorFunction
}
};
+template<typename T>
+struct BuiltInEqualsComparatorFunction : public AbstractComparatorFunction
+{
+ BuiltInEqualsComparatorFunction()
+ : AbstractComparatorFunction(0, equals, destroy) {}
+ static bool equals(const AbstractComparatorFunction *, const void *l, const void *r)
+ {
+ const T *lhs = static_cast<const T *>(l);
+ const T *rhs = static_cast<const T *>(r);
+ return *lhs == *rhs;
+ }
+
+ static void destroy(AbstractComparatorFunction *_this)
+ {
+ delete static_cast<BuiltInEqualsComparatorFunction *>(_this);
+ }
+};
+
struct AbstractConverterFunction
{
typedef bool (*Converter)(const AbstractConverterFunction *, const void *, void*);
@@ -435,7 +455,8 @@ public:
SharedPointerToQObject = 0x20,
WeakPointerToQObject = 0x40,
TrackingPointerToQObject = 0x80,
- WasDeclaredAsMetaType = 0x100
+ WasDeclaredAsMetaType = 0x100,
+ IsGadget = 0x200
};
Q_DECLARE_FLAGS(TypeFlags, TypeFlag)
@@ -469,9 +490,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);
@@ -517,6 +548,16 @@ public:
return registerComparatorFunction( &f, typeId);
}
template<typename T>
+ static bool registerEqualsComparator()
+ {
+ Q_STATIC_ASSERT_X((!QMetaTypeId2<T>::IsBuiltIn),
+ "QMetaType::registerEqualsComparator: The type must be a custom type.");
+ const int typeId = qMetaTypeId<T>();
+ static const QtPrivate::BuiltInEqualsComparatorFunction<T> f;
+ return registerComparatorFunction( &f, typeId);
+ }
+
+ template<typename T>
static bool hasRegisteredComparators()
{
return hasRegisteredComparators(qMetaTypeId<T>());
@@ -597,6 +638,7 @@ public:
static bool convert(const void *from, int fromTypeId, void *to, int toTypeId);
static bool compare(const void *lhs, const void *rhs, int typeId, int* result);
+ static bool equals(const void *lhs, const void *rhs, int typeId, int* result);
static bool debugStream(QDebug& dbg, const void *rhs, int typeId);
template<typename From, typename To>
@@ -640,16 +682,13 @@ private:
static bool registerDebugStreamOperatorFunction(const QtPrivate::AbstractDebugStreamFunction *f, int type);
#endif
+// ### Qt6: FIXME: Remove the special Q_CC_MSVC handling, it was introduced to maintain BC.
#if !defined(Q_NO_TEMPLATE_FRIENDS) && !defined(Q_CC_MSVC)
#ifndef Q_QDOC
- template<typename T>
- friend bool qRegisterSequentialConverter();
template<typename, bool> friend struct QtPrivate::ValueTypeIsMetaType;
template<typename, typename> friend struct QtPrivate::ConverterMemberFunction;
template<typename, typename> friend struct QtPrivate::ConverterMemberFunctionOk;
template<typename, typename, typename> friend struct QtPrivate::ConverterFunctor;
- template<typename T>
- friend bool qRegisterAssociativeConverter();
template<typename, bool> friend struct QtPrivate::AssociativeValueTypeIsMetaType;
template<typename, bool> friend struct QtPrivate::IsMetaTypePair;
template<typename, typename> friend struct QtPrivate::MetaTypeSmartPointerHelper;
@@ -661,8 +700,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 +741,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 +768,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,17 +1355,48 @@ 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*) };
+ };
+
+ char qt_getEnumMetaObject(...);
+ char qt_getEnumMetaObject(); // Workaround bugs in MSVC.
+
+ template<typename T>
+ struct IsQEnumHelper {
+ static const T &declval();
+ enum { Value = sizeof(qt_getEnumMetaObject(declval())) == sizeof(QMetaObject*) };
+ };
+
+ template<typename T, typename Enable = void>
struct MetaObjectForType
{
static inline const QMetaObject *value() { return 0; }
};
-
+ template<>
+ struct MetaObjectForType<void>
+ {
+ static inline const QMetaObject *value() { return Q_NULLPTR; }
+ };
+ template<typename T>
+ struct MetaObjectForType<T*, typename QEnableIf<IsPointerToTypeDerivedFromQObject<T*>::Value>::Type>
+ {
+ static inline const QMetaObject *value() { return &T::staticMetaObject; }
+ };
template<typename T>
- struct MetaObjectForType<T*, /* isPointerToTypeDerivedFromQObject = */ true>
+ struct MetaObjectForType<T, typename QEnableIf<IsGadgetHelper<T>::Value>::Type>
{
static inline const QMetaObject *value() { return &T::staticMetaObject; }
};
+ template<typename T>
+ struct MetaObjectForType<T, typename QEnableIf<IsQEnumHelper<T>::Value>::Type >
+ {
+ static inline const QMetaObject *value() { return qt_getEnumMetaObject(T()); }
+ };
template<typename T>
struct IsSharedPointerToTypeDerivedFromQObject
@@ -1512,6 +1568,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 +1604,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 +1654,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 +2022,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 +2057,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 f2ceb7081c..b29376e851 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -177,6 +177,7 @@ void (*QAbstractDeclarativeData::parentChanged)(QAbstractDeclarativeData *, QObj
void (*QAbstractDeclarativeData::signalEmitted)(QAbstractDeclarativeData *, QObject *, int, void **) = 0;
int (*QAbstractDeclarativeData::receivers)(QAbstractDeclarativeData *, const QObject *, int) = 0;
bool (*QAbstractDeclarativeData::isSignalConnected)(QAbstractDeclarativeData *, const QObject *, int) = 0;
+void (*QAbstractDeclarativeData::setWidgetParent)(QObject *, QObject *) = 0;
QObjectData::~QObjectData() {}
@@ -2661,8 +2662,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);
@@ -4094,14 +4095,30 @@ 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;
+}
+
+QDebug qt_QMetaEnum_debugOperator(QDebug &dbg, int value, const QMetaObject *meta, const char *name)
+{
+ QDebugStateSaver saver(dbg);
+ QMetaEnum me = meta->enumerator(meta->indexOfEnumerator(name));
+ const char *key = me.valueToKey(value);
+ dbg.nospace() << meta->className() << "::" << name << '(';
+ if (key)
+ dbg << key;
+ else
+ dbg << value;
+ dbg << ')';
+ return dbg;
}
#endif
diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h
index 092c57ef7f..20ff9981b1 100644
--- a/src/corelib/kernel/qobject.h
+++ b/src/corelib/kernel/qobject.h
@@ -448,6 +448,8 @@ protected:
QScopedPointer<QObjectData> d_ptr;
static const QMetaObject staticQtMetaObject;
+ friend inline const QMetaObject *qt_getQtMetaObject() Q_DECL_NOEXCEPT
+ { return &staticQtMetaObject; }
friend struct QMetaObject;
friend struct QMetaObjectPrivate;
@@ -545,6 +547,16 @@ template <class T> inline const char * qobject_interface_iid()
#ifndef QT_NO_DEBUG_STREAM
Q_CORE_EXPORT QDebug operator<<(QDebug, const QObject *);
+Q_CORE_EXPORT QDebug qt_QMetaEnum_debugOperator(QDebug&, int value, const QMetaObject *meta, const char *name);
+
+template<typename T>
+typename QtPrivate::QEnableIf<QtPrivate::IsQEnumHelper<T>::Value , QDebug>::Type
+operator<<(QDebug &dbg, T value)
+{
+ const QMetaObject *obj = qt_getEnumMetaObject(value);
+ const char *name = qt_getEnumName(value);
+ return qt_QMetaEnum_debugOperator(dbg, typename QFlags<T>::Int(value), obj, name);
+}
#endif
class QSignalBlocker
diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h
index ba26ff7bfb..dba5f0265f 100644
--- a/src/corelib/kernel/qobject_p.h
+++ b/src/corelib/kernel/qobject_p.h
@@ -87,6 +87,7 @@ public:
static void (*signalEmitted)(QAbstractDeclarativeData *, QObject *, int, void **);
static int (*receivers)(QAbstractDeclarativeData *, const QObject *, int);
static bool (*isSignalConnected)(QAbstractDeclarativeData *, const QObject *, int);
+ static void (*setWidgetParent)(QObject *, QObject *); // Used by the QML engine to specify parents for widgets. Set by QtWidgets.
};
// This is an implementation of QAbstractDeclarativeData that is identical with
@@ -414,9 +415,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..af99546f04 100644
--- a/src/corelib/kernel/qobjectdefs.h
+++ b/src/corelib/kernel/qobjectdefs.h
@@ -84,6 +84,10 @@ class QString;
#define Q_OVERRIDE(text)
#define Q_ENUMS(x)
#define Q_FLAGS(x)
+#define Q_ENUM(ENUM) \
+ friend Q_DECL_CONSTEXPR const QMetaObject *qt_getEnumMetaObject(ENUM) Q_DECL_NOEXCEPT { return &staticMetaObject; } \
+ friend Q_DECL_CONSTEXPR const char *qt_getEnumName(ENUM) Q_DECL_NOEXCEPT { return #ENUM; }
+#define Q_FLAG(ENUM) Q_ENUM(ENUM)
#define Q_SCRIPTABLE
#define Q_INVOKABLE
#define Q_SIGNAL
@@ -138,15 +142,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 +172,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
@@ -175,6 +190,8 @@ private:
#define Q_OVERRIDE(text) Q_OVERRIDE(text)
#define Q_ENUMS(x) Q_ENUMS(x)
#define Q_FLAGS(x) Q_FLAGS(x)
+#define Q_ENUM(x) Q_ENUM(x)
+#define Q_FLAGS(x) Q_FLAGS(x)
/* qmake ignore Q_OBJECT */
#define Q_OBJECT Q_OBJECT
/* qmake ignore Q_OBJECT */
diff --git a/src/corelib/kernel/qsharedmemory.cpp b/src/corelib/kernel/qsharedmemory.cpp
index 22d1148677..c5452fe8ab 100644
--- a/src/corelib/kernel/qsharedmemory.cpp
+++ b/src/corelib/kernel/qsharedmemory.cpp
@@ -69,6 +69,8 @@ QSharedMemoryPrivate::makePlatformSafeKey(const QString &key,
result.append(QLatin1String(hex));
#ifdef Q_OS_WIN
return result;
+#elif defined(QT_POSIX_IPC)
+ return QLatin1Char('/') + result;
#else
return QDir::tempPath() + QLatin1Char('/') + result;
#endif
diff --git a/src/corelib/kernel/qsharedmemory_p.h b/src/corelib/kernel/qsharedmemory_p.h
index 0e2f40bf8c..f1e29b9741 100644
--- a/src/corelib/kernel/qsharedmemory_p.h
+++ b/src/corelib/kernel/qsharedmemory_p.h
@@ -122,6 +122,8 @@ public:
const QString &prefix = QLatin1String("qipc_sharedmemory_"));
#ifdef Q_OS_WIN
Qt::HANDLE handle();
+#elif defined(QT_POSIX_IPC)
+ int handle();
#else
key_t handle();
#endif
@@ -147,6 +149,8 @@ public:
private:
#ifdef Q_OS_WIN
Qt::HANDLE hand;
+#elif defined(QT_POSIX_IPC)
+ int hand;
#else
key_t unix_key;
#endif
diff --git a/src/corelib/kernel/qsharedmemory_posix.cpp b/src/corelib/kernel/qsharedmemory_posix.cpp
new file mode 100644
index 0000000000..0015bda8d9
--- /dev/null
+++ b/src/corelib/kernel/qsharedmemory_posix.cpp
@@ -0,0 +1,231 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Konstantin Ritt <ritt.ks@gmail.com>
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Tobias Koenig <tobias.koenig@kdab.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 "qplatformdefs.h"
+
+#include "qsharedmemory.h"
+#include "qsharedmemory_p.h"
+#include "qsystemsemaphore.h"
+#include <qfile.h>
+
+#include <errno.h>
+
+#ifdef QT_POSIX_IPC
+
+#ifndef QT_NO_SHAREDMEMORY
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "private/qcore_unix_p.h"
+
+QT_BEGIN_NAMESPACE
+
+int QSharedMemoryPrivate::handle()
+{
+ // don't allow making handles on empty keys
+ const QString safeKey = makePlatformSafeKey(key);
+ if (safeKey.isEmpty()) {
+ errorString = QSharedMemory::tr("%1: key is empty").arg(QLatin1String("QSharedMemory::handle"));
+ error = QSharedMemory::KeyError;
+ return 0;
+ }
+
+ return 1;
+}
+
+bool QSharedMemoryPrivate::cleanHandle()
+{
+ qt_safe_close(hand);
+ hand = -1;
+
+ return true;
+}
+
+bool QSharedMemoryPrivate::create(int size)
+{
+ if (!handle())
+ return false;
+
+ const QByteArray shmName = QFile::encodeName(makePlatformSafeKey(key));
+
+ int fd;
+#ifdef O_CLOEXEC
+ // First try with O_CLOEXEC flag, if that fails, fall back to normal flags
+ EINTR_LOOP(fd, ::shm_open(shmName.constData(), O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, 0600));
+ if (fd == -1)
+ EINTR_LOOP(fd, ::shm_open(shmName.constData(), O_RDWR | O_CREAT | O_EXCL, 0600));
+#else
+ EINTR_LOOP(fd, ::shm_open(shmName.constData(), O_RDWR | O_CREAT | O_EXCL, 0600));
+#endif
+ if (fd == -1) {
+ const int errorNumber = errno;
+ const QString function = QLatin1String("QSharedMemory::create");
+ switch (errorNumber) {
+ case ENAMETOOLONG:
+ case EINVAL:
+ errorString = QSharedMemory::tr("%1: bad name").arg(function);
+ error = QSharedMemory::KeyError;
+ break;
+ default:
+ setErrorString(function);
+ }
+ return false;
+ }
+
+ // the size may only be set once
+ int ret;
+ EINTR_LOOP(ret, QT_FTRUNCATE(fd, size));
+ if (ret == -1) {
+ setErrorString(QLatin1String("QSharedMemory::create (ftruncate)"));
+ qt_safe_close(fd);
+ return false;
+ }
+
+ qt_safe_close(fd);
+
+ return true;
+}
+
+bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode)
+{
+ const QByteArray shmName = QFile::encodeName(makePlatformSafeKey(key));
+
+ const int oflag = (mode == QSharedMemory::ReadOnly ? O_RDONLY : O_RDWR);
+ const mode_t omode = (mode == QSharedMemory::ReadOnly ? 0400 : 0600);
+
+#ifdef O_CLOEXEC
+ // First try with O_CLOEXEC flag, if that fails, fall back to normal flags
+ EINTR_LOOP(hand, ::shm_open(shmName.constData(), oflag | O_CLOEXEC, omode));
+ if (hand == -1)
+ EINTR_LOOP(hand, ::shm_open(shmName.constData(), oflag, omode));
+#else
+ EINTR_LOOP(hand, ::shm_open(shmName.constData(), oflag, omode));
+#endif
+ if (hand == -1) {
+ const int errorNumber = errno;
+ const QString function = QLatin1String("QSharedMemory::attach (shm_open)");
+ switch (errorNumber) {
+ case ENAMETOOLONG:
+ case EINVAL:
+ errorString = QSharedMemory::tr("%1: bad name").arg(function);
+ error = QSharedMemory::KeyError;
+ break;
+ default:
+ setErrorString(function);
+ }
+ hand = -1;
+ return false;
+ }
+
+ // grab the size
+ QT_STATBUF st;
+ if (QT_FSTAT(hand, &st) == -1) {
+ setErrorString(QLatin1String("QSharedMemory::attach (fstat)"));
+ cleanHandle();
+ return false;
+ }
+ size = st.st_size;
+
+ // grab the memory
+ const int mprot = (mode == QSharedMemory::ReadOnly ? PROT_READ : PROT_READ | PROT_WRITE);
+ memory = QT_MMAP(0, size, mprot, MAP_SHARED, hand, 0);
+ if (memory == MAP_FAILED || !memory) {
+ setErrorString(QLatin1String("QSharedMemory::attach (mmap)"));
+ cleanHandle();
+ memory = 0;
+ size = 0;
+ return false;
+ }
+
+#ifdef F_ADD_SEALS
+ // Make sure the shared memory region will not shrink
+ // otherwise someone could cause SIGBUS on us.
+ // (see http://lwn.net/Articles/594919/)
+ fcntl(hand, F_ADD_SEALS, F_SEAL_SHRINK);
+#endif
+
+ return true;
+}
+
+bool QSharedMemoryPrivate::detach()
+{
+ // detach from the memory segment
+ if (::munmap(memory, size) == -1) {
+ setErrorString(QLatin1String("QSharedMemory::detach (munmap)"));
+ return false;
+ }
+ memory = 0;
+ size = 0;
+
+#ifdef Q_OS_QNX
+ // On QNX the st_nlink field of struct stat contains the number of
+ // active shm_open() connections to the shared memory file, so we
+ // can use it to automatically clean up the file once the last
+ // user has detached from it.
+
+ // get the number of current attachments
+ int shm_nattch = 0;
+ QT_STATBUF st;
+ if (QT_FSTAT(hand, &st) == 0) {
+ // subtract 2 from linkcount: one for our own open and one for the dir entry
+ shm_nattch = st.st_nlink - 2;
+ }
+
+ cleanHandle();
+
+ // if there are no attachments then unlink the shared memory
+ if (shm_nattch == 0) {
+ const QByteArray shmName = QFile::encodeName(makePlatformSafeKey(key));
+ if (::shm_unlink(shmName.constData()) == -1 && errno != ENOENT)
+ setErrorString(QLatin1String("QSharedMemory::detach (shm_unlink)"));
+ }
+#else
+ // On non-QNX systems (tested Linux and Haiku), the st_nlink field is always 1,
+ // so we'll simply leak the shared memory files.
+ cleanHandle();
+#endif
+
+ return true;
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_SHAREDMEMORY
+
+#endif // QT_POSIX_IPC
diff --git a/src/corelib/kernel/qsharedmemory_systemv.cpp b/src/corelib/kernel/qsharedmemory_systemv.cpp
new file mode 100644
index 0000000000..b3fe300a43
--- /dev/null
+++ b/src/corelib/kernel/qsharedmemory_systemv.cpp
@@ -0,0 +1,254 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** 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 "qplatformdefs.h"
+
+#include "qsharedmemory.h"
+#include "qsharedmemory_p.h"
+#include "qsystemsemaphore.h"
+#include <qdir.h>
+#include <qdebug.h>
+
+#include <errno.h>
+
+#ifndef QT_POSIX_IPC
+
+#ifndef QT_NO_SHAREDMEMORY
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#endif //QT_NO_SHAREDMEMORY
+
+#include "private/qcore_unix_p.h"
+
+#ifndef QT_NO_SHAREDMEMORY
+QT_BEGIN_NAMESPACE
+
+/*!
+ \internal
+
+ If not already made create the handle used for accessing the shared memory.
+*/
+key_t QSharedMemoryPrivate::handle()
+{
+ // already made
+ if (unix_key)
+ return unix_key;
+
+ // don't allow making handles on empty keys
+ if (nativeKey.isEmpty()) {
+ errorString = QSharedMemory::tr("%1: key is empty").arg(QLatin1String("QSharedMemory::handle:"));
+ error = QSharedMemory::KeyError;
+ return 0;
+ }
+
+ // ftok requires that an actual file exists somewhere
+ if (!QFile::exists(nativeKey)) {
+ errorString = QSharedMemory::tr("%1: UNIX key file doesn't exist").arg(QLatin1String("QSharedMemory::handle:"));
+ error = QSharedMemory::NotFound;
+ return 0;
+ }
+
+ unix_key = ftok(QFile::encodeName(nativeKey).constData(), 'Q');
+ if (-1 == unix_key) {
+ errorString = QSharedMemory::tr("%1: ftok failed").arg(QLatin1String("QSharedMemory::handle:"));
+ error = QSharedMemory::KeyError;
+ unix_key = 0;
+ }
+ return unix_key;
+}
+
+#endif // QT_NO_SHAREDMEMORY
+
+#if !(defined(QT_NO_SHAREDMEMORY) && defined(QT_NO_SYSTEMSEMAPHORE))
+/*!
+ \internal
+ Creates the unix file if needed.
+ returns \c true if the unix file was created.
+
+ -1 error
+ 0 already existed
+ 1 created
+ */
+int QSharedMemoryPrivate::createUnixKeyFile(const QString &fileName)
+{
+ int fd = qt_safe_open(QFile::encodeName(fileName).constData(),
+ O_EXCL | O_CREAT | O_RDWR, 0640);
+ if (-1 == fd) {
+ if (errno == EEXIST)
+ return 0;
+ return -1;
+ } else {
+ close(fd);
+ }
+ return 1;
+}
+#endif // QT_NO_SHAREDMEMORY && QT_NO_SYSTEMSEMAPHORE
+
+#ifndef QT_NO_SHAREDMEMORY
+
+bool QSharedMemoryPrivate::cleanHandle()
+{
+ unix_key = 0;
+ return true;
+}
+
+bool QSharedMemoryPrivate::create(int size)
+{
+ // build file if needed
+ bool createdFile = false;
+ int built = createUnixKeyFile(nativeKey);
+ if (built == -1) {
+ errorString = QSharedMemory::tr("%1: unable to make key").arg(QLatin1String("QSharedMemory::handle:"));
+ error = QSharedMemory::KeyError;
+ return false;
+ }
+ if (built == 1) {
+ createdFile = true;
+ }
+
+ // get handle
+ if (!handle()) {
+ if (createdFile)
+ QFile::remove(nativeKey);
+ return false;
+ }
+
+ // create
+ if (-1 == shmget(unix_key, size, 0600 | IPC_CREAT | IPC_EXCL)) {
+ QString function = QLatin1String("QSharedMemory::create");
+ switch (errno) {
+ case EINVAL:
+ errorString = QSharedMemory::tr("%1: system-imposed size restrictions").arg(QLatin1String("QSharedMemory::handle"));
+ error = QSharedMemory::InvalidSize;
+ break;
+ default:
+ setErrorString(function);
+ }
+ if (createdFile && error != QSharedMemory::AlreadyExists)
+ QFile::remove(nativeKey);
+ return false;
+ }
+
+ return true;
+}
+
+bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode)
+{
+ // grab the shared memory segment id
+ int id = shmget(unix_key, 0, (mode == QSharedMemory::ReadOnly ? 0400 : 0600));
+ if (-1 == id) {
+ setErrorString(QLatin1String("QSharedMemory::attach (shmget)"));
+ return false;
+ }
+
+ // grab the memory
+ memory = shmat(id, 0, (mode == QSharedMemory::ReadOnly ? SHM_RDONLY : 0));
+ if ((void*) - 1 == memory) {
+ memory = 0;
+ setErrorString(QLatin1String("QSharedMemory::attach (shmat)"));
+ return false;
+ }
+
+ // grab the size
+ shmid_ds shmid_ds;
+ if (!shmctl(id, IPC_STAT, &shmid_ds)) {
+ size = (int)shmid_ds.shm_segsz;
+ } else {
+ setErrorString(QLatin1String("QSharedMemory::attach (shmctl)"));
+ return false;
+ }
+
+ return true;
+}
+
+bool QSharedMemoryPrivate::detach()
+{
+ // detach from the memory segment
+ if (-1 == shmdt(memory)) {
+ QString function = QLatin1String("QSharedMemory::detach");
+ switch (errno) {
+ case EINVAL:
+ errorString = QSharedMemory::tr("%1: not attached").arg(function);
+ error = QSharedMemory::NotFound;
+ break;
+ default:
+ setErrorString(function);
+ }
+ return false;
+ }
+ memory = 0;
+ size = 0;
+
+ // Get the number of current attachments
+ int id = shmget(unix_key, 0, 0400);
+ cleanHandle();
+
+ struct shmid_ds shmid_ds;
+ if (0 != shmctl(id, IPC_STAT, &shmid_ds)) {
+ switch (errno) {
+ case EINVAL:
+ return true;
+ default:
+ return false;
+ }
+ }
+ // If there are no attachments then remove it.
+ if (shmid_ds.shm_nattch == 0) {
+ // mark for removal
+ if (-1 == shmctl(id, IPC_RMID, &shmid_ds)) {
+ setErrorString(QLatin1String("QSharedMemory::remove"));
+ switch (errno) {
+ case EINVAL:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ // remove file
+ if (!QFile::remove(nativeKey))
+ return false;
+ }
+ return true;
+}
+
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_SHAREDMEMORY
+
+#endif // QT_POSIX_IPC
diff --git a/src/corelib/kernel/qsharedmemory_unix.cpp b/src/corelib/kernel/qsharedmemory_unix.cpp
index 8d616af4fe..5ba770c212 100644
--- a/src/corelib/kernel/qsharedmemory_unix.cpp
+++ b/src/corelib/kernel/qsharedmemory_unix.cpp
@@ -36,7 +36,6 @@
#include "qsharedmemory.h"
#include "qsharedmemory_p.h"
#include "qsystemsemaphore.h"
-#include <qdir.h>
#include <qdebug.h>
#include <errno.h>
@@ -44,7 +43,11 @@
#ifndef QT_NO_SHAREDMEMORY
#include <sys/types.h>
#include <sys/ipc.h>
+#ifndef QT_POSIX_IPC
#include <sys/shm.h>
+#else
+#include <sys/mman.h>
+#endif
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
@@ -60,7 +63,11 @@ QSharedMemoryPrivate::QSharedMemoryPrivate()
#ifndef QT_NO_SYSTEMSEMAPHORE
systemSemaphore(QString()), lockedByMe(false),
#endif
+#ifndef QT_POSIX_IPC
unix_key(0)
+#else
+ hand(-1)
+#endif
{
}
@@ -95,196 +102,6 @@ void QSharedMemoryPrivate::setErrorString(const QString &function)
}
}
-/*!
- \internal
-
- If not already made create the handle used for accessing the shared memory.
-*/
-key_t QSharedMemoryPrivate::handle()
-{
- // already made
- if (unix_key)
- return unix_key;
-
- // don't allow making handles on empty keys
- if (nativeKey.isEmpty()) {
- errorString = QSharedMemory::tr("%1: key is empty").arg(QLatin1String("QSharedMemory::handle:"));
- error = QSharedMemory::KeyError;
- return 0;
- }
-
- // ftok requires that an actual file exists somewhere
- if (!QFile::exists(nativeKey)) {
- errorString = QSharedMemory::tr("%1: UNIX key file doesn't exist").arg(QLatin1String("QSharedMemory::handle:"));
- error = QSharedMemory::NotFound;
- return 0;
- }
-
- unix_key = ftok(QFile::encodeName(nativeKey).constData(), 'Q');
- if (-1 == unix_key) {
- errorString = QSharedMemory::tr("%1: ftok failed").arg(QLatin1String("QSharedMemory::handle:"));
- error = QSharedMemory::KeyError;
- unix_key = 0;
- }
- return unix_key;
-}
-
-#endif // QT_NO_SHAREDMEMORY
-
-#if !(defined(QT_NO_SHAREDMEMORY) && defined(QT_NO_SYSTEMSEMAPHORE))
-/*!
- \internal
- Creates the unix file if needed.
- returns \c true if the unix file was created.
-
- -1 error
- 0 already existed
- 1 created
- */
-int QSharedMemoryPrivate::createUnixKeyFile(const QString &fileName)
-{
- int fd = qt_safe_open(QFile::encodeName(fileName).constData(),
- O_EXCL | O_CREAT | O_RDWR, 0640);
- if (-1 == fd) {
- if (errno == EEXIST)
- return 0;
- return -1;
- } else {
- close(fd);
- }
- return 1;
-}
-#endif // QT_NO_SHAREDMEMORY && QT_NO_SYSTEMSEMAPHORE
-
-#ifndef QT_NO_SHAREDMEMORY
-
-bool QSharedMemoryPrivate::cleanHandle()
-{
- unix_key = 0;
- return true;
-}
-
-bool QSharedMemoryPrivate::create(int size)
-{
- // build file if needed
- bool createdFile = false;
- int built = createUnixKeyFile(nativeKey);
- if (built == -1) {
- errorString = QSharedMemory::tr("%1: unable to make key").arg(QLatin1String("QSharedMemory::handle:"));
- error = QSharedMemory::KeyError;
- return false;
- }
- if (built == 1) {
- createdFile = true;
- }
-
- // get handle
- if (!handle()) {
- if (createdFile)
- QFile::remove(nativeKey);
- return false;
- }
-
- // create
- if (-1 == shmget(unix_key, size, 0600 | IPC_CREAT | IPC_EXCL)) {
- QString function = QLatin1String("QSharedMemory::create");
- switch (errno) {
- case EINVAL:
- errorString = QSharedMemory::tr("%1: system-imposed size restrictions").arg(QLatin1String("QSharedMemory::handle"));
- error = QSharedMemory::InvalidSize;
- break;
- default:
- setErrorString(function);
- }
- if (createdFile && error != QSharedMemory::AlreadyExists)
- QFile::remove(nativeKey);
- return false;
- }
-
- return true;
-}
-
-bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode)
-{
- // grab the shared memory segment id
- int id = shmget(unix_key, 0, (mode == QSharedMemory::ReadOnly ? 0400 : 0600));
- if (-1 == id) {
- setErrorString(QLatin1String("QSharedMemory::attach (shmget)"));
- return false;
- }
-
- // grab the memory
- memory = shmat(id, 0, (mode == QSharedMemory::ReadOnly ? SHM_RDONLY : 0));
- if ((void*) - 1 == memory) {
- memory = 0;
- setErrorString(QLatin1String("QSharedMemory::attach (shmat)"));
- return false;
- }
-
- // grab the size
- shmid_ds shmid_ds;
- if (!shmctl(id, IPC_STAT, &shmid_ds)) {
- size = (int)shmid_ds.shm_segsz;
- } else {
- setErrorString(QLatin1String("QSharedMemory::attach (shmctl)"));
- return false;
- }
-
- return true;
-}
-
-bool QSharedMemoryPrivate::detach()
-{
- // detach from the memory segment
- if (-1 == shmdt(memory)) {
- QString function = QLatin1String("QSharedMemory::detach");
- switch (errno) {
- case EINVAL:
- errorString = QSharedMemory::tr("%1: not attached").arg(function);
- error = QSharedMemory::NotFound;
- break;
- default:
- setErrorString(function);
- }
- return false;
- }
- memory = 0;
- size = 0;
-
- // Get the number of current attachments
- int id = shmget(unix_key, 0, 0400);
- cleanHandle();
-
- struct shmid_ds shmid_ds;
- if (0 != shmctl(id, IPC_STAT, &shmid_ds)) {
- switch (errno) {
- case EINVAL:
- return true;
- default:
- return false;
- }
- }
- // If there are no attachments then remove it.
- if (shmid_ds.shm_nattch == 0) {
- // mark for removal
- if (-1 == shmctl(id, IPC_RMID, &shmid_ds)) {
- setErrorString(QLatin1String("QSharedMemory::remove"));
- switch (errno) {
- case EINVAL:
- return true;
- default:
- return false;
- }
- }
-
- // remove file
- if (!QFile::remove(nativeKey))
- return false;
- }
- return true;
-}
-
-
QT_END_NAMESPACE
#endif // QT_NO_SHAREDMEMORY
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/qsystemsemaphore.cpp b/src/corelib/kernel/qsystemsemaphore.cpp
index 27955885a8..bf6b0ef4cf 100644
--- a/src/corelib/kernel/qsystemsemaphore.cpp
+++ b/src/corelib/kernel/qsystemsemaphore.cpp
@@ -222,7 +222,7 @@ void QSystemSemaphore::setKey(const QString &key, int initialValue, AccessMode m
if (key == d->key && mode == Open)
return;
d->clearError();
-#if !defined(Q_OS_WIN)
+#if !defined(Q_OS_WIN) && !defined(QT_POSIX_IPC)
// optimization to not destroy/create the file & semaphore
if (key == d->key && mode == Create && d->createdSemaphore && d->createdFile) {
d->initialValue = initialValue;
diff --git a/src/corelib/kernel/qsystemsemaphore_android.cpp b/src/corelib/kernel/qsystemsemaphore_android.cpp
index 8ff47960f8..f80bb8e548 100644
--- a/src/corelib/kernel/qsystemsemaphore_android.cpp
+++ b/src/corelib/kernel/qsystemsemaphore_android.cpp
@@ -41,8 +41,8 @@
QT_BEGIN_NAMESPACE
QSystemSemaphorePrivate::QSystemSemaphorePrivate() :
- semaphore(-1), createdFile(false),
- createdSemaphore(false), unix_key(-1), error(QSystemSemaphore::NoError)
+ unix_key(-1), semaphore(-1), createdFile(false),
+ createdSemaphore(false), error(QSystemSemaphore::NoError)
{
}
diff --git a/src/corelib/kernel/qsystemsemaphore_p.h b/src/corelib/kernel/qsystemsemaphore_p.h
index d71ab4bc36..762c54480d 100644
--- a/src/corelib/kernel/qsystemsemaphore_p.h
+++ b/src/corelib/kernel/qsystemsemaphore_p.h
@@ -53,6 +53,9 @@
#ifndef Q_OS_WINCE
# include <sys/types.h>
#endif
+#ifdef QT_POSIX_IPC
+# include <semaphore.h>
+#endif
QT_BEGIN_NAMESPACE
@@ -75,6 +78,9 @@ public:
#ifdef Q_OS_WIN
Qt::HANDLE handle(QSystemSemaphore::AccessMode mode = QSystemSemaphore::Open);
void setErrorString(const QString &function);
+#elif defined(QT_POSIX_IPC)
+ bool handle(QSystemSemaphore::AccessMode mode = QSystemSemaphore::Open);
+ void setErrorString(const QString &function);
#else
key_t handle(QSystemSemaphore::AccessMode mode = QSystemSemaphore::Open);
void setErrorString(const QString &function);
@@ -88,11 +94,14 @@ public:
#ifdef Q_OS_WIN
Qt::HANDLE semaphore;
Qt::HANDLE semaphoreLock;
+#elif defined(QT_POSIX_IPC)
+ sem_t *semaphore;
+ bool createdSemaphore;
#else
+ key_t unix_key;
int semaphore;
bool createdFile;
bool createdSemaphore;
- key_t unix_key;
#endif
QString errorString;
QSystemSemaphore::SystemSemaphoreError error;
diff --git a/src/corelib/kernel/qsystemsemaphore_posix.cpp b/src/corelib/kernel/qsystemsemaphore_posix.cpp
new file mode 100644
index 0000000000..1ee643a6ab
--- /dev/null
+++ b/src/corelib/kernel/qsystemsemaphore_posix.cpp
@@ -0,0 +1,182 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Konstantin Ritt <ritt.ks@gmail.com>
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Tobias Koenig <tobias.koenig@kdab.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 "qsystemsemaphore.h"
+#include "qsystemsemaphore_p.h"
+
+#include <qdebug.h>
+#include <qfile.h>
+#include <qcoreapplication.h>
+
+#ifdef QT_POSIX_IPC
+
+#ifndef QT_NO_SYSTEMSEMAPHORE
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "private/qcore_unix_p.h"
+
+// OpenBSD 4.2 doesn't define EIDRM, see BUGS section:
+// http://www.openbsd.org/cgi-bin/man.cgi?query=semop&manpath=OpenBSD+4.2
+#if defined(Q_OS_OPENBSD) && !defined(EIDRM)
+#define EIDRM EINVAL
+#endif
+
+QT_BEGIN_NAMESPACE
+
+bool QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode)
+{
+ if (semaphore != SEM_FAILED)
+ return true; // we already have a semaphore
+
+ if (fileName.isEmpty()) {
+ errorString = QCoreApplication::tr("%1: key is empty", "QSystemSemaphore").arg(QLatin1String("QSystemSemaphore::handle"));
+ error = QSystemSemaphore::KeyError;
+ return false;
+ }
+
+ const QByteArray semName = QFile::encodeName(fileName);
+
+ // Always try with O_EXCL so we know whether we created the semaphore.
+ int oflag = O_CREAT | O_EXCL;
+ for (int tryNum = 0, maxTries = 1; tryNum < maxTries; ++tryNum) {
+ do {
+ semaphore = ::sem_open(semName.constData(), oflag, 0600, initialValue);
+ } while (semaphore == SEM_FAILED && errno == EINTR);
+ if (semaphore == SEM_FAILED && errno == EEXIST) {
+ if (mode == QSystemSemaphore::Create) {
+ if (::sem_unlink(semName.constData()) == -1 && errno != ENOENT) {
+ setErrorString(QLatin1String("QSystemSemaphore::handle (sem_unlink)"));
+ return false;
+ }
+ // Race condition: the semaphore might be recreated before
+ // we call sem_open again, so we'll retry several times.
+ maxTries = 3;
+ } else {
+ // Race condition: if it no longer exists at the next sem_open
+ // call, we won't realize we created it, so we'll leak it later.
+ oflag &= ~O_EXCL;
+ maxTries = 2;
+ }
+ } else {
+ break;
+ }
+ }
+
+ if (semaphore == SEM_FAILED) {
+ setErrorString(QLatin1String("QSystemSemaphore::handle"));
+ return false;
+ }
+
+ createdSemaphore = (oflag & O_EXCL) != 0;
+
+ return true;
+}
+
+void QSystemSemaphorePrivate::cleanHandle()
+{
+ if (semaphore != SEM_FAILED) {
+ if (::sem_close(semaphore) == -1) {
+ setErrorString(QLatin1String("QSystemSemaphore::cleanHandle (sem_close)"));
+#if defined QSYSTEMSEMAPHORE_DEBUG
+ qDebug() << QLatin1String("QSystemSemaphore::cleanHandle sem_close failed.");
+#endif
+ }
+ semaphore = SEM_FAILED;
+ }
+
+ if (createdSemaphore) {
+ if (::sem_unlink(QFile::encodeName(fileName).constData()) == -1 && errno != ENOENT) {
+ setErrorString(QLatin1String("QSystemSemaphore::cleanHandle (sem_unlink)"));
+#if defined QSYSTEMSEMAPHORE_DEBUG
+ qDebug() << QLatin1String("QSystemSemaphore::cleanHandle sem_unlink failed.");
+#endif
+ }
+ createdSemaphore = false;
+ }
+}
+
+bool QSystemSemaphorePrivate::modifySemaphore(int count)
+{
+ if (!handle())
+ return false;
+
+ if (count > 0) {
+ int cnt = count;
+ do {
+ if (::sem_post(semaphore) == -1) {
+ setErrorString(QLatin1String("QSystemSemaphore::modifySemaphore (sem_post)"));
+#if defined QSYSTEMSEMAPHORE_DEBUG
+ qDebug() << QLatin1String("QSystemSemaphore::modify sem_post failed") << count << errno;
+#endif
+ // rollback changes to preserve the SysV semaphore behavior
+ for ( ; cnt < count; ++cnt) {
+ int res;
+ EINTR_LOOP(res, ::sem_wait(semaphore));
+ }
+ return false;
+ }
+ --cnt;
+ } while (cnt > 0);
+ } else {
+ int res;
+ EINTR_LOOP(res, ::sem_wait(semaphore));
+ if (res == -1) {
+ // If the semaphore was removed be nice and create it and then modifySemaphore again
+ if (errno == EINVAL || errno == EIDRM) {
+ semaphore = SEM_FAILED;
+ return modifySemaphore(count);
+ }
+ setErrorString(QLatin1String("QSystemSemaphore::modifySemaphore (sem_wait)"));
+#if defined QSYSTEMSEMAPHORE_DEBUG
+ qDebug() << QLatin1String("QSystemSemaphore::modify sem_wait failed") << count << errno;
+#endif
+ return false;
+ }
+ }
+
+ clearError();
+ return true;
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_SYSTEMSEMAPHORE
+
+#endif // QT_POSIX_IPC
diff --git a/src/corelib/kernel/qsystemsemaphore_systemv.cpp b/src/corelib/kernel/qsystemsemaphore_systemv.cpp
new file mode 100644
index 0000000000..f212f5e49f
--- /dev/null
+++ b/src/corelib/kernel/qsystemsemaphore_systemv.cpp
@@ -0,0 +1,198 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** 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 "qsystemsemaphore.h"
+#include "qsystemsemaphore_p.h"
+
+#include <qdebug.h>
+#include <qfile.h>
+#include <qcoreapplication.h>
+
+#ifndef QT_POSIX_IPC
+
+#ifndef QT_NO_SYSTEMSEMAPHORE
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "private/qcore_unix_p.h"
+
+// OpenBSD 4.2 doesn't define EIDRM, see BUGS section:
+// http://www.openbsd.org/cgi-bin/man.cgi?query=semop&manpath=OpenBSD+4.2
+#if defined(Q_OS_OPENBSD) && !defined(EIDRM)
+#define EIDRM EINVAL
+#endif
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \internal
+
+ Setup unix_key
+ */
+key_t QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode)
+{
+ if (key.isEmpty()){
+ errorString = QCoreApplication::tr("%1: key is empty", "QSystemSemaphore").arg(QLatin1String("QSystemSemaphore::handle:"));
+ error = QSystemSemaphore::KeyError;
+ return -1;
+ }
+
+ // ftok requires that an actual file exists somewhere
+ if (-1 != unix_key)
+ return unix_key;
+
+ // Create the file needed for ftok
+ int built = QSharedMemoryPrivate::createUnixKeyFile(fileName);
+ if (-1 == built) {
+ errorString = QCoreApplication::tr("%1: unable to make key", "QSystemSemaphore").arg(QLatin1String("QSystemSemaphore::handle:"));
+ error = QSystemSemaphore::KeyError;
+ return -1;
+ }
+ createdFile = (1 == built);
+
+ // Get the unix key for the created file
+ unix_key = ftok(QFile::encodeName(fileName).constData(), 'Q');
+ if (-1 == unix_key) {
+ errorString = QCoreApplication::tr("%1: ftok failed", "QSystemSemaphore").arg(QLatin1String("QSystemSemaphore::handle:"));
+ error = QSystemSemaphore::KeyError;
+ return -1;
+ }
+
+ // Get semaphore
+ semaphore = semget(unix_key, 1, 0600 | IPC_CREAT | IPC_EXCL);
+ if (-1 == semaphore) {
+ if (errno == EEXIST)
+ semaphore = semget(unix_key, 1, 0600 | IPC_CREAT);
+ if (-1 == semaphore) {
+ setErrorString(QLatin1String("QSystemSemaphore::handle"));
+ cleanHandle();
+ return -1;
+ }
+ } else {
+ createdSemaphore = true;
+ // Force cleanup of file, it is possible that it can be left over from a crash
+ createdFile = true;
+ }
+
+ if (mode == QSystemSemaphore::Create) {
+ createdSemaphore = true;
+ createdFile = true;
+ }
+
+ // Created semaphore so initialize its value.
+ if (createdSemaphore && initialValue >= 0) {
+ qt_semun init_op;
+ init_op.val = initialValue;
+ if (-1 == semctl(semaphore, 0, SETVAL, init_op)) {
+ setErrorString(QLatin1String("QSystemSemaphore::handle"));
+ cleanHandle();
+ return -1;
+ }
+ }
+
+ return unix_key;
+}
+
+/*!
+ \internal
+
+ Cleanup the unix_key
+ */
+void QSystemSemaphorePrivate::cleanHandle()
+{
+ unix_key = -1;
+
+ // remove the file if we made it
+ if (createdFile) {
+ QFile::remove(fileName);
+ createdFile = false;
+ }
+
+ if (createdSemaphore) {
+ if (-1 != semaphore) {
+ if (-1 == semctl(semaphore, 0, IPC_RMID, 0)) {
+ setErrorString(QLatin1String("QSystemSemaphore::cleanHandle"));
+#if defined QSYSTEMSEMAPHORE_DEBUG
+ qDebug() << QLatin1String("QSystemSemaphore::cleanHandle semctl failed.");
+#endif
+ }
+ semaphore = -1;
+ }
+ createdSemaphore = false;
+ }
+}
+
+/*!
+ \internal
+ */
+bool QSystemSemaphorePrivate::modifySemaphore(int count)
+{
+ if (-1 == handle())
+ return false;
+
+ struct sembuf operation;
+ operation.sem_num = 0;
+ operation.sem_op = count;
+ operation.sem_flg = SEM_UNDO;
+
+ int res;
+ EINTR_LOOP(res, semop(semaphore, &operation, 1));
+ if (-1 == res) {
+ // If the semaphore was removed be nice and create it and then modifySemaphore again
+ if (errno == EINVAL || errno == EIDRM) {
+ semaphore = -1;
+ cleanHandle();
+ handle();
+ return modifySemaphore(count);
+ }
+ setErrorString(QLatin1String("QSystemSemaphore::modifySemaphore"));
+#if defined QSYSTEMSEMAPHORE_DEBUG
+ qDebug() << QLatin1String("QSystemSemaphore::modify failed") << count << semctl(semaphore, 0, GETVAL) << errno << EIDRM << EINVAL;
+#endif
+ return false;
+ }
+
+ clearError();
+ return true;
+}
+
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_SYSTEMSEMAPHORE
+
+#endif // QT_POSIX_IPC
diff --git a/src/corelib/kernel/qsystemsemaphore_unix.cpp b/src/corelib/kernel/qsystemsemaphore_unix.cpp
index 3d0cc76804..e8b3f14375 100644
--- a/src/corelib/kernel/qsystemsemaphore_unix.cpp
+++ b/src/corelib/kernel/qsystemsemaphore_unix.cpp
@@ -35,30 +35,29 @@
#include "qsystemsemaphore_p.h"
#include <qdebug.h>
-#include <qfile.h>
#include <qcoreapplication.h>
#ifndef QT_NO_SYSTEMSEMAPHORE
#include <sys/types.h>
#include <sys/ipc.h>
+#ifndef QT_POSIX_IPC
#include <sys/sem.h>
+#endif
#include <fcntl.h>
#include <errno.h>
#include "private/qcore_unix_p.h"
-// OpenBSD 4.2 doesn't define EIDRM, see BUGS section:
-// http://www.openbsd.org/cgi-bin/man.cgi?query=semop&manpath=OpenBSD+4.2
-#if defined(Q_OS_OPENBSD) && !defined(EIDRM)
-#define EIDRM EINVAL
-#endif
-
QT_BEGIN_NAMESPACE
QSystemSemaphorePrivate::QSystemSemaphorePrivate() :
- semaphore(-1), createdFile(false),
- createdSemaphore(false), unix_key(-1), error(QSystemSemaphore::NoError)
+#ifndef QT_POSIX_IPC
+ unix_key(-1), semaphore(-1), createdFile(false),
+#else
+ semaphore(SEM_FAILED),
+#endif // QT_POSIX_IPC
+ createdSemaphore(false), error(QSystemSemaphore::NoError)
{
}
@@ -93,139 +92,6 @@ void QSystemSemaphorePrivate::setErrorString(const QString &function)
}
}
-/*!
- \internal
-
- Setup unix_key
- */
-key_t QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode)
-{
- if (key.isEmpty()){
- errorString = QCoreApplication::tr("%1: key is empty", "QSystemSemaphore").arg(QLatin1String("QSystemSemaphore::handle:"));
- error = QSystemSemaphore::KeyError;
- return -1;
- }
-
- // ftok requires that an actual file exists somewhere
- if (-1 != unix_key)
- return unix_key;
-
- // Create the file needed for ftok
- int built = QSharedMemoryPrivate::createUnixKeyFile(fileName);
- if (-1 == built) {
- errorString = QCoreApplication::tr("%1: unable to make key", "QSystemSemaphore").arg(QLatin1String("QSystemSemaphore::handle:"));
- error = QSystemSemaphore::KeyError;
- return -1;
- }
- createdFile = (1 == built);
-
- // Get the unix key for the created file
- unix_key = ftok(QFile::encodeName(fileName).constData(), 'Q');
- if (-1 == unix_key) {
- errorString = QCoreApplication::tr("%1: ftok failed", "QSystemSemaphore").arg(QLatin1String("QSystemSemaphore::handle:"));
- error = QSystemSemaphore::KeyError;
- return -1;
- }
-
- // Get semaphore
- semaphore = semget(unix_key, 1, 0600 | IPC_CREAT | IPC_EXCL);
- if (-1 == semaphore) {
- if (errno == EEXIST)
- semaphore = semget(unix_key, 1, 0600 | IPC_CREAT);
- if (-1 == semaphore) {
- setErrorString(QLatin1String("QSystemSemaphore::handle"));
- cleanHandle();
- return -1;
- }
- } else {
- createdSemaphore = true;
- // Force cleanup of file, it is possible that it can be left over from a crash
- createdFile = true;
- }
-
- if (mode == QSystemSemaphore::Create) {
- createdSemaphore = true;
- createdFile = true;
- }
-
- // Created semaphore so initialize its value.
- if (createdSemaphore && initialValue >= 0) {
- qt_semun init_op;
- init_op.val = initialValue;
- if (-1 == semctl(semaphore, 0, SETVAL, init_op)) {
- setErrorString(QLatin1String("QSystemSemaphore::handle"));
- cleanHandle();
- return -1;
- }
- }
-
- return unix_key;
-}
-
-/*!
- \internal
-
- Cleanup the unix_key
- */
-void QSystemSemaphorePrivate::cleanHandle()
-{
- unix_key = -1;
-
- // remove the file if we made it
- if (createdFile) {
- QFile::remove(fileName);
- createdFile = false;
- }
-
- if (createdSemaphore) {
- if (-1 != semaphore) {
- if (-1 == semctl(semaphore, 0, IPC_RMID, 0)) {
- setErrorString(QLatin1String("QSystemSemaphore::cleanHandle"));
-#if defined QSYSTEMSEMAPHORE_DEBUG
- qDebug() << QLatin1String("QSystemSemaphore::cleanHandle semctl failed.");
-#endif
- }
- semaphore = -1;
- }
- createdSemaphore = false;
- }
-}
-
-/*!
- \internal
- */
-bool QSystemSemaphorePrivate::modifySemaphore(int count)
-{
- if (-1 == handle())
- return false;
-
- struct sembuf operation;
- operation.sem_num = 0;
- operation.sem_op = count;
- operation.sem_flg = SEM_UNDO;
-
- int res;
- EINTR_LOOP(res, semop(semaphore, &operation, 1));
- if (-1 == res) {
- // If the semaphore was removed be nice and create it and then modifySemaphore again
- if (errno == EINVAL || errno == EIDRM) {
- semaphore = -1;
- cleanHandle();
- handle();
- return modifySemaphore(count);
- }
- setErrorString(QLatin1String("QSystemSemaphore::modifySemaphore"));
-#if defined QSYSTEMSEMAPHORE_DEBUG
- qDebug() << QLatin1String("QSystemSemaphore::modify failed") << count << semctl(semaphore, 0, GETVAL) << errno << EIDRM << EINVAL;
-#endif
- return false;
- }
-
- clearError();
- return true;
-}
-
-
QT_END_NAMESPACE
#endif // QT_NO_SYSTEMSEMAPHORE
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 f76201802b..df1b4ed872 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,26 +3183,137 @@ 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;
- if (QMetaType::compare(QT_PREPEND_NAMESPACE(constData(v1.d)), QT_PREPEND_NAMESPACE(constData(v2.d)), v1.d.type, &result))
+ if (QMetaType::equals(QT_PREPEND_NAMESPACE(constData(v1.d)), QT_PREPEND_NAMESPACE(constData(v2.d)), v1.d.type, &result))
return result == 0;
}
return handlerManager[v1.d.type]->compare(&v1.d, &v2.d);
@@ -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;
@@ -3844,11 +4001,11 @@ void QAssociativeIterable::const_iterator::end()
m_impl.end();
}
-void find(QAssociativeIterable::const_iterator &it, const QVariant &key)
+void QAssociativeIterable::const_iterator::find(const QVariant &key)
{
- Q_ASSERT(key.userType() == it.m_impl._metaType_id_key);
+ Q_ASSERT(key.userType() == m_impl._metaType_id_key);
const QtMetaTypePrivate::VariantData dkey(key.userType(), key.constData(), 0 /*key.flags()*/);
- it.m_impl.find(dkey);
+ m_impl.find(dkey);
}
/*!
@@ -3878,7 +4035,7 @@ QAssociativeIterable::const_iterator QAssociativeIterable::end() const
}
/*!
- \internal
+ \since 5.5
Returns a QAssociativeIterable::const_iterator for the given key \a key
in the container, if the types are convertible.
@@ -3889,12 +4046,12 @@ QAssociativeIterable::const_iterator QAssociativeIterable::end() const
\sa begin(), end(), value()
*/
-QAssociativeIterable::const_iterator find(const QAssociativeIterable &iterable, const QVariant &key)
+QAssociativeIterable::const_iterator QAssociativeIterable::find(const QVariant &key) const
{
- QAssociativeIterable::const_iterator it(iterable, new QAtomicInt(0));
+ const_iterator it(*this, new QAtomicInt(0));
QVariant key_ = key;
- if (key_.canConvert(iterable.m_impl._metaType_id_key) && key_.convert(iterable.m_impl._metaType_id_key))
- find(it, key_);
+ if (key_.canConvert(m_impl._metaType_id_key) && key_.convert(m_impl._metaType_id_key))
+ it.find(key_);
else
it.end();
return it;
@@ -3902,10 +4059,12 @@ QAssociativeIterable::const_iterator find(const QAssociativeIterable &iterable,
/*!
Returns the value for the given \a key in the container, if the types are convertible.
+
+ \sa find()
*/
QVariant QAssociativeIterable::value(const QVariant &key) const
{
- const const_iterator it = find(*this, key);
+ const const_iterator it = find(key);
if (it == end())
return QVariant();
return *it;
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h
index 90f3e8fbae..c9513a837b 100644
--- a/src/corelib/kernel/qvariant.h
+++ b/src/corelib/kernel/qvariant.h
@@ -189,7 +189,7 @@ class Q_CORE_EXPORT QVariant
LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type
};
- inline QVariant();
+ QVariant() Q_DECL_NOTHROW : d() {}
~QVariant();
QVariant(Type type);
QVariant(int typeId, const void *copy);
@@ -253,13 +253,13 @@ class Q_CORE_EXPORT QVariant
QVariant& operator=(const QVariant &other);
#ifdef Q_COMPILER_RVALUE_REFS
- inline QVariant(QVariant &&other) : d(other.d)
+ inline QVariant(QVariant &&other) Q_DECL_NOTHROW : d(other.d)
{ other.d = Private(); }
- inline QVariant &operator=(QVariant &&other)
+ inline QVariant &operator=(QVariant &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
- inline void swap(QVariant &other) { qSwap(d, other.d); }
+ inline void swap(QVariant &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
Type type() const;
int userType() const;
@@ -360,15 +360,15 @@ class Q_CORE_EXPORT QVariant
};
struct Private
{
- inline Private(): type(Invalid), is_shared(false), is_null(true)
+ inline Private() Q_DECL_NOTHROW : type(Invalid), is_shared(false), is_null(true)
{ data.ptr = 0; }
// Internal constructor for initialized variants.
- explicit inline Private(uint variantType)
+ explicit inline Private(uint variantType) Q_DECL_NOTHROW
: type(variantType), is_shared(false), is_null(false)
{}
- inline Private(const Private &other)
+ inline Private(const Private &other) Q_DECL_NOTHROW
: data(other.data), type(other.type),
is_shared(other.is_shared), is_null(other.is_null)
{}
@@ -520,8 +520,6 @@ inline void qVariantSetValue<QVariant>(QVariant &v, const QVariant &t)
v = t;
}
-
-inline QVariant::QVariant() {}
inline bool QVariant::isValid() const { return d.type != Invalid; }
template<typename T>
@@ -633,9 +631,7 @@ public:
void begin();
void end();
- // ### Qt 5.5: make find() (1st one) a member function
- friend void find(const_iterator &it, const QVariant &key);
- friend const_iterator find(const QAssociativeIterable &iterable, const QVariant &key);
+ void find(const QVariant &key);
public:
~const_iterator();
const_iterator(const const_iterator &other);
@@ -665,9 +661,7 @@ public:
const_iterator begin() const;
const_iterator end() const;
-private: // ### Qt 5.5: make it a public find() member function:
- friend const_iterator find(const QAssociativeIterable &iterable, const QVariant &key);
-public:
+ const_iterator find(const QVariant &key) const;
QVariant value(const QVariant &key) const;
diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h
index 9b9e266f8e..9e4f468872 100644
--- a/src/corelib/kernel/qvariant_p.h
+++ b/src/corelib/kernel/qvariant_p.h
@@ -54,7 +54,6 @@
QT_BEGIN_NAMESPACE
-namespace {
template<typename T>
struct QVariantIntegrator
{
@@ -64,7 +63,6 @@ struct QVariantIntegrator
Q_STATIC_ASSERT(QVariantIntegrator<double>::CanUseInternalSpace);
Q_STATIC_ASSERT(QVariantIntegrator<long int>::CanUseInternalSpace);
Q_STATIC_ASSERT(QVariantIntegrator<qulonglong>::CanUseInternalSpace);
-} // namespace
#ifdef Q_CC_SUN // Sun CC picks the wrong overload, so introduce awful hack
@@ -104,7 +102,7 @@ inline T *v_cast(QVariant::Private *d, T * = 0)
template <class T> class QVariantPrivateSharedEx : public QVariant::PrivateShared
{
public:
- QVariantPrivateSharedEx() : QVariant::PrivateShared(&m_t) { }
+ QVariantPrivateSharedEx() : QVariant::PrivateShared(&m_t), m_t() { }
QVariantPrivateSharedEx(const T&t) : QVariant::PrivateShared(&m_t), m_t(t) { }
private:
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/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp
index bd5032dcc0..e474450dd1 100644
--- a/src/corelib/plugin/qfactoryloader.cpp
+++ b/src/corelib/plugin/qfactoryloader.cpp
@@ -54,6 +54,16 @@ Q_GLOBAL_STATIC(QList<QFactoryLoader *>, qt_factory_loaders)
Q_GLOBAL_STATIC_WITH_ARGS(QMutex, qt_factoryloader_mutex, (QMutex::Recursive))
+namespace {
+
+// avoid duplicate QStringLiteral data:
+inline QString iidKeyLiteral() { return QStringLiteral("IID"); }
+inline QString versionKeyLiteral() { return QStringLiteral("version"); }
+inline QString metaDataKeyLiteral() { return QStringLiteral("MetaData"); }
+inline QString keysKeyLiteral() { return QStringLiteral("Keys"); }
+
+}
+
class QFactoryLoaderPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QFactoryLoader)
@@ -162,12 +172,12 @@ void QFactoryLoader::update()
QStringList keys;
bool metaDataOk = false;
- QString iid = library->metaData.value(QLatin1String("IID")).toString();
+ QString iid = library->metaData.value(iidKeyLiteral()).toString();
if (iid == QLatin1String(d->iid.constData(), d->iid.size())) {
- QJsonObject object = library->metaData.value(QLatin1String("MetaData")).toObject();
+ QJsonObject object = library->metaData.value(metaDataKeyLiteral()).toObject();
metaDataOk = true;
- QJsonArray k = object.value(QLatin1String("Keys")).toArray();
+ QJsonArray k = object.value(keysKeyLiteral()).toArray();
for (int i = 0; i < k.size(); ++i)
keys += d->cs ? k.at(i).toString() : k.at(i).toString().toLower();
}
@@ -190,9 +200,9 @@ void QFactoryLoader::update()
QLibraryPrivate *previous = d->keyMap.value(key);
int prev_qt_version = 0;
if (previous) {
- prev_qt_version = (int)previous->metaData.value(QLatin1String("version")).toDouble();
+ prev_qt_version = (int)previous->metaData.value(versionKeyLiteral()).toDouble();
}
- int qt_version = (int)library->metaData.value(QLatin1String("version")).toDouble();
+ int qt_version = (int)library->metaData.value(versionKeyLiteral()).toDouble();
if (!previous || (prev_qt_version > QT_VERSION && qt_version <= QT_VERSION)) {
d->keyMap[key] = library;
++keyUsageCount;
@@ -229,7 +239,7 @@ QList<QJsonObject> QFactoryLoader::metaData() const
foreach (const QStaticPlugin &plugin, QPluginLoader::staticPlugins()) {
const QJsonObject object = plugin.metaData();
- if (object.value(QLatin1String("IID")) != QLatin1String(d->iid.constData(), d->iid.size()))
+ if (object.value(iidKeyLiteral()) != QLatin1String(d->iid.constData(), d->iid.size()))
continue;
metaData.append(object);
}
@@ -261,7 +271,7 @@ QObject *QFactoryLoader::instance(int index) const
QVector<QStaticPlugin> staticPlugins = QPluginLoader::staticPlugins();
for (int i = 0; i < staticPlugins.count(); ++i) {
const QJsonObject object = staticPlugins.at(i).metaData();
- if (object.value(QLatin1String("IID")) != QLatin1String(d->iid.constData(), d->iid.size()))
+ if (object.value(iidKeyLiteral()) != QLatin1String(d->iid.constData(), d->iid.size()))
continue;
if (index == 0)
@@ -290,10 +300,6 @@ void QFactoryLoader::refreshAll()
}
}
-// avoid duplicate QStringLiteral data:
-static inline QString metaDataKeyLiteral() { return QStringLiteral("MetaData"); }
-static inline QString keysKeyLiteral() { return QStringLiteral("Keys"); }
-
QMultiMap<int, QString> QFactoryLoader::keyMap() const
{
QMultiMap<int, QString> result;
diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp
index 832ee250c7..489cede959 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
*/
@@ -601,7 +606,7 @@ bool QLibraryPrivate::loadPlugin()
*/
bool QLibrary::isLibrary(const QString &fileName)
{
-#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
+#if defined(Q_OS_WIN)
return fileName.endsWith(QLatin1String(".dll"), Qt::CaseInsensitive);
#else
QString completeSuffix = QFileInfo(fileName).completeSuffix();
@@ -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..9f5aa421d8 100644
--- a/src/corelib/plugin/qlibrary.h
+++ b/src/corelib/plugin/qlibrary.h
@@ -47,15 +47,17 @@ class Q_CORE_EXPORT QLibrary : public QObject
Q_OBJECT
Q_PROPERTY(QString fileName READ fileName WRITE setFileName)
Q_PROPERTY(LoadHints loadHints READ loadHints WRITE setLoadHints)
- Q_FLAGS(LoadHint LoadHints)
public:
enum LoadHint {
ResolveAllSymbolsHint = 0x01,
ExportExternalSymbolsHint = 0x02,
LoadArchiveMemberHint = 0x04,
- PreventUnloadHint = 0x08
+ PreventUnloadHint = 0x08,
+ DeepBindHint = 0x10
};
Q_DECLARE_FLAGS(LoadHints, LoadHint)
+ Q_FLAG(LoadHint)
+ Q_FLAG(LoadHints)
explicit QLibrary(QObject *parent = 0);
explicit QLibrary(const QString& fileName, QObject *parent = 0);
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..cccf5430a8 100644
--- a/src/corelib/statemachine/qhistorystate.h
+++ b/src/corelib/statemachine/qhistorystate.h
@@ -47,12 +47,12 @@ class Q_CORE_EXPORT QHistoryState : public QAbstractState
Q_OBJECT
Q_PROPERTY(QAbstractState* defaultState READ defaultState WRITE setDefaultState NOTIFY defaultStateChanged)
Q_PROPERTY(HistoryType historyType READ historyType WRITE setHistoryType NOTIFY historyTypeChanged)
- Q_ENUMS(HistoryType)
public:
enum HistoryType {
ShallowHistory,
DeepHistory
};
+ Q_ENUM(HistoryType)
QHistoryState(QState *parent = 0);
QHistoryState(HistoryType type, QState *parent = 0);
@@ -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..65e927e07a 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
@@ -53,17 +53,18 @@ class Q_CORE_EXPORT QState : public QAbstractState
Q_PROPERTY(QAbstractState* initialState READ initialState WRITE setInitialState NOTIFY initialStateChanged)
Q_PROPERTY(QAbstractState* errorState READ errorState WRITE setErrorState NOTIFY errorStateChanged)
Q_PROPERTY(ChildMode childMode READ childMode WRITE setChildMode NOTIFY childModeChanged)
- Q_ENUMS(ChildMode RestorePolicy)
public:
enum ChildMode {
ExclusiveStates,
ParallelStates
};
+ Q_ENUM(ChildMode)
enum RestorePolicy {
DontRestoreProperties,
RestoreProperties
};
+ Q_ENUM(RestorePolicy)
QState(QState *parent = 0);
QState(ChildMode childMode, QState *parent = 0);
@@ -74,6 +75,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 +130,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..fa5e49c882 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -882,11 +882,10 @@ QVariant QStateMachinePrivate::savedValueForRestorable(const QList<QAbstractStat
#ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG
qDebug() << q_func() << ": savedValueForRestorable(" << exitedStates_sorted << object << propertyName << ")";
#endif
- RestorableId id(object, propertyName);
for (int i = exitedStates_sorted.size() - 1; i >= 0; --i) {
QAbstractState *s = exitedStates_sorted.at(i);
QHash<RestorableId, QVariant> restorables = registeredRestorablesForState.value(s);
- QHash<RestorableId, QVariant>::const_iterator it = restorables.constFind(id);
+ QHash<RestorableId, QVariant>::const_iterator it = restorables.constFind(RestorableId(object, propertyName));
if (it != restorables.constEnd()) {
#ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG
qDebug() << q_func() << ": using" << it.value() << "from" << s;
@@ -897,7 +896,7 @@ QVariant QStateMachinePrivate::savedValueForRestorable(const QList<QAbstractStat
#ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG
qDebug() << q_func() << ": falling back to current value";
#endif
- return id.first->property(id.second);
+ return object->property(propertyName);
}
void QStateMachinePrivate::registerRestorable(QAbstractState *state, QObject *object, const QByteArray &propertyName,
@@ -948,14 +947,15 @@ QList<QPropertyAssignment> QStateMachinePrivate::restorablesToPropertyList(const
QList<QPropertyAssignment> result;
QHash<RestorableId, QVariant>::const_iterator it;
for (it = restorables.constBegin(); it != restorables.constEnd(); ++it) {
- if (!it.key().first) {
+ const RestorableId &id = it.key();
+ if (!id.object()) {
// Property object was deleted
continue;
}
#ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG
- qDebug() << q_func() << ": restoring" << it.key().first << it.key().second << "to" << it.value();
+ qDebug() << q_func() << ": restoring" << id.object() << id.proertyName() << "to" << it.value();
#endif
- result.append(QPropertyAssignment(it.key().first, it.key().second, it.value(), /*explicitlySet=*/false));
+ result.append(QPropertyAssignment(id.object(), id.propertyName(), it.value(), /*explicitlySet=*/false));
}
return result;
}
@@ -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/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h
index 465d8aff0d..51eed07548 100644
--- a/src/corelib/statemachine/qstatemachine_p.h
+++ b/src/corelib/statemachine/qstatemachine_p.h
@@ -189,7 +189,24 @@ public:
void cancelAllDelayedEvents();
#ifndef QT_NO_PROPERTIES
- typedef QPair<QPointer<QObject>, QByteArray> RestorableId;
+ class RestorableId {
+ QPointer<QObject> guard;
+ QObject *obj;
+ QByteArray prop;
+ // two overloads because friends can't have default arguments
+ friend uint qHash(const RestorableId &key, uint seed) Q_DECL_NOEXCEPT_EXPR(noexcept(std::declval<QByteArray>()))
+ { return qHash(qMakePair(key.obj, key.prop), seed); }
+ friend uint qHash(const RestorableId &key) Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(key, 0U)))
+ { return qHash(key, 0U); }
+ friend bool operator==(const RestorableId &lhs, const RestorableId &rhs) Q_DECL_NOTHROW
+ { return lhs.obj == rhs.obj && lhs.prop == rhs.prop; }
+ friend bool operator!=(const RestorableId &lhs, const RestorableId &rhs) Q_DECL_NOTHROW
+ { return !operator==(lhs, rhs); }
+ public:
+ explicit RestorableId(QObject *o, QByteArray p) Q_DECL_NOTHROW : guard(o), obj(o), prop(qMove(p)) {}
+ QObject *object() const Q_DECL_NOTHROW { return guard; }
+ QByteArray propertyName() const Q_DECL_NOTHROW { return prop; }
+ };
QHash<QAbstractState*, QHash<RestorableId, QVariant> > registeredRestorablesForState;
bool hasRestorable(QAbstractState *state, QObject *object, const QByteArray &propertyName) const;
QVariant savedValueForRestorable(const QList<QAbstractState*> &exitedStates_sorted,
diff --git a/src/corelib/thread/qatomic.h b/src/corelib/thread/qatomic.h
index 72cb3866a5..c273973472 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/qmutex.h b/src/corelib/thread/qmutex.h
index 626ba0b1bb..acbd9f32d1 100644
--- a/src/corelib/thread/qmutex.h
+++ b/src/corelib/thread/qmutex.h
@@ -176,12 +176,12 @@ class Q_CORE_EXPORT QMutex
public:
enum RecursionMode { NonRecursive, Recursive };
- inline explicit QMutex(RecursionMode mode = NonRecursive) { Q_UNUSED(mode); }
+ inline explicit QMutex(RecursionMode mode = NonRecursive) Q_DECL_NOTHROW { Q_UNUSED(mode); }
- inline void lock() {}
- inline bool tryLock(int timeout = 0) { Q_UNUSED(timeout); return true; }
- inline void unlock() {}
- inline bool isRecursive() { return true; }
+ inline void lock() Q_DECL_NOTHROW {}
+ inline bool tryLock(int timeout = 0) Q_DECL_NOTHROW { Q_UNUSED(timeout); return true; }
+ inline void unlock() Q_DECL_NOTHROW {}
+ inline bool isRecursive() Q_DECL_NOTHROW { return true; }
private:
Q_DISABLE_COPY(QMutex)
@@ -190,12 +190,12 @@ private:
class Q_CORE_EXPORT QMutexLocker
{
public:
- inline explicit QMutexLocker(QMutex *) {}
- inline ~QMutexLocker() {}
+ inline explicit QMutexLocker(QMutex *) Q_DECL_NOTHROW {}
+ inline ~QMutexLocker() Q_DECL_NOTHROW {}
- inline void unlock() {}
- void relock() {}
- inline QMutex *mutex() const { return 0; }
+ inline void unlock() Q_DECL_NOTHROW {}
+ void relock() Q_DECL_NOTHROW {}
+ inline QMutex *mutex() const Q_DECL_NOTHROW { return Q_NULLPTR; }
private:
Q_DISABLE_COPY(QMutexLocker)
diff --git a/src/corelib/thread/qreadwritelock.h b/src/corelib/thread/qreadwritelock.h
index 4260d090b6..01adaa927a 100644
--- a/src/corelib/thread/qreadwritelock.h
+++ b/src/corelib/thread/qreadwritelock.h
@@ -172,18 +172,18 @@ class Q_CORE_EXPORT QReadWriteLock
{
public:
enum RecursionMode { NonRecursive, Recursive };
- inline explicit QReadWriteLock(RecursionMode = NonRecursive) { }
+ inline explicit QReadWriteLock(RecursionMode = NonRecursive) Q_DECL_NOTHROW { }
inline ~QReadWriteLock() { }
- static inline void lockForRead() { }
- static inline bool tryLockForRead() { return true; }
- static inline bool tryLockForRead(int timeout) { Q_UNUSED(timeout); return true; }
+ static inline void lockForRead() Q_DECL_NOTHROW { }
+ static inline bool tryLockForRead() Q_DECL_NOTHROW { return true; }
+ static inline bool tryLockForRead(int timeout) Q_DECL_NOTHROW { Q_UNUSED(timeout); return true; }
- static inline void lockForWrite() { }
- static inline bool tryLockForWrite() { return true; }
- static inline bool tryLockForWrite(int timeout) { Q_UNUSED(timeout); return true; }
+ static inline void lockForWrite() Q_DECL_NOTHROW { }
+ static inline bool tryLockForWrite() Q_DECL_NOTHROW { return true; }
+ static inline bool tryLockForWrite(int timeout) Q_DECL_NOTHROW { Q_UNUSED(timeout); return true; }
- static inline void unlock() { }
+ static inline void unlock() Q_DECL_NOTHROW { }
private:
Q_DISABLE_COPY(QReadWriteLock)
@@ -192,12 +192,12 @@ private:
class Q_CORE_EXPORT QReadLocker
{
public:
- inline QReadLocker(QReadWriteLock *) { }
- inline ~QReadLocker() { }
+ inline QReadLocker(QReadWriteLock *) Q_DECL_NOTHROW { }
+ inline ~QReadLocker() Q_DECL_NOTHROW { }
- static inline void unlock() { }
- static inline void relock() { }
- static inline QReadWriteLock *readWriteLock() { return 0; }
+ static inline void unlock() Q_DECL_NOTHROW { }
+ static inline void relock() Q_DECL_NOTHROW { }
+ static inline QReadWriteLock *readWriteLock() Q_DECL_NOTHROW { return Q_NULLPTR; }
private:
Q_DISABLE_COPY(QReadLocker)
@@ -206,12 +206,12 @@ private:
class Q_CORE_EXPORT QWriteLocker
{
public:
- inline explicit QWriteLocker(QReadWriteLock *) { }
- inline ~QWriteLocker() { }
+ inline explicit QWriteLocker(QReadWriteLock *) Q_DECL_NOTHROW { }
+ inline ~QWriteLocker() Q_DECL_NOTHROW { }
- static inline void unlock() { }
- static inline void relock() { }
- static inline QReadWriteLock *readWriteLock() { return 0; }
+ static inline void unlock() Q_DECL_NOTHROW { }
+ static inline void relock() Q_DECL_NOTHROW { }
+ static inline QReadWriteLock *readWriteLock() Q_DECL_NOTHROW { return Q_NULLPTR; }
private:
Q_DISABLE_COPY(QWriteLocker)
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/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp
index 9a14503584..09659297d0 100644
--- a/src/corelib/thread/qthread_unix.cpp
+++ b/src/corelib/thread/qthread_unix.cpp
@@ -241,15 +241,9 @@ void QAdoptedThread::init()
QThreadPrivate
*/
-#if defined(Q_C_CALLBACKS)
extern "C" {
-#endif
-
typedef void*(*QtThreadCallback)(void*);
-
-#if defined(Q_C_CALLBACKS)
}
-#endif
#endif // QT_NO_THREAD
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/thread/qwaitcondition_unix.cpp b/src/corelib/thread/qwaitcondition_unix.cpp
index 3bcf3202a1..979a5f2300 100644
--- a/src/corelib/thread/qwaitcondition_unix.cpp
+++ b/src/corelib/thread/qwaitcondition_unix.cpp
@@ -70,7 +70,7 @@ void qt_initialize_pthread_cond(pthread_cond_t *cond, const char *where)
pthread_condattr_t condattr;
pthread_condattr_init(&condattr);
-#if !defined(Q_OS_MAC) && !defined(Q_OS_ANDROID) && (_POSIX_MONOTONIC_CLOCK-0 >= 0)
+#if !defined(Q_OS_MAC) && !defined(Q_OS_ANDROID) && !defined(Q_OS_HAIKU) && (_POSIX_MONOTONIC_CLOCK-0 >= 0)
if (QElapsedTimer::clockType() == QElapsedTimer::MonotonicClock)
pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC);
#endif
diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h
index 0ba3cad5e9..cffe0128b0 100644
--- a/src/corelib/tools/qalgorithms.h
+++ b/src/corelib/tools/qalgorithms.h
@@ -37,7 +37,9 @@
#include <QtCore/qglobal.h>
QT_BEGIN_NAMESPACE
-
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations")
+QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations")
/*
Warning: The contents of QAlgorithmsPrivate is not a part of the public Qt API
@@ -582,7 +584,7 @@ Q_DECL_CONSTEXPR inline uint qPopulationCount(long unsigned int v)
#undef QALGORITHMS_USE_BUILTIN_POPCOUNT
#endif
-
+QT_WARNING_POP
QT_END_NAMESPACE
#endif // QALGORITHMS_H
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/qarraydata.h b/src/corelib/tools/qarraydata.h
index 2119b3d4ac..df44503a8e 100644
--- a/src/corelib/tools/qarraydata.h
+++ b/src/corelib/tools/qarraydata.h
@@ -113,7 +113,7 @@ struct Q_CORE_EXPORT QArrayData
size_t alignment) Q_DECL_NOTHROW;
static const QArrayData shared_null[2];
- static QArrayData *sharedNull() { return const_cast<QArrayData*>(shared_null); }
+ static QArrayData *sharedNull() Q_DECL_NOTHROW { return const_cast<QArrayData*>(shared_null); }
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QArrayData::AllocationOptions)
@@ -237,7 +237,7 @@ struct QTypedArrayData
return result;
}
- static QTypedArrayData *sharedNull()
+ static QTypedArrayData *sharedNull() Q_DECL_NOTHROW
{
Q_STATIC_ASSERT(sizeof(QTypedArrayData) == sizeof(QArrayData));
return static_cast<QTypedArrayData *>(QArrayData::sharedNull());
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/qbitarray.h b/src/corelib/tools/qbitarray.h
index 768dfa912d..8d550554ff 100644
--- a/src/corelib/tools/qbitarray.h
+++ b/src/corelib/tools/qbitarray.h
@@ -53,12 +53,12 @@ public:
QBitArray(const QBitArray &other) : d(other.d) {}
inline QBitArray &operator=(const QBitArray &other) { d = other.d; return *this; }
#ifdef Q_COMPILER_RVALUE_REFS
- inline QBitArray(QBitArray &&other) : d(std::move(other.d)) {}
- inline QBitArray &operator=(QBitArray &&other)
+ inline QBitArray(QBitArray &&other) Q_DECL_NOTHROW : d(std::move(other.d)) {}
+ inline QBitArray &operator=(QBitArray &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
- inline void swap(QBitArray &other) { qSwap(d, other.d); }
+ inline void swap(QBitArray &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
inline int size() const { return (d.size() << 3) - *d.constData(); }
inline int count() const { return (d.size() << 3) - *d.constData(); }
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index bd0215902c..7f6dab38c0 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>
@@ -55,6 +57,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,
@@ -249,7 +309,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;
@@ -284,7 +344,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;
@@ -925,7 +985,7 @@ static inline char qToLower(char c)
Assigns \a other to this byte array and returns a reference to
this byte array.
*/
-QByteArray &QByteArray::operator=(const QByteArray & other)
+QByteArray &QByteArray::operator=(const QByteArray & other) Q_DECL_NOTHROW
{
other.d->ref.ref();
if (!d->ref.deref())
@@ -1495,8 +1555,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;
@@ -2687,6 +2750,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.
@@ -2695,21 +2760,52 @@ QByteArray QByteArray::mid(int pos, int len) const
\sa toUpper(), {8-bit Character Comparisons}
*/
-QByteArray QByteArray::toLower() const
+
+// prevent the compiler from inlining 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>
+Q_NEVER_INLINE
+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.
@@ -2719,18 +2815,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()
@@ -3110,6 +3202,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.
@@ -3124,32 +3218,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.
@@ -3164,29 +3245,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.
@@ -4062,15 +4131,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;
@@ -4098,16 +4161,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;
}
@@ -4302,12 +4357,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())
@@ -4340,8 +4389,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..0daf2535bc 100644
--- a/src/corelib/tools/qbytearray.h
+++ b/src/corelib/tools/qbytearray.h
@@ -185,22 +185,23 @@ public:
};
Q_DECLARE_FLAGS(Base64Options, Base64Option)
- inline QByteArray();
+ inline QByteArray() Q_DECL_NOTHROW;
QByteArray(const char *, int size = -1);
QByteArray(int size, char c);
QByteArray(int size, Qt::Initialization);
- inline QByteArray(const QByteArray &);
+ inline QByteArray(const QByteArray &) Q_DECL_NOTHROW;
inline ~QByteArray();
- QByteArray &operator=(const QByteArray &);
+ QByteArray &operator=(const QByteArray &) Q_DECL_NOTHROW;
QByteArray &operator=(const char *str);
#ifdef Q_COMPILER_RVALUE_REFS
- inline QByteArray(QByteArray && other) : d(other.d) { other.d = Data::sharedNull(); }
- inline QByteArray &operator=(QByteArray &&other)
+ inline QByteArray(QByteArray && other) Q_DECL_NOTHROW : d(other.d) { other.d = Data::sharedNull(); }
+ inline QByteArray &operator=(QByteArray &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
- inline void swap(QByteArray &other) { qSwap(d, other.d); }
+ inline void swap(QByteArray &other) Q_DECL_NOTHROW
+ { qSwap(d, other.d); }
inline int size() const;
bool isEmpty() const;
@@ -259,11 +260,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 +447,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);
@@ -427,7 +466,7 @@ public:
Q_DECLARE_OPERATORS_FOR_FLAGS(QByteArray::Base64Options)
-inline QByteArray::QByteArray(): d(Data::sharedNull()) { }
+inline QByteArray::QByteArray() Q_DECL_NOTHROW : d(Data::sharedNull()) { }
inline QByteArray::~QByteArray() { if (!d->ref.deref()) Data::deallocate(d); }
inline int QByteArray::size() const
{ return d->size; }
@@ -457,7 +496,7 @@ inline void QByteArray::detach()
{ if (d->ref.isShared() || (d->offset != sizeof(QByteArrayData))) reallocData(uint(d->size) + 1u, d->detachFlags()); }
inline bool QByteArray::isDetached() const
{ return !d->ref.isShared(); }
-inline QByteArray::QByteArray(const QByteArray &a) : d(a.d)
+inline QByteArray::QByteArray(const QByteArray &a) Q_DECL_NOTHROW : d(a.d)
{ d->ref.ref(); }
inline int QByteArray::capacity() const
diff --git a/src/corelib/tools/qbytearraymatcher.h b/src/corelib/tools/qbytearraymatcher.h
index c7b83a98cc..a49ae2fd9d 100644
--- a/src/corelib/tools/qbytearraymatcher.h
+++ b/src/corelib/tools/qbytearraymatcher.h
@@ -66,11 +66,6 @@ public:
private:
QByteArrayMatcherPrivate *d;
QByteArray q_pattern;
-#ifdef Q_CC_RVCT
-// explicitly allow anonymous unions for RVCT to prevent compiler warnings
-# pragma push
-# pragma anon_unions
-#endif
struct Data {
uchar q_skiptable[256];
const uchar *p;
@@ -80,9 +75,6 @@ private:
uint dummy[256];
Data p;
};
-#ifdef Q_CC_RVCT
-# pragma pop
-#endif
};
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qcache.h b/src/corelib/tools/qcache.h
index 960e0422a1..80fdb8c9cd 100644
--- a/src/corelib/tools/qcache.h
+++ b/src/corelib/tools/qcache.h
@@ -83,7 +83,7 @@ class QCache
Q_DISABLE_COPY(QCache)
public:
- inline explicit QCache(int maxCost = 100);
+ inline explicit QCache(int maxCost = 100) Q_DECL_NOTHROW;
inline ~QCache() { clear(); }
inline int maxCost() const { return mx; }
@@ -110,7 +110,7 @@ private:
};
template <class Key, class T>
-inline QCache<Key, T>::QCache(int amaxCost)
+inline QCache<Key, T>::QCache(int amaxCost) Q_DECL_NOTHROW
: f(0), l(0), mx(amaxCost), total(0) {}
template <class Key, class T>
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/qcollator.h b/src/corelib/tools/qcollator.h
index f9ae44cf6b..98f06bcc1f 100644
--- a/src/corelib/tools/qcollator.h
+++ b/src/corelib/tools/qcollator.h
@@ -52,10 +52,10 @@ public:
~QCollatorSortKey();
QCollatorSortKey &operator=(const QCollatorSortKey &other);
#ifdef Q_COMPILER_RVALUE_REFS
- inline QCollatorSortKey &operator=(QCollatorSortKey &&other)
+ inline QCollatorSortKey &operator=(QCollatorSortKey &&other) Q_DECL_NOTHROW
{ swap(other); return *this; }
#endif
- void swap(QCollatorSortKey &other)
+ void swap(QCollatorSortKey &other) Q_DECL_NOTHROW
{ d.swap(other.d); }
int compare(const QCollatorSortKey &key) const;
@@ -82,13 +82,13 @@ public:
~QCollator();
QCollator &operator=(const QCollator &);
#ifdef Q_COMPILER_RVALUE_REFS
- QCollator(QCollator &&other)
+ QCollator(QCollator &&other) Q_DECL_NOTHROW
: d(other.d) { other.d = 0; }
- QCollator &operator=(QCollator &&other)
+ QCollator &operator=(QCollator &&other) Q_DECL_NOTHROW
{ swap(other); return *this; }
#endif
- void swap(QCollator &other)
+ void swap(QCollator &other) Q_DECL_NOTHROW
{ qSwap(d, other.d); }
void setLocale(const QLocale &locale);
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 082b721e82..b95ccc0874 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 or [+-]HH 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'));
}
}
@@ -3186,13 +3186,11 @@ QTimeZone QDateTime::timeZone() const
d->m_timeZone = QTimeZone(d->m_offsetFromUtc);
return d->m_timeZone;
case Qt::UTC:
- if (!d->m_timeZone.isValid())
- d->m_timeZone = QTimeZone(QTimeZonePrivate::utcQByteArray());
- return d->m_timeZone;
- case Qt::TimeZone :
+ return QTimeZone::utc();
+ case Qt::TimeZone:
return d->m_timeZone;
case Qt::LocalTime:
- return QTimeZone(QTimeZone::systemTimeZoneId());
+ return QTimeZone::systemTimeZone();
}
return QTimeZone();
}
@@ -3603,11 +3601,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)
@@ -3747,7 +3745,7 @@ QDateTime QDateTime::addDays(qint64 ndays) const
localMSecsToEpochMSecs(timeToMSecs(date, time), &date, &time);
#ifndef QT_BOOTSTRAPPED
else if (d->m_spec == Qt::TimeZone)
- d->zoneMSecsToEpochMSecs(timeToMSecs(date, time), d->m_timeZone, &date, &time);
+ QDateTimePrivate::zoneMSecsToEpochMSecs(timeToMSecs(date, time), d->m_timeZone, &date, &time);
#endif // QT_BOOTSTRAPPED
dt.d->setDateTime(date, time);
return dt;
@@ -3781,7 +3779,7 @@ QDateTime QDateTime::addMonths(int nmonths) const
localMSecsToEpochMSecs(timeToMSecs(date, time), &date, &time);
#ifndef QT_BOOTSTRAPPED
else if (d->m_spec == Qt::TimeZone)
- d->zoneMSecsToEpochMSecs(timeToMSecs(date, time), d->m_timeZone, &date, &time);
+ QDateTimePrivate::zoneMSecsToEpochMSecs(timeToMSecs(date, time), d->m_timeZone, &date, &time);
#endif // QT_BOOTSTRAPPED
dt.d->setDateTime(date, time);
return dt;
@@ -3815,7 +3813,7 @@ QDateTime QDateTime::addYears(int nyears) const
localMSecsToEpochMSecs(timeToMSecs(date, time), &date, &time);
#ifndef QT_BOOTSTRAPPED
else if (d->m_spec == Qt::TimeZone)
- d->zoneMSecsToEpochMSecs(timeToMSecs(date, time), d->m_timeZone, &date, &time);
+ QDateTimePrivate::zoneMSecsToEpochMSecs(timeToMSecs(date, time), d->m_timeZone, &date, &time);
#endif // QT_BOOTSTRAPPED
dt.d->setDateTime(date, time);
return dt;
@@ -4204,6 +4202,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
@@ -4358,7 +4389,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) {
@@ -4449,7 +4480,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);
@@ -4469,7 +4500,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();
@@ -4488,9 +4519,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();
}
}
@@ -4523,7 +4554,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();
@@ -4538,7 +4569,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();
}
@@ -4563,10 +4594,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)
@@ -4993,7 +5024,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/qeasingcurve.h b/src/corelib/tools/qeasingcurve.h
index 702842eb68..a3866c72a2 100644
--- a/src/corelib/tools/qeasingcurve.h
+++ b/src/corelib/tools/qeasingcurve.h
@@ -50,7 +50,6 @@ class QPointF;
class Q_CORE_EXPORT QEasingCurve
{
Q_GADGET
- Q_ENUMS(Type)
public:
enum Type {
Linear,
@@ -67,6 +66,7 @@ public:
InCurve, OutCurve, SineCurve, CosineCurve,
BezierSpline, TCBSpline, Custom, NCurveTypes
};
+ Q_ENUM(Type)
QEasingCurve(Type type = Linear);
QEasingCurve(const QEasingCurve &other);
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..cd198743bf 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;
@@ -420,7 +418,7 @@ QHashData *QHashData::detach_helper(void (*node_duplicate)(Node *, void *),
Node *e;
};
if (this == &shared_null)
- qt_initialize_qhash_seed();
+ qt_initialize_qhash_seed(); // may throw
d = new QHashData;
d->fakeNext = 0;
d->buckets = 0;
@@ -430,7 +428,7 @@ QHashData *QHashData::detach_helper(void (*node_duplicate)(Node *, void *),
d->userNumBits = userNumBits;
d->numBits = numBits;
d->numBuckets = numBuckets;
- d->seed = uint(qt_qhash_seed.load());
+ d->seed = (this == &shared_null) ? uint(qt_qhash_seed.load()) : seed;
d->sharable = true;
d->strictAlignment = nodeAlign > 8;
d->reserved = 0;
@@ -667,6 +665,85 @@ void QHashData::checkSanity()
Types \c T1 and \c T2 must be supported by qHash().
*/
+/*! \fn uint qHashRange(InputIterator first, InputIterator last, uint seed = 0)
+ \relates QHash
+ \since 5.5
+
+ Returns the hash value for the range [\a{first},\a{last}), using \a seed
+ to seed the calculation, by successively applying qHash() to each
+ element and combining the hash values into a single one.
+
+ The return value of this function depends on the order of elements
+ in the range. That means that
+
+ \code
+ {0, 1, 2}
+ \endcode
+
+ and
+ \code
+ {1, 2, 0}
+ \endcode
+
+ hash to \b{different} values. If order does not matter, for example for hash
+ tables, use qHashRangeCommutative() instead. If you are hashing raw
+ memory, use qHashBits().
+
+ Use this function only to implement qHash() for your own custom
+ types. For example, here's how you could implement a qHash() overload for
+ std::vector<int>:
+
+ \snippet code/src_corelib_tools_qhash.cpp qhashrange
+
+ It bears repeating that the implementation of qHashRange() - like
+ the qHash() overloads offered by Qt - may change at any time. You
+ \b{must not} rely on the fact that qHashRange() will give the same
+ results (for the same inputs) across different Qt versions, even
+ if qHash() for the element type would.
+
+ \sa qHashBits(), qHashRangeCommutative()
+*/
+
+/*! \fn uint qHashRangeCommutative(InputIterator first, InputIterator last, uint seed = 0)
+ \relates QHash
+ \since 5.5
+
+ Returns the hash value for the range [\a{first},\a{last}), using \a seed
+ to seed the calculation, by successively applying qHash() to each
+ element and combining the hash values into a single one.
+
+ The return value of this function does not depend on the order of
+ elements in the range. That means that
+
+ \code
+ {0, 1, 2}
+ \endcode
+
+ and
+ \code
+ {1, 2, 0}
+ \endcode
+
+ hash to the \b{same} values. If order matters, for example, for vectors
+ and arrays, use qHashRange() instead. If you are hashing raw
+ memory, use qHashBits().
+
+ Use this function only to implement qHash() for your own custom
+ types. For example, here's how you could implement a qHash() overload for
+ std::unordered_set<int>:
+
+ \snippet code/src_corelib_tools_qhash.cpp qhashrangecommutative
+
+ It bears repeating that the implementation of
+ qHashRangeCommutative() - like the qHash() overloads offered by Qt
+ - may change at any time. You \b{must not} rely on the fact that
+ qHashRangeCommutative() will give the same results (for the same
+ inputs) across different Qt versions, even if qHash() for the
+ element type would.
+
+ \sa qHashBits(), qHashRange()
+*/
+
/*! \fn uint qHashBits(const void *p, size_t len, uint seed = 0)
\relates QHash
\since 5.4
@@ -675,15 +752,21 @@ void QHashData::checkSanity()
to by \a p, using \a seed to seed the calculation.
Use this function only to implement qHash() for your own custom
- types. E.g., here's how you could implement a qHash() overload for
+ types. For example, here's how you could implement a qHash() overload for
std::vector<int>:
\snippet code/src_corelib_tools_qhash.cpp qhashbits
+ This takes advantage of the fact that std::vector lays out its data
+ contiguously. If that is not the case, or the contained type has
+ padding, you should use qHashRange() instead.
+
It bears repeating that the implementation of qHashBits() - like
the qHash() overloads offered by Qt - may change at any time. You
\b{must not} rely on the fact that qHashBits() will give the same
results (for the same inputs) across different Qt versions.
+
+ \sa qHashRange(), qHashRangeCommutative()
*/
/*! \fn uint qHash(char key, uint seed = 0)
@@ -1047,7 +1130,7 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
This randomization of QHash is enabled by default. Even though programs
should never depend on a particular QHash ordering, there may be situations
- where you temporarily need deterministic behavior, e.g. for debugging or
+ where you temporarily need deterministic behavior, for example for debugging or
regression testing. To disable the randomization, define the environment
variable \c QT_HASH_SEED. The contents of that variable, interpreted as a
decimal value, will be used as the seed for qHash().
@@ -1063,7 +1146,7 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
*/
/*!
- \fn QHash::QHash(QHash<Key, T> &&other)
+ \fn QHash::QHash(QHash &&other)
Move-constructs a QHash instance, making it point at the same
object that \a other was pointing to.
@@ -1081,7 +1164,7 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
compiled in C++11 mode.
*/
-/*! \fn QHash::QHash(const QHash<Key, T> &other)
+/*! \fn QHash::QHash(const QHash &other)
Constructs a copy of \a other.
@@ -1099,34 +1182,34 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
iterators of this hash become invalid.
*/
-/*! \fn QHash<Key, T> &QHash::operator=(const QHash<Key, T> &other)
+/*! \fn QHash &QHash::operator=(const QHash &other)
Assigns \a other to this hash and returns a reference to this hash.
*/
/*!
- \fn QHash<Key, T> &QHash::operator=(QHash<Key, T> &&other)
+ \fn QHash &QHash::operator=(QHash &&other)
Move-assigns \a other to this QHash instance.
\since 5.2
*/
-/*! \fn void QHash::swap(QHash<Key, T> &other)
+/*! \fn void QHash::swap(QHash &other)
\since 4.8
Swaps hash \a other with this hash. This operation is very
fast and never fails.
*/
-/*! \fn void QMultiHash::swap(QMultiHash<Key, T> &other)
+/*! \fn void QMultiHash::swap(QMultiHash &other)
\since 4.8
Swaps hash \a other with this hash. This operation is very
fast and never fails.
*/
-/*! \fn bool QHash::operator==(const QHash<Key, T> &other) const
+/*! \fn bool QHash::operator==(const QHash &other) const
Returns \c true if \a other is equal to this hash; otherwise returns
false.
@@ -1139,7 +1222,7 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
\sa operator!=()
*/
-/*! \fn bool QHash::operator!=(const QHash<Key, T> &other) const
+/*! \fn bool QHash::operator!=(const QHash &other) const
Returns \c true if \a other is not equal to this hash; otherwise
returns \c false.
@@ -1239,7 +1322,7 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
\internal
*/
-/*! \fn bool QHash::isSharedWith(const QHash<Key, T> &other) const
+/*! \fn bool QHash::isSharedWith(const QHash &other) const
\internal
*/
@@ -1561,7 +1644,7 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
\sa insert(), values()
*/
-/*! \fn QHash<Key, T> &QHash::unite(const QHash<Key, T> &other)
+/*! \fn QHash &QHash::unite(const QHash &other)
Inserts all the items in the \a other hash into this hash. If a
key is common to both hashes, the resulting hash will contain the
@@ -2227,12 +2310,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 +2320,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 +2329,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 +2342,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 +2360,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..e0387d4644 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -40,6 +41,7 @@
#include <QtCore/qpair.h>
#include <QtCore/qrefcount.h>
+#include <numeric> // for std::accumulate
#ifdef Q_COMPILER_INITIALIZER_LISTS
#include <initializer_list>
#endif
@@ -101,6 +103,44 @@ template<typename T> inline uint qHash(const T &t, uint seed)
Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(t)))
{ return (qHash(t) ^ seed); }
+namespace QtPrivate {
+
+struct QHashCombine {
+ typedef uint result_type;
+ template <typename T>
+ Q_DECL_CONSTEXPR result_type operator()(uint seed, const T &t) const Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(t)))
+ // combiner taken from N3876 / boost::hash_combine
+ { return seed ^ (qHash(t) + 0x9e3779b9 + (seed << 6) + (seed >> 2)) ; }
+};
+
+struct QHashCombineCommutative {
+ // QHashCombine is a good hash combiner, but is not commutative,
+ // ie. it depends on the order of the input elements. That is
+ // usually what we want: {0,1,3} should hash differently than
+ // {1,3,0}. Except when it isn't (e.g. for QSet and
+ // QHash). Therefore, provide a commutative combiner, too.
+ typedef uint result_type;
+ template <typename T>
+ Q_DECL_CONSTEXPR result_type operator()(uint seed, const T &t) const Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(t)))
+ { return seed + qHash(t); } // don't use xor!
+};
+
+} // namespace QtPrivate
+
+template <typename InputIterator>
+inline uint qHashRange(InputIterator first, InputIterator last, uint seed = 0)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(*first))) // assume iterator operations don't throw
+{
+ return std::accumulate(first, last, seed, QtPrivate::QHashCombine());
+}
+
+template <typename InputIterator>
+inline uint qHashRangeCommutative(InputIterator first, InputIterator last, uint seed = 0)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(*first))) // assume iterator operations don't throw
+{
+ return std::accumulate(first, last, seed, QtPrivate::QHashCombineCommutative());
+}
+
template <typename T1, typename T2> inline uint qHash(const QPair<T1, T2> &key, uint seed = 0)
Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(key.first, seed)) && noexcept(qHash(key.second, seed)))
{
@@ -288,7 +328,7 @@ class QHash
static inline int alignOfNode() { return qMax<int>(sizeof(void*), Q_ALIGNOF(Node)); }
public:
- inline QHash() : d(const_cast<QHashData *>(&QHashData::shared_null)) { }
+ inline QHash() Q_DECL_NOTHROW : d(const_cast<QHashData *>(&QHashData::shared_null)) { }
#ifdef Q_COMPILER_INITIALIZER_LISTS
inline QHash(std::initializer_list<std::pair<Key,T> > list)
: d(const_cast<QHashData *>(&QHashData::shared_null))
@@ -298,19 +338,19 @@ public:
insert(it->first, it->second);
}
#endif
- inline QHash(const QHash<Key, T> &other) : d(other.d) { d->ref.ref(); if (!d->sharable) detach(); }
- inline ~QHash() { if (!d->ref.deref()) freeData(d); }
+ QHash(const QHash &other) : d(other.d) { d->ref.ref(); if (!d->sharable) detach(); }
+ ~QHash() { if (!d->ref.deref()) freeData(d); }
- QHash<Key, T> &operator=(const QHash<Key, T> &other);
+ QHash &operator=(const QHash &other);
#ifdef Q_COMPILER_RVALUE_REFS
- inline QHash(QHash<Key, T> &&other) : d(other.d) { other.d = const_cast<QHashData *>(&QHashData::shared_null); }
- inline QHash<Key, T> &operator=(QHash<Key, T> &&other)
+ QHash(QHash &&other) Q_DECL_NOTHROW : d(other.d) { other.d = const_cast<QHashData *>(&QHashData::shared_null); }
+ QHash &operator=(QHash &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
- inline void swap(QHash<Key, T> &other) { qSwap(d, other.d); }
+ void swap(QHash &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
- bool operator==(const QHash<Key, T> &other) const;
- inline bool operator!=(const QHash<Key, T> &other) const { return !(*this == other); }
+ bool operator==(const QHash &other) const;
+ bool operator!=(const QHash &other) const { return !(*this == other); }
inline int size() const { return d->size; }
@@ -325,7 +365,7 @@ public:
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
inline void setSharable(bool sharable) { if (!sharable) detach(); if (d != &QHashData::shared_null) d->sharable = sharable; }
#endif
- inline bool isSharedWith(const QHash<Key, T> &other) const { return d == other.d; }
+ bool isSharedWith(const QHash &other) const { return d == other.d; }
void clear();
@@ -488,7 +528,7 @@ public:
const_iterator constFind(const Key &key) const;
iterator insert(const Key &key, const T &value);
iterator insertMulti(const Key &key, const T &value);
- QHash<Key, T> &unite(const QHash<Key, T> &other);
+ QHash &unite(const QHash &other);
// STL compatibility
typedef T mapped_type;
@@ -564,9 +604,9 @@ QHash<Key, T>::createNode(uint ah, const Key &akey, const T &avalue, Node **anex
}
template <class Key, class T>
-Q_INLINE_TEMPLATE QHash<Key, T> &QHash<Key, T>::unite(const QHash<Key, T> &other)
+Q_INLINE_TEMPLATE QHash<Key, T> &QHash<Key, T>::unite(const QHash &other)
{
- QHash<Key, T> copy(other);
+ QHash copy(other);
const_iterator it = copy.constEnd();
while (it != copy.constBegin()) {
--it;
@@ -584,7 +624,7 @@ Q_OUTOFLINE_TEMPLATE void QHash<Key, T>::freeData(QHashData *x)
template <class Key, class T>
Q_INLINE_TEMPLATE void QHash<Key, T>::clear()
{
- *this = QHash<Key,T>();
+ *this = QHash();
}
template <class Key, class T>
@@ -597,7 +637,7 @@ Q_OUTOFLINE_TEMPLATE void QHash<Key, T>::detach_helper()
}
template <class Key, class T>
-Q_INLINE_TEMPLATE QHash<Key, T> &QHash<Key, T>::operator=(const QHash<Key, T> &other)
+Q_INLINE_TEMPLATE QHash<Key, T> &QHash<Key, T>::operator=(const QHash &other)
{
if (d != other.d) {
QHashData *o = other.d;
@@ -925,7 +965,7 @@ Q_OUTOFLINE_TEMPLATE typename QHash<Key, T>::Node **QHash<Key, T>::findNode(cons
}
template <class Key, class T>
-Q_OUTOFLINE_TEMPLATE bool QHash<Key, T>::operator==(const QHash<Key, T> &other) const
+Q_OUTOFLINE_TEMPLATE bool QHash<Key, T>::operator==(const QHash &other) const
{
if (size() != other.size())
return false;
@@ -964,7 +1004,7 @@ public:
}
#endif
QMultiHash(const QHash<Key, T> &other) : QHash<Key, T>(other) {}
- inline void swap(QMultiHash<Key, T> &other) { QHash<Key, T>::swap(other); } // prevent QMultiHash<->QHash swaps
+ void swap(QMultiHash &other) { QHash<Key, T>::swap(other); } // prevent QMultiHash<->QHash swaps
inline typename QHash<Key, T>::iterator replace(const Key &key, const T &value)
{ return QHash<Key, T>::insert(key, value); }
@@ -977,29 +1017,11 @@ 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)
- // 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;
using QHash<Key, T>::count;
using QHash<Key, T>::find;
using QHash<Key, T>::constFind;
-#else
- inline bool contains(const Key &key) const
- { return QHash<Key, T>::contains(key); }
- inline int remove(const Key &key)
- { return QHash<Key, T>::remove(key); }
- inline int count(const Key &key) const
- { return QHash<Key, T>::count(key); }
- inline int count() const
- { return QHash<Key, T>::count(); }
- inline typename QHash<Key, T>::iterator find(const Key &key)
- { return QHash<Key, T>::find(key); }
- inline typename QHash<Key, T>::const_iterator find(const Key &key) const
- { return QHash<Key, T>::find(key); }
- inline typename QHash<Key, T>::const_iterator constFind(const Key &key) const
- { return QHash<Key, T>::constFind(key); }
-#endif
bool contains(const Key &key, const T &value) const;
diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp
index fe5e0f33b4..a5e43e2ca5 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;
@@ -473,6 +475,12 @@ void **QListData::erase(void **xi)
If T is a QByteArray, this class has a couple more members that can be
used. See the documentation for QByteArrayList for more information.
+ If T is QString, this class has the following additional members:
+ \l{QStringList::filter()}{filter},
+ \l{QStringList::join()}{join},
+ \l{QStringList::removeDuplicates()}{removeDuplicates},
+ \l{QStringList::sort()}{sort}.
+
\sa QListIterator, QMutableListIterator, QLinkedList, QVector
*/
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index e33be9a2f1..2031c32069 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -112,7 +112,7 @@ class QList : public QListSpecialMethods<T>
union { QListData p; QListData::Data *d; };
public:
- inline QList() : d(const_cast<QListData::Data *>(&QListData::shared_null)) { }
+ inline QList() Q_DECL_NOTHROW : d(const_cast<QListData::Data *>(&QListData::shared_null)) { }
QList(const QList<T> &l);
~QList();
QList<T> &operator=(const QList<T> &l);
@@ -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;
@@ -951,6 +948,7 @@ Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(List)
QT_END_NAMESPACE
#include <QtCore/qbytearraylist.h>
+#include <QtCore/qstringlist.h>
#ifdef Q_CC_MSVC
#pragma warning( pop )
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index a923be50c0..78334563dd 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -2744,30 +2744,6 @@ QString QLocaleData::doubleToString(const QChar _zero, const QChar plus, const Q
int decpt, sign;
QString digits;
-#ifdef QT_QLOCALE_USES_FCVT
- // NOT thread safe!
- if (form == DFDecimal) {
- digits = QLatin1String(fcvt(d, precision, &decpt, &sign));
- } else {
- int pr = precision;
- if (form == DFExponent)
- ++pr;
- else if (form == DFSignificantDigits && pr == 0)
- pr = 1;
- digits = QLatin1String(ecvt(d, pr, &decpt, &sign));
-
- // Chop trailing zeros
- if (digits.length() > 0) {
- int last_nonzero_idx = digits.length() - 1;
- while (last_nonzero_idx > 0
- && digits.unicode()[last_nonzero_idx] == QLatin1Char('0'))
- --last_nonzero_idx;
- digits.truncate(last_nonzero_idx + 1);
- }
-
- }
-
-#else
int mode;
if (form == DFDecimal)
mode = 3;
@@ -2795,7 +2771,6 @@ QString QLocaleData::doubleToString(const QChar _zero, const QChar plus, const Q
}
if (buff != 0)
free(buff);
-#endif // QT_QLOCALE_USES_FCVT
if (_zero.unicode() != '0') {
ushort z = _zero.unicode() - '0';
diff --git a/src/corelib/tools/qlocale.h b/src/corelib/tools/qlocale.h
index f965ae6562..145b67f9f1 100644
--- a/src/corelib/tools/qlocale.h
+++ b/src/corelib/tools/qlocale.h
@@ -55,9 +55,6 @@ class QLocalePrivate;
class Q_CORE_EXPORT QLocale
{
Q_GADGET
- Q_ENUMS(Language)
- Q_ENUMS(Country)
- Q_ENUMS(MeasurementSystem)
friend class QString;
friend class QStringRef;
friend class QByteArray;
@@ -781,12 +778,16 @@ public:
};
// GENERATED PART ENDS HERE
+ Q_ENUM(Language)
+ Q_ENUM(Country)
+
enum MeasurementSystem {
MetricSystem,
ImperialUSSystem,
ImperialUKSystem,
ImperialSystem = ImperialUSSystem // Qt 4 compatibility
};
+ Q_ENUM(MeasurementSystem)
enum FormatType { LongFormat, ShortFormat, NarrowFormat };
enum NumberOption {
diff --git a/src/corelib/tools/qlocale_tools.cpp b/src/corelib/tools/qlocale_tools.cpp
index 1b246a29de..fa4843361c 100644
--- a/src/corelib/tools/qlocale_tools.cpp
+++ b/src/corelib/tools/qlocale_tools.cpp
@@ -63,10 +63,8 @@
QT_BEGIN_NAMESPACE
-#ifndef QT_QLOCALE_USES_FCVT
static char *_qdtoa( NEEDS_VOLATILE double d, int mode, int ndigits, int *decpt,
int *sign, char **rve, char **digits_str);
-#endif
QString qulltoa(qulonglong l, int base, const QChar _zero)
{
@@ -390,8 +388,6 @@ qlonglong qstrtoll(const char *nptr, const char **endptr, int base, bool *ok)
return acc;
}
-#ifndef QT_QLOCALE_USES_FCVT
-
/* From: NetBSD: strtod.c,v 1.26 1998/02/03 18:44:21 perry Exp */
/* $FreeBSD: src/lib/libc/stdlib/netbsd_strtod.c,v 1.2.2.2 2001/03/02 17:14:15 tegge Exp $ */
@@ -2780,54 +2776,5 @@ static char *_qdtoa( NEEDS_VOLATILE double d, int mode, int ndigits, int *decpt,
*rve = s;
return s0;
}
-#else
-// NOT thread safe!
-
-#include <errno.h>
-
-Q_CORE_EXPORT char *qdtoa( double d, int mode, int ndigits, int *decpt, int *sign, char **rve, char **resultp)
-{
- if(rve)
- *rve = 0;
-
- char *res;
- if (mode == 0)
- ndigits = 80;
-
- if (mode == 3)
- res = fcvt(d, ndigits, decpt, sign);
- else
- res = ecvt(d, ndigits, decpt, sign);
-
- int n = qstrlen(res);
- if (mode == 0) { // remove trailing 0's
- const int stop = qMax(1, *decpt);
- int i;
- for (i = n-1; i >= stop; --i) {
- if (res[i] != '0')
- break;
- }
- n = i + 1;
- }
- *resultp = static_cast<char*>(malloc(n + 1));
- Q_CHECK_PTR(resultp);
- qstrncpy(*resultp, res, n + 1);
- return *resultp;
-}
-
-Q_CORE_EXPORT double qstrtod(const char *s00, const char **se, bool *ok)
-{
- double ret = strtod((char*)s00, (char**)se);
- if (ok) {
- if((ret == 0.0l && errno == ERANGE)
- || ret == HUGE_VAL || ret == -HUGE_VAL)
- *ok = false;
- else
- *ok = true; // the result will be that we don't report underflow in this case
- }
- return ret;
-}
-
-#endif // QT_QLOCALE_USES_FCVT
QT_END_NAMESPACE
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..4b1fc65b22 100644
--- a/src/corelib/tools/qmap.h
+++ b/src/corelib/tools/qmap.h
@@ -1157,29 +1157,11 @@ 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)
- // 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;
using QMap<Key, T>::count;
using QMap<Key, T>::find;
using QMap<Key, T>::constFind;
-#else
- inline bool contains(const Key &key) const
- { return QMap<Key, T>::contains(key); }
- inline int remove(const Key &key)
- { return QMap<Key, T>::remove(key); }
- inline int count(const Key &key) const
- { return QMap<Key, T>::count(key); }
- inline int count() const
- { return QMap<Key, T>::count(); }
- inline typename QMap<Key, T>::iterator find(const Key &key)
- { return QMap<Key, T>::find(key); }
- inline typename QMap<Key, T>::const_iterator find(const Key &key) const
- { return QMap<Key, T>::find(key); }
- inline typename QMap<Key, T>::const_iterator constFind(const Key &key) const
- { return QMap<Key, T>::constFind(key); }
-#endif
bool contains(const Key &key, const T &value) const;
diff --git a/src/corelib/tools/qmargins.h b/src/corelib/tools/qmargins.h
index 33a2766345..a0c88f61e3 100644
--- a/src/corelib/tools/qmargins.h
+++ b/src/corelib/tools/qmargins.h
@@ -45,29 +45,29 @@ QT_BEGIN_NAMESPACE
class QMargins
{
public:
- Q_DECL_CONSTEXPR QMargins();
- Q_DECL_CONSTEXPR QMargins(int left, int top, int right, int bottom);
-
- Q_DECL_CONSTEXPR bool isNull() const;
-
- Q_DECL_CONSTEXPR int left() const;
- Q_DECL_CONSTEXPR int top() const;
- 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_CONSTEXPR QMargins() Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QMargins(int left, int top, int right, int bottom) Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR bool isNull() const Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR int left() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR int top() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR int right() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR int bottom() const Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR void setLeft(int left) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR void setTop(int top) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR void setRight(int right) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR void setBottom(int bottom) Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator+=(const QMargins &margins) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator-=(const QMargins &margins) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator+=(int) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator-=(int) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator*=(int) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator/=(int);
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator*=(qreal) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator/=(qreal);
private:
int m_left;
@@ -75,8 +75,8 @@ private:
int m_right;
int m_bottom;
- friend Q_DECL_CONSTEXPR inline bool operator==(const QMargins &, const QMargins &);
- friend Q_DECL_CONSTEXPR inline bool operator!=(const QMargins &, const QMargins &);
+ friend Q_DECL_CONSTEXPR inline bool operator==(const QMargins &, const QMargins &) Q_DECL_NOTHROW;
+ friend Q_DECL_CONSTEXPR inline bool operator!=(const QMargins &, const QMargins &) Q_DECL_NOTHROW;
};
Q_DECLARE_TYPEINFO(QMargins, Q_MOVABLE_TYPE);
@@ -93,40 +93,40 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QMargins &);
QMargins inline functions
*****************************************************************************/
-Q_DECL_CONSTEXPR inline QMargins::QMargins() : m_left(0), m_top(0), m_right(0), m_bottom(0) {}
+Q_DECL_CONSTEXPR inline QMargins::QMargins() Q_DECL_NOTHROW : m_left(0), m_top(0), m_right(0), m_bottom(0) {}
-Q_DECL_CONSTEXPR inline QMargins::QMargins(int aleft, int atop, int aright, int abottom)
+Q_DECL_CONSTEXPR inline QMargins::QMargins(int aleft, int atop, int aright, int abottom) Q_DECL_NOTHROW
: m_left(aleft), m_top(atop), m_right(aright), m_bottom(abottom) {}
-Q_DECL_CONSTEXPR inline bool QMargins::isNull() const
+Q_DECL_CONSTEXPR inline bool QMargins::isNull() const Q_DECL_NOTHROW
{ return m_left==0 && m_top==0 && m_right==0 && m_bottom==0; }
-Q_DECL_CONSTEXPR inline int QMargins::left() const
+Q_DECL_CONSTEXPR inline int QMargins::left() const Q_DECL_NOTHROW
{ return m_left; }
-Q_DECL_CONSTEXPR inline int QMargins::top() const
+Q_DECL_CONSTEXPR inline int QMargins::top() const Q_DECL_NOTHROW
{ return m_top; }
-Q_DECL_CONSTEXPR inline int QMargins::right() const
+Q_DECL_CONSTEXPR inline int QMargins::right() const Q_DECL_NOTHROW
{ return m_right; }
-Q_DECL_CONSTEXPR inline int QMargins::bottom() const
+Q_DECL_CONSTEXPR inline int QMargins::bottom() const Q_DECL_NOTHROW
{ return m_bottom; }
-inline void QMargins::setLeft(int aleft)
+Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setLeft(int aleft) Q_DECL_NOTHROW
{ m_left = aleft; }
-inline void QMargins::setTop(int atop)
+Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setTop(int atop) Q_DECL_NOTHROW
{ m_top = atop; }
-inline void QMargins::setRight(int aright)
+Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setRight(int aright) Q_DECL_NOTHROW
{ m_right = aright; }
-inline void QMargins::setBottom(int abottom)
+Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setBottom(int abottom) Q_DECL_NOTHROW
{ m_bottom = abottom; }
-Q_DECL_CONSTEXPR inline bool operator==(const QMargins &m1, const QMargins &m2)
+Q_DECL_CONSTEXPR inline bool operator==(const QMargins &m1, const QMargins &m2) Q_DECL_NOTHROW
{
return
m1.m_left == m2.m_left &&
@@ -135,7 +135,7 @@ Q_DECL_CONSTEXPR inline bool operator==(const QMargins &m1, const QMargins &m2)
m1.m_bottom == m2.m_bottom;
}
-Q_DECL_CONSTEXPR inline bool operator!=(const QMargins &m1, const QMargins &m2)
+Q_DECL_CONSTEXPR inline bool operator!=(const QMargins &m1, const QMargins &m2) Q_DECL_NOTHROW
{
return
m1.m_left != m2.m_left ||
@@ -144,55 +144,55 @@ Q_DECL_CONSTEXPR inline bool operator!=(const QMargins &m1, const QMargins &m2)
m1.m_bottom != m2.m_bottom;
}
-Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &m1, const QMargins &m2)
+Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &m1, const QMargins &m2) Q_DECL_NOTHROW
{
return QMargins(m1.left() + m2.left(), m1.top() + m2.top(),
m1.right() + m2.right(), m1.bottom() + m2.bottom());
}
-Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &m1, const QMargins &m2)
+Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &m1, const QMargins &m2) Q_DECL_NOTHROW
{
return QMargins(m1.left() - m2.left(), m1.top() - m2.top(),
m1.right() - m2.right(), m1.bottom() - m2.bottom());
}
-Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &lhs, int rhs)
+Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &lhs, int rhs) Q_DECL_NOTHROW
{
return QMargins(lhs.left() + rhs, lhs.top() + rhs,
lhs.right() + rhs, lhs.bottom() + rhs);
}
-Q_DECL_CONSTEXPR inline QMargins operator+(int lhs, const QMargins &rhs)
+Q_DECL_CONSTEXPR inline QMargins operator+(int lhs, const QMargins &rhs) Q_DECL_NOTHROW
{
return QMargins(rhs.left() + lhs, rhs.top() + lhs,
rhs.right() + lhs, rhs.bottom() + lhs);
}
-Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &lhs, int rhs)
+Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &lhs, int rhs) Q_DECL_NOTHROW
{
return QMargins(lhs.left() - rhs, lhs.top() - rhs,
lhs.right() - rhs, lhs.bottom() - rhs);
}
-Q_DECL_CONSTEXPR inline QMargins operator*(const QMargins &margins, int factor)
+Q_DECL_CONSTEXPR inline QMargins operator*(const QMargins &margins, int factor) Q_DECL_NOTHROW
{
return QMargins(margins.left() * factor, margins.top() * factor,
margins.right() * factor, margins.bottom() * factor);
}
-Q_DECL_CONSTEXPR inline QMargins operator*(int factor, const QMargins &margins)
+Q_DECL_CONSTEXPR inline QMargins operator*(int factor, const QMargins &margins) Q_DECL_NOTHROW
{
return QMargins(margins.left() * factor, margins.top() * factor,
margins.right() * factor, margins.bottom() * factor);
}
-Q_DECL_CONSTEXPR inline QMargins operator*(const QMargins &margins, qreal factor)
+Q_DECL_CONSTEXPR inline QMargins operator*(const QMargins &margins, qreal factor) Q_DECL_NOTHROW
{
return QMargins(qRound(margins.left() * factor), qRound(margins.top() * factor),
qRound(margins.right() * factor), qRound(margins.bottom() * factor));
}
-Q_DECL_CONSTEXPR inline QMargins operator*(qreal factor, const QMargins &margins)
+Q_DECL_CONSTEXPR inline QMargins operator*(qreal factor, const QMargins &margins) Q_DECL_NOTHROW
{
return QMargins(qRound(margins.left() * factor), qRound(margins.top() * factor),
qRound(margins.right() * factor), qRound(margins.bottom() * factor));
@@ -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) Q_DECL_NOTHROW
{
return *this = *this + margins;
}
-inline QMargins &QMargins::operator-=(const QMargins &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator-=(const QMargins &margins) Q_DECL_NOTHROW
{
return *this = *this - margins;
}
-inline QMargins &QMargins::operator+=(int margin)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator+=(int margin) Q_DECL_NOTHROW
{
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) Q_DECL_NOTHROW
{
m_left -= margin;
m_top -= margin;
@@ -238,32 +238,32 @@ inline QMargins &QMargins::operator-=(int margin)
return *this;
}
-inline QMargins &QMargins::operator*=(int factor)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator*=(int factor) Q_DECL_NOTHROW
{
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) Q_DECL_NOTHROW
{
return *this = *this * factor;
}
-inline QMargins &QMargins::operator/=(qreal divisor)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator/=(qreal divisor)
{
return *this = *this / divisor;
}
-Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &margins)
+Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &margins) Q_DECL_NOTHROW
{
return margins;
}
-Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &margins)
+Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &margins) Q_DECL_NOTHROW
{
return QMargins(-margins.left(), -margins.top(), -margins.right(), -margins.bottom());
}
@@ -279,30 +279,30 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QMargins &);
class QMarginsF
{
public:
- Q_DECL_CONSTEXPR QMarginsF();
- Q_DECL_CONSTEXPR QMarginsF(qreal left, qreal top, qreal right, qreal bottom);
- Q_DECL_CONSTEXPR QMarginsF(const QMargins &margins);
+ Q_DECL_CONSTEXPR QMarginsF() Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QMarginsF(qreal left, qreal top, qreal right, qreal bottom) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QMarginsF(const QMargins &margins) Q_DECL_NOTHROW;
- Q_DECL_CONSTEXPR bool isNull() const;
+ Q_DECL_CONSTEXPR bool isNull() const Q_DECL_NOTHROW;
- Q_DECL_CONSTEXPR qreal left() const;
- Q_DECL_CONSTEXPR qreal top() const;
- Q_DECL_CONSTEXPR qreal right() const;
- Q_DECL_CONSTEXPR qreal bottom() const;
+ Q_DECL_CONSTEXPR qreal left() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR qreal top() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR qreal right() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR qreal bottom() const Q_DECL_NOTHROW;
- 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_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR void setTop(qreal top) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR void setRight(qreal right) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR void setBottom(qreal bottom) Q_DECL_NOTHROW;
- 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_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator-=(const QMarginsF &margins) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator+=(qreal addend) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator-=(qreal subtrahend) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator*=(qreal factor) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator/=(qreal divisor);
- Q_DECL_CONSTEXPR inline QMargins toMargins() const;
+ Q_DECL_CONSTEXPR inline QMargins toMargins() const Q_DECL_NOTHROW;
private:
qreal m_left;
@@ -326,43 +326,44 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QMarginsF &);
QMarginsF inline functions
*****************************************************************************/
-Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF() : m_left(0), m_top(0), m_right(0), m_bottom(0) {}
+Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF() Q_DECL_NOTHROW
+ : m_left(0), m_top(0), m_right(0), m_bottom(0) {}
-Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(qreal aleft, qreal atop, qreal aright, qreal abottom)
+Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(qreal aleft, qreal atop, qreal aright, qreal abottom) Q_DECL_NOTHROW
: m_left(aleft), m_top(atop), m_right(aright), m_bottom(abottom) {}
-Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(const QMargins &margins)
+Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(const QMargins &margins) Q_DECL_NOTHROW
: m_left(margins.left()), m_top(margins.top()), m_right(margins.right()), m_bottom(margins.bottom()) {}
-Q_DECL_CONSTEXPR inline bool QMarginsF::isNull() const
+Q_DECL_CONSTEXPR inline bool QMarginsF::isNull() const Q_DECL_NOTHROW
{ return qFuzzyIsNull(m_left) && qFuzzyIsNull(m_top) && qFuzzyIsNull(m_right) && qFuzzyIsNull(m_bottom); }
-Q_DECL_CONSTEXPR inline qreal QMarginsF::left() const
+Q_DECL_CONSTEXPR inline qreal QMarginsF::left() const Q_DECL_NOTHROW
{ return m_left; }
-Q_DECL_CONSTEXPR inline qreal QMarginsF::top() const
+Q_DECL_CONSTEXPR inline qreal QMarginsF::top() const Q_DECL_NOTHROW
{ return m_top; }
-Q_DECL_CONSTEXPR inline qreal QMarginsF::right() const
+Q_DECL_CONSTEXPR inline qreal QMarginsF::right() const Q_DECL_NOTHROW
{ return m_right; }
-Q_DECL_CONSTEXPR inline qreal QMarginsF::bottom() const
+Q_DECL_CONSTEXPR inline qreal QMarginsF::bottom() const Q_DECL_NOTHROW
{ return m_bottom; }
-inline void QMarginsF::setLeft(qreal aleft)
+Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setLeft(qreal aleft) Q_DECL_NOTHROW
{ m_left = aleft; }
-inline void QMarginsF::setTop(qreal atop)
+Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setTop(qreal atop) Q_DECL_NOTHROW
{ m_top = atop; }
-inline void QMarginsF::setRight(qreal aright)
+Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setRight(qreal aright) Q_DECL_NOTHROW
{ m_right = aright; }
-inline void QMarginsF::setBottom(qreal abottom)
+Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setBottom(qreal abottom) Q_DECL_NOTHROW
{ m_bottom = abottom; }
-Q_DECL_CONSTEXPR inline bool operator==(const QMarginsF &lhs, const QMarginsF &rhs)
+Q_DECL_CONSTEXPR inline bool operator==(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return qFuzzyCompare(lhs.left(), rhs.left())
&& qFuzzyCompare(lhs.top(), rhs.top())
@@ -370,48 +371,48 @@ Q_DECL_CONSTEXPR inline bool operator==(const QMarginsF &lhs, const QMarginsF &r
&& qFuzzyCompare(lhs.bottom(), rhs.bottom());
}
-Q_DECL_CONSTEXPR inline bool operator!=(const QMarginsF &lhs, const QMarginsF &rhs)
+Q_DECL_CONSTEXPR inline bool operator!=(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return !operator==(lhs, rhs);
}
-Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, const QMarginsF &rhs)
+Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return QMarginsF(lhs.left() + rhs.left(), lhs.top() + rhs.top(),
lhs.right() + rhs.right(), lhs.bottom() + rhs.bottom());
}
-Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, const QMarginsF &rhs)
+Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return QMarginsF(lhs.left() - rhs.left(), lhs.top() - rhs.top(),
lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom());
}
-Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, qreal rhs)
+Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, qreal rhs) Q_DECL_NOTHROW
{
return QMarginsF(lhs.left() + rhs, lhs.top() + rhs,
lhs.right() + rhs, lhs.bottom() + rhs);
}
-Q_DECL_CONSTEXPR inline QMarginsF operator+(qreal lhs, const QMarginsF &rhs)
+Q_DECL_CONSTEXPR inline QMarginsF operator+(qreal lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return QMarginsF(rhs.left() + lhs, rhs.top() + lhs,
rhs.right() + lhs, rhs.bottom() + lhs);
}
-Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, qreal rhs)
+Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, qreal rhs) Q_DECL_NOTHROW
{
return QMarginsF(lhs.left() - rhs, lhs.top() - rhs,
lhs.right() - rhs, lhs.bottom() - rhs);
}
-Q_DECL_CONSTEXPR inline QMarginsF operator*(const QMarginsF &lhs, qreal rhs)
+Q_DECL_CONSTEXPR inline QMarginsF operator*(const QMarginsF &lhs, qreal rhs) Q_DECL_NOTHROW
{
return QMarginsF(lhs.left() * rhs, lhs.top() * rhs,
lhs.right() * rhs, lhs.bottom() * rhs);
}
-Q_DECL_CONSTEXPR inline QMarginsF operator*(qreal lhs, const QMarginsF &rhs)
+Q_DECL_CONSTEXPR inline QMarginsF operator*(qreal lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return QMarginsF(rhs.left() * lhs, rhs.top() * lhs,
rhs.right() * lhs, rhs.bottom() * lhs);
@@ -423,17 +424,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) Q_DECL_NOTHROW
{
return *this = *this + margins;
}
-inline QMarginsF &QMarginsF::operator-=(const QMarginsF &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator-=(const QMarginsF &margins) Q_DECL_NOTHROW
{
return *this = *this - margins;
}
-inline QMarginsF &QMarginsF::operator+=(qreal addend)
+Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator+=(qreal addend) Q_DECL_NOTHROW
{
m_left += addend;
m_top += addend;
@@ -442,7 +443,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) Q_DECL_NOTHROW
{
m_left -= subtrahend;
m_top -= subtrahend;
@@ -451,27 +452,27 @@ inline QMarginsF &QMarginsF::operator-=(qreal subtrahend)
return *this;
}
-inline QMarginsF &QMarginsF::operator*=(qreal factor)
+Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator*=(qreal factor) Q_DECL_NOTHROW
{
return *this = *this * factor;
}
-inline QMarginsF &QMarginsF::operator/=(qreal divisor)
+Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator/=(qreal divisor)
{
return *this = *this / divisor;
}
-Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &margins)
+Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &margins) Q_DECL_NOTHROW
{
return margins;
}
-Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &margins)
+Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &margins) Q_DECL_NOTHROW
{
return QMarginsF(-margins.left(), -margins.top(), -margins.right(), -margins.bottom());
}
-Q_DECL_CONSTEXPR inline QMargins QMarginsF::toMargins() const
+Q_DECL_CONSTEXPR inline QMargins QMarginsF::toMargins() const Q_DECL_NOTHROW
{
return QMargins(qRound(m_left), qRound(m_top), qRound(m_right), qRound(m_bottom));
}
diff --git a/src/corelib/tools/qpair.h b/src/corelib/tools/qpair.h
index 76b7abd263..4cba0a8421 100644
--- a/src/corelib/tools/qpair.h
+++ b/src/corelib/tools/qpair.h
@@ -52,7 +52,7 @@ 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>
@@ -60,14 +60,26 @@ struct QPair
// can't use std::move here as it's not constexpr in C++11:
: first(static_cast<TT1 &&>(p.first)), second(static_cast<TT2 &&>(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
+ Q_DECL_RELAXED_CONSTEXPR void swap(QPair &other)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(qSwap(other.first, other.first)) && noexcept(qSwap(other.second, other.second)))
+ {
+ // use qSwap() to pick up ADL swaps automatically:
+ qSwap(first, other.first);
+ qSwap(second, other.second);
+ }
+
T1 first;
T2 second;
};
+template <typename T1, typename T2>
+void swap(QPair<T1, T2> &lhs, QPair<T1, T2> &rhs) Q_DECL_NOEXCEPT_EXPR(noexcept(lhs.swap(rhs)))
+{ lhs.swap(rhs); }
+
// mark QPair<T1,T2> as complex/movable/primitive depending on the
// typeinfos of the constituents:
template<class T1, class T2>
@@ -75,38 +87,45 @@ class QTypeInfo<QPair<T1, T2> > : public QTypeInfoMerger<QPair<T1, T2>, T1, T2>
template <class T1, class T2>
Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator==(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(p1.first == p2.first && p1.second == p2.second))
{ return p1.first == p2.first && p1.second == p2.second; }
template <class T1, class T2>
Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator!=(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(!(p1 == p2)))
{ return !(p1 == p2); }
template <class T1, class T2>
Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator<(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(p1.first < p2.first || (!(p2.first < p1.first) && p1.second < p2.second)))
{
return p1.first < p2.first || (!(p2.first < p1.first) && p1.second < p2.second);
}
template <class T1, class T2>
Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator>(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(p2 < p1))
{
return p2 < p1;
}
template <class T1, class T2>
Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator<=(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(!(p2 < p1)))
{
return !(p2 < p1);
}
template <class T1, class T2>
Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator>=(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(!(p1 < p2)))
{
return !(p1 < p2);
}
template <class T1, class T2>
Q_DECL_CONSTEXPR Q_OUTOFLINE_TEMPLATE QPair<T1, T2> qMakePair(const T1 &x, const T2 &y)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(QPair<T1, T2>(x, y)))
{
return QPair<T1, T2>(x, y);
}
diff --git a/src/corelib/tools/qpair.qdoc b/src/corelib/tools/qpair.qdoc
index be329a0df0..f7b3c05db0 100644
--- a/src/corelib/tools/qpair.qdoc
+++ b/src/corelib/tools/qpair.qdoc
@@ -116,6 +116,31 @@
\sa qMakePair()
*/
+/*!
+ \fn void QPair::swap(QPair &other)
+ \since 5.5
+
+ Swaps this pair with \a other.
+
+ Equivalent to
+ \code
+ qSwap(this->first, other.first);
+ qSwap(this->second, other.second);
+ \endcode
+
+ Swap overloads are found in namespace \c std as well as via
+ argument-dependent lookup (ADL) in \c{T}'s namespace.
+*/
+
+/*!
+ \fn void swap(QPair<T1, T2> &lhs, QPair<T1, T2> &rhs)
+ \overload
+ \relates QPair
+ \since 5.5
+
+ Swaps \a lhs with \a rhs.
+*/
+
/*! \fn bool operator==(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
\relates QPair
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.cpp b/src/corelib/tools/qrect.cpp
index dc46f85fb5..ed53db0838 100644
--- a/src/corelib/tools/qrect.cpp
+++ b/src/corelib/tools/qrect.cpp
@@ -36,8 +36,6 @@
#include "qdebug.h"
#include "qmath.h"
-#include <math.h>
-
QT_BEGIN_NAMESPACE
/*!
@@ -295,7 +293,7 @@ QT_BEGIN_NAMESPACE
\sa isValid(), isEmpty()
*/
-QRect QRect::normalized() const
+QRect QRect::normalized() const Q_DECL_NOTHROW
{
QRect r;
if (x2 < x1 - 1) { // swap bad x values
@@ -804,7 +802,7 @@ QRect QRect::normalized() const
\sa intersects()
*/
-bool QRect::contains(const QPoint &p, bool proper) const
+bool QRect::contains(const QPoint &p, bool proper) const Q_DECL_NOTHROW
{
int l, r;
if (x2 < x1 - 1) {
@@ -868,7 +866,7 @@ bool QRect::contains(const QPoint &p, bool proper) const
rectangle (not on the edge).
*/
-bool QRect::contains(const QRect &r, bool proper) const
+bool QRect::contains(const QRect &r, bool proper) const Q_DECL_NOTHROW
{
if (isNull() || r.isNull())
return false;
@@ -946,7 +944,7 @@ bool QRect::contains(const QRect &r, bool proper) const
\sa operator|=(), united()
*/
-QRect QRect::operator|(const QRect &r) const
+QRect QRect::operator|(const QRect &r) const Q_DECL_NOTHROW
{
if (isNull())
return r;
@@ -1017,7 +1015,7 @@ QRect QRect::operator|(const QRect &r) const
\sa operator&=(), intersected()
*/
-QRect QRect::operator&(const QRect &r) const
+QRect QRect::operator&(const QRect &r) const Q_DECL_NOTHROW
{
if (isNull() || r.isNull())
return QRect();
@@ -1096,7 +1094,7 @@ QRect QRect::operator&(const QRect &r) const
\sa contains()
*/
-bool QRect::intersects(const QRect &r) const
+bool QRect::intersects(const QRect &r) const Q_DECL_NOTHROW
{
if (isNull() || r.isNull())
return false;
@@ -1522,7 +1520,7 @@ QDebug operator<<(QDebug dbg, const QRect &r)
\sa isValid(), isEmpty()
*/
-QRectF QRectF::normalized() const
+QRectF QRectF::normalized() const Q_DECL_NOTHROW
{
QRectF r = *this;
if (r.w < 0) {
@@ -1935,7 +1933,7 @@ QRectF QRectF::normalized() const
\sa intersects()
*/
-bool QRectF::contains(const QPointF &p) const
+bool QRectF::contains(const QPointF &p) const Q_DECL_NOTHROW
{
qreal l = xp;
qreal r = xp;
@@ -1981,7 +1979,7 @@ bool QRectF::contains(const QPointF &p) const
otherwise returns \c false.
*/
-bool QRectF::contains(const QRectF &r) const
+bool QRectF::contains(const QRectF &r) const Q_DECL_NOTHROW
{
qreal l1 = xp;
qreal r1 = xp;
@@ -2119,7 +2117,7 @@ bool QRectF::contains(const QRectF &r) const
\sa united(), operator|=()
*/
-QRectF QRectF::operator|(const QRectF &r) const
+QRectF QRectF::operator|(const QRectF &r) const Q_DECL_NOTHROW
{
if (isNull())
return r;
@@ -2188,7 +2186,7 @@ QRectF QRectF::operator|(const QRectF &r) const
\sa operator&=(), intersected()
*/
-QRectF QRectF::operator&(const QRectF &r) const
+QRectF QRectF::operator&(const QRectF &r) const Q_DECL_NOTHROW
{
qreal l1 = xp;
qreal r1 = xp;
@@ -2273,7 +2271,7 @@ QRectF QRectF::operator&(const QRectF &r) const
\sa contains()
*/
-bool QRectF::intersects(const QRectF &r) const
+bool QRectF::intersects(const QRectF &r) const Q_DECL_NOTHROW
{
qreal l1 = xp;
qreal r1 = xp;
@@ -2340,7 +2338,7 @@ bool QRectF::intersects(const QRectF &r) const
\sa toRect()
*/
-QRect QRectF::toAlignedRect() const
+QRect QRectF::toAlignedRect() const Q_DECL_NOTHROW
{
int xmin = int(qFloor(xp));
int xmax = int(qCeil(xp + w));
diff --git a/src/corelib/tools/qrect.h b/src/corelib/tools/qrect.h
index b5be5724af..a98ef565f7 100644
--- a/src/corelib/tools/qrect.h
+++ b/src/corelib/tools/qrect.h
@@ -47,100 +47,100 @@ QT_BEGIN_NAMESPACE
class Q_CORE_EXPORT QRect
{
public:
- Q_DECL_CONSTEXPR QRect() : x1(0), y1(0), x2(-1), y2(-1) {}
- Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QPoint &bottomright);
- Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QSize &size);
- Q_DECL_CONSTEXPR QRect(int left, int top, int width, int height);
-
- Q_DECL_CONSTEXPR inline bool isNull() const;
- Q_DECL_CONSTEXPR inline bool isEmpty() const;
- Q_DECL_CONSTEXPR inline bool isValid() const;
-
- Q_DECL_CONSTEXPR inline int left() const;
- Q_DECL_CONSTEXPR inline int top() const;
- Q_DECL_CONSTEXPR inline int right() const;
- Q_DECL_CONSTEXPR inline int bottom() const;
- QRect normalized() const Q_REQUIRED_RESULT;
-
- 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_CONSTEXPR inline QPoint topLeft() const;
- Q_DECL_CONSTEXPR inline QPoint bottomRight() const;
- Q_DECL_CONSTEXPR inline QPoint topRight() const;
- 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_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);
-
- inline void setRect(int x, int y, int w, int h);
- 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;
-
- 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);
-
- QRect operator|(const QRect &r) const;
- QRect operator&(const QRect &r) const;
- inline QRect& operator|=(const QRect &r);
- inline QRect& operator&=(const QRect &r);
-
- bool contains(const QRect &r, bool proper = false) const;
- bool contains(const QPoint &p, bool proper=false) const;
- inline bool contains(int x, int y) const;
- inline bool contains(int x, int y, bool proper) const;
- inline QRect united(const QRect &other) const Q_REQUIRED_RESULT;
- inline QRect intersected(const QRect &other) const Q_REQUIRED_RESULT;
- bool intersects(const QRect &r) const;
-
- 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_CONSTEXPR QRect() Q_DECL_NOTHROW : x1(0), y1(0), x2(-1), y2(-1) {}
+ Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QPoint &bottomright) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QSize &size) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QRect(int left, int top, int width, int height) Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline bool isNull() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline bool isEmpty() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline int left() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline int top() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline int right() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline int bottom() const Q_DECL_NOTHROW;
+ QRect normalized() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+
+ Q_DECL_CONSTEXPR inline int x() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline int y() const Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setLeft(int pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setTop(int pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setRight(int pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setBottom(int pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setX(int x) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setY(int y) Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void setTopLeft(const QPoint &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setBottomRight(const QPoint &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setTopRight(const QPoint &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setBottomLeft(const QPoint &p) Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline QPoint topLeft() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QPoint bottomRight() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QPoint topRight() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QPoint bottomLeft() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QPoint center() const Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void moveLeft(int pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTop(int pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveRight(int pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveBottom(int pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTopLeft(const QPoint &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveBottomRight(const QPoint &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTopRight(const QPoint &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveBottomLeft(const QPoint &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveCenter(const QPoint &p) Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void translate(int dx, int dy) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void translate(const QPoint &p) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QRect translated(int dx, int dy) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ Q_DECL_CONSTEXPR inline QRect translated(const QPoint &p) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTo(int x, int t) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTo(const QPoint &p) Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void setRect(int x, int y, int w, int h) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void getRect(int *x, int *y, int *w, int *h) const;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void setCoords(int x1, int y1, int x2, int y2) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void getCoords(int *x1, int *y1, int *x2, int *y2) const;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void adjust(int x1, int y1, int x2, int y2) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QRect adjusted(int x1, int y1, int x2, int y2) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+
+ Q_DECL_CONSTEXPR inline QSize size() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline int width() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline int height() const Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setWidth(int w) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setHeight(int h) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setSize(const QSize &s) Q_DECL_NOTHROW;
+
+ QRect operator|(const QRect &r) const Q_DECL_NOTHROW;
+ QRect operator&(const QRect &r) const Q_DECL_NOTHROW;
+ inline QRect& operator|=(const QRect &r) Q_DECL_NOTHROW;
+ inline QRect& operator&=(const QRect &r) Q_DECL_NOTHROW;
+
+ bool contains(const QRect &r, bool proper = false) const Q_DECL_NOTHROW;
+ bool contains(const QPoint &p, bool proper=false) const Q_DECL_NOTHROW;
+ inline bool contains(int x, int y) const Q_DECL_NOTHROW;
+ inline bool contains(int x, int y, bool proper) const Q_DECL_NOTHROW;
+ inline QRect united(const QRect &other) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ inline QRect intersected(const QRect &other) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ bool intersects(const QRect &r) const Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline QRect marginsAdded(const QMargins &margins) const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QRect marginsRemoved(const QMargins &margins) const Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline QRect &operator+=(const QMargins &margins) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline QRect &operator-=(const QMargins &margins) Q_DECL_NOTHROW;
#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED QRect unite(const QRect &r) const Q_REQUIRED_RESULT { return united(r); }
- QT_DEPRECATED QRect intersect(const QRect &r) const Q_REQUIRED_RESULT { return intersected(r); }
+ QT_DEPRECATED QRect unite(const QRect &r) const Q_DECL_NOTHROW Q_REQUIRED_RESULT { return united(r); }
+ QT_DEPRECATED QRect intersect(const QRect &r) const Q_DECL_NOTHROW Q_REQUIRED_RESULT { return intersected(r); }
#endif
- friend Q_DECL_CONSTEXPR inline bool operator==(const QRect &, const QRect &);
- friend Q_DECL_CONSTEXPR inline bool operator!=(const QRect &, const QRect &);
+ friend Q_DECL_CONSTEXPR inline bool operator==(const QRect &, const QRect &) Q_DECL_NOTHROW;
+ friend Q_DECL_CONSTEXPR inline bool operator!=(const QRect &, const QRect &) Q_DECL_NOTHROW;
private:
int x1;
@@ -150,8 +150,8 @@ private:
};
Q_DECLARE_TYPEINFO(QRect, Q_MOVABLE_TYPE);
-Q_DECL_CONSTEXPR inline bool operator==(const QRect &, const QRect &);
-Q_DECL_CONSTEXPR inline bool operator!=(const QRect &, const QRect &);
+Q_DECL_CONSTEXPR inline bool operator==(const QRect &, const QRect &) Q_DECL_NOTHROW;
+Q_DECL_CONSTEXPR inline bool operator!=(const QRect &, const QRect &) Q_DECL_NOTHROW;
/*****************************************************************************
@@ -166,97 +166,97 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRect &);
QRect inline member functions
*****************************************************************************/
-Q_DECL_CONSTEXPR inline QRect::QRect(int aleft, int atop, int awidth, int aheight)
+Q_DECL_CONSTEXPR inline QRect::QRect(int aleft, int atop, int awidth, int aheight) Q_DECL_NOTHROW
: x1(aleft), y1(atop), x2(aleft + awidth - 1), y2(atop + aheight - 1) {}
-Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QPoint &abottomRight)
+Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QPoint &abottomRight) Q_DECL_NOTHROW
: x1(atopLeft.x()), y1(atopLeft.y()), x2(abottomRight.x()), y2(abottomRight.y()) {}
-Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QSize &asize)
+Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QSize &asize) Q_DECL_NOTHROW
: x1(atopLeft.x()), y1(atopLeft.y()), x2(atopLeft.x()+asize.width() - 1), y2(atopLeft.y()+asize.height() - 1) {}
-Q_DECL_CONSTEXPR inline bool QRect::isNull() const
+Q_DECL_CONSTEXPR inline bool QRect::isNull() const Q_DECL_NOTHROW
{ return x2 == x1 - 1 && y2 == y1 - 1; }
-Q_DECL_CONSTEXPR inline bool QRect::isEmpty() const
+Q_DECL_CONSTEXPR inline bool QRect::isEmpty() const Q_DECL_NOTHROW
{ return x1 > x2 || y1 > y2; }
-Q_DECL_CONSTEXPR inline bool QRect::isValid() const
+Q_DECL_CONSTEXPR inline bool QRect::isValid() const Q_DECL_NOTHROW
{ return x1 <= x2 && y1 <= y2; }
-Q_DECL_CONSTEXPR inline int QRect::left() const
+Q_DECL_CONSTEXPR inline int QRect::left() const Q_DECL_NOTHROW
{ return x1; }
-Q_DECL_CONSTEXPR inline int QRect::top() const
+Q_DECL_CONSTEXPR inline int QRect::top() const Q_DECL_NOTHROW
{ return y1; }
-Q_DECL_CONSTEXPR inline int QRect::right() const
+Q_DECL_CONSTEXPR inline int QRect::right() const Q_DECL_NOTHROW
{ return x2; }
-Q_DECL_CONSTEXPR inline int QRect::bottom() const
+Q_DECL_CONSTEXPR inline int QRect::bottom() const Q_DECL_NOTHROW
{ return y2; }
-Q_DECL_CONSTEXPR inline int QRect::x() const
+Q_DECL_CONSTEXPR inline int QRect::x() const Q_DECL_NOTHROW
{ return x1; }
-Q_DECL_CONSTEXPR inline int QRect::y() const
+Q_DECL_CONSTEXPR inline int QRect::y() const Q_DECL_NOTHROW
{ return y1; }
-inline void QRect::setLeft(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setLeft(int pos) Q_DECL_NOTHROW
{ x1 = pos; }
-inline void QRect::setTop(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setTop(int pos) Q_DECL_NOTHROW
{ y1 = pos; }
-inline void QRect::setRight(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setRight(int pos) Q_DECL_NOTHROW
{ x2 = pos; }
-inline void QRect::setBottom(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setBottom(int pos) Q_DECL_NOTHROW
{ y2 = pos; }
-inline void QRect::setTopLeft(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setTopLeft(const QPoint &p) Q_DECL_NOTHROW
{ x1 = p.x(); y1 = p.y(); }
-inline void QRect::setBottomRight(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setBottomRight(const QPoint &p) Q_DECL_NOTHROW
{ x2 = p.x(); y2 = p.y(); }
-inline void QRect::setTopRight(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setTopRight(const QPoint &p) Q_DECL_NOTHROW
{ x2 = p.x(); y1 = p.y(); }
-inline void QRect::setBottomLeft(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setBottomLeft(const QPoint &p) Q_DECL_NOTHROW
{ x1 = p.x(); y2 = p.y(); }
-inline void QRect::setX(int ax)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setX(int ax) Q_DECL_NOTHROW
{ x1 = ax; }
-inline void QRect::setY(int ay)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setY(int ay) Q_DECL_NOTHROW
{ y1 = ay; }
-Q_DECL_CONSTEXPR inline QPoint QRect::topLeft() const
+Q_DECL_CONSTEXPR inline QPoint QRect::topLeft() const Q_DECL_NOTHROW
{ return QPoint(x1, y1); }
-Q_DECL_CONSTEXPR inline QPoint QRect::bottomRight() const
+Q_DECL_CONSTEXPR inline QPoint QRect::bottomRight() const Q_DECL_NOTHROW
{ return QPoint(x2, y2); }
-Q_DECL_CONSTEXPR inline QPoint QRect::topRight() const
+Q_DECL_CONSTEXPR inline QPoint QRect::topRight() const Q_DECL_NOTHROW
{ return QPoint(x2, y1); }
-Q_DECL_CONSTEXPR inline QPoint QRect::bottomLeft() const
+Q_DECL_CONSTEXPR inline QPoint QRect::bottomLeft() const Q_DECL_NOTHROW
{ return QPoint(x1, y2); }
-Q_DECL_CONSTEXPR inline QPoint QRect::center() const
+Q_DECL_CONSTEXPR inline QPoint QRect::center() const Q_DECL_NOTHROW
{ return QPoint((x1+x2)/2, (y1+y2)/2); }
-Q_DECL_CONSTEXPR inline int QRect::width() const
+Q_DECL_CONSTEXPR inline int QRect::width() const Q_DECL_NOTHROW
{ return x2 - x1 + 1; }
-Q_DECL_CONSTEXPR inline int QRect::height() const
+Q_DECL_CONSTEXPR inline int QRect::height() const Q_DECL_NOTHROW
{ return y2 - y1 + 1; }
-Q_DECL_CONSTEXPR inline QSize QRect::size() const
+Q_DECL_CONSTEXPR inline QSize QRect::size() const Q_DECL_NOTHROW
{ return QSize(width(), height()); }
-inline void QRect::translate(int dx, int dy)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::translate(int dx, int dy) Q_DECL_NOTHROW
{
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) Q_DECL_NOTHROW
{
x1 += p.x();
y1 += p.y();
@@ -272,13 +272,13 @@ inline void QRect::translate(const QPoint &p)
y2 += p.y();
}
-Q_DECL_CONSTEXPR inline QRect QRect::translated(int dx, int dy) const
+Q_DECL_CONSTEXPR inline QRect QRect::translated(int dx, int dy) const Q_DECL_NOTHROW
{ return QRect(QPoint(x1 + dx, y1 + dy), QPoint(x2 + dx, y2 + dy)); }
-Q_DECL_CONSTEXPR inline QRect QRect::translated(const QPoint &p) const
+Q_DECL_CONSTEXPR inline QRect QRect::translated(const QPoint &p) const Q_DECL_NOTHROW
{ 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) Q_DECL_NOTHROW
{
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) Q_DECL_NOTHROW
{
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) Q_DECL_NOTHROW
{ x2 += (pos - x1); x1 = pos; }
-inline void QRect::moveTop(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTop(int pos) Q_DECL_NOTHROW
{ y2 += (pos - y1); y1 = pos; }
-inline void QRect::moveRight(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveRight(int pos) Q_DECL_NOTHROW
{
x1 += (pos - x2);
x2 = pos;
}
-inline void QRect::moveBottom(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveBottom(int pos) Q_DECL_NOTHROW
{
y1 += (pos - y2);
y2 = pos;
}
-inline void QRect::moveTopLeft(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTopLeft(const QPoint &p) Q_DECL_NOTHROW
{
moveLeft(p.x());
moveTop(p.y());
}
-inline void QRect::moveBottomRight(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveBottomRight(const QPoint &p) Q_DECL_NOTHROW
{
moveRight(p.x());
moveBottom(p.y());
}
-inline void QRect::moveTopRight(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTopRight(const QPoint &p) Q_DECL_NOTHROW
{
moveRight(p.x());
moveTop(p.y());
}
-inline void QRect::moveBottomLeft(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveBottomLeft(const QPoint &p) Q_DECL_NOTHROW
{
moveLeft(p.x());
moveBottom(p.y());
}
-inline void QRect::moveCenter(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveCenter(const QPoint &p) Q_DECL_NOTHROW
{
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) Q_DECL_NOTHROW
{
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) Q_DECL_NOTHROW
{
x1 = xp1;
y1 = yp1;
@@ -378,10 +378,10 @@ inline void QRect::setCoords(int xp1, int yp1, int xp2, int yp2)
y2 = yp2;
}
-Q_DECL_CONSTEXPR inline QRect QRect::adjusted(int xp1, int yp1, int xp2, int yp2) const
+Q_DECL_CONSTEXPR inline QRect QRect::adjusted(int xp1, int yp1, int xp2, int yp2) const Q_DECL_NOTHROW
{ 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) Q_DECL_NOTHROW
{
x1 += dx1;
y1 += dy1;
@@ -389,97 +389,97 @@ 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) Q_DECL_NOTHROW
{ x2 = (x1 + w - 1); }
-inline void QRect::setHeight(int h)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setHeight(int h) Q_DECL_NOTHROW
{ y2 = (y1 + h - 1); }
-inline void QRect::setSize(const QSize &s)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setSize(const QSize &s) Q_DECL_NOTHROW
{
x2 = (s.width() + x1 - 1);
y2 = (s.height() + y1 - 1);
}
-inline bool QRect::contains(int ax, int ay, bool aproper) const
+inline bool QRect::contains(int ax, int ay, bool aproper) const Q_DECL_NOTHROW
{
return contains(QPoint(ax, ay), aproper);
}
-inline bool QRect::contains(int ax, int ay) const
+inline bool QRect::contains(int ax, int ay) const Q_DECL_NOTHROW
{
return contains(QPoint(ax, ay), false);
}
-inline QRect& QRect::operator|=(const QRect &r)
+inline QRect& QRect::operator|=(const QRect &r) Q_DECL_NOTHROW
{
*this = *this | r;
return *this;
}
-inline QRect& QRect::operator&=(const QRect &r)
+inline QRect& QRect::operator&=(const QRect &r) Q_DECL_NOTHROW
{
*this = *this & r;
return *this;
}
-inline QRect QRect::intersected(const QRect &other) const
+inline QRect QRect::intersected(const QRect &other) const Q_DECL_NOTHROW
{
return *this & other;
}
-inline QRect QRect::united(const QRect &r) const
+inline QRect QRect::united(const QRect &r) const Q_DECL_NOTHROW
{
return *this | r;
}
-Q_DECL_CONSTEXPR inline bool operator==(const QRect &r1, const QRect &r2)
+Q_DECL_CONSTEXPR inline bool operator==(const QRect &r1, const QRect &r2) Q_DECL_NOTHROW
{
return r1.x1==r2.x1 && r1.x2==r2.x2 && r1.y1==r2.y1 && r1.y2==r2.y2;
}
-Q_DECL_CONSTEXPR inline bool operator!=(const QRect &r1, const QRect &r2)
+Q_DECL_CONSTEXPR inline bool operator!=(const QRect &r1, const QRect &r2) Q_DECL_NOTHROW
{
return r1.x1!=r2.x1 || r1.x2!=r2.x2 || r1.y1!=r2.y1 || r1.y2!=r2.y2;
}
-Q_DECL_CONSTEXPR inline QRect operator+(const QRect &rectangle, const QMargins &margins)
+Q_DECL_CONSTEXPR inline QRect operator+(const QRect &rectangle, const QMargins &margins) Q_DECL_NOTHROW
{
return QRect(QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()),
QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom()));
}
-Q_DECL_CONSTEXPR inline QRect operator+(const QMargins &margins, const QRect &rectangle)
+Q_DECL_CONSTEXPR inline QRect operator+(const QMargins &margins, const QRect &rectangle) Q_DECL_NOTHROW
{
return QRect(QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()),
QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom()));
}
-Q_DECL_CONSTEXPR inline QRect operator-(const QRect &lhs, const QMargins &rhs)
+Q_DECL_CONSTEXPR inline QRect operator-(const QRect &lhs, const QMargins &rhs) Q_DECL_NOTHROW
{
return QRect(QPoint(lhs.left() + rhs.left(), lhs.top() + rhs.top()),
QPoint(lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom()));
}
-Q_DECL_CONSTEXPR inline QRect QRect::marginsAdded(const QMargins &margins) const
+Q_DECL_CONSTEXPR inline QRect QRect::marginsAdded(const QMargins &margins) const Q_DECL_NOTHROW
{
return QRect(QPoint(x1 - margins.left(), y1 - margins.top()),
QPoint(x2 + margins.right(), y2 + margins.bottom()));
}
-Q_DECL_CONSTEXPR inline QRect QRect::marginsRemoved(const QMargins &margins) const
+Q_DECL_CONSTEXPR inline QRect QRect::marginsRemoved(const QMargins &margins) const Q_DECL_NOTHROW
{
return QRect(QPoint(x1 + margins.left(), y1 + margins.top()),
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) Q_DECL_NOTHROW
{
*this = marginsAdded(margins);
return *this;
}
-inline QRect &QRect::operator-=(const QMargins &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QRect &QRect::operator-=(const QMargins &margins) Q_DECL_NOTHROW
{
*this = marginsRemoved(margins);
return *this;
@@ -493,104 +493,104 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QRect &);
class Q_CORE_EXPORT QRectF
{
public:
- Q_DECL_CONSTEXPR QRectF() : xp(0.), yp(0.), w(0.), h(0.) {}
- Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QSizeF &size);
- Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QPointF &bottomRight);
- Q_DECL_CONSTEXPR QRectF(qreal left, qreal top, qreal width, qreal height);
- Q_DECL_CONSTEXPR QRectF(const QRect &rect);
-
- Q_DECL_CONSTEXPR inline bool isNull() const;
- Q_DECL_CONSTEXPR inline bool isEmpty() const;
- Q_DECL_CONSTEXPR inline bool isValid() const;
- QRectF normalized() const Q_REQUIRED_RESULT;
-
- Q_DECL_CONSTEXPR inline qreal left() const { return xp; }
- Q_DECL_CONSTEXPR inline qreal top() const { return yp; }
- Q_DECL_CONSTEXPR inline qreal right() const { return xp + w; }
- Q_DECL_CONSTEXPR inline qreal bottom() const { return yp + h; }
-
- 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_CONSTEXPR inline QPointF topLeft() const { return QPointF(xp, yp); }
- Q_DECL_CONSTEXPR inline QPointF bottomRight() const { return QPointF(xp+w, yp+h); }
- Q_DECL_CONSTEXPR inline QPointF topRight() const { return QPointF(xp+w, yp); }
- 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);
-
- 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);
-
- inline void translate(qreal dx, qreal dy);
- 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);
-
- inline void setRect(qreal x, qreal y, qreal w, qreal h);
- 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;
-
- 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);
-
- QRectF operator|(const QRectF &r) const;
- QRectF operator&(const QRectF &r) const;
- inline QRectF& operator|=(const QRectF &r);
- inline QRectF& operator&=(const QRectF &r);
-
- bool contains(const QRectF &r) const;
- bool contains(const QPointF &p) const;
- inline bool contains(qreal x, qreal y) const;
- inline QRectF united(const QRectF &other) const Q_REQUIRED_RESULT;
- inline QRectF intersected(const QRectF &other) const Q_REQUIRED_RESULT;
- bool intersects(const QRectF &r) const;
-
- 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_CONSTEXPR QRectF() Q_DECL_NOTHROW : xp(0.), yp(0.), w(0.), h(0.) {}
+ Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QSizeF &size) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QPointF &bottomRight) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QRectF(qreal left, qreal top, qreal width, qreal height) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QRectF(const QRect &rect) Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline bool isNull() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline bool isEmpty() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOTHROW;
+ QRectF normalized() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+
+ Q_DECL_CONSTEXPR inline qreal left() const Q_DECL_NOTHROW { return xp; }
+ Q_DECL_CONSTEXPR inline qreal top() const Q_DECL_NOTHROW { return yp; }
+ Q_DECL_CONSTEXPR inline qreal right() const Q_DECL_NOTHROW { return xp + w; }
+ Q_DECL_CONSTEXPR inline qreal bottom() const Q_DECL_NOTHROW { return yp + h; }
+
+ Q_DECL_CONSTEXPR inline qreal x() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline qreal y() const Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setLeft(qreal pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setTop(qreal pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setRight(qreal pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setBottom(qreal pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setX(qreal pos) Q_DECL_NOTHROW { setLeft(pos); }
+ Q_DECL_RELAXED_CONSTEXPR inline void setY(qreal pos) Q_DECL_NOTHROW { setTop(pos); }
+
+ Q_DECL_CONSTEXPR inline QPointF topLeft() const Q_DECL_NOTHROW { return QPointF(xp, yp); }
+ Q_DECL_CONSTEXPR inline QPointF bottomRight() const Q_DECL_NOTHROW { return QPointF(xp+w, yp+h); }
+ Q_DECL_CONSTEXPR inline QPointF topRight() const Q_DECL_NOTHROW { return QPointF(xp+w, yp); }
+ Q_DECL_CONSTEXPR inline QPointF bottomLeft() const Q_DECL_NOTHROW { return QPointF(xp, yp+h); }
+ Q_DECL_CONSTEXPR inline QPointF center() const Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void setTopLeft(const QPointF &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setBottomRight(const QPointF &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setTopRight(const QPointF &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setBottomLeft(const QPointF &p) Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void moveLeft(qreal pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTop(qreal pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveRight(qreal pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveBottom(qreal pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTopLeft(const QPointF &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveBottomRight(const QPointF &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTopRight(const QPointF &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveBottomLeft(const QPointF &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveCenter(const QPointF &p) Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void translate(qreal dx, qreal dy) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void translate(const QPointF &p) Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline QRectF translated(qreal dx, qreal dy) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ Q_DECL_CONSTEXPR inline QRectF translated(const QPointF &p) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTo(qreal x, qreal y) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTo(const QPointF &p) Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void setRect(qreal x, qreal y, qreal w, qreal h) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void getRect(qreal *x, qreal *y, qreal *w, qreal *h) const;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void setCoords(qreal x1, qreal y1, qreal x2, qreal y2) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void adjust(qreal x1, qreal y1, qreal x2, qreal y2) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+
+ Q_DECL_CONSTEXPR inline QSizeF size() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline qreal width() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline qreal height() const Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setWidth(qreal w) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setHeight(qreal h) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setSize(const QSizeF &s) Q_DECL_NOTHROW;
+
+ QRectF operator|(const QRectF &r) const Q_DECL_NOTHROW;
+ QRectF operator&(const QRectF &r) const Q_DECL_NOTHROW;
+ inline QRectF& operator|=(const QRectF &r) Q_DECL_NOTHROW;
+ inline QRectF& operator&=(const QRectF &r) Q_DECL_NOTHROW;
+
+ bool contains(const QRectF &r) const Q_DECL_NOTHROW;
+ bool contains(const QPointF &p) const Q_DECL_NOTHROW;
+ inline bool contains(qreal x, qreal y) const Q_DECL_NOTHROW;
+ inline QRectF united(const QRectF &other) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ inline QRectF intersected(const QRectF &other) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ bool intersects(const QRectF &r) const Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline QRectF marginsAdded(const QMarginsF &margins) const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QRectF marginsRemoved(const QMarginsF &margins) const Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline QRectF &operator+=(const QMarginsF &margins) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline QRectF &operator-=(const QMarginsF &margins) Q_DECL_NOTHROW;
#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED QRectF unite(const QRectF &r) const Q_REQUIRED_RESULT { return united(r); }
- QT_DEPRECATED QRectF intersect(const QRectF &r) const Q_REQUIRED_RESULT { return intersected(r); }
+ QT_DEPRECATED QRectF unite(const QRectF &r) const Q_DECL_NOTHROW Q_REQUIRED_RESULT { return united(r); }
+ QT_DEPRECATED QRectF intersect(const QRectF &r) const Q_DECL_NOTHROW Q_REQUIRED_RESULT { return intersected(r); }
#endif
- friend Q_DECL_CONSTEXPR inline bool operator==(const QRectF &, const QRectF &);
- friend Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &, const QRectF &);
+ friend Q_DECL_CONSTEXPR inline bool operator==(const QRectF &, const QRectF &) Q_DECL_NOTHROW;
+ friend Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &, const QRectF &) Q_DECL_NOTHROW;
- Q_DECL_CONSTEXPR inline QRect toRect() const Q_REQUIRED_RESULT;
- QRect toAlignedRect() const Q_REQUIRED_RESULT;
+ Q_DECL_CONSTEXPR inline QRect toRect() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ QRect toAlignedRect() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
private:
qreal xp;
@@ -600,8 +600,8 @@ private:
};
Q_DECLARE_TYPEINFO(QRectF, Q_MOVABLE_TYPE);
-Q_DECL_CONSTEXPR inline bool operator==(const QRectF &, const QRectF &);
-Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &, const QRectF &);
+Q_DECL_CONSTEXPR inline bool operator==(const QRectF &, const QRectF &) Q_DECL_NOTHROW;
+Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &, const QRectF &) Q_DECL_NOTHROW;
/*****************************************************************************
@@ -616,119 +616,136 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRectF &);
QRectF inline member functions
*****************************************************************************/
-Q_DECL_CONSTEXPR inline QRectF::QRectF(qreal aleft, qreal atop, qreal awidth, qreal aheight)
+Q_DECL_CONSTEXPR inline QRectF::QRectF(qreal aleft, qreal atop, qreal awidth, qreal aheight) Q_DECL_NOTHROW
: xp(aleft), yp(atop), w(awidth), h(aheight)
{
}
-Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QSizeF &asize)
+Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QSizeF &asize) Q_DECL_NOTHROW
: xp(atopLeft.x()), yp(atopLeft.y()), w(asize.width()), h(asize.height())
{
}
-Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QPointF &abottomRight)
+Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QPointF &abottomRight) Q_DECL_NOTHROW
: xp(atopLeft.x()), yp(atopLeft.y()), w(abottomRight.x() - atopLeft.x()), h(abottomRight.y() - atopLeft.y())
{
}
-Q_DECL_CONSTEXPR inline QRectF::QRectF(const QRect &r)
+Q_DECL_CONSTEXPR inline QRectF::QRectF(const QRect &r) Q_DECL_NOTHROW
: xp(r.x()), yp(r.y()), w(r.width()), h(r.height())
{
}
-Q_DECL_CONSTEXPR inline bool QRectF::isNull() const
+Q_DECL_CONSTEXPR inline bool QRectF::isNull() const Q_DECL_NOTHROW
{ return w == 0. && h == 0.; }
-Q_DECL_CONSTEXPR inline bool QRectF::isEmpty() const
+Q_DECL_CONSTEXPR inline bool QRectF::isEmpty() const Q_DECL_NOTHROW
{ return w <= 0. || h <= 0.; }
-Q_DECL_CONSTEXPR inline bool QRectF::isValid() const
+Q_DECL_CONSTEXPR inline bool QRectF::isValid() const Q_DECL_NOTHROW
{ return w > 0. && h > 0.; }
-Q_DECL_CONSTEXPR inline qreal QRectF::x() const
+Q_DECL_CONSTEXPR inline qreal QRectF::x() const Q_DECL_NOTHROW
{ return xp; }
-Q_DECL_CONSTEXPR inline qreal QRectF::y() const
+Q_DECL_CONSTEXPR inline qreal QRectF::y() const Q_DECL_NOTHROW
{ 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) Q_DECL_NOTHROW
+{ 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) Q_DECL_NOTHROW
+{ 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) Q_DECL_NOTHROW
+{ 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) Q_DECL_NOTHROW
+{ 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) Q_DECL_NOTHROW
+{ 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) Q_DECL_NOTHROW
+{ 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) Q_DECL_NOTHROW
+{ 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) Q_DECL_NOTHROW
+{ setRight(p.x()); setBottom(p.y()); }
-Q_DECL_CONSTEXPR inline QPointF QRectF::center() const
+Q_DECL_CONSTEXPR inline QPointF QRectF::center() const Q_DECL_NOTHROW
{ 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) Q_DECL_NOTHROW
+{ xp = pos; }
-inline void QRectF::moveTop(qreal pos) { yp = pos; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTop(qreal pos) Q_DECL_NOTHROW
+{ yp = pos; }
-inline void QRectF::moveRight(qreal pos) { xp = pos - w; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveRight(qreal pos) Q_DECL_NOTHROW
+{ xp = pos - w; }
-inline void QRectF::moveBottom(qreal pos) { yp = pos - h; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveBottom(qreal pos) Q_DECL_NOTHROW
+{ 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) Q_DECL_NOTHROW
+{ 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) Q_DECL_NOTHROW
+{ 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) Q_DECL_NOTHROW
+{ 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) Q_DECL_NOTHROW
+{ 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) Q_DECL_NOTHROW
+{ xp = p.x() - w/2; yp = p.y() - h/2; }
-Q_DECL_CONSTEXPR inline qreal QRectF::width() const
+Q_DECL_CONSTEXPR inline qreal QRectF::width() const Q_DECL_NOTHROW
{ return w; }
-Q_DECL_CONSTEXPR inline qreal QRectF::height() const
+Q_DECL_CONSTEXPR inline qreal QRectF::height() const Q_DECL_NOTHROW
{ return h; }
-Q_DECL_CONSTEXPR inline QSizeF QRectF::size() const
+Q_DECL_CONSTEXPR inline QSizeF QRectF::size() const Q_DECL_NOTHROW
{ return QSizeF(w, h); }
-inline void QRectF::translate(qreal dx, qreal dy)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::translate(qreal dx, qreal dy) Q_DECL_NOTHROW
{
xp += dx;
yp += dy;
}
-inline void QRectF::translate(const QPointF &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::translate(const QPointF &p) Q_DECL_NOTHROW
{
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) Q_DECL_NOTHROW
{
xp = ax;
yp = ay;
}
-inline void QRectF::moveTo(const QPointF &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTo(const QPointF &p) Q_DECL_NOTHROW
{
xp = p.x();
yp = p.y();
}
-Q_DECL_CONSTEXPR inline QRectF QRectF::translated(qreal dx, qreal dy) const
+Q_DECL_CONSTEXPR inline QRectF QRectF::translated(qreal dx, qreal dy) const Q_DECL_NOTHROW
{ return QRectF(xp + dx, yp + dy, w, h); }
-Q_DECL_CONSTEXPR inline QRectF QRectF::translated(const QPointF &p) const
+Q_DECL_CONSTEXPR inline QRectF QRectF::translated(const QPointF &p) const Q_DECL_NOTHROW
{ 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 +753,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) Q_DECL_NOTHROW
{
this->xp = ax;
this->yp = ay;
@@ -744,7 +761,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 +769,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) Q_DECL_NOTHROW
{
xp = xp1;
yp = yp1;
@@ -760,105 +777,105 @@ 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) Q_DECL_NOTHROW
{ 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
+Q_DECL_CONSTEXPR inline QRectF QRectF::adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) const Q_DECL_NOTHROW
{ 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) Q_DECL_NOTHROW
{ this->w = aw; }
-inline void QRectF::setHeight(qreal ah)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setHeight(qreal ah) Q_DECL_NOTHROW
{ this->h = ah; }
-inline void QRectF::setSize(const QSizeF &s)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setSize(const QSizeF &s) Q_DECL_NOTHROW
{
w = s.width();
h = s.height();
}
-inline bool QRectF::contains(qreal ax, qreal ay) const
+inline bool QRectF::contains(qreal ax, qreal ay) const Q_DECL_NOTHROW
{
return contains(QPointF(ax, ay));
}
-inline QRectF& QRectF::operator|=(const QRectF &r)
+inline QRectF& QRectF::operator|=(const QRectF &r) Q_DECL_NOTHROW
{
*this = *this | r;
return *this;
}
-inline QRectF& QRectF::operator&=(const QRectF &r)
+inline QRectF& QRectF::operator&=(const QRectF &r) Q_DECL_NOTHROW
{
*this = *this & r;
return *this;
}
-inline QRectF QRectF::intersected(const QRectF &r) const
+inline QRectF QRectF::intersected(const QRectF &r) const Q_DECL_NOTHROW
{
return *this & r;
}
-inline QRectF QRectF::united(const QRectF &r) const
+inline QRectF QRectF::united(const QRectF &r) const Q_DECL_NOTHROW
{
return *this | r;
}
-Q_DECL_CONSTEXPR inline bool operator==(const QRectF &r1, const QRectF &r2)
+Q_DECL_CONSTEXPR inline bool operator==(const QRectF &r1, const QRectF &r2) Q_DECL_NOTHROW
{
return qFuzzyCompare(r1.xp, r2.xp) && qFuzzyCompare(r1.yp, r2.yp)
&& qFuzzyCompare(r1.w, r2.w) && qFuzzyCompare(r1.h, r2.h);
}
-Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &r1, const QRectF &r2)
+Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &r1, const QRectF &r2) Q_DECL_NOTHROW
{
return !qFuzzyCompare(r1.xp, r2.xp) || !qFuzzyCompare(r1.yp, r2.yp)
|| !qFuzzyCompare(r1.w, r2.w) || !qFuzzyCompare(r1.h, r2.h);
}
-Q_DECL_CONSTEXPR inline QRect QRectF::toRect() const
+Q_DECL_CONSTEXPR inline QRect QRectF::toRect() const Q_DECL_NOTHROW
{
return QRect(qRound(xp), qRound(yp), qRound(w), qRound(h));
}
-Q_DECL_CONSTEXPR inline QRectF operator+(const QRectF &lhs, const QMarginsF &rhs)
+Q_DECL_CONSTEXPR inline QRectF operator+(const QRectF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return QRectF(QPointF(lhs.left() - rhs.left(), lhs.top() - rhs.top()),
QSizeF(lhs.width() + rhs.left() + rhs.right(), lhs.height() + rhs.top() + rhs.bottom()));
}
-Q_DECL_CONSTEXPR inline QRectF operator+(const QMarginsF &lhs, const QRectF &rhs)
+Q_DECL_CONSTEXPR inline QRectF operator+(const QMarginsF &lhs, const QRectF &rhs) Q_DECL_NOTHROW
{
return QRectF(QPointF(rhs.left() - lhs.left(), rhs.top() - lhs.top()),
QSizeF(rhs.width() + lhs.left() + lhs.right(), rhs.height() + lhs.top() + lhs.bottom()));
}
-Q_DECL_CONSTEXPR inline QRectF operator-(const QRectF &lhs, const QMarginsF &rhs)
+Q_DECL_CONSTEXPR inline QRectF operator-(const QRectF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return QRectF(QPointF(lhs.left() + rhs.left(), lhs.top() + rhs.top()),
QSizeF(lhs.width() - rhs.left() - rhs.right(), lhs.height() - rhs.top() - rhs.bottom()));
}
-Q_DECL_CONSTEXPR inline QRectF QRectF::marginsAdded(const QMarginsF &margins) const
+Q_DECL_CONSTEXPR inline QRectF QRectF::marginsAdded(const QMarginsF &margins) const Q_DECL_NOTHROW
{
return QRectF(QPointF(xp - margins.left(), yp - margins.top()),
QSizeF(w + margins.left() + margins.right(), h + margins.top() + margins.bottom()));
}
-Q_DECL_CONSTEXPR inline QRectF QRectF::marginsRemoved(const QMarginsF &margins) const
+Q_DECL_CONSTEXPR inline QRectF QRectF::marginsRemoved(const QMarginsF &margins) const Q_DECL_NOTHROW
{
return QRectF(QPointF(xp + margins.left(), yp + margins.top()),
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) Q_DECL_NOTHROW
{
*this = marginsAdded(margins);
return *this;
}
-inline QRectF &QRectF::operator-=(const QMarginsF &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QRectF &QRectF::operator-=(const QMarginsF &margins) Q_DECL_NOTHROW
{
*this = marginsRemoved(margins);
return *this;
diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp
index b679377fc0..71d897082b 100644
--- a/src/corelib/tools/qregexp.cpp
+++ b/src/corelib/tools/qregexp.cpp
@@ -45,7 +45,6 @@
#include "qstringlist.h"
#include "qstringmatcher.h"
#include "qvector.h"
-#include "private/qfunctions_p.h"
#include <limits.h>
#include <algorithm>
@@ -877,7 +876,7 @@ struct QRegExpEngineKey
}
};
-Q_STATIC_GLOBAL_OPERATOR bool operator==(const QRegExpEngineKey &key1, const QRegExpEngineKey &key2)
+static bool operator==(const QRegExpEngineKey &key1, const QRegExpEngineKey &key2)
{
return key1.pattern == key2.pattern && key1.patternSyntax == key2.patternSyntax
&& key1.cs == key2.cs;
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..8e19a53142 100644
--- a/src/corelib/tools/qregularexpression.h
+++ b/src/corelib/tools/qregularexpression.h
@@ -77,11 +77,11 @@ public:
QRegularExpression &operator=(const QRegularExpression &re);
#ifdef Q_COMPILER_RVALUE_REFS
- inline QRegularExpression &operator=(QRegularExpression &&re)
+ QRegularExpression &operator=(QRegularExpression &&re) Q_DECL_NOTHROW
{ d.swap(re.d); return *this; }
#endif
- inline void swap(QRegularExpression &re) { d.swap(re.d); }
+ void swap(QRegularExpression &other) Q_DECL_NOTHROW { d.swap(other.d); }
QString pattern() const;
void setPattern(const QString &pattern);
@@ -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);
@@ -159,10 +169,10 @@ public:
QRegularExpressionMatch &operator=(const QRegularExpressionMatch &match);
#ifdef Q_COMPILER_RVALUE_REFS
- inline QRegularExpressionMatch &operator=(QRegularExpressionMatch &&match)
+ QRegularExpressionMatch &operator=(QRegularExpressionMatch &&match) Q_DECL_NOTHROW
{ d.swap(match.d); return *this; }
#endif
- inline void swap(QRegularExpressionMatch &match) { d.swap(match.d); }
+ void swap(QRegularExpressionMatch &other) Q_DECL_NOTHROW { d.swap(other.d); }
QRegularExpression regularExpression() const;
QRegularExpression::MatchType matchType() const;
@@ -216,10 +226,10 @@ public:
QRegularExpressionMatchIterator(const QRegularExpressionMatchIterator &iterator);
QRegularExpressionMatchIterator &operator=(const QRegularExpressionMatchIterator &iterator);
#ifdef Q_COMPILER_RVALUE_REFS
- inline QRegularExpressionMatchIterator &operator=(QRegularExpressionMatchIterator &&iterator)
+ QRegularExpressionMatchIterator &operator=(QRegularExpressionMatchIterator &&iterator) Q_DECL_NOTHROW
{ d.swap(iterator.d); return *this; }
#endif
- void swap(QRegularExpressionMatchIterator &iterator) { d.swap(iterator.d); }
+ void swap(QRegularExpressionMatchIterator &other) Q_DECL_NOTHROW { d.swap(other.d); }
bool isValid() const;
diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h
index 2279f1bc2a..610c099733 100644
--- a/src/corelib/tools/qringbuffer_p.h
+++ b/src/corelib/tools/qringbuffer_p.h
@@ -63,7 +63,7 @@ public:
}
inline const char *readPointer() const {
- return buffers.isEmpty() ? 0 : (buffers.first().constData() + head);
+ return bufferSize == 0 ? Q_NULLPTR : (buffers.first().constData() + head);
}
// access the bytes at a specified position
@@ -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/qset.h b/src/corelib/tools/qset.h
index 662afbf84a..baa412a550 100644
--- a/src/corelib/tools/qset.h
+++ b/src/corelib/tools/qset.h
@@ -237,6 +237,15 @@ private:
}
};
+template <typename T>
+uint qHash(const QSet<T> &key, uint seed = 0)
+Q_DECL_NOEXCEPT_EXPR(noexcept(qHashRangeCommutative(key.begin(), key.end(), seed)))
+{
+ return qHashRangeCommutative(key.begin(), key.end(), seed);
+}
+
+// inline function implementations
+
template <class T>
Q_INLINE_TEMPLATE void QSet<T>::reserve(int asize) { q_hash.reserve(asize); }
diff --git a/src/corelib/tools/qset.qdoc b/src/corelib/tools/qset.qdoc
index ab7d72611e..73599a2a72 100644
--- a/src/corelib/tools/qset.qdoc
+++ b/src/corelib/tools/qset.qdoc
@@ -968,3 +968,14 @@
\sa{Serializing Qt Data Types}{Format of the QDataStream operators}
*/
+
+/*!
+ \fn uint qHash(const QSet<T> &key, uint seed = 0)
+ \relates QHash
+ \since 5.5
+
+ Returns the hash value for the \a key, using \a seed to seed the calculation.
+
+ The hash value is independent of the order of elements in \a key, that is, sets
+ that contain the same elements hash to the same value.
+*/
diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h
index 53f51b7f2e..183b9ff238 100644
--- a/src/corelib/tools/qshareddata.h
+++ b/src/corelib/tools/qshareddata.h
@@ -79,7 +79,7 @@ public:
inline QSharedDataPointer() { d = 0; }
inline ~QSharedDataPointer() { if (d && !d->ref.deref()) delete d; }
- explicit QSharedDataPointer(T *data);
+ explicit QSharedDataPointer(T *data) Q_DECL_NOTHROW;
inline QSharedDataPointer(const QSharedDataPointer<T> &o) : d(o.d) { if (d) d->ref.ref(); }
inline QSharedDataPointer<T> & operator=(const QSharedDataPointer<T> &o) {
if (o.d != d) {
@@ -104,14 +104,14 @@ public:
return *this;
}
#ifdef Q_COMPILER_RVALUE_REFS
- QSharedDataPointer(QSharedDataPointer &&o) : d(o.d) { o.d = 0; }
- inline QSharedDataPointer<T> &operator=(QSharedDataPointer<T> &&other)
+ QSharedDataPointer(QSharedDataPointer &&o) Q_DECL_NOTHROW : d(o.d) { o.d = Q_NULLPTR; }
+ inline QSharedDataPointer<T> &operator=(QSharedDataPointer<T> &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
inline bool operator!() const { return !d; }
- inline void swap(QSharedDataPointer &other)
+ inline void swap(QSharedDataPointer &other) Q_DECL_NOTHROW
{ qSwap(d, other.d); }
protected:
@@ -155,7 +155,7 @@ public:
inline QExplicitlySharedDataPointer() { d = 0; }
inline ~QExplicitlySharedDataPointer() { if (d && !d->ref.deref()) delete d; }
- explicit QExplicitlySharedDataPointer(T *data);
+ explicit QExplicitlySharedDataPointer(T *data) Q_DECL_NOTHROW;
inline QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<T> &o) : d(o.d) { if (d) d->ref.ref(); }
template<class X>
@@ -193,14 +193,14 @@ public:
return *this;
}
#ifdef Q_COMPILER_RVALUE_REFS
- inline QExplicitlySharedDataPointer(QExplicitlySharedDataPointer &&o) : d(o.d) { o.d = 0; }
- inline QExplicitlySharedDataPointer<T> &operator=(QExplicitlySharedDataPointer<T> &&other)
+ inline QExplicitlySharedDataPointer(QExplicitlySharedDataPointer &&o) Q_DECL_NOTHROW : d(o.d) { o.d = Q_NULLPTR; }
+ inline QExplicitlySharedDataPointer<T> &operator=(QExplicitlySharedDataPointer<T> &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
inline bool operator!() const { return !d; }
- inline void swap(QExplicitlySharedDataPointer &other)
+ inline void swap(QExplicitlySharedDataPointer &other) Q_DECL_NOTHROW
{ qSwap(d, other.d); }
protected:
@@ -213,7 +213,8 @@ private:
};
template <class T>
-Q_INLINE_TEMPLATE QSharedDataPointer<T>::QSharedDataPointer(T *adata) : d(adata)
+Q_INLINE_TEMPLATE QSharedDataPointer<T>::QSharedDataPointer(T *adata) Q_DECL_NOTHROW
+ : d(adata)
{ if (d) d->ref.ref(); }
template <class T>
@@ -249,7 +250,8 @@ Q_OUTOFLINE_TEMPLATE void QExplicitlySharedDataPointer<T>::detach_helper()
}
template <class T>
-Q_INLINE_TEMPLATE QExplicitlySharedDataPointer<T>::QExplicitlySharedDataPointer(T *adata) : d(adata)
+Q_INLINE_TEMPLATE QExplicitlySharedDataPointer<T>::QExplicitlySharedDataPointer(T *adata) Q_DECL_NOTHROW
+ : d(adata)
{ if (d) d->ref.ref(); }
template <class T>
@@ -273,12 +275,12 @@ namespace std {
QT_BEGIN_NAMESPACE
template <class T>
-Q_INLINE_TEMPLATE uint qHash(const QSharedDataPointer<T> &ptr, uint seed = 0)
+Q_INLINE_TEMPLATE uint qHash(const QSharedDataPointer<T> &ptr, uint seed = 0) Q_DECL_NOTHROW
{
return qHash(ptr.data(), seed);
}
template <class T>
-Q_INLINE_TEMPLATE uint qHash(const QExplicitlySharedDataPointer<T> &ptr, uint seed = 0)
+Q_INLINE_TEMPLATE uint qHash(const QExplicitlySharedDataPointer<T> &ptr, uint seed = 0) Q_DECL_NOTHROW
{
return qHash(ptr.data(), seed);
}
diff --git a/src/corelib/tools/qsize.cpp b/src/corelib/tools/qsize.cpp
index 4c124162a1..12673ccd0c 100644
--- a/src/corelib/tools/qsize.cpp
+++ b/src/corelib/tools/qsize.cpp
@@ -156,7 +156,7 @@ QT_BEGIN_NAMESPACE
\sa setWidth(), setHeight(), transposed()
*/
-void QSize::transpose()
+void QSize::transpose() Q_DECL_NOTHROW
{
int tmp = wd;
wd = ht;
@@ -217,7 +217,7 @@ void QSize::transpose()
Return a size scaled to a rectangle with the given size \a s,
according to the specified \a mode.
*/
-QSize QSize::scaled(const QSize &s, Qt::AspectRatioMode mode) const
+QSize QSize::scaled(const QSize &s, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW
{
if (mode == Qt::IgnoreAspectRatio || wd == 0 || ht == 0) {
return s;
@@ -590,7 +590,7 @@ QDebug operator<<(QDebug dbg, const QSize &s)
\sa setWidth(), setHeight(), transposed()
*/
-void QSizeF::transpose()
+void QSizeF::transpose() Q_DECL_NOTHROW
{
qreal tmp = wd;
wd = ht;
@@ -651,7 +651,7 @@ void QSizeF::transpose()
Returns a size scaled to a rectangle with the given size \a s,
according to the specified \a mode.
*/
-QSizeF QSizeF::scaled(const QSizeF &s, Qt::AspectRatioMode mode) const
+QSizeF QSizeF::scaled(const QSizeF &s, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW
{
if (mode == Qt::IgnoreAspectRatio || qIsNull(wd) || qIsNull(ht)) {
return s;
diff --git a/src/corelib/tools/qsize.h b/src/corelib/tools/qsize.h
index 6b5cf2dd7d..037b532f37 100644
--- a/src/corelib/tools/qsize.h
+++ b/src/corelib/tools/qsize.h
@@ -42,42 +42,42 @@ QT_BEGIN_NAMESPACE
class Q_CORE_EXPORT QSize
{
public:
- Q_DECL_CONSTEXPR QSize();
- Q_DECL_CONSTEXPR QSize(int w, int h);
-
- Q_DECL_CONSTEXPR inline bool isNull() const;
- Q_DECL_CONSTEXPR inline bool isEmpty() const;
- Q_DECL_CONSTEXPR inline bool isValid() 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);
- void transpose();
- Q_DECL_CONSTEXPR inline QSize transposed() const;
-
- inline void scale(int w, int h, Qt::AspectRatioMode mode);
- inline void scale(const QSize &s, Qt::AspectRatioMode mode);
- QSize scaled(int w, int h, Qt::AspectRatioMode mode) const;
- QSize scaled(const QSize &s, Qt::AspectRatioMode mode) const;
-
- Q_DECL_CONSTEXPR inline QSize expandedTo(const QSize &) const;
- Q_DECL_CONSTEXPR inline QSize boundedTo(const QSize &) const;
-
- inline int &rwidth();
- inline int &rheight();
-
- inline QSize &operator+=(const QSize &);
- inline QSize &operator-=(const QSize &);
- inline QSize &operator*=(qreal c);
+ Q_DECL_CONSTEXPR QSize() Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QSize(int w, int h) Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline bool isNull() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline bool isEmpty() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline int width() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline int height() const Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setWidth(int w) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setHeight(int h) Q_DECL_NOTHROW;
+ void transpose() Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QSize transposed() const Q_DECL_NOTHROW;
+
+ inline void scale(int w, int h, Qt::AspectRatioMode mode) Q_DECL_NOTHROW;
+ inline void scale(const QSize &s, Qt::AspectRatioMode mode) Q_DECL_NOTHROW;
+ QSize scaled(int w, int h, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW;
+ QSize scaled(const QSize &s, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline QSize expandedTo(const QSize &) const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QSize boundedTo(const QSize &) const Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline int &rwidth() Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline int &rheight() Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline QSize &operator+=(const QSize &) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline QSize &operator-=(const QSize &) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline QSize &operator*=(qreal c) Q_DECL_NOTHROW;
inline QSize &operator/=(qreal c);
- friend inline Q_DECL_CONSTEXPR bool operator==(const QSize &, const QSize &);
- friend inline Q_DECL_CONSTEXPR bool operator!=(const QSize &, const QSize &);
- friend inline Q_DECL_CONSTEXPR const QSize operator+(const QSize &, const QSize &);
- friend inline Q_DECL_CONSTEXPR const QSize operator-(const QSize &, const QSize &);
- friend inline Q_DECL_CONSTEXPR const QSize operator*(const QSize &, qreal);
- friend inline Q_DECL_CONSTEXPR const QSize operator*(qreal, const QSize &);
+ friend inline Q_DECL_CONSTEXPR bool operator==(const QSize &, const QSize &) Q_DECL_NOTHROW;
+ friend inline Q_DECL_CONSTEXPR bool operator!=(const QSize &, const QSize &) Q_DECL_NOTHROW;
+ friend inline Q_DECL_CONSTEXPR const QSize operator+(const QSize &, const QSize &) Q_DECL_NOTHROW;
+ friend inline Q_DECL_CONSTEXPR const QSize operator-(const QSize &, const QSize &) Q_DECL_NOTHROW;
+ friend inline Q_DECL_CONSTEXPR const QSize operator*(const QSize &, qreal) Q_DECL_NOTHROW;
+ friend inline Q_DECL_CONSTEXPR const QSize operator*(qreal, const QSize &) Q_DECL_NOTHROW;
friend inline const QSize operator/(const QSize &, qreal);
private:
@@ -100,74 +100,74 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QSize &);
QSize inline functions
*****************************************************************************/
-Q_DECL_CONSTEXPR inline QSize::QSize() : wd(-1), ht(-1) {}
+Q_DECL_CONSTEXPR inline QSize::QSize() Q_DECL_NOTHROW : wd(-1), ht(-1) {}
-Q_DECL_CONSTEXPR inline QSize::QSize(int w, int h) : wd(w), ht(h) {}
+Q_DECL_CONSTEXPR inline QSize::QSize(int w, int h) Q_DECL_NOTHROW : wd(w), ht(h) {}
-Q_DECL_CONSTEXPR inline bool QSize::isNull() const
+Q_DECL_CONSTEXPR inline bool QSize::isNull() const Q_DECL_NOTHROW
{ return wd==0 && ht==0; }
-Q_DECL_CONSTEXPR inline bool QSize::isEmpty() const
+Q_DECL_CONSTEXPR inline bool QSize::isEmpty() const Q_DECL_NOTHROW
{ return wd<1 || ht<1; }
-Q_DECL_CONSTEXPR inline bool QSize::isValid() const
+Q_DECL_CONSTEXPR inline bool QSize::isValid() const Q_DECL_NOTHROW
{ return wd>=0 && ht>=0; }
-Q_DECL_CONSTEXPR inline int QSize::width() const
+Q_DECL_CONSTEXPR inline int QSize::width() const Q_DECL_NOTHROW
{ return wd; }
-Q_DECL_CONSTEXPR inline int QSize::height() const
+Q_DECL_CONSTEXPR inline int QSize::height() const Q_DECL_NOTHROW
{ return ht; }
-inline void QSize::setWidth(int w)
+Q_DECL_RELAXED_CONSTEXPR inline void QSize::setWidth(int w) Q_DECL_NOTHROW
{ wd = w; }
-inline void QSize::setHeight(int h)
+Q_DECL_RELAXED_CONSTEXPR inline void QSize::setHeight(int h) Q_DECL_NOTHROW
{ ht = h; }
-Q_DECL_CONSTEXPR inline QSize QSize::transposed() const
+Q_DECL_CONSTEXPR inline QSize QSize::transposed() const Q_DECL_NOTHROW
{ return QSize(ht, wd); }
-inline void QSize::scale(int w, int h, Qt::AspectRatioMode mode)
+inline void QSize::scale(int w, int h, Qt::AspectRatioMode mode) Q_DECL_NOTHROW
{ scale(QSize(w, h), mode); }
-inline void QSize::scale(const QSize &s, Qt::AspectRatioMode mode)
+inline void QSize::scale(const QSize &s, Qt::AspectRatioMode mode) Q_DECL_NOTHROW
{ *this = scaled(s, mode); }
-inline QSize QSize::scaled(int w, int h, Qt::AspectRatioMode mode) const
+inline QSize QSize::scaled(int w, int h, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW
{ return scaled(QSize(w, h), mode); }
-inline int &QSize::rwidth()
+Q_DECL_RELAXED_CONSTEXPR inline int &QSize::rwidth() Q_DECL_NOTHROW
{ return wd; }
-inline int &QSize::rheight()
+Q_DECL_RELAXED_CONSTEXPR inline int &QSize::rheight() Q_DECL_NOTHROW
{ return ht; }
-inline QSize &QSize::operator+=(const QSize &s)
+Q_DECL_RELAXED_CONSTEXPR inline QSize &QSize::operator+=(const QSize &s) Q_DECL_NOTHROW
{ 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) Q_DECL_NOTHROW
{ wd-=s.wd; ht-=s.ht; return *this; }
-inline QSize &QSize::operator*=(qreal c)
+Q_DECL_RELAXED_CONSTEXPR inline QSize &QSize::operator*=(qreal c) Q_DECL_NOTHROW
{ wd = qRound(wd*c); ht = qRound(ht*c); return *this; }
-Q_DECL_CONSTEXPR inline bool operator==(const QSize &s1, const QSize &s2)
+Q_DECL_CONSTEXPR inline bool operator==(const QSize &s1, const QSize &s2) Q_DECL_NOTHROW
{ return s1.wd == s2.wd && s1.ht == s2.ht; }
-Q_DECL_CONSTEXPR inline bool operator!=(const QSize &s1, const QSize &s2)
+Q_DECL_CONSTEXPR inline bool operator!=(const QSize &s1, const QSize &s2) Q_DECL_NOTHROW
{ return s1.wd != s2.wd || s1.ht != s2.ht; }
-Q_DECL_CONSTEXPR inline const QSize operator+(const QSize & s1, const QSize & s2)
+Q_DECL_CONSTEXPR inline const QSize operator+(const QSize & s1, const QSize & s2) Q_DECL_NOTHROW
{ return QSize(s1.wd+s2.wd, s1.ht+s2.ht); }
-Q_DECL_CONSTEXPR inline const QSize operator-(const QSize &s1, const QSize &s2)
+Q_DECL_CONSTEXPR inline const QSize operator-(const QSize &s1, const QSize &s2) Q_DECL_NOTHROW
{ return QSize(s1.wd-s2.wd, s1.ht-s2.ht); }
-Q_DECL_CONSTEXPR inline const QSize operator*(const QSize &s, qreal c)
+Q_DECL_CONSTEXPR inline const QSize operator*(const QSize &s, qreal c) Q_DECL_NOTHROW
{ return QSize(qRound(s.wd*c), qRound(s.ht*c)); }
-Q_DECL_CONSTEXPR inline const QSize operator*(qreal c, const QSize &s)
+Q_DECL_CONSTEXPR inline const QSize operator*(qreal c, const QSize &s) Q_DECL_NOTHROW
{ return QSize(qRound(s.wd*c), qRound(s.ht*c)); }
inline QSize &QSize::operator/=(qreal c)
@@ -183,12 +183,12 @@ inline const QSize operator/(const QSize &s, qreal c)
return QSize(qRound(s.wd/c), qRound(s.ht/c));
}
-Q_DECL_CONSTEXPR inline QSize QSize::expandedTo(const QSize & otherSize) const
+Q_DECL_CONSTEXPR inline QSize QSize::expandedTo(const QSize & otherSize) const Q_DECL_NOTHROW
{
return QSize(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht));
}
-Q_DECL_CONSTEXPR inline QSize QSize::boundedTo(const QSize & otherSize) const
+Q_DECL_CONSTEXPR inline QSize QSize::boundedTo(const QSize & otherSize) const Q_DECL_NOTHROW
{
return QSize(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht));
}
@@ -201,46 +201,46 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QSize &);
class Q_CORE_EXPORT QSizeF
{
public:
- Q_DECL_CONSTEXPR QSizeF();
- Q_DECL_CONSTEXPR QSizeF(const QSize &sz);
- Q_DECL_CONSTEXPR QSizeF(qreal w, qreal h);
-
- inline bool isNull() const;
- Q_DECL_CONSTEXPR inline bool isEmpty() const;
- Q_DECL_CONSTEXPR inline bool isValid() 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);
- void transpose();
- Q_DECL_CONSTEXPR inline QSizeF transposed() const;
-
- inline void scale(qreal w, qreal h, Qt::AspectRatioMode mode);
- inline void scale(const QSizeF &s, Qt::AspectRatioMode mode);
- QSizeF scaled(qreal w, qreal h, Qt::AspectRatioMode mode) const;
- QSizeF scaled(const QSizeF &s, Qt::AspectRatioMode mode) const;
-
- Q_DECL_CONSTEXPR inline QSizeF expandedTo(const QSizeF &) const;
- Q_DECL_CONSTEXPR inline QSizeF boundedTo(const QSizeF &) const;
-
- inline qreal &rwidth();
- inline qreal &rheight();
-
- inline QSizeF &operator+=(const QSizeF &);
- inline QSizeF &operator-=(const QSizeF &);
- inline QSizeF &operator*=(qreal c);
+ Q_DECL_CONSTEXPR QSizeF() Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QSizeF(const QSize &sz) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QSizeF(qreal w, qreal h) Q_DECL_NOTHROW;
+
+ inline bool isNull() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline bool isEmpty() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline qreal width() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline qreal height() const Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setWidth(qreal w) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setHeight(qreal h) Q_DECL_NOTHROW;
+ void transpose() Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QSizeF transposed() const Q_DECL_NOTHROW;
+
+ inline void scale(qreal w, qreal h, Qt::AspectRatioMode mode) Q_DECL_NOTHROW;
+ inline void scale(const QSizeF &s, Qt::AspectRatioMode mode) Q_DECL_NOTHROW;
+ QSizeF scaled(qreal w, qreal h, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW;
+ QSizeF scaled(const QSizeF &s, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline QSizeF expandedTo(const QSizeF &) const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QSizeF boundedTo(const QSizeF &) const Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline qreal &rwidth() Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline qreal &rheight() Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline QSizeF &operator+=(const QSizeF &) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline QSizeF &operator-=(const QSizeF &) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline QSizeF &operator*=(qreal c) Q_DECL_NOTHROW;
inline QSizeF &operator/=(qreal c);
- friend Q_DECL_CONSTEXPR inline bool operator==(const QSizeF &, const QSizeF &);
- friend Q_DECL_CONSTEXPR inline bool operator!=(const QSizeF &, const QSizeF &);
- friend Q_DECL_CONSTEXPR inline const QSizeF operator+(const QSizeF &, const QSizeF &);
- friend Q_DECL_CONSTEXPR inline const QSizeF operator-(const QSizeF &, const QSizeF &);
- friend Q_DECL_CONSTEXPR inline const QSizeF operator*(const QSizeF &, qreal);
- friend Q_DECL_CONSTEXPR inline const QSizeF operator*(qreal, const QSizeF &);
+ friend Q_DECL_CONSTEXPR inline bool operator==(const QSizeF &, const QSizeF &) Q_DECL_NOTHROW;
+ friend Q_DECL_CONSTEXPR inline bool operator!=(const QSizeF &, const QSizeF &) Q_DECL_NOTHROW;
+ friend Q_DECL_CONSTEXPR inline const QSizeF operator+(const QSizeF &, const QSizeF &) Q_DECL_NOTHROW;
+ friend Q_DECL_CONSTEXPR inline const QSizeF operator-(const QSizeF &, const QSizeF &) Q_DECL_NOTHROW;
+ friend Q_DECL_CONSTEXPR inline const QSizeF operator*(const QSizeF &, qreal) Q_DECL_NOTHROW;
+ friend Q_DECL_CONSTEXPR inline const QSizeF operator*(qreal, const QSizeF &) Q_DECL_NOTHROW;
friend inline const QSizeF operator/(const QSizeF &, qreal);
- Q_DECL_CONSTEXPR inline QSize toSize() const;
+ Q_DECL_CONSTEXPR inline QSize toSize() const Q_DECL_NOTHROW;
private:
qreal wd;
@@ -263,76 +263,76 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QSizeF &);
QSizeF inline functions
*****************************************************************************/
-Q_DECL_CONSTEXPR inline QSizeF::QSizeF() : wd(-1.), ht(-1.) {}
+Q_DECL_CONSTEXPR inline QSizeF::QSizeF() Q_DECL_NOTHROW : wd(-1.), ht(-1.) {}
-Q_DECL_CONSTEXPR inline QSizeF::QSizeF(const QSize &sz) : wd(sz.width()), ht(sz.height()) {}
+Q_DECL_CONSTEXPR inline QSizeF::QSizeF(const QSize &sz) Q_DECL_NOTHROW : wd(sz.width()), ht(sz.height()) {}
-Q_DECL_CONSTEXPR inline QSizeF::QSizeF(qreal w, qreal h) : wd(w), ht(h) {}
+Q_DECL_CONSTEXPR inline QSizeF::QSizeF(qreal w, qreal h) Q_DECL_NOTHROW : wd(w), ht(h) {}
-inline bool QSizeF::isNull() const
+inline bool QSizeF::isNull() const Q_DECL_NOTHROW
{ return qIsNull(wd) && qIsNull(ht); }
-Q_DECL_CONSTEXPR inline bool QSizeF::isEmpty() const
+Q_DECL_CONSTEXPR inline bool QSizeF::isEmpty() const Q_DECL_NOTHROW
{ return wd <= 0. || ht <= 0.; }
-Q_DECL_CONSTEXPR inline bool QSizeF::isValid() const
+Q_DECL_CONSTEXPR inline bool QSizeF::isValid() const Q_DECL_NOTHROW
{ return wd >= 0. && ht >= 0.; }
-Q_DECL_CONSTEXPR inline qreal QSizeF::width() const
+Q_DECL_CONSTEXPR inline qreal QSizeF::width() const Q_DECL_NOTHROW
{ return wd; }
-Q_DECL_CONSTEXPR inline qreal QSizeF::height() const
+Q_DECL_CONSTEXPR inline qreal QSizeF::height() const Q_DECL_NOTHROW
{ return ht; }
-inline void QSizeF::setWidth(qreal w)
+Q_DECL_RELAXED_CONSTEXPR inline void QSizeF::setWidth(qreal w) Q_DECL_NOTHROW
{ wd = w; }
-inline void QSizeF::setHeight(qreal h)
+Q_DECL_RELAXED_CONSTEXPR inline void QSizeF::setHeight(qreal h) Q_DECL_NOTHROW
{ ht = h; }
-Q_DECL_CONSTEXPR inline QSizeF QSizeF::transposed() const
+Q_DECL_CONSTEXPR inline QSizeF QSizeF::transposed() const Q_DECL_NOTHROW
{ return QSizeF(ht, wd); }
-inline void QSizeF::scale(qreal w, qreal h, Qt::AspectRatioMode mode)
+inline void QSizeF::scale(qreal w, qreal h, Qt::AspectRatioMode mode) Q_DECL_NOTHROW
{ scale(QSizeF(w, h), mode); }
-inline void QSizeF::scale(const QSizeF &s, Qt::AspectRatioMode mode)
+inline void QSizeF::scale(const QSizeF &s, Qt::AspectRatioMode mode) Q_DECL_NOTHROW
{ *this = scaled(s, mode); }
-inline QSizeF QSizeF::scaled(qreal w, qreal h, Qt::AspectRatioMode mode) const
+inline QSizeF QSizeF::scaled(qreal w, qreal h, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW
{ return scaled(QSizeF(w, h), mode); }
-inline qreal &QSizeF::rwidth()
+Q_DECL_RELAXED_CONSTEXPR inline qreal &QSizeF::rwidth() Q_DECL_NOTHROW
{ return wd; }
-inline qreal &QSizeF::rheight()
+Q_DECL_RELAXED_CONSTEXPR inline qreal &QSizeF::rheight() Q_DECL_NOTHROW
{ return ht; }
-inline QSizeF &QSizeF::operator+=(const QSizeF &s)
+Q_DECL_RELAXED_CONSTEXPR inline QSizeF &QSizeF::operator+=(const QSizeF &s) Q_DECL_NOTHROW
{ 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) Q_DECL_NOTHROW
{ wd -= s.wd; ht -= s.ht; return *this; }
-inline QSizeF &QSizeF::operator*=(qreal c)
+Q_DECL_RELAXED_CONSTEXPR inline QSizeF &QSizeF::operator*=(qreal c) Q_DECL_NOTHROW
{ wd *= c; ht *= c; return *this; }
-Q_DECL_CONSTEXPR inline bool operator==(const QSizeF &s1, const QSizeF &s2)
+Q_DECL_CONSTEXPR inline bool operator==(const QSizeF &s1, const QSizeF &s2) Q_DECL_NOTHROW
{ return qFuzzyCompare(s1.wd, s2.wd) && qFuzzyCompare(s1.ht, s2.ht); }
-Q_DECL_CONSTEXPR inline bool operator!=(const QSizeF &s1, const QSizeF &s2)
+Q_DECL_CONSTEXPR inline bool operator!=(const QSizeF &s1, const QSizeF &s2) Q_DECL_NOTHROW
{ return !qFuzzyCompare(s1.wd, s2.wd) || !qFuzzyCompare(s1.ht, s2.ht); }
-Q_DECL_CONSTEXPR inline const QSizeF operator+(const QSizeF & s1, const QSizeF & s2)
+Q_DECL_CONSTEXPR inline const QSizeF operator+(const QSizeF & s1, const QSizeF & s2) Q_DECL_NOTHROW
{ return QSizeF(s1.wd+s2.wd, s1.ht+s2.ht); }
-Q_DECL_CONSTEXPR inline const QSizeF operator-(const QSizeF &s1, const QSizeF &s2)
+Q_DECL_CONSTEXPR inline const QSizeF operator-(const QSizeF &s1, const QSizeF &s2) Q_DECL_NOTHROW
{ return QSizeF(s1.wd-s2.wd, s1.ht-s2.ht); }
-Q_DECL_CONSTEXPR inline const QSizeF operator*(const QSizeF &s, qreal c)
+Q_DECL_CONSTEXPR inline const QSizeF operator*(const QSizeF &s, qreal c) Q_DECL_NOTHROW
{ return QSizeF(s.wd*c, s.ht*c); }
-Q_DECL_CONSTEXPR inline const QSizeF operator*(qreal c, const QSizeF &s)
+Q_DECL_CONSTEXPR inline const QSizeF operator*(qreal c, const QSizeF &s) Q_DECL_NOTHROW
{ return QSizeF(s.wd*c, s.ht*c); }
inline QSizeF &QSizeF::operator/=(qreal c)
@@ -348,17 +348,17 @@ inline const QSizeF operator/(const QSizeF &s, qreal c)
return QSizeF(s.wd/c, s.ht/c);
}
-Q_DECL_CONSTEXPR inline QSizeF QSizeF::expandedTo(const QSizeF & otherSize) const
+Q_DECL_CONSTEXPR inline QSizeF QSizeF::expandedTo(const QSizeF & otherSize) const Q_DECL_NOTHROW
{
return QSizeF(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht));
}
-Q_DECL_CONSTEXPR inline QSizeF QSizeF::boundedTo(const QSizeF & otherSize) const
+Q_DECL_CONSTEXPR inline QSizeF QSizeF::boundedTo(const QSizeF & otherSize) const Q_DECL_NOTHROW
{
return QSizeF(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht));
}
-Q_DECL_CONSTEXPR inline QSize QSizeF::toSize() const
+Q_DECL_CONSTEXPR inline QSize QSizeF::toSize() const Q_DECL_NOTHROW
{
return QSize(qRound(wd), qRound(ht));
}
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 9921d5cfbb..50184f4696 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()
*/
@@ -1328,7 +1356,7 @@ const QString::Null QString::null = { };
windows) and ucs4 if the size of wchar_t is 4 bytes (most Unix
systems).
- \sa fromUtf16(), fromLatin1(), fromLocal8Bit(), fromUtf8(), fromUcs4()
+ \sa fromUtf16(), fromLatin1(), fromLocal8Bit(), fromUtf8(), fromUcs4(), fromStdU16String(), fromStdU32String()
*/
/*! \fn QString QString::fromWCharArray(const wchar_t *string, int size)
@@ -1353,7 +1381,7 @@ const QString::Null QString::null = { };
This method is mostly useful to pass a QString to a function
that accepts a std::wstring object.
- \sa utf16(), toLatin1(), toUtf8(), toLocal8Bit()
+ \sa utf16(), toLatin1(), toUtf8(), toLocal8Bit(), toStdU16String(), toStdU32String()
*/
int QString::toUcs4_helper(const ushort *uc, int length, uint *out)
@@ -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);
@@ -1703,7 +1734,7 @@ void QString::expand(int i)
string.
*/
-QString &QString::operator=(const QString &other)
+QString &QString::operator=(const QString &other) Q_DECL_NOTHROW
{
other.d->ref.ref();
if (!d->ref.deref())
@@ -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()) {
@@ -4555,7 +4632,7 @@ QString QString::fromUtf8_helper(const char *str, int size)
QString makes a deep copy of the Unicode data.
- \sa utf16(), setUtf16()
+ \sa utf16(), setUtf16(), fromStdU16String()
*/
QString QString::fromUtf16(const ushort *unicode, int size)
{
@@ -4579,7 +4656,7 @@ QString QString::fromUtf16(const ushort *unicode, int size)
If \a size is -1 (default), \a unicode must be terminated
with a 0.
- \sa toUcs4(), fromUtf16(), utf16(), setUtf16(), fromWCharArray()
+ \sa toUcs4(), fromUtf16(), utf16(), setUtf16(), fromWCharArray(), fromStdU32String()
*/
QString QString::fromUcs4(const uint *unicode, int size)
{
@@ -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,114 @@ 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>
+Q_NEVER_INLINE
+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 +5650,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
@@ -6630,24 +6571,25 @@ QString QString::number(double n, char f, int prec)
}
namespace {
-template<class ResultList, class StringSource, typename MidMethod, typename Separtor>
-static ResultList splitString(const StringSource &source, MidMethod mid, const Separtor &sep,
+template<class ResultList, class StringSource>
+static ResultList splitString(const StringSource &source, const QChar *sep,
QString::SplitBehavior behavior, Qt::CaseSensitivity cs, const int separatorSize)
{
ResultList list;
int start = 0;
int end;
int extra = 0;
- while ((end = source.indexOf(sep, start + extra, cs)) != -1) {
+ while ((end = qFindString(source.constData(), source.size(), start + extra, sep, separatorSize, cs)) != -1) {
if (start != end || behavior == QString::KeepEmptyParts)
- list.append((source.*mid)(start, end - start));
+ list.append(source.mid(start, end - start));
start = end + separatorSize;
extra = (separatorSize == 0 ? 1 : 0);
}
if (start != source.size() || behavior == QString::KeepEmptyParts)
- list.append((source.*mid)(start, -1));
+ list.append(source.mid(start, -1));
return list;
}
+
} // namespace
/*!
@@ -6670,7 +6612,7 @@ static ResultList splitString(const StringSource &source, MidMethod mid, const S
*/
QStringList QString::split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
{
- return splitString<QStringList>(*this, &QString::mid, sep, behavior, cs, sep.size());
+ return splitString<QStringList>(*this, sep.constData(), behavior, cs, sep.size());
}
/*!
@@ -6693,14 +6635,14 @@ QStringList QString::split(const QString &sep, SplitBehavior behavior, Qt::CaseS
*/
QVector<QStringRef> QString::splitRef(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
{
- return splitString<QVector<QStringRef> >(*this, &QString::midRef, sep, behavior, cs, sep.size());
+ return splitString<QVector<QStringRef> >(QStringRef(this), sep.constData(), behavior, cs, sep.size());
}
/*!
\overload
*/
QStringList QString::split(QChar sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
{
- return splitString<QStringList>(*this, &QString::mid, sep, behavior, cs, 1);
+ return splitString<QStringList>(*this, &sep, behavior, cs, 1);
}
/*!
@@ -6709,7 +6651,7 @@ QStringList QString::split(QChar sep, SplitBehavior behavior, Qt::CaseSensitivit
*/
QVector<QStringRef> QString::splitRef(QChar sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
{
- return splitString<QVector<QStringRef> >(*this, &QString::midRef, sep, behavior, cs, 1);
+ return splitString<QVector<QStringRef> >(QStringRef(this), &sep, behavior, cs, 1);
}
/*!
@@ -6731,7 +6673,7 @@ QVector<QStringRef> QString::splitRef(QChar sep, SplitBehavior behavior, Qt::Cas
*/
QVector<QStringRef> QStringRef::split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const
{
- return splitString<QVector<QStringRef> >(*this, &QStringRef::mid, sep, behavior, cs, sep.size());
+ return splitString<QVector<QStringRef> >(*this, sep.constData(), behavior, cs, sep.size());
}
/*!
@@ -6740,7 +6682,7 @@ QVector<QStringRef> QStringRef::split(const QString &sep, QString::SplitBehavior
*/
QVector<QStringRef> QStringRef::split(QChar sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const
{
- return splitString<QVector<QStringRef> >(*this, &QStringRef::mid, sep, behavior, cs, 1);
+ return splitString<QVector<QStringRef> >(*this, &sep, behavior, cs, 1);
}
#ifndef QT_NO_REGEXP
@@ -7654,49 +7596,79 @@ static int getEscape(const QChar *uc, int *pos, int len, int maxNumber = 999)
return -1;
}
+namespace {
+class ArgMapper {
+ QVarLengthArray<int, 16> argPosToNumberMap; // maps from argument position to number
+public:
+ void found(int n) { argPosToNumberMap.push_back(n); }
+
+ struct AssignmentResult {
+ int numArgs;
+ int lastNumber;
+ };
+
+ AssignmentResult assignArgumentNumberToEachOfTheNs(int numArgs)
+ {
+ std::sort(argPosToNumberMap.begin(), argPosToNumberMap.end());
+ argPosToNumberMap.erase(std::unique(argPosToNumberMap.begin(), argPosToNumberMap.end()),
+ argPosToNumberMap.end());
+
+ if (argPosToNumberMap.size() > numArgs)
+ argPosToNumberMap.resize(numArgs);
+
+ int lastNumber = argPosToNumberMap.empty() ? -1 : argPosToNumberMap.back();
+ int arg = argPosToNumberMap.size();
+
+ const AssignmentResult result = {arg, lastNumber};
+ return result;
+ }
+
+ int numberToArgsIndex(int number) const
+ {
+ if (number != -1) {
+ const int * const it = std::find(argPosToNumberMap.begin(), argPosToNumberMap.end(), number);
+ return it == argPosToNumberMap.end() ? -1 : it - argPosToNumberMap.begin();
+ } else {
+ return -1;
+ }
+ }
+};
+} // unnamed namespace
+
QString QString::multiArg(int numArgs, const QString **args) const
{
QString result;
- QMap<int, int> numbersUsed;
+ ArgMapper mapper;
const QChar *uc = (const QChar *) d->data();
const int len = d->size;
const int end = len - 1;
- int lastNumber = -1;
int i = 0;
- // populate the numbersUsed map with the %n's that actually occur in the string
+ // populate the arg-mapper with the %n's that actually occur in the string
while (i < end) {
if (uc[i] == QLatin1Char('%')) {
int number = getEscape(uc, &i, len);
if (number != -1) {
- numbersUsed.insert(number, -1);
+ mapper.found(number);
continue;
}
}
++i;
}
- // assign an argument number to each of the %n's
- QMap<int, int>::iterator j = numbersUsed.begin();
- QMap<int, int>::iterator jend = numbersUsed.end();
- int arg = 0;
- while (j != jend && arg < numArgs) {
- *j = arg++;
- lastNumber = j.key();
- ++j;
- }
+ const ArgMapper::AssignmentResult r = mapper.assignArgumentNumberToEachOfTheNs(numArgs);
// sanity
- if (numArgs > arg) {
- qWarning("QString::arg: %d argument(s) missing in %s", numArgs - arg, toLocal8Bit().data());
- numArgs = arg;
+ if (numArgs > r.numArgs) {
+ qWarning("QString::arg: %d argument(s) missing in %s", numArgs - r.numArgs, toLocal8Bit().data());
+ numArgs = r.numArgs;
}
i = 0;
while (i < len) {
if (uc[i] == QLatin1Char('%') && i != end) {
- int number = getEscape(uc, &i, len, lastNumber);
- int arg = numbersUsed[number];
+ int number = getEscape(uc, &i, len, r.lastNumber);
+ int arg = mapper.numberToArgsIndex(number);
if (number != -1 && arg != -1) {
result += *args[arg];
continue;
@@ -7942,6 +7914,46 @@ QString &QString::setRawData(const QChar *unicode, int size)
return *this;
}
+/*! \fn QString QString::fromStdU16String(const std::u16string &str)
+ \since 5.5
+
+ Returns a copy of the \a str string. The given string is assumed
+ to be encoded in UTF-16.
+
+ \sa fromUtf16(), fromStdWString(), fromStdU32String()
+*/
+
+/*!
+ \fn std::u16string QString::toStdU16String() const
+ \since 5.5
+
+ Returns a std::u16string object with the data contained in this
+ QString. The Unicode data is the same as returned by the utf16()
+ method.
+
+ \sa utf16(), toStdWString(), toStdU32String()
+*/
+
+/*! \fn QString QString::fromStdU32String(const std::u32string &str)
+ \since 5.5
+
+ Returns a copy of the \a str string. The given string is assumed
+ to be encoded in UCS-4.
+
+ \sa fromUcs4(), fromStdWString(), fromStdU16String()
+*/
+
+/*!
+ \fn std::u32string QString::toStdU32String() const
+ \since 5.5
+
+ Returns a std::u32string object with the data contained in this
+ QString. The Unicode data is the same as returned by the toUcs4()
+ method.
+
+ \sa toUcs4(), toStdWString(), toStdU16String()
+*/
+
/*! \class QLatin1String
\inmodule QtCore
\brief The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
@@ -9843,20 +9855,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..0deb664dc7 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;
@@ -206,22 +210,22 @@ class Q_CORE_EXPORT QString
public:
typedef QStringData Data;
- inline QString();
+ inline QString() Q_DECL_NOTHROW;
explicit QString(const QChar *unicode, int size = -1);
QString(QChar c);
QString(int size, QChar c);
inline QString(QLatin1String latin1);
- inline QString(const QString &);
+ inline QString(const QString &) Q_DECL_NOTHROW;
inline ~QString();
QString &operator=(QChar c);
- QString &operator=(const QString &);
+ QString &operator=(const QString &) Q_DECL_NOTHROW;
inline QString &operator=(QLatin1String latin1);
#ifdef Q_COMPILER_RVALUE_REFS
- inline QString(QString && other) : d(other.d) { other.d = Data::sharedNull(); }
- inline QString &operator=(QString &&other)
+ inline QString(QString && other) Q_DECL_NOTHROW : d(other.d) { other.d = Data::sharedNull(); }
+ inline QString &operator=(QString &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
- inline void swap(QString &other) { qSwap(d, other.d); }
+ inline void swap(QString &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
inline int size() const { return d->size; }
inline int count() const { return d->size; }
inline int length() const;
@@ -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))
{}
@@ -686,6 +733,13 @@ public:
static inline QString fromStdWString(const std::wstring &s);
inline std::wstring toStdWString() const;
+#if defined(Q_COMPILER_UNICODE_STRINGS) || defined(Q_QDOC)
+ static inline QString fromStdU16String(const std::u16string &s);
+ inline std::u16string toStdU16String() const;
+ static inline QString fromStdU32String(const std::u32string &s);
+ inline std::u32string toStdU32String() const;
+#endif
+
#if defined(Q_OS_MAC) || defined(Q_QDOC)
static QString fromCFString(CFStringRef string);
CFStringRef toCFString() const Q_DECL_CF_RETURNS_RETAINED;
@@ -734,6 +788,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);
@@ -808,7 +872,7 @@ inline QString &QString::operator=(QLatin1String s)
}
inline void QString::clear()
{ if (!isNull()) *this = QString(); }
-inline QString::QString(const QString &other) : d(other.d)
+inline QString::QString(const QString &other) Q_DECL_NOTHROW : d(other.d)
{ Q_ASSERT(&other != this); d->ref.ref(); }
inline int QString::capacity() const
{ return d->alloc ? d->alloc - 1 : 0; }
@@ -867,11 +931,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 +943,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)
{
@@ -988,7 +1047,7 @@ inline void QCharRef::setRow(uchar arow) { QChar(*this).setRow(arow); }
inline void QCharRef::setCell(uchar acell) { QChar(*this).setCell(acell); }
-inline QString::QString() : d(Data::sharedNull()) {}
+inline QString::QString() Q_DECL_NOTHROW : d(Data::sharedNull()) {}
inline QString::~QString() { if (!d->ref.deref()) Data::deallocate(d); }
inline void QString::reserve(int asize)
@@ -1083,7 +1142,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 +1233,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 +1261,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)
@@ -1242,6 +1301,25 @@ inline std::wstring QString::toStdWString() const
inline QString QString::fromStdWString(const std::wstring &s)
{ return fromWCharArray(s.data(), int(s.size())); }
+#if defined(Q_COMPILER_UNICODE_STRINGS)
+inline QString QString::fromStdU16String(const std::u16string &s)
+{ return fromUtf16(s.data(), int(s.size())); }
+
+inline std::u16string QString::toStdU16String() const
+{ return std::u16string(reinterpret_cast<const char16_t*>(utf16()), length()); }
+
+inline QString QString::fromStdU32String(const std::u32string &s)
+{ return fromUcs4(s.data(), int(s.size())); }
+
+inline std::u32string QString::toStdU32String() const
+{
+ std::u32string u32str(length(), char32_t(0));
+ int len = toUcs4_helper(d->data(), length(), reinterpret_cast<uint*>(&u32str[0]));
+ u32str.resize(len);
+ return u32str;
+}
+#endif
+
#if !defined(QT_NO_DATASTREAM) || (defined(QT_BOOTSTRAPPED) && !defined(QT_BUILD_QMAKE))
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QString &);
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QString &);
@@ -1355,7 +1433,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 +1507,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 +1533,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..f82981b9dc 100644
--- a/src/corelib/tools/qstringlist.h
+++ b/src/corelib/tools/qstringlist.h
@@ -31,33 +31,70 @@
**
****************************************************************************/
+#include <QtCore/qlist.h>
+
#ifndef QSTRINGLIST_H
#define QSTRINGLIST_H
#include <QtCore/qalgorithms.h>
-#include <QtCore/qdatastream.h>
-#include <QtCore/qlist.h>
#include <QtCore/qregexp.h>
#include <QtCore/qstring.h>
#include <QtCore/qstringmatcher.h>
QT_BEGIN_NAMESPACE
-
class QRegExp;
class QRegularExpression;
typedef QListIterator<QString> QStringListIterator;
typedef QMutableListIterator<QString> QMutableStringListIterator;
+class QStringList;
+
+#ifdef Q_QDOC
+class QStringList : public QList<QString>
+#else
+template <> struct QListSpecialMethods<QString>
+#endif
+{
+public:
+ inline void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive);
+ inline int removeDuplicates();
+
+ inline QString join(const QString &sep) const;
+ inline QString join(QChar sep) const;
+
+ inline QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
+ inline QStringList &replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
+
+#ifndef QT_NO_REGEXP
+ inline QStringList filter(const QRegExp &rx) const;
+ inline QStringList &replaceInStrings(const QRegExp &rx, const QString &after);
+#endif
+
+#ifndef QT_BOOTSTRAPPED
+#ifndef QT_NO_REGULAREXPRESSION
+ inline QStringList filter(const QRegularExpression &re) const;
+ inline QStringList &replaceInStrings(const QRegularExpression &re, const QString &after);
+#endif // QT_NO_REGULAREXPRESSION
+#endif // QT_BOOTSTRAPPED
+
+#ifndef Q_QDOC
+private:
+ inline QStringList *self();
+ inline const QStringList *self() const;
+};
+
+// ### Qt6: check if there's a better way
class QStringList : public QList<QString>
{
+#endif
public:
- inline QStringList() { }
+ inline QStringList() Q_DECL_NOTHROW { }
inline explicit QStringList(const QString &i) { append(i); }
inline QStringList(const QList<QString> &l) : QList<QString>(l) { }
#ifdef Q_COMPILER_RVALUE_REFS
- inline QStringList(QList<QString> &&l) : QList<QString>(std::move(l)) { }
+ inline QStringList(QList<QString> &&l) Q_DECL_NOTHROW : QList<QString>(std::move(l)) { }
#endif
#ifdef Q_COMPILER_INITIALIZER_LISTS
inline QStringList(std::initializer_list<QString> args) : QList<QString>(args) { }
@@ -66,21 +103,12 @@ public:
QStringList &operator=(const QList<QString> &other)
{ QList<QString>::operator=(other); return *this; }
#ifdef Q_COMPILER_RVALUE_REFS
- QStringList &operator=(QList<QString> &&other)
+ QStringList &operator=(QList<QString> &&other) Q_DECL_NOTHROW
{ QList<QString>::operator=(std::move(other)); return *this; }
#endif
- inline void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive);
- inline int removeDuplicates();
-
- inline QString join(const QString &sep) const;
- inline QString join(QChar sep) const;
-
- inline QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
inline bool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
- inline QStringList &replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
-
inline QStringList operator+(const QStringList &other) const
{ QStringList n = *this; n += other; return n; }
inline QStringList &operator<<(const QString &str)
@@ -91,8 +119,6 @@ public:
{ *this += l; return *this; }
#ifndef QT_NO_REGEXP
- inline QStringList filter(const QRegExp &rx) const;
- inline QStringList &replaceInStrings(const QRegExp &rx, const QString &after);
inline int indexOf(const QRegExp &rx, int from = 0) const;
inline int lastIndexOf(const QRegExp &rx, int from = -1) const;
inline int indexOf(QRegExp &rx, int from = 0) const;
@@ -101,26 +127,22 @@ public:
#ifndef QT_BOOTSTRAPPED
#ifndef QT_NO_REGULAREXPRESSION
- inline QStringList filter(const QRegularExpression &re) const;
- inline QStringList &replaceInStrings(const QRegularExpression &re, const QString &after);
inline int indexOf(const QRegularExpression &re, int from = 0) const;
inline int lastIndexOf(const QRegularExpression &re, int from = -1) const;
#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);
+inline QStringList *QListSpecialMethods<QString>::self()
+{ return static_cast<QStringList *>(this); }
+inline const QStringList *QListSpecialMethods<QString>::self() const
+{ return static_cast<const QStringList *>(this); }
+
namespace QtPrivate {
void Q_CORE_EXPORT QStringList_sort(QStringList *that, Qt::CaseSensitivity cs);
int Q_CORE_EXPORT QStringList_removeDuplicates(QStringList *that);
@@ -151,29 +173,29 @@ namespace QtPrivate {
#endif // QT_BOOTSTRAPPED
}
-inline void QStringList::sort(Qt::CaseSensitivity cs)
+inline void QListSpecialMethods<QString>::sort(Qt::CaseSensitivity cs)
{
- QtPrivate::QStringList_sort(this, cs);
+ QtPrivate::QStringList_sort(self(), cs);
}
-inline int QStringList::removeDuplicates()
+inline int QListSpecialMethods<QString>::removeDuplicates()
{
- return QtPrivate::QStringList_removeDuplicates(this);
+ return QtPrivate::QStringList_removeDuplicates(self());
}
-inline QString QStringList::join(const QString &sep) const
+inline QString QListSpecialMethods<QString>::join(const QString &sep) const
{
- return QtPrivate::QStringList_join(this, sep.constData(), sep.length());
+ return QtPrivate::QStringList_join(self(), sep.constData(), sep.length());
}
-inline QString QStringList::join(QChar sep) const
+inline QString QListSpecialMethods<QString>::join(QChar sep) const
{
- return QtPrivate::QStringList_join(this, &sep, 1);
+ return QtPrivate::QStringList_join(self(), &sep, 1);
}
-inline QStringList QStringList::filter(const QString &str, Qt::CaseSensitivity cs) const
+inline QStringList QListSpecialMethods<QString>::filter(const QString &str, Qt::CaseSensitivity cs) const
{
- return QtPrivate::QStringList_filter(this, str, cs);
+ return QtPrivate::QStringList_filter(self(), str, cs);
}
inline bool QStringList::contains(const QString &str, Qt::CaseSensitivity cs) const
@@ -181,22 +203,29 @@ inline bool QStringList::contains(const QString &str, Qt::CaseSensitivity cs) co
return QtPrivate::QStringList_contains(this, str, cs);
}
-inline QStringList &QStringList::replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs)
+inline QStringList &QListSpecialMethods<QString>::replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs)
+{
+ QtPrivate::QStringList_replaceInStrings(self(), before, after, cs);
+ return *self();
+}
+
+inline QStringList operator+(const QList<QString> &one, const QStringList &other)
{
- QtPrivate::QStringList_replaceInStrings(this, before, after, cs);
- return *this;
+ QStringList n = one;
+ n += other;
+ return n;
}
#ifndef QT_NO_REGEXP
-inline QStringList &QStringList::replaceInStrings(const QRegExp &rx, const QString &after)
+inline QStringList &QListSpecialMethods<QString>::replaceInStrings(const QRegExp &rx, const QString &after)
{
- QtPrivate::QStringList_replaceInStrings(this, rx, after);
- return *this;
+ QtPrivate::QStringList_replaceInStrings(self(), rx, after);
+ return *self();
}
-inline QStringList QStringList::filter(const QRegExp &rx) const
+inline QStringList QListSpecialMethods<QString>::filter(const QRegExp &rx) const
{
- return QtPrivate::QStringList_filter(this, rx);
+ return QtPrivate::QStringList_filter(self(), rx);
}
inline int QStringList::indexOf(const QRegExp &rx, int from) const
@@ -222,15 +251,15 @@ inline int QStringList::lastIndexOf(QRegExp &rx, int from) const
#ifndef QT_BOOTSTRAPPED
#ifndef QT_NO_REGULAREXPRESSION
-inline QStringList &QStringList::replaceInStrings(const QRegularExpression &rx, const QString &after)
+inline QStringList &QListSpecialMethods<QString>::replaceInStrings(const QRegularExpression &rx, const QString &after)
{
- QtPrivate::QStringList_replaceInStrings(this, rx, after);
- return *this;
+ QtPrivate::QStringList_replaceInStrings(self(), rx, after);
+ return *self();
}
-inline QStringList QStringList::filter(const QRegularExpression &rx) const
+inline QStringList QListSpecialMethods<QString>::filter(const QRegularExpression &rx) const
{
- return QtPrivate::QStringList_filter(this, rx);
+ return QtPrivate::QStringList_filter(self(), rx);
}
inline int QStringList::indexOf(const QRegularExpression &rx, int from) const
@@ -245,17 +274,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/qstringmatcher.h b/src/corelib/tools/qstringmatcher.h
index 00e5fc1587..d416831434 100644
--- a/src/corelib/tools/qstringmatcher.h
+++ b/src/corelib/tools/qstringmatcher.h
@@ -66,11 +66,6 @@ private:
QStringMatcherPrivate *d_ptr;
QString q_pattern;
Qt::CaseSensitivity q_cs;
-#ifdef Q_CC_RVCT
-// explicitly allow anonymous unions for RVCT to prevent compiler warnings
-# pragma push
-# pragma anon_unions
-#endif
struct Data {
uchar q_skiptable[256];
const QChar *uc;
@@ -80,9 +75,6 @@ private:
uint q_data[256];
Data p;
};
-#ifdef Q_CC_RVCT
-# pragma pop
-#endif
};
QT_END_NAMESPACE
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..30c4c60167 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
@@ -785,6 +789,29 @@ QByteArray QTimeZone::systemTimeZoneId()
}
/*!
+ \since 5.5
+ Returns a QTimeZone object that refers to the local system time, as
+ specified by systemTimeZoneId().
+
+ \sa utc()
+*/
+QTimeZone QTimeZone::systemTimeZone()
+{
+ return QTimeZone(QTimeZone::systemTimeZoneId());
+}
+
+/*!
+ \since 5.5
+ Returns a QTimeZone object that refers to UTC (Universal Time Coordinated).
+
+ \sa systemTimeZone()
+*/
+QTimeZone QTimeZone::utc()
+{
+ return QTimeZone(QTimeZonePrivate::utcQByteArray());
+}
+
+/*!
Returns \c true if a given time zone \a ianaId is available on this system.
\sa availableTimeZoneIds()
diff --git a/src/corelib/tools/qtimezone.h b/src/corelib/tools/qtimezone.h
index ffc2316b5f..e35cee6bbe 100644
--- a/src/corelib/tools/qtimezone.h
+++ b/src/corelib/tools/qtimezone.h
@@ -79,10 +79,10 @@ public:
QTimeZone &operator=(const QTimeZone &other);
#ifdef Q_COMPILER_RVALUE_REFS
- QTimeZone &operator=(QTimeZone &&other) { swap(other); return *this; }
+ QTimeZone &operator=(QTimeZone &&other) Q_DECL_NOTHROW { swap(other); return *this; }
#endif
- void swap(QTimeZone &other)
+ void swap(QTimeZone &other) Q_DECL_NOTHROW
{ d.swap(other.d); }
bool operator==(const QTimeZone &other) const;
@@ -117,6 +117,8 @@ public:
OffsetDataList transitions(const QDateTime &fromDateTime, const QDateTime &toDateTime) const;
static QByteArray systemTimeZoneId();
+ static QTimeZone systemTimeZone();
+ static QTimeZone utc();
static bool isTimeZoneIdAvailable(const QByteArray &ianaId);
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..4b44c6a262 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
@@ -179,7 +183,7 @@ public:
QUtcTimeZonePrivate(const QUtcTimeZonePrivate &other);
virtual ~QUtcTimeZonePrivate();
- QTimeZonePrivate *clone();
+ QTimeZonePrivate *clone() Q_DECL_OVERRIDE;
QLocale::Country country() const Q_DECL_OVERRIDE;
QString comment() const Q_DECL_OVERRIDE;
@@ -224,7 +228,7 @@ public:
QIcuTimeZonePrivate(const QIcuTimeZonePrivate &other);
~QIcuTimeZonePrivate();
- QTimeZonePrivate *clone();
+ QTimeZonePrivate *clone() Q_DECL_OVERRIDE;
QString displayName(QTimeZone::TimeType timeType, QTimeZone::NameType nameType,
const QLocale &locale) const Q_DECL_OVERRIDE;
@@ -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:
@@ -267,7 +271,7 @@ public:
QTzTimeZonePrivate(const QTzTimeZonePrivate &other);
~QTzTimeZonePrivate();
- QTimeZonePrivate *clone();
+ QTimeZonePrivate *clone() Q_DECL_OVERRIDE;
QLocale::Country country() const Q_DECL_OVERRIDE;
QString comment() const Q_DECL_OVERRIDE;
@@ -334,7 +338,7 @@ public:
QMacTimeZonePrivate(const QMacTimeZonePrivate &other);
~QMacTimeZonePrivate();
- QTimeZonePrivate *clone();
+ QTimeZonePrivate *clone() Q_DECL_OVERRIDE;
QString comment() const Q_DECL_OVERRIDE;
@@ -385,7 +389,7 @@ public:
QWinTimeZonePrivate(const QWinTimeZonePrivate &other);
~QWinTimeZonePrivate();
- QTimeZonePrivate *clone();
+ QTimeZonePrivate *clone() Q_DECL_OVERRIDE;
QString comment() const Q_DECL_OVERRIDE;
@@ -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() Q_DECL_OVERRIDE;
+
+ 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/qunicodetables.cpp b/src/corelib/tools/qunicodetables.cpp
index 072e8ad920..477a0441b0 100644
--- a/src/corelib/tools/qunicodetables.cpp
+++ b/src/corelib/tools/qunicodetables.cpp
@@ -6912,44 +6912,44 @@ static const Properties uc_properties[] = {
{ 12, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 12, 0 }
};
-Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(uint ucs4)
+Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(uint ucs4) Q_DECL_NOTHROW
{
const int index = GET_PROP_INDEX(ucs4);
return uc_properties + index;
}
-Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(ushort ucs2)
+Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(ushort ucs2) Q_DECL_NOTHROW
{
const int index = GET_PROP_INDEX_UCS2(ucs2);
return uc_properties + index;
}
-Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4)
+Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4) Q_DECL_NOTHROW
{
return qGetProp(ucs4);
}
-Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2)
+Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2) Q_DECL_NOTHROW
{
return qGetProp(ucs2);
}
-Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(uint ucs4)
+Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(uint ucs4) Q_DECL_NOTHROW
{
return (GraphemeBreakClass)qGetProp(ucs4)->graphemeBreakClass;
}
-Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(uint ucs4)
+Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(uint ucs4) Q_DECL_NOTHROW
{
return (WordBreakClass)qGetProp(ucs4)->wordBreakClass;
}
-Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(uint ucs4)
+Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(uint ucs4) Q_DECL_NOTHROW
{
return (SentenceBreakClass)qGetProp(ucs4)->sentenceBreakClass;
}
-Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(uint ucs4)
+Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(uint ucs4) Q_DECL_NOTHROW
{
return (LineBreakClass)qGetProp(ucs4)->lineBreakClass;
}
diff --git a/src/corelib/tools/qunicodetables_p.h b/src/corelib/tools/qunicodetables_p.h
index 64e1ad12b5..34da53ac58 100644
--- a/src/corelib/tools/qunicodetables_p.h
+++ b/src/corelib/tools/qunicodetables_p.h
@@ -79,8 +79,8 @@ struct Properties {
ushort script : 8; /* 7 used */
};
-Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4);
-Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2);
+Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4) Q_DECL_NOTHROW;
+Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2) Q_DECL_NOTHROW;
enum GraphemeBreakClass {
GraphemeBreak_Other,
@@ -147,20 +147,20 @@ enum LineBreakClass {
LineBreak_BK
};
-Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(uint ucs4);
-inline GraphemeBreakClass graphemeBreakClass(QChar ch)
+Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(uint ucs4) Q_DECL_NOTHROW;
+inline GraphemeBreakClass graphemeBreakClass(QChar ch) Q_DECL_NOTHROW
{ return graphemeBreakClass(ch.unicode()); }
-Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(uint ucs4);
-inline WordBreakClass wordBreakClass(QChar ch)
+Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(uint ucs4) Q_DECL_NOTHROW;
+inline WordBreakClass wordBreakClass(QChar ch) Q_DECL_NOTHROW
{ return wordBreakClass(ch.unicode()); }
-Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(uint ucs4);
-inline SentenceBreakClass sentenceBreakClass(QChar ch)
+Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(uint ucs4) Q_DECL_NOTHROW;
+inline SentenceBreakClass sentenceBreakClass(QChar ch) Q_DECL_NOTHROW
{ return sentenceBreakClass(ch.unicode()); }
-Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(uint ucs4);
-inline LineBreakClass lineBreakClass(QChar ch)
+Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(uint ucs4) Q_DECL_NOTHROW;
+inline LineBreakClass lineBreakClass(QChar ch) Q_DECL_NOTHROW
{ return lineBreakClass(ch.unicode()); }
} // namespace QUnicodeTables
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..c3d65b7d51 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -61,7 +61,7 @@ class QVector
Data *d;
public:
- inline QVector() : d(Data::sharedNull()) { }
+ inline QVector() Q_DECL_NOTHROW : d(Data::sharedNull()) { }
explicit QVector(int size);
QVector(int size, const T &t);
inline QVector(const QVector<T> &v);
@@ -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/qversionnumber.cpp b/src/corelib/tools/qversionnumber.cpp
index 3c8a9db086..7817cabe33 100644
--- a/src/corelib/tools/qversionnumber.cpp
+++ b/src/corelib/tools/qversionnumber.cpp
@@ -473,13 +473,7 @@ QDebug operator<<(QDebug debug, const QVersionNumber &version)
*/
uint qHash(const QVersionNumber &key, uint seed)
{
- uint hash = seed;
- for (QVector<int>::const_iterator it = key.m_segments.begin(), end = key.m_segments.end(); it != end; ++it) {
- // used to preserve order
- // see N3876 for more information
- hash ^= qHash(*it) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
- }
- return hash;
+ return qHashRange(key.m_segments.begin(), key.m_segments.end(), seed);
}
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qversionnumber_p.h b/src/corelib/tools/qversionnumber_p.h
index a951b2f1a0..883aae11ff 100644
--- a/src/corelib/tools/qversionnumber_p.h
+++ b/src/corelib/tools/qversionnumber_p.h
@@ -59,7 +59,7 @@ Q_CORE_EXPORT QDataStream& operator<<(QDataStream &out, const QVersionNumber &ve
Q_CORE_EXPORT QDataStream& operator>>(QDataStream &in, QVersionNumber &version);
#endif
-class Q_CORE_EXPORT QVersionNumber
+class QVersionNumber
{
public:
inline QVersionNumber() Q_DECL_NOTHROW
@@ -150,17 +150,17 @@ public:
inline int segmentCount() const Q_DECL_NOTHROW Q_REQUIRED_RESULT
{ return m_segments.size(); }
- bool isPrefixOf(const QVersionNumber &other) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ Q_CORE_EXPORT bool isPrefixOf(const QVersionNumber &other) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
- static int compare(const QVersionNumber &v1, const QVersionNumber &v2) Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ Q_CORE_EXPORT static int compare(const QVersionNumber &v1, const QVersionNumber &v2) Q_DECL_NOTHROW Q_REQUIRED_RESULT;
- static Q_DECL_PURE_FUNCTION QVersionNumber commonPrefix(const QVersionNumber &v1, const QVersionNumber &v2) Q_REQUIRED_RESULT;
+ Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber commonPrefix(const QVersionNumber &v1, const QVersionNumber &v2) Q_REQUIRED_RESULT;
- QString toString() const Q_REQUIRED_RESULT;
- static Q_DECL_PURE_FUNCTION QVersionNumber fromString(const QString &string, int *suffixIndex = 0) Q_REQUIRED_RESULT;
+ Q_CORE_EXPORT QString toString() const Q_REQUIRED_RESULT;
+ Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber fromString(const QString &string, int *suffixIndex = 0) Q_REQUIRED_RESULT;
private:
- static QVersionNumber normalizedImpl(QVector<int> &segs) Q_REQUIRED_RESULT;
+ Q_CORE_EXPORT static QVersionNumber normalizedImpl(QVector<int> &segs) Q_REQUIRED_RESULT;
#ifndef QT_NO_DATASTREAM
friend Q_CORE_EXPORT QDataStream& operator>>(QDataStream &in, QVersionNumber &version);
diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri
index cef802fa76..c4c347d6ff 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 \
@@ -66,6 +67,7 @@ HEADERS += \
tools/qtimezone.h \
tools/qtimezoneprivate_p.h \
tools/qtimezoneprivate_data_p.h \
+ tools/qtools_p.h \
tools/qelapsedtimer.h \
tools/qunicodetables_p.h \
tools/qunicodetools_p.h \
@@ -128,13 +130,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
@@ -207,7 +215,7 @@ INCLUDEPATH += ../3rdparty/md5 \
../3rdparty/sha3
# Note: libm should be present by default becaue this is C++
-!macx-icc:!vxworks:unix:LIBS_PRIVATE += -lm
+!macx-icc:!vxworks:!haiku:unix:LIBS_PRIVATE += -lm
TR_EXCLUDE += ../3rdparty/*
diff --git a/src/corelib/xml/qxmlstream.cpp b/src/corelib/xml/qxmlstream.cpp
index ad10c63686..f79c8e65fa 100644
--- a/src/corelib/xml/qxmlstream.cpp
+++ b/src/corelib/xml/qxmlstream.cpp
@@ -2396,15 +2396,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 {