From 7a4f05f89927fd9ca8771550f1405d99e3961c24 Mon Sep 17 00:00:00 2001 From: Alexis Menard Date: Wed, 17 Mar 2010 08:30:39 +0100 Subject: Display the itemSendScenePositionChange properly when debugging. Also a harmless test added to check that the flag is actually set. Reviewed-by:TrustMe --- src/gui/graphicsview/qgraphicsitem.cpp | 2 +- tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index b712016..3c255ef 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -11141,7 +11141,7 @@ QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlags flags) { debug << '('; bool f = false; - for (int i = 0; i < 16; ++i) { + for (int i = 0; i < 17; ++i) { if (flags & (1 << i)) { if (f) debug << '|'; diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 4d9f23f..c0ad8bf 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -9767,6 +9767,9 @@ void tst_QGraphicsItem::scenePosChange() child1->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, true); grandChild2->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, true); + QVERIFY(child1->flags() & QGraphicsItem::ItemSendsScenePositionChanges); + QVERIFY(grandChild2->flags() & QGraphicsItem::ItemSendsScenePositionChanges); + QGraphicsScene scene; scene.addItem(root); -- cgit v0.12 From c3a8819a68cff387178a0f37de62611b98e0a665 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Wed, 17 Mar 2010 11:24:37 +0100 Subject: Use a toolbar for the designer property editor This makes the designer plugin a little bit more consistent. It also helps cosmeticaly in creator as we get a better separation between the tool bar and the treeview. Reviewed-by: thorbjorn --- tools/designer/src/components/widgetbox/widgetbox.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/designer/src/components/widgetbox/widgetbox.cpp b/tools/designer/src/components/widgetbox/widgetbox.cpp index 512d6ba..091135a 100644 --- a/tools/designer/src/components/widgetbox/widgetbox.cpp +++ b/tools/designer/src/components/widgetbox/widgetbox.cpp @@ -74,7 +74,10 @@ WidgetBox::WidgetBox(QDesignerFormEditorInterface *core, QWidget *parent, Qt::Wi FilterWidget *filterWidget = new FilterWidget(0, FilterWidget::LayoutAlignNone); filterWidget->setRefuseFocus(true); connect(filterWidget, SIGNAL(filterChanged(QString)), m_view, SLOT(filter(QString))); - l->addWidget(filterWidget); + + QToolBar *toolBar = new QToolBar(this); + toolBar->addWidget(filterWidget); + l->addWidget(toolBar); // View connect(m_view, SIGNAL(pressed(QString,QString,QPoint)), -- cgit v0.12 From 782a5c8537831143d52df99c434bb1e5420d7113 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 18 Feb 2010 11:31:05 +0100 Subject: Initial version of QTimestamp class. Only the generic, non-monotonic QTime-based version available right now Task-number: QT-2965 --- src/corelib/tools/qdatetime.h | 1 + src/corelib/tools/qtimestamp.h | 106 +++++++++++++++++++++++++++++++ src/corelib/tools/qtimestamp_generic.cpp | 93 +++++++++++++++++++++++++++ src/corelib/tools/tools.pri | 3 + tests/auto/qtimestamp/qtimestamp.pro | 13 ++++ tests/auto/qtimestamp/tst_qtimestamp.cpp | 68 ++++++++++++++++++++ 6 files changed, 284 insertions(+) create mode 100644 src/corelib/tools/qtimestamp.h create mode 100644 src/corelib/tools/qtimestamp_generic.cpp create mode 100644 tests/auto/qtimestamp/qtimestamp.pro create mode 100644 tests/auto/qtimestamp/tst_qtimestamp.cpp diff --git a/src/corelib/tools/qdatetime.h b/src/corelib/tools/qdatetime.h index 6fdc855..75b5985 100644 --- a/src/corelib/tools/qdatetime.h +++ b/src/corelib/tools/qdatetime.h @@ -204,6 +204,7 @@ private: friend class QDateTime; friend class QDateTimePrivate; + friend class QTimestamp; #ifndef QT_NO_DATASTREAM friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QTime &); friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QTime &); diff --git a/src/corelib/tools/qtimestamp.h b/src/corelib/tools/qtimestamp.h new file mode 100644 index 0000000..f923cd4 --- /dev/null +++ b/src/corelib/tools/qtimestamp.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTIMESTAMP_H +#define QTIMESTAMP_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Core) + +class Q_CORE_EXPORT QTimestamp +{ +public: + static bool isMonotonic(); + + void start(); + qint64 restart() + { + qint64 r = elapsed(); + start(); + return r; + } + + qint64 elapsed() const; + bool hasExpired(qint64 timeout) const + { + // if timeout is -1, quint64(timeout) is LLINT_MAX, so this will be + // considered as never expired + return quint64(elapsed()) > quint64(timeout); + } + + qint64 msecsTo(const QTimestamp &other) const; + void addMSecs(int ms); + qint64 secsTo(const QTimestamp &other) const; + void addSecs(int secs); + + bool operator==(const QTimestamp &other) const + { return t1 == other.t1 && t2 == other.t2; } + bool operator!=(const QTimestamp &other) const + { return !(*this == other); } + + friend bool Q_CORE_EXPORT operator<(const QTimestamp &v1, const QTimestamp &v2); + friend qint64 operator-(const QTimestamp &v1, const QTimestamp &v2) + { return v2.msecsTo(v1); } + + friend QTimestamp &operator+=(QTimestamp &ts, qint64 ms) + { ts.addMSecs(ms); return ts; } + friend QTimestamp operator+(const QTimestamp &ts, qint64 ms) + { QTimestamp copy(ts); return copy += ms; } + friend QTimestamp &operator-=(QTimestamp &ts, qint64 ms) + { ts.addMSecs(-ms); return ts; } + friend QTimestamp operator-(const QTimestamp &ts, qint64 ms) + { QTimestamp copy(ts); return copy -= ms; } + +private: + qint64 t1; + qint64 t2; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QTIMESTAMP_H diff --git a/src/corelib/tools/qtimestamp_generic.cpp b/src/corelib/tools/qtimestamp_generic.cpp new file mode 100644 index 0000000..18c5026 --- /dev/null +++ b/src/corelib/tools/qtimestamp_generic.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtimestamp.h" +#include "qdatetime.h" + +QT_BEGIN_NAMESPACE + +bool QTimestamp::isMonotonic() +{ + return false; +} + +void QTimestamp::start() +{ + QTime t = QTime::currentTime(); + t1 = t.mds; + t2 = 0; +} + +qint64 QTimestamp::elapsed() const +{ + QTime t = QTime::currentTime(); + return t.mds - t1; +} + +qint64 QTimestamp::msecsTo(const QTimestamp &other) const +{ + qint64 diff = other.t1 - t1; + if (diff < 0) // passed midnight + diff += 86400 * 1000; + return diff; +} + +void QTimestamp::addMSecs(int ms) +{ + t1 += ms; +} + +qint64 QTimestamp::secsTo(const QTimestamp &other) const +{ + return msecsTo(other) / 1000; +} + +void QTimestamp::addSecs(int secs) +{ + t1 += secs * 1000; +} + +bool operator<(const QTimestamp &v1, const QTimestamp &v2) +{ + return v1.t1 < v2.t1; +} + +QT_END_NAMESPACE diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index 6d64915..49f2f16 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -42,6 +42,7 @@ HEADERS += \ tools/qstringmatcher.h \ tools/qtextboundaryfinder.h \ tools/qtimeline.h \ + tools/qtimestamp.h \ tools/qunicodetables_p.h \ tools/qvarlengtharray.h \ tools/qvector.h \ @@ -81,6 +82,8 @@ SOURCES += \ symbian:SOURCES+=tools/qlocale_symbian.cpp +unix:SOURCES += tools/qtimestamp_generic.cpp + #zlib support contains(QT_CONFIG, zlib) { wince*: DEFINES += NO_ERRNO_H diff --git a/tests/auto/qtimestamp/qtimestamp.pro b/tests/auto/qtimestamp/qtimestamp.pro new file mode 100644 index 0000000..3a06390 --- /dev/null +++ b/tests/auto/qtimestamp/qtimestamp.pro @@ -0,0 +1,13 @@ +load(qttest_p4) +QT -= gui + +SOURCES += tst_qtimestamp.cpp +wince* { + DEFINES += SRCDIR=\\\"\\\" +} else:symbian { + # do not define SRCDIR at all + TARGET.EPOCHEAPSIZE = 0x100000 0x3000000 +} else { + DEFINES += SRCDIR=\\\"$$PWD/\\\" +} + diff --git a/tests/auto/qtimestamp/tst_qtimestamp.cpp b/tests/auto/qtimestamp/tst_qtimestamp.cpp new file mode 100644 index 0000000..5a0b230 --- /dev/null +++ b/tests/auto/qtimestamp/tst_qtimestamp.cpp @@ -0,0 +1,68 @@ +#include +#include +#include +#include + +class tst_QTimestamp : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void basics(); + void elapsed(); +}; + +void tst_QTimestamp::basics() +{ + QTimestamp t1; + t1.start(); + + QCOMPARE(t1, t1); + QVERIFY(!(t1 != t1)); + QVERIFY(!(t1 < t1)); + QCOMPARE(t1.msecsTo(t1), qint64(0)); + QCOMPARE(t1.secsTo(t1), qint64(0)); + QCOMPARE(t1 + 0, t1); + QCOMPARE(t1 - 0, t1); + + QTimestamp t2 = t1; + t2 += 1000; // so we can use secsTo + + QVERIFY(t1 != t2); + QVERIFY(!(t1 == t2)); + QVERIFY(t1 < t2); + QVERIFY(!(t2 < t1)); + QCOMPARE(t1.msecsTo(t2), qint64(1000)); + QCOMPARE(t1.secsTo(t2), qint64(1)); + QCOMPARE(t2 - t1, qint64(1000)); + QCOMPARE(t1 - t2, qint64(-1000)); +} + +void tst_QTimestamp::elapsed() +{ + QTimestamp t1; + t1.start(); + + QTest::qWait(100); + QTimestamp t2; + t2.start(); + + QVERIFY(t1 != t2); + QVERIFY(!(t1 == t2)); + QVERIFY(t1 < t2); + QVERIFY(t1.msecsTo(t2) > 0); + // don't check: t1.secsTo(t2) + QVERIFY(t1 - t2 < 0); + + QVERIFY(t1.elapsed() > 0); + QVERIFY(t1.hasExpired(50)); + QVERIFY(!t1.hasExpired(500)); + QVERIFY(!t2.hasExpired(0)); + + QVERIFY(!t1.hasExpired(-1)); + QVERIFY(!t2.hasExpired(-1)); +} + +QTEST_MAIN(tst_QTimestamp); + +#include "tst_qtimestamp.moc" -- cgit v0.12 From e33a545fc76ad99db39680433b151815175f8b76 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 18 Feb 2010 12:21:53 +0100 Subject: Add the Mac implementation of QTimestamp. Task-number: QT-2965 --- src/corelib/tools/qtimestamp_mac.cpp | 109 +++++++++++++++++++++++++++++++++++ src/corelib/tools/tools.pri | 3 +- 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/corelib/tools/qtimestamp_mac.cpp diff --git a/src/corelib/tools/qtimestamp_mac.cpp b/src/corelib/tools/qtimestamp_mac.cpp new file mode 100644 index 0000000..bdc91d1 --- /dev/null +++ b/src/corelib/tools/qtimestamp_mac.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtimestamp.h" +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +bool QTimestamp::isMonotonic() +{ + return true; +} + +static mach_timebase_info_data_t info = {0,0}; +static qint64 absoluteToMSecs(qint64 cpuTime) +{ + if (info.denom == 0) + mach_timebase_info(&info); + qint64 nsecs = cpuTime * info.numer / info.denom; + return nsecs / (1000*1000ull); +} + +static qint64 msecsToAbsolute(qint64 ms) +{ + if (info.denom == 0) + mach_timebase_info(&info); + qint64 nsecs = ms * 1000000ull; + return nsecs * info.denom / info.numer; +} + +void QTimestamp::start() +{ + t1 = mach_absolute_time(); + t2 = 0; +} + +qint64 QTimestamp::elapsed() const +{ + uint64_t cpu_time = mach_absolute_time(); + return absoluteToMSecs(cpu_time - t1); +} + +qint64 QTimestamp::msecsTo(const QTimestamp &other) const +{ + return absoluteToMSecs(other.t1 - t1); +} + +void QTimestamp::addMSecs(int ms) +{ + t1 += msecsToAbsolute(ms); +} + +qint64 QTimestamp::secsTo(const QTimestamp &other) const +{ + return msecsTo(other) / 1000; +} + +void QTimestamp::addSecs(int secs) +{ + t1 += secs * 1000; +} + +bool operator<(const QTimestamp &v1, const QTimestamp &v2) +{ + return v1.t1 < v2.t1; +} + +QT_END_NAMESPACE diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index 49f2f16..3599cc7 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -82,7 +82,8 @@ SOURCES += \ symbian:SOURCES+=tools/qlocale_symbian.cpp -unix:SOURCES += tools/qtimestamp_generic.cpp +mac:SOURCES += tools/qtimestamp_mac.cpp +else:SOURCES += tools/qtimestamp_generic.cpp #zlib support contains(QT_CONFIG, zlib) { -- cgit v0.12 From 495581a1278f534e855d6122cdcb719c1df6d40b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 18 Feb 2010 12:50:52 +0100 Subject: Add the non-Mac Unix implementation of QTimestamp. Task-number: QT-2965 --- src/corelib/tools/qtimestamp_unix.cpp | 149 ++++++++++++++++++++++++++++++++++ src/corelib/tools/tools.pri | 1 + 2 files changed, 150 insertions(+) create mode 100644 src/corelib/tools/qtimestamp_unix.cpp diff --git a/src/corelib/tools/qtimestamp_unix.cpp b/src/corelib/tools/qtimestamp_unix.cpp new file mode 100644 index 0000000..b82259f --- /dev/null +++ b/src/corelib/tools/qtimestamp_unix.cpp @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtimestamp.h" +#include +#include +#include + +#if !defined(QT_NO_CLOCK_MONOTONIC) +# if defined(QT_BOOTSTRAPPED) +# define QT_NO_CLOCK_MONOTONIC +# endif +#endif + +QT_BEGIN_NAMESPACE + +bool QTimestamp::isMonotonic() +{ +#if (_POSIX_MONOTONIC_CLOCK-0 > 0) + return true; +#else + static int returnValue = 0; + + if (returnValue == 0) { +# if (_POSIX_MONOTONIC_CLOCK-0 < 0) + returnValue = -1; +# elif (_POSIX_MONOTONIC_CLOCK == 0) + // detect if the system support monotonic timers + long x = sysconf(_SC_MONOTONIC_CLOCK); + returnValue = (x >= 200112L) ? 1 : -1; +# endif + } + + return returnValue != -1; +#endif +} + +static qint64 fractionAdjustment() +{ + if (QTimestamp::isMonotonic()) { + // the monotonic timer is measured in nanoseconds + // 1 ms = 1000000 ns + return 1000*1000ull; + } else { + // gettimeofday is measured in microseconds + // 1 ms = 1000 us + return 1000; + } +} + +void QTimestamp::start() +{ +#if (_POSIX_MONOTONIC_CLOCK-0 > 0) + timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + t1 = ts.tv_sec; + t2 = ts.tv_nsec; +#else +# if !defined(QT_NO_CLOCK_MONOTONIC) && !defined(QT_BOOTSTRAPPED) + if (isMonotonic()) { + timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + t1 = ts.tv_sec; + t2 = ts.tv_nsec; + return; + } +# endif + // use gettimeofday + timeval tv; + ::gettimeofday(&tv, 0); + t1 = tv.tv_sec; + t2 = tv.tv_usec; +#endif +} + +qint64 QTimestamp::elapsed() const +{ + QTimestamp now; + now.start(); + return msecsTo(now); +} + +qint64 QTimestamp::msecsTo(const QTimestamp &other) const +{ + qint64 secs = other.t1 - t1; + qint64 fraction = other.t2 - t2; + return secs * 1000 + fraction / fractionAdjustment(); +} + +void QTimestamp::addMSecs(int ms) +{ + t1 += ms / 1000; + t2 += ms % 1000 * fractionAdjustment(); +} + +qint64 QTimestamp::secsTo(const QTimestamp &other) const +{ + return other.t1 - t1; +} + +void QTimestamp::addSecs(int secs) +{ + t1 += secs; +} + +bool operator<(const QTimestamp &v1, const QTimestamp &v2) +{ + return v1.t1 < v2.t1 || (v1.t1 == v2.t1 && v1.t2 < v2.t2); +} + +QT_END_NAMESPACE diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index 3599cc7..b8a0ae1 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -83,6 +83,7 @@ SOURCES += \ symbian:SOURCES+=tools/qlocale_symbian.cpp mac:SOURCES += tools/qtimestamp_mac.cpp +else:unix:SOURCES += tools/qtimestamp_unix.cpp else:SOURCES += tools/qtimestamp_generic.cpp #zlib support -- cgit v0.12 From 3e20aa117f4867aa40e03103fcb4e1a54b42dd1c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 18 Feb 2010 13:05:47 +0100 Subject: Add the Windows implementation of QTimestamp Task-number: QT-2965 --- src/corelib/tools/qtimestamp_win.cpp | 120 +++++++++++++++++++++++++++++++++++ src/corelib/tools/tools.pri | 1 + 2 files changed, 121 insertions(+) create mode 100644 src/corelib/tools/qtimestamp_win.cpp diff --git a/src/corelib/tools/qtimestamp_win.cpp b/src/corelib/tools/qtimestamp_win.cpp new file mode 100644 index 0000000..99faebd --- /dev/null +++ b/src/corelib/tools/qtimestamp_win.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtimestamp.h" +#include + +typedef ULONGLONG (WINAPI *PtrGetTickCount64)(void); +static PtrGetTickCount64 ptrGetTickCount64 = 0; + +QT_BEGIN_NAMESPACE + +static void resolveLibs() +{ + static bool done = false; + if (done) + return; + + // try to get GetTickCount64 from the system + HMODULE kernel32 = GetModuleHandleW(L"kernel32"); + if (!kernel32) + return; + +#if defined(Q_OS_WINCE) + // does this function exist on WinCE, or will ever exist? + ptrGetTickCount64 = (PtrGetTickCount64)GetProcAddress(kernel32, L"GetTickCount64"); +#else + ptrGetTickCount64 = (PtrGetTickCount64)GetProcAddress(kernel32, "GetTickCount64"); +#endif + + done = true; +} + +static quint64 getTickCount() +{ + resolveLibs(); + if (ptrGetTickCount64) + return ptrGetTickCount64(); + return GetTickCount(); +} + +bool QTimestamp::isMonotonic() +{ + return true; +} + +void QTimestamp::start() +{ + t1 = getTickCount(); + t2 = 0; +} + +qint64 QTimestamp::elapsed() const +{ + return getTickCount() - t1; +} + +qint64 QTimestamp::msecsTo(const QTimestamp &other) const +{ + return other.t1 - t1; +} + +void QTimestamp::addMSecs(int ms) +{ + t1 += ms; +} + +qint64 QTimestamp::secsTo(const QTimestamp &other) const +{ + return msecsTo(other) / 1000; +} + +void QTimestamp::addSecs(int secs) +{ + t1 += secs * 1000; +} + +bool operator<(const QTimestamp &v1, const QTimestamp &v2) +{ + return v1.t1 < v2.t1; +} + +QT_END_NAMESPACE diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index b8a0ae1..863f86e 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -84,6 +84,7 @@ symbian:SOURCES+=tools/qlocale_symbian.cpp mac:SOURCES += tools/qtimestamp_mac.cpp else:unix:SOURCES += tools/qtimestamp_unix.cpp +else:win32:SOURCES += tools/qtimestamp_win.cpp else:SOURCES += tools/qtimestamp_generic.cpp #zlib support -- cgit v0.12 From ca0def08d1ec2575546f7bfa3759f24288ba8e2a Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 19 Feb 2010 14:10:05 +0100 Subject: Add the Symbian version of QTimestamp. This code is disabled --- src/corelib/tools/qtimestamp_symbian.cpp | 117 +++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/corelib/tools/qtimestamp_symbian.cpp diff --git a/src/corelib/tools/qtimestamp_symbian.cpp b/src/corelib/tools/qtimestamp_symbian.cpp new file mode 100644 index 0000000..e78597c --- /dev/null +++ b/src/corelib/tools/qtimestamp_symbian.cpp @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtimestamp.h" +#include + +QT_BEGIN_NAMESPACE + +// return quint64 to avoid sign-extension +static quint64 getMillisecondFromTick() +{ + static TInt nanokernel_tick_period; + if (!nanokernel_tick_period) + HAL::Get(HAL::ENanoTickPeriod, nanokernel_tick_period); + return nanokernel_tick_period * User::NTickCount(); +} + +static qint64 difference(qint64 a, qint64 b) +{ + qint64 retval = a - b; + // there can be 32-bit rollover + // assume there were rollovers if the difference is negative by more than + // 75% of the 32-bit range + + if (retval < Q_INT64_C(-0xc0000000)) + retval += Q_UINT64_C(0x100000000); + return retval; +} + +bool QTimestamp::isMonotonic() +{ + return true; +} + +void QTimestamp::start() +{ + t1 = getMillisecondFromTick(); + t2 = 0; +} + +qint64 QTimestamp::restart() +{ + qint64 oldt1 = t1; + t1 = getMillisecondFromTick(); + return difference(t1, oldt1); +} + +qint64 QTimestamp::elapsed() const +{ + return difference(getMillisecondFromTick(), t1); +} + +qint64 QTimestamp::msecsTo(const QTimestamp &other) const +{ + return difference(other.t1, t1); +} + +void QTimestamp::addMSecs(int ms) +{ + // simulate a 32-bit rollover + t1 = quint32(t1 + ms); +} + +qint64 QTimestamp::secsTo(const QTimestamp &other) const +{ + return msecsTo(other) / 1000; +} + +void QTimestamp::addSecs(int secs) +{ + addMSecs(secs * 1000); +} + +bool operator<(const QTimestamp &v1, const QTimestamp &v2) +{ + return difference(v1.t1, v2.t1) < 0; +} + +QT_END_NAMESPACE -- cgit v0.12 From 49d949b644b94fbd6c1946ffddcc1b8675ffa9ef Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 18 Feb 2010 13:56:46 +0100 Subject: Make qcore_unix.cpp share code with QTimestamp --- src/corelib/kernel/qcore_unix.cpp | 65 +--------------------------- src/corelib/kernel/qcore_unix_p.h | 4 +- src/corelib/kernel/qeventdispatcher_unix.cpp | 9 ++-- src/corelib/tools/qtimestamp_mac.cpp | 25 ++++++++--- src/corelib/tools/qtimestamp_unix.cpp | 62 ++++++++++++++++---------- 5 files changed, 68 insertions(+), 97 deletions(-) diff --git a/src/corelib/kernel/qcore_unix.cpp b/src/corelib/kernel/qcore_unix.cpp index 0fd965b..9146923 100644 --- a/src/corelib/kernel/qcore_unix.cpp +++ b/src/corelib/kernel/qcore_unix.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qcore_unix_p.h" +#include "qtimestamp.h" #ifndef Q_OS_VXWORKS # if !defined(Q_OS_HPUX) || defined(__ia64) @@ -56,74 +57,12 @@ #include #endif -#if !defined(QT_NO_CLOCK_MONOTONIC) -# if defined(QT_BOOTSTRAPPED) -# define QT_NO_CLOCK_MONOTONIC -# endif -#endif - QT_BEGIN_NAMESPACE -bool qt_gettime_is_monotonic() -{ -#if (_POSIX_MONOTONIC_CLOCK-0 > 0) || defined(Q_OS_MAC) - return true; -#else - static int returnValue = 0; - - if (returnValue == 0) { -# if (_POSIX_MONOTONIC_CLOCK-0 < 0) - returnValue = -1; -# elif (_POSIX_MONOTONIC_CLOCK == 0) - // detect if the system support monotonic timers - long x = sysconf(_SC_MONOTONIC_CLOCK); - returnValue = (x >= 200112L) ? 1 : -1; -# endif - } - - return returnValue != -1; -#endif -} - -timeval qt_gettime() -{ - timeval tv; -#if defined(Q_OS_MAC) - static mach_timebase_info_data_t info = {0,0}; - if (info.denom == 0) - mach_timebase_info(&info); - - uint64_t cpu_time = mach_absolute_time(); - uint64_t nsecs = cpu_time * (info.numer / info.denom); - tv.tv_sec = nsecs / 1000000000ull; - tv.tv_usec = (nsecs / 1000) - (tv.tv_sec * 1000000); - return tv; -#elif (_POSIX_MONOTONIC_CLOCK-0 > 0) - timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - tv.tv_sec = ts.tv_sec; - tv.tv_usec = ts.tv_nsec / 1000; - return tv; -#else -# if !defined(QT_NO_CLOCK_MONOTONIC) && !defined(QT_BOOTSTRAPPED) - if (qt_gettime_is_monotonic()) { - timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - tv.tv_sec = ts.tv_sec; - tv.tv_usec = ts.tv_nsec / 1000; - return tv; - } -# endif - // use gettimeofday - ::gettimeofday(&tv, 0); - return tv; -#endif -} - static inline bool time_update(struct timeval *tv, const struct timeval &start, const struct timeval &timeout) { - if (!qt_gettime_is_monotonic()) { + if (!QTimestamp::isMonotonic()) { // we cannot recalculate the timeout without a monotonic clock as the time may have changed return false; } diff --git a/src/corelib/kernel/qcore_unix_p.h b/src/corelib/kernel/qcore_unix_p.h index 297b25d..59d66f7 100644 --- a/src/corelib/kernel/qcore_unix_p.h +++ b/src/corelib/kernel/qcore_unix_p.h @@ -314,8 +314,8 @@ static inline pid_t qt_safe_waitpid(pid_t pid, int *status, int options) # define _POSIX_MONOTONIC_CLOCK -1 #endif -bool qt_gettime_is_monotonic(); -timeval qt_gettime(); +timeval qt_gettime(); // in qtimestamp_mac.cpp or qtimestamp_unix.cpp + Q_CORE_EXPORT int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept, const struct timeval *tv); diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp index a141887..7a671d1 100644 --- a/src/corelib/kernel/qeventdispatcher_unix.cpp +++ b/src/corelib/kernel/qeventdispatcher_unix.cpp @@ -45,6 +45,7 @@ #include "qpair.h" #include "qsocketnotifier.h" #include "qthread.h" +#include "qtimestamp.h" #include "qeventdispatcher_unix_p.h" #include @@ -311,12 +312,10 @@ int QEventDispatcherUNIXPrivate::doSelect(QEventLoop::ProcessEventsFlags flags, QTimerInfoList::QTimerInfoList() { - currentTime = qt_gettime(); - #if (_POSIX_MONOTONIC_CLOCK-0 <= 0) && !defined(Q_OS_MAC) - if (!qt_gettime_is_monotonic()) { + if (!QTimestamp::isMonotonic()) { // not using monotonic timers, initialize the timeChanged() machinery - previousTime = currentTime; + previousTime = qt_gettime(); tms unused; previousTicks = times(&unused); @@ -393,7 +392,7 @@ bool QTimerInfoList::timeChanged(timeval *delta) void QTimerInfoList::repairTimersIfNeeded() { - if (qt_gettime_is_monotonic()) + if (QTimestamp::isMonotonic()) return; timeval delta; if (timeChanged(&delta)) diff --git a/src/corelib/tools/qtimestamp_mac.cpp b/src/corelib/tools/qtimestamp_mac.cpp index bdc91d1..e1a7d79 100644 --- a/src/corelib/tools/qtimestamp_mac.cpp +++ b/src/corelib/tools/qtimestamp_mac.cpp @@ -53,20 +53,35 @@ bool QTimestamp::isMonotonic() } static mach_timebase_info_data_t info = {0,0}; -static qint64 absoluteToMSecs(qint64 cpuTime) +static qint64 absoluteToNSecs(qint64 cpuTime) { if (info.denom == 0) mach_timebase_info(&info); qint64 nsecs = cpuTime * info.numer / info.denom; - return nsecs / (1000*1000ull); + return nsecs; +} + +static qint64 absoluteToMSecs(qint64 cpuTime) +{ + return absoluteToNSecs(cpuTime) / 1000000; } static qint64 msecsToAbsolute(qint64 ms) { if (info.denom == 0) mach_timebase_info(&info); - qint64 nsecs = ms * 1000000ull; - return nsecs * info.denom / info.numer; + return ms * 1000000 * info.denom / info.numer; +} + +timeval qt_gettime() +{ + timeval tv; + + uint64_t cpu_time = mach_absolute_time(); + uint64_t nsecs = absoluteToNSecs(cpu_time); + tv.tv_sec = nsecs / 1000000000ull; + tv.tv_usec = (nsecs / 1000) - (tv.tv_sec * 1000000); + return tv; } void QTimestamp::start() @@ -98,7 +113,7 @@ qint64 QTimestamp::secsTo(const QTimestamp &other) const void QTimestamp::addSecs(int secs) { - t1 += secs * 1000; + t1 += msecsToAbsolute(secs * 1000); } bool operator<(const QTimestamp &v1, const QTimestamp &v2) diff --git a/src/corelib/tools/qtimestamp_unix.cpp b/src/corelib/tools/qtimestamp_unix.cpp index b82259f..dbf49c1 100644 --- a/src/corelib/tools/qtimestamp_unix.cpp +++ b/src/corelib/tools/qtimestamp_unix.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qtimestamp.h" +#include "qpair.h" #include #include #include @@ -52,6 +53,19 @@ QT_BEGIN_NAMESPACE +static qint64 fractionAdjustment() +{ + if (QTimestamp::isMonotonic()) { + // the monotonic timer is measured in nanoseconds + // 1 ms = 1000000 ns + return 1000*1000ull; + } else { + // gettimeofday is measured in microseconds + // 1 ms = 1000 us + return 1000; + } +} + bool QTimestamp::isMonotonic() { #if (_POSIX_MONOTONIC_CLOCK-0 > 0) @@ -73,44 +87,48 @@ bool QTimestamp::isMonotonic() #endif } -static qint64 fractionAdjustment() -{ - if (QTimestamp::isMonotonic()) { - // the monotonic timer is measured in nanoseconds - // 1 ms = 1000000 ns - return 1000*1000ull; - } else { - // gettimeofday is measured in microseconds - // 1 ms = 1000 us - return 1000; - } -} - -void QTimestamp::start() +static inline QPair do_gettime() { #if (_POSIX_MONOTONIC_CLOCK-0 > 0) timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - t1 = ts.tv_sec; - t2 = ts.tv_nsec; + return qMakePair(ts.tv_sec, ts.tv_nsec); #else # if !defined(QT_NO_CLOCK_MONOTONIC) && !defined(QT_BOOTSTRAPPED) - if (isMonotonic()) { + if (QTimestamp::isMonotonic()) { timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - t1 = ts.tv_sec; - t2 = ts.tv_nsec; - return; + return qMakePair(ts.tv_sec, ts.tv_nsec); } # endif // use gettimeofday timeval tv; ::gettimeofday(&tv, 0); - t1 = tv.tv_sec; - t2 = tv.tv_usec; + return qMakePair(tv.tv_sec, tv.tv_usec); #endif } +// used in qcore_unix.cpp and qeventdispatcher_unix.cpp +timeval qt_gettime() +{ + QPair r = do_gettime(); + + timeval tv; + tv.tv_sec = r.first; + tv.tv_usec = r.second; + if (QTimestamp::isMonotonic()) + tv.tv_usec /= 1000; + + return tv; +} + +void QTimestamp::start() +{ + QPair r = do_gettime(); + t1 = r.first; + t2 = r.second; +} + qint64 QTimestamp::elapsed() const { QTimestamp now; -- cgit v0.12 From 8c9446cd2058fde086df92f6b7d97e4770cf8dc6 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 18 Feb 2010 19:47:10 +0100 Subject: Add a qtimestamp.cpp with some common functions. Had to add invalidate() and isValid() functions because that's what QUnifiedTimer expects (QAbstractAnimation). Also move restart() to each implementation for efficiency. Task-number: QT-2965 --- src/corelib/tools/qtimestamp.cpp | 65 ++++++++++++++++++++++++++++++++ src/corelib/tools/qtimestamp.h | 16 ++------ src/corelib/tools/qtimestamp_generic.cpp | 8 ++++ src/corelib/tools/qtimestamp_mac.cpp | 8 ++++ src/corelib/tools/qtimestamp_unix.cpp | 13 +++++++ src/corelib/tools/qtimestamp_win.cpp | 7 ++++ src/corelib/tools/tools.pri | 1 + tests/auto/qtimestamp/tst_qtimestamp.cpp | 34 +++++++++++++++-- 8 files changed, 136 insertions(+), 16 deletions(-) create mode 100644 src/corelib/tools/qtimestamp.cpp diff --git a/src/corelib/tools/qtimestamp.cpp b/src/corelib/tools/qtimestamp.cpp new file mode 100644 index 0000000..b861099 --- /dev/null +++ b/src/corelib/tools/qtimestamp.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtimestamp.h" + +QT_BEGIN_NAMESPACE + +static const qint64 invalidData = Q_INT64_C(0x8000000000000000); + +void QTimestamp::invalidate() +{ + t1 = t2 = invalidData; +} + +bool QTimestamp::isValid() const +{ + return t1 != invalidData && t2 != invalidData; +} + +bool QTimestamp::hasExpired(qint64 timeout) const +{ + // if timeout is -1, quint64(timeout) is LLINT_MAX, so this will be + // considered as never expired + return quint64(elapsed()) > quint64(timeout); +} + +QT_END_NAMESPACE diff --git a/src/corelib/tools/qtimestamp.h b/src/corelib/tools/qtimestamp.h index f923cd4..1e913f0 100644 --- a/src/corelib/tools/qtimestamp.h +++ b/src/corelib/tools/qtimestamp.h @@ -56,20 +56,12 @@ public: static bool isMonotonic(); void start(); - qint64 restart() - { - qint64 r = elapsed(); - start(); - return r; - } + qint64 restart(); + void invalidate(); + bool isValid() const; qint64 elapsed() const; - bool hasExpired(qint64 timeout) const - { - // if timeout is -1, quint64(timeout) is LLINT_MAX, so this will be - // considered as never expired - return quint64(elapsed()) > quint64(timeout); - } + bool hasExpired(qint64 timeout) const; qint64 msecsTo(const QTimestamp &other) const; void addMSecs(int ms); diff --git a/src/corelib/tools/qtimestamp_generic.cpp b/src/corelib/tools/qtimestamp_generic.cpp index 18c5026..9930932 100644 --- a/src/corelib/tools/qtimestamp_generic.cpp +++ b/src/corelib/tools/qtimestamp_generic.cpp @@ -56,6 +56,14 @@ void QTimestamp::start() t2 = 0; } +qint64 QTimestamp::restart() +{ + QTime t = QTime::currentTime(); + qint64 old = t1; + t1 = t.mds; + return t1 - old; +} + qint64 QTimestamp::elapsed() const { QTime t = QTime::currentTime(); diff --git a/src/corelib/tools/qtimestamp_mac.cpp b/src/corelib/tools/qtimestamp_mac.cpp index e1a7d79..a80e7ee 100644 --- a/src/corelib/tools/qtimestamp_mac.cpp +++ b/src/corelib/tools/qtimestamp_mac.cpp @@ -90,6 +90,14 @@ void QTimestamp::start() t2 = 0; } +qint64 QTimestamp::restart() +{ + qint64 old = t1; + t1 = mach_absolute_time(); + + return absoluteToMSecs(t1 - old); +} + qint64 QTimestamp::elapsed() const { uint64_t cpu_time = mach_absolute_time(); diff --git a/src/corelib/tools/qtimestamp_unix.cpp b/src/corelib/tools/qtimestamp_unix.cpp index dbf49c1..75371e7 100644 --- a/src/corelib/tools/qtimestamp_unix.cpp +++ b/src/corelib/tools/qtimestamp_unix.cpp @@ -129,6 +129,19 @@ void QTimestamp::start() t2 = r.second; } +qint64 QTimestamp::restart() +{ + QPair r = do_gettime(); + qint64 oldt1 = t1; + qint64 oldt2 = t2; + t1 = r.first; + t2 = r.second; + + r.first -= oldt1; + r.second -= oldt2; + return r.first * 1000 + r.second / fractionAdjustment(); +} + qint64 QTimestamp::elapsed() const { QTimestamp now; diff --git a/src/corelib/tools/qtimestamp_win.cpp b/src/corelib/tools/qtimestamp_win.cpp index 99faebd..72d38d0 100644 --- a/src/corelib/tools/qtimestamp_win.cpp +++ b/src/corelib/tools/qtimestamp_win.cpp @@ -87,6 +87,13 @@ void QTimestamp::start() t2 = 0; } +qint64 QTimestamp::restart() +{ + qint64 oldt1 = t1; + t1 = getTickCount(); + return t1 - oldt1; +} + qint64 QTimestamp::elapsed() const { return getTickCount() - t1; diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index 863f86e..e1097c4 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -77,6 +77,7 @@ SOURCES += \ tools/qstringlist.cpp \ tools/qtextboundaryfinder.cpp \ tools/qtimeline.cpp \ + tools/qtimestamp.cpp \ tools/qvector.cpp \ tools/qvsnprintf.cpp diff --git a/tests/auto/qtimestamp/tst_qtimestamp.cpp b/tests/auto/qtimestamp/tst_qtimestamp.cpp index 5a0b230..ab1e959 100644 --- a/tests/auto/qtimestamp/tst_qtimestamp.cpp +++ b/tests/auto/qtimestamp/tst_qtimestamp.cpp @@ -3,15 +3,32 @@ #include #include +static const int minResolution = 50; // the minimum resolution for the tests + class tst_QTimestamp : public QObject { Q_OBJECT private Q_SLOTS: + void validity(); void basics(); void elapsed(); }; +void tst_QTimestamp::validity() +{ + QTimestamp t; + + t.invalidate(); + QVERIFY(!t.isValid()); + + t.start(); + QVERIFY(t.isValid()); + + t.invalidate(); + QVERIFY(!t.isValid()); +} + void tst_QTimestamp::basics() { QTimestamp t1; @@ -36,6 +53,9 @@ void tst_QTimestamp::basics() QCOMPARE(t1.secsTo(t2), qint64(1)); QCOMPARE(t2 - t1, qint64(1000)); QCOMPARE(t1 - t2, qint64(-1000)); + + qint64 elapsed = t1.restart(); + QVERIFY(elapsed < minResolution); } void tst_QTimestamp::elapsed() @@ -43,7 +63,7 @@ void tst_QTimestamp::elapsed() QTimestamp t1; t1.start(); - QTest::qWait(100); + QTest::qWait(4*minResolution); QTimestamp t2; t2.start(); @@ -55,12 +75,18 @@ void tst_QTimestamp::elapsed() QVERIFY(t1 - t2 < 0); QVERIFY(t1.elapsed() > 0); - QVERIFY(t1.hasExpired(50)); - QVERIFY(!t1.hasExpired(500)); - QVERIFY(!t2.hasExpired(0)); + QVERIFY(t1.hasExpired(minResolution)); + QVERIFY(!t1.hasExpired(8*minResolution)); + QVERIFY(!t2.hasExpired(minResolution)); QVERIFY(!t1.hasExpired(-1)); QVERIFY(!t2.hasExpired(-1)); + + qint64 elapsed = t1.restart(); + QVERIFY(elapsed > 3*minResolution); + QVERIFY(elapsed < 5*minResolution); + qint64 diff = t1 - t2; + QVERIFY(diff < minResolution); } QTEST_MAIN(tst_QTimestamp); -- cgit v0.12 From cd33d38ce0067719b0215264a22685a91b2e08dc Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 18 Feb 2010 18:27:45 +0100 Subject: Port QtCore uses of QTime as a stopwatch to QTimestamp. tst_qtimeline improvement: from 56187446 to 53915928 (callgrind) --- src/corelib/animation/qabstractanimation.cpp | 1 + src/corelib/animation/qabstractanimation_p.h | 57 +--------------------------- src/corelib/io/qprocess.cpp | 6 +-- src/corelib/io/qprocess_unix.cpp | 8 ++-- src/corelib/kernel/qcoreapplication.cpp | 4 +- src/corelib/tools/qtimeline.cpp | 4 +- 6 files changed, 14 insertions(+), 66 deletions(-) diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index f834a80..82b3003 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -170,6 +170,7 @@ QUnifiedTimer::QUnifiedTimer() : currentAnimationIdx(0), consistentTiming(false), slowMode(false), isPauseTimerActive(false), runningLeafAnimations(0) { + time.invalidate(); } QUnifiedTimer *QUnifiedTimer::instance() diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h index 8bc3224..3eb4948 100644 --- a/src/corelib/animation/qabstractanimation_p.h +++ b/src/corelib/animation/qabstractanimation_p.h @@ -56,6 +56,7 @@ #include #include #include +#include #include #ifdef Q_OS_WIN @@ -113,61 +114,7 @@ private: Q_DECLARE_PUBLIC(QAbstractAnimation) }; -class ElapsedTimer -{ -public: - ElapsedTimer() { - invalidate(); - } - - void invalidate() { - m_started = -1; - } - - bool isValid() const { - return m_started >= 0; - } - - void start() { - m_started = getTickCount_sys(); - } - - qint64 elapsed() const { - qint64 current = getTickCount_sys(); - qint64 delta = current - m_started; - if (delta < 0) - delta += getPeriod_sys(); //we wrapped around - return delta; - } - -private: - enum { - MSECS_PER_HOUR = 3600000, - MSECS_PER_MIN = 60000 - }; - - qint64 m_started; - - quint64 getPeriod_sys() const { -#ifdef Q_OS_WIN - return Q_UINT64_C(0x100000000); -#else - // fallback - return 86400 * 1000; -#endif - } - - qint64 getTickCount_sys() const { -#ifdef Q_OS_WIN - return ::GetTickCount(); -#else - // fallback - const QTime t = QTime::currentTime(); - return MSECS_PER_HOUR * t.hour() + MSECS_PER_MIN * t.minute() + 1000 * t.second() + t.msec(); -#endif - } -}; - +typedef QTimestamp ElapsedTimer; class QUnifiedTimer : public QObject { diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 12a992a..6250094 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -88,7 +88,7 @@ QT_END_NAMESPACE #include "qprocess_p.h" #include -#include +#include #include #include #include @@ -1639,7 +1639,7 @@ bool QProcess::waitForBytesWritten(int msecs) if (d->processState == QProcess::NotRunning) return false; if (d->processState == QProcess::Starting) { - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); bool started = waitForStarted(msecs); if (!started) @@ -1676,7 +1676,7 @@ bool QProcess::waitForFinished(int msecs) if (d->processState == QProcess::NotRunning) return false; if (d->processState == QProcess::Starting) { - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); bool started = waitForStarted(msecs); if (!started) diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 5119ec0..511154a 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -92,7 +92,6 @@ QT_END_NAMESPACE #include #include -#include #include #include #include @@ -101,6 +100,7 @@ QT_END_NAMESPACE #include #include #include +#include #include #include @@ -933,7 +933,7 @@ bool QProcessPrivate::waitForReadyRead(int msecs) qDebug("QProcessPrivate::waitForReadyRead(%d)", msecs); #endif - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); forever { @@ -1005,7 +1005,7 @@ bool QProcessPrivate::waitForBytesWritten(int msecs) qDebug("QProcessPrivate::waitForBytesWritten(%d)", msecs); #endif - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); while (!writeBuffer.isEmpty()) { @@ -1072,7 +1072,7 @@ bool QProcessPrivate::waitForFinished(int msecs) qDebug("QProcessPrivate::waitForFinished(%d)", msecs); #endif - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); forever { diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 2da5a7d..3d6364b 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -47,7 +47,6 @@ #include "qeventloop.h" #include "qcorecmdlineargs_p.h" #include -#include #include #include #include @@ -59,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -917,7 +917,7 @@ void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags, int m QThreadData *data = QThreadData::current(); if (!data->eventDispatcher) return; - QTime start; + QTimestamp start; start.start(); if (flags & QEventLoop::DeferredDeletion) QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); diff --git a/src/corelib/tools/qtimeline.cpp b/src/corelib/tools/qtimeline.cpp index 877a77a..57977bc 100644 --- a/src/corelib/tools/qtimeline.cpp +++ b/src/corelib/tools/qtimeline.cpp @@ -42,9 +42,9 @@ #include "qtimeline.h" #include -#include #include #include +#include QT_BEGIN_NAMESPACE @@ -70,7 +70,7 @@ public: int currentTime; int timerId; - QTime timer; + QTimestamp timer; QTimeLine::Direction direction; QEasingCurve easingCurve; -- cgit v0.12 From ec5b7ea367389234697a98d7243243ec689be724 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 18 Feb 2010 19:48:41 +0100 Subject: Port QtNetwork uses of QTime as a stopwatch to QTimestamp. --- src/network/socket/qabstractsocket.cpp | 10 +++++----- src/network/socket/qhttpsocketengine.cpp | 6 +++--- src/network/socket/qlocalsocket_unix.cpp | 4 ++-- src/network/socket/qnativesocketengine_unix.cpp | 4 ++-- src/network/socket/qsocks5socketengine.cpp | 18 +++++++++--------- src/network/ssl/qsslsocket.cpp | 10 +++++----- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index 95721ee..fc50ee5 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -365,12 +365,12 @@ #include "private/qhostinfo_p.h" #include -#include #include #include #include #include #include +#include #ifndef QT_NO_OPENSSL #include @@ -1738,7 +1738,7 @@ bool QAbstractSocket::waitForConnected(int msecs) bool wasPendingClose = d->pendingClose; d->pendingClose = false; - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); if (d->state == HostLookupState) { @@ -1819,7 +1819,7 @@ bool QAbstractSocket::waitForReadyRead(int msecs) return false; } - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); // handle a socket in connecting state @@ -1878,7 +1878,7 @@ bool QAbstractSocket::waitForBytesWritten(int msecs) if (d->writeBuffer.isEmpty()) return false; - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); // handle a socket in connecting state @@ -1960,7 +1960,7 @@ bool QAbstractSocket::waitForDisconnected(int msecs) return false; } - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); // handle a socket in connecting state diff --git a/src/network/socket/qhttpsocketengine.cpp b/src/network/socket/qhttpsocketengine.cpp index 3293ff5..9d412ac 100644 --- a/src/network/socket/qhttpsocketengine.cpp +++ b/src/network/socket/qhttpsocketengine.cpp @@ -42,9 +42,9 @@ #include "qhttpsocketengine_p.h" #include "qtcpsocket.h" #include "qhostaddress.h" -#include "qdatetime.h" #include "qurl.h" #include "qhttp.h" +#include "qtimestamp.h" #if !defined(QT_NO_NETWORKPROXY) && !defined(QT_NO_HTTP) #include @@ -319,7 +319,7 @@ bool QHttpSocketEngine::waitForRead(int msecs, bool *timedOut) if (!d->socket || d->socket->state() == QAbstractSocket::UnconnectedState) return false; - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); // Wait for more data if nothing is available. @@ -366,7 +366,7 @@ bool QHttpSocketEngine::waitForWrite(int msecs, bool *timedOut) return true; } - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); // If we're not connected yet, wait until we are, and until bytes have diff --git a/src/network/socket/qlocalsocket_unix.cpp b/src/network/socket/qlocalsocket_unix.cpp index 1ca11d8..20301ba 100644 --- a/src/network/socket/qlocalsocket_unix.cpp +++ b/src/network/socket/qlocalsocket_unix.cpp @@ -52,9 +52,9 @@ #include #include -#include #include #include +#include #ifdef Q_OS_VXWORKS # include @@ -534,7 +534,7 @@ bool QLocalSocket::waitForConnected(int msec) int result = -1; // on Linux timeout will be updated by select, but _not_ on other systems. - QTime timer; + QTimestamp timer; timer.start(); while (state() == ConnectingState && (-1 == msec || timer.elapsed() < msec)) { diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp index 9a2c349..7c1fc17 100644 --- a/src/network/socket/qnativesocketengine_unix.cpp +++ b/src/network/socket/qnativesocketengine_unix.cpp @@ -44,8 +44,8 @@ #include "private/qnet_unix_p.h" #include "qiodevice.h" #include "qhostaddress.h" +#include "qtimestamp.h" #include "qvarlengtharray.h" -#include "qdatetime.h" #include #include #include @@ -1003,7 +1003,7 @@ int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool checkRead, bool c #ifndef Q_OS_SYMBIAN ret = qt_safe_select(socketDescriptor + 1, &fdread, &fdwrite, 0, timeout < 0 ? 0 : &tv); #else - QTime timer; + QTimestamp timer; timer.start(); do { diff --git a/src/network/socket/qsocks5socketengine.cpp b/src/network/socket/qsocks5socketengine.cpp index 924530e..0c6a01a 100644 --- a/src/network/socket/qsocks5socketengine.cpp +++ b/src/network/socket/qsocks5socketengine.cpp @@ -49,7 +49,7 @@ #include "qdebug.h" #include "qhash.h" #include "qqueue.h" -#include "qdatetime.h" +#include "qtimestamp.h" #include "qmutex.h" #include "qthread.h" #include "qcoreapplication.h" @@ -308,7 +308,7 @@ struct QSocks5BindData : public QSocks5Data quint16 localPort; QHostAddress peerAddress; quint16 peerPort; - QDateTime timeStamp; + QTimestamp timeStamp; }; struct QSocks5RevivedDatagram @@ -369,7 +369,7 @@ void QSocks5BindStore::add(int socketDescriptor, QSocks5BindData *bindData) if (store.contains(socketDescriptor)) { // qDebug() << "delete it"; } - bindData->timeStamp = QDateTime::currentDateTime(); + bindData->timeStamp.start(); store.insert(socketDescriptor, bindData); // start sweep timer if not started if (sweepTimerId == -1) @@ -412,7 +412,7 @@ void QSocks5BindStore::timerEvent(QTimerEvent * event) QMutableHashIterator it(store); while (it.hasNext()) { it.next(); - if (it.value()->timeStamp.secsTo(QDateTime::currentDateTime()) > 350) { + if (it.value()->timeStamp.hasExpired(350000)) { QSOCKS5_DEBUG << "QSocks5BindStore removing JJJJ"; it.remove(); } @@ -1355,7 +1355,7 @@ bool QSocks5SocketEngine::bind(const QHostAddress &address, quint16 port) } int msecs = SOCKS5_BLOCKING_BIND_TIMEOUT; - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); d->data->controlSocket->connectToHost(d->proxyInfo.hostName(), d->proxyInfo.port()); if (!d->waitForConnected(msecs, 0) || @@ -1455,7 +1455,7 @@ void QSocks5SocketEngine::close() if (d->data && d->data->controlSocket) { if (d->data->controlSocket->state() == QAbstractSocket::ConnectedState) { int msecs = 100; - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); while (!d->data->controlSocket->bytesToWrite()) { if (!d->data->controlSocket->waitForBytesWritten(qt_timeout_value(msecs, stopWatch.elapsed()))) @@ -1674,7 +1674,7 @@ bool QSocks5SocketEnginePrivate::waitForConnected(int msecs, bool *timedOut) mode == BindMode ? BindSuccess : UdpAssociateSuccess; - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); while (socks5State != wantedState) { @@ -1699,7 +1699,7 @@ bool QSocks5SocketEngine::waitForRead(int msecs, bool *timedOut) d->readNotificationActivated = false; - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); // are we connected yet? @@ -1749,7 +1749,7 @@ bool QSocks5SocketEngine::waitForWrite(int msecs, bool *timedOut) Q_D(QSocks5SocketEngine); QSOCKS5_DEBUG << "waitForWrite" << msecs; - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); // are we connected yet? diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp index 9623570..895e32c 100644 --- a/src/network/ssl/qsslsocket.cpp +++ b/src/network/ssl/qsslsocket.cpp @@ -286,8 +286,8 @@ #include #include -#include #include +#include #include #include @@ -1393,7 +1393,7 @@ bool QSslSocket::waitForEncrypted(int msecs) if (d->mode == UnencryptedMode && !d->autoStartHandshake) return false; - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); if (d->plainSocket->state() != QAbstractSocket::ConnectedState) { @@ -1433,7 +1433,7 @@ bool QSslSocket::waitForReadyRead(int msecs) bool *previousReadyReadEmittedPointer = d->readyReadEmittedPointer; d->readyReadEmittedPointer = &readyReadEmitted; - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); if (!d->connectionEncrypted) { @@ -1470,7 +1470,7 @@ bool QSslSocket::waitForBytesWritten(int msecs) if (d->mode == UnencryptedMode) return d->plainSocket->waitForBytesWritten(msecs); - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); if (!d->connectionEncrypted) { @@ -1508,7 +1508,7 @@ bool QSslSocket::waitForDisconnected(int msecs) if (d->mode == UnencryptedMode) return d->plainSocket->waitForDisconnected(msecs); - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); if (!d->connectionEncrypted) { -- cgit v0.12 From 0f771c62f5253a969f5a8a81bfd9254b9bd58b8f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 18 Feb 2010 20:00:36 +0100 Subject: Port QtGui uses of QTime as a stopwatch to QTimestamp --- src/gui/dialogs/qfileinfogatherer.cpp | 8 +++++--- src/gui/dialogs/qfileinfogatherer_p.h | 5 +++-- src/gui/dialogs/qprogressdialog.cpp | 4 ++-- src/gui/itemviews/qabstractitemview.cpp | 3 ++- src/gui/itemviews/qabstractitemview_p.h | 4 ++-- src/gui/itemviews/qtreeview.cpp | 3 ++- src/gui/kernel/qclipboard_x11.cpp | 15 ++++++--------- src/gui/kernel/qdnd_x11.cpp | 12 ++++-------- src/gui/kernel/qgesture_p.h | 4 ++-- src/gui/kernel/qstandardgestures.cpp | 7 +++---- src/gui/kernel/qwidget_x11.cpp | 4 ++-- src/gui/kernel/qx11embed_x11.cpp | 4 ++-- src/gui/styles/qplastiquestyle.cpp | 4 ++-- src/gui/styles/qwindowsstyle_p.h | 4 ++-- src/gui/text/qfontdatabase_x11.cpp | 8 ++++---- src/gui/widgets/qabstractslider.cpp | 10 +++++----- src/gui/widgets/qabstractslider_p.h | 3 ++- src/gui/widgets/qeffects.cpp | 6 +++--- src/gui/widgets/qscrollbar.cpp | 4 ++-- src/gui/widgets/qworkspace.cpp | 10 +++++----- 20 files changed, 60 insertions(+), 62 deletions(-) diff --git a/src/gui/dialogs/qfileinfogatherer.cpp b/src/gui/dialogs/qfileinfogatherer.cpp index 3b08bf6..a565c45 100644 --- a/src/gui/dialogs/qfileinfogatherer.cpp +++ b/src/gui/dialogs/qfileinfogatherer.cpp @@ -297,7 +297,8 @@ void QFileInfoGatherer::getFileInfos(const QString &path, const QStringList &fil return; } - QTime base = QTime::currentTime(); + QTimestamp base; + base.start(); QFileInfo fileInfo; bool firstTime = true; QList > updatedFiles; @@ -326,9 +327,10 @@ void QFileInfoGatherer::getFileInfos(const QString &path, const QStringList &fil emit directoryLoaded(path); } -void QFileInfoGatherer::fetch(const QFileInfo &fileInfo, QTime &base, bool &firstTime, QList > &updatedFiles, const QString &path) { +void QFileInfoGatherer::fetch(const QFileInfo &fileInfo, QTimestamp &base, bool &firstTime, QList > &updatedFiles, const QString &path) { updatedFiles.append(QPair(fileInfo.fileName(), fileInfo)); - QTime current = QTime::currentTime(); + QTimestamp current; + current.start(); if ((firstTime && updatedFiles.count() > 100) || base.msecsTo(current) > 1000) { emit updates(path, updatedFiles); updatedFiles.clear(); diff --git a/src/gui/dialogs/qfileinfogatherer_p.h b/src/gui/dialogs/qfileinfogatherer_p.h index eff6b3c..a2b9acd 100644 --- a/src/gui/dialogs/qfileinfogatherer_p.h +++ b/src/gui/dialogs/qfileinfogatherer_p.h @@ -60,9 +60,10 @@ #include #include #include -#include #include +#include #include +#include QT_BEGIN_NAMESPACE @@ -174,7 +175,7 @@ protected: void getFileInfos(const QString &path, const QStringList &files); private: - void fetch(const QFileInfo &info, QTime &base, bool &firstTime, QList > &updatedFiles, const QString &path); + void fetch(const QFileInfo &info, QTimestamp &base, bool &firstTime, QList > &updatedFiles, const QString &path); QString translateDriveName(const QFileInfo &drive) const; QMutex mutex; diff --git a/src/gui/dialogs/qprogressdialog.cpp b/src/gui/dialogs/qprogressdialog.cpp index 4fffdba..602f47c 100644 --- a/src/gui/dialogs/qprogressdialog.cpp +++ b/src/gui/dialogs/qprogressdialog.cpp @@ -46,7 +46,6 @@ #include "qshortcut.h" #include "qpainter.h" #include "qdrawutil.h" -#include "qdatetime.h" #include "qlabel.h" #include "qprogressbar.h" #include "qapplication.h" @@ -54,6 +53,7 @@ #include "qpushbutton.h" #include "qcursor.h" #include "qtimer.h" +#include "qtimestamp.h" #include #include @@ -103,7 +103,7 @@ public: QTimer *forceTimer; bool shown_once; bool cancellation_flag; - QTime starttime; + QTimestamp starttime; #ifndef QT_NO_CURSOR QCursor parentCursor; #endif diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index dd9a7e6..34b5e13 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -2839,7 +2839,8 @@ void QAbstractItemView::keyboardSearch(const QString &search) QModelIndex start = currentIndex().isValid() ? currentIndex() : d->model->index(0, 0, d->root); - QTime now(QTime::currentTime()); + QTimestamp now; + now.start(); bool skipRow = false; if (search.isEmpty() || (d->keyboardInputTime.msecsTo(now) > QApplication::keyboardInputInterval())) { diff --git a/src/gui/itemviews/qabstractitemview_p.h b/src/gui/itemviews/qabstractitemview_p.h index 82fd1a6..4af98b4 100644 --- a/src/gui/itemviews/qabstractitemview_p.h +++ b/src/gui/itemviews/qabstractitemview_p.h @@ -56,7 +56,6 @@ #include "private/qabstractscrollarea_p.h" #include "private/qabstractitemmodel_p.h" #include "QtGui/qapplication.h" -#include "QtCore/qdatetime.h" #include "QtGui/qevent.h" #include "QtGui/qmime.h" #include "QtGui/qpainter.h" @@ -65,6 +64,7 @@ #include "QtCore/qdebug.h" #include "QtGui/qpainter.h" #include "QtCore/qbasictimer.h" +#include "QtCore/qtimestamp.h" #ifndef QT_NO_ITEMVIEWS @@ -390,7 +390,7 @@ public: #endif QString keyboardInput; - QTime keyboardInputTime; + QTimestamp keyboardInputTime; bool autoScroll; QBasicTimer autoScrollTimer; diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index 4135ba0..9f8c322 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -958,7 +958,8 @@ void QTreeView::keyboardSearch(const QString &search) else start = d->model->index(0, 0, d->root); - QTime now(QTime::currentTime()); + QTimestamp now; + now.start(); bool skipRow = false; if (search.isEmpty() || (d->keyboardInputTime.msecsTo(now) > QApplication::keyboardInputInterval())) { diff --git a/src/gui/kernel/qclipboard_x11.cpp b/src/gui/kernel/qclipboard_x11.cpp index 047bd09..2a9706b 100644 --- a/src/gui/kernel/qclipboard_x11.cpp +++ b/src/gui/kernel/qclipboard_x11.cpp @@ -65,7 +65,6 @@ #include "qapplication.h" #include "qdesktopwidget.h" #include "qbitmap.h" -#include "qdatetime.h" #include "qiodevice.h" #include "qbuffer.h" #include "qtextcodec.h" @@ -76,6 +75,7 @@ #include "qt_x11_p.h" #include "qx11info_x11.h" #include "qimagewriter.h" +#include "qtimestamp.h" #include "qvariant.h" #include "qdnd_p.h" #include @@ -516,8 +516,9 @@ static Bool checkForClipboardEvents(Display *, XEvent *e, XPointer) bool QX11Data::clipboardWaitForEvent(Window win, int type, XEvent *event, int timeout) { - QTime started = QTime::currentTime(); - QTime now = started; + QTimestamp started; + started.start(); + QTimestamp now = started; if (QAbstractEventDispatcher::instance()->inherits("QtMotif") || QApplication::clipboard()->property("useEventLoopWhenWaiting").toBool()) { @@ -545,9 +546,7 @@ bool QX11Data::clipboardWaitForEvent(Window win, int type, XEvent *event, int ti XSync(X11->display, false); usleep(50000); - now = QTime::currentTime(); - if (started > now) // crossed midnight - started = now; + now.start(); QEventLoop::ProcessEventsFlags flags(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers @@ -576,9 +575,7 @@ bool QX11Data::clipboardWaitForEvent(Window win, int type, XEvent *event, int ti if (XCheckIfEvent(X11->display, &e, checkForClipboardEvents, 0)) qApp->x11ProcessEvent(&e); - now = QTime::currentTime(); - if ( started > now ) // crossed midnight - started = now; + now.start(); XFlush(X11->display); diff --git a/src/gui/kernel/qdnd_x11.cpp b/src/gui/kernel/qdnd_x11.cpp index 9591b9a..0d24ed7 100644 --- a/src/gui/kernel/qdnd_x11.cpp +++ b/src/gui/kernel/qdnd_x11.cpp @@ -51,10 +51,10 @@ #include "qbitmap.h" #include "qdesktopwidget.h" #include "qevent.h" -#include "qdatetime.h" #include "qiodevice.h" #include "qpointer.h" #include "qcursor.h" +#include "qtimestamp.h" #include "qvariant.h" #include "qvector.h" #include "qurl.h" @@ -1911,23 +1911,19 @@ Qt::DropAction QDragManager::drag(QDrag * o) // then we could still have problems, but this is highly unlikely QApplication::flush(); - QTime started = QTime::currentTime(); - QTime now = started; + QTimestamp timer; + timer.start(); do { XEvent event; if (XCheckTypedEvent(X11->display, ClientMessage, &event)) qApp->x11ProcessEvent(&event); - now = QTime::currentTime(); - if (started > now) // crossed midnight - started = now; - // sleep 50 ms, so we don't use up CPU cycles all the time. struct timeval usleep_tv; usleep_tv.tv_sec = 0; usleep_tv.tv_usec = 50000; select(0, 0, 0, 0, &usleep_tv); - } while (object && started.msecsTo(now) < 1000); + } while (object && timer.hasExpired(1000)); } object = o; diff --git a/src/gui/kernel/qgesture_p.h b/src/gui/kernel/qgesture_p.h index 649a310..84d8b7c 100644 --- a/src/gui/kernel/qgesture_p.h +++ b/src/gui/kernel/qgesture_p.h @@ -55,8 +55,8 @@ #include "qrect.h" #include "qpoint.h" -#include "qdatetime.h" #include "qgesture.h" +#include "qtimestamp.h" #include "private/qobject_p.h" QT_BEGIN_NAMESPACE @@ -148,7 +148,7 @@ public: QPoint lastPositions[3]; bool started; qreal speed; - QTime time; + QTimestamp time; }; class QTapGesturePrivate : public QGesturePrivate diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp index 86bf1b2e..a575717 100644 --- a/src/gui/kernel/qstandardgestures.cpp +++ b/src/gui/kernel/qstandardgestures.cpp @@ -301,7 +301,7 @@ QGestureRecognizer::Result QSwipeGestureRecognizer::recognize(QGesture *state, switch (event->type()) { case QEvent::TouchBegin: { d->speed = 1; - d->time = QTime::currentTime(); + d->time.start(); d->started = true; result = QGestureRecognizer::MayBeGesture; break; @@ -338,11 +338,10 @@ QGestureRecognizer::Result QSwipeGestureRecognizer::recognize(QGesture *state, p3.screenPos().y() - d->lastPositions[2].y()) / 3; const int distance = xDistance >= yDistance ? xDistance : yDistance; - int elapsedTime = d->time.msecsTo(QTime::currentTime()); + int elapsedTime = d->time.restart(); if (!elapsedTime) elapsedTime = 1; d->speed = 0.9 * d->speed + distance / elapsedTime; - d->time = QTime::currentTime(); d->swipeAngle = QLineF(p1.startScreenPos(), p1.screenPos()).angle(); static const int MoveThreshold = 50; @@ -405,7 +404,7 @@ void QSwipeGestureRecognizer::reset(QGesture *state) d->lastPositions[0] = d->lastPositions[1] = d->lastPositions[2] = QPoint(); d->started = false; d->speed = 0; - d->time = QTime(); + d->time.invalidate(); QGestureRecognizer::reset(state); } diff --git a/src/gui/kernel/qwidget_x11.cpp b/src/gui/kernel/qwidget_x11.cpp index 10fb009..3fbb9ce 100644 --- a/src/gui/kernel/qwidget_x11.cpp +++ b/src/gui/kernel/qwidget_x11.cpp @@ -49,7 +49,7 @@ #include "qbitmap.h" #include "qlayout.h" #include "qtextcodec.h" -#include "qdatetime.h" +#include "qtimestamp.h" #include "qcursor.h" #include "qstack.h" #include "qcolormap.h" @@ -352,7 +352,7 @@ Q_GUI_EXPORT void qt_x11_wait_for_window_manager(QWidget* w) return; QApplication::flush(); XEvent ev; - QTime t; + QTimestamp t; t.start(); static const int maximumWaitTime = 2000; if (!w->testAttribute(Qt::WA_WState_Created)) diff --git a/src/gui/kernel/qx11embed_x11.cpp b/src/gui/kernel/qx11embed_x11.cpp index 35850db..b92a5b1 100644 --- a/src/gui/kernel/qx11embed_x11.cpp +++ b/src/gui/kernel/qx11embed_x11.cpp @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include #include #include @@ -1231,7 +1231,7 @@ void QX11EmbedContainer::embedClient(WId id) For safety, we will not wait more than 500 ms, so that we can preemptively workaround buggy window managers. */ - QTime t; + QTimestamp t; t.start(); functorData data; diff --git a/src/gui/styles/qplastiquestyle.cpp b/src/gui/styles/qplastiquestyle.cpp index 9f69fd8..9f4d48e 100644 --- a/src/gui/styles/qplastiquestyle.cpp +++ b/src/gui/styles/qplastiquestyle.cpp @@ -56,7 +56,6 @@ static const int blueFrameWidth = 2; // with of line edit focus frame #include #include #include -#include #include #include #include @@ -81,6 +80,7 @@ static const int blueFrameWidth = 2; // with of line edit focus frame #include #include #include +#include #include #include #include @@ -980,7 +980,7 @@ public: #ifndef QT_NO_PROGRESSBAR QList bars; int progressBarAnimateTimer; - QTime timer; + QTimestamp timer; #endif }; diff --git a/src/gui/styles/qwindowsstyle_p.h b/src/gui/styles/qwindowsstyle_p.h index 808abe1..92060d8 100644 --- a/src/gui/styles/qwindowsstyle_p.h +++ b/src/gui/styles/qwindowsstyle_p.h @@ -58,8 +58,8 @@ #ifndef QT_NO_STYLE_WINDOWS #include -#include #include +#include QT_BEGIN_NAMESPACE @@ -80,7 +80,7 @@ public: QList bars; int animationFps; int animateTimer; - QTime startTime; + QTimestamp startTime; int animateStep; QColor inactiveCaptionText; QColor activeCaptionColor; diff --git a/src/gui/text/qfontdatabase_x11.cpp b/src/gui/text/qfontdatabase_x11.cpp index bb1e60d..fd3cba8 100644 --- a/src/gui/text/qfontdatabase_x11.cpp +++ b/src/gui/text/qfontdatabase_x11.cpp @@ -41,9 +41,9 @@ #include -#include #include #include +#include #include #include "qx11info_x11.h" @@ -1218,7 +1218,7 @@ static void load(const QString &family = QString(), int script = -1, bool forceX } #ifdef QFONTDATABASE_DEBUG - QTime t; + QTimestamp t; t.start(); #endif @@ -1301,7 +1301,7 @@ static void initializeDb() if (!db || db->count) return; - QTime t; + QTimestamp t; t.start(); #ifndef QT_NO_FONTCONFIG @@ -1314,7 +1314,7 @@ static void initializeDb() } loadFontConfig(); - FD_DEBUG("QFontDatabase: loaded FontConfig: %d ms", t.elapsed()); + FD_DEBUG("QFontDatabase: loaded FontConfig: %d ms", int(t.elapsed())); #endif t.start(); diff --git a/src/gui/widgets/qabstractslider.cpp b/src/gui/widgets/qabstractslider.cpp index 522d472..8f53116 100644 --- a/src/gui/widgets/qabstractslider.cpp +++ b/src/gui/widgets/qabstractslider.cpp @@ -764,12 +764,12 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) SliderAction action = SliderNoAction; #ifdef QT_KEYPAD_NAVIGATION if (ev->isAutoRepeat()) { - if (d->firstRepeat.isNull()) - d->firstRepeat = QTime::currentTime(); + if (!d->firstRepeat.isValid()) + d->firstRepeat.start(); else if (1 == d->repeatMultiplier) { // This is the interval in milli seconds which one key repetition // takes. - const int repeatMSecs = d->firstRepeat.msecsTo(QTime::currentTime()); + const int repeatMSecs = d->firstRepeat.elapsed(); /** * The time it takes to currently navigate the whole slider. @@ -787,8 +787,8 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) } } - else if (!d->firstRepeat.isNull()) { - d->firstRepeat = QTime(); + else if (!d->firstRepeat.isValid()) { + d->firstRepeat.invalidate() d->repeatMultiplier = 1; } diff --git a/src/gui/widgets/qabstractslider_p.h b/src/gui/widgets/qabstractslider_p.h index 6e6ff6e..c8c29b5 100644 --- a/src/gui/widgets/qabstractslider_p.h +++ b/src/gui/widgets/qabstractslider_p.h @@ -54,6 +54,7 @@ // #include "QtCore/qbasictimer.h" +#include "QtCore/qtimestamp.h" #include "private/qwidget_p.h" #include "qstyle.h" @@ -103,7 +104,7 @@ public: /** * The time of when the first auto repeating key press event occurs. */ - QTime firstRepeat; + QTimestamp firstRepeat; #endif diff --git a/src/gui/widgets/qeffects.cpp b/src/gui/widgets/qeffects.cpp index dd7fc48..9dd853f 100644 --- a/src/gui/widgets/qeffects.cpp +++ b/src/gui/widgets/qeffects.cpp @@ -41,7 +41,6 @@ #include "qapplication.h" #ifndef QT_NO_EFFECTS -#include "qdatetime.h" #include "qdesktopwidget.h" #include "qeffects_p.h" #include "qevent.h" @@ -50,6 +49,7 @@ #include "qpixmap.h" #include "qpointer.h" #include "qtimer.h" +#include "qtimestamp.h" #include "qdebug.h" QT_BEGIN_NAMESPACE @@ -103,7 +103,7 @@ private: int elapsed; bool showWidget; QTimer anim; - QTime checkTime; + QTimestamp checkTime; double windowOpacity; }; @@ -384,7 +384,7 @@ private: int orientation; QTimer anim; - QTime checkTime; + QTimestamp checkTime; QPixmap pm; }; diff --git a/src/gui/widgets/qscrollbar.cpp b/src/gui/widgets/qscrollbar.cpp index c0eeb2f..894300d 100644 --- a/src/gui/widgets/qscrollbar.cpp +++ b/src/gui/widgets/qscrollbar.cpp @@ -47,7 +47,7 @@ #include "qstyle.h" #include "qstyleoption.h" #include "qmenu.h" -#include +#include #ifndef QT_NO_SCROLLBAR @@ -613,7 +613,7 @@ void QScrollBar::mousePressEvent(QMouseEvent *e) } const int initialDelay = 500; // default threshold d->activateControl(d->pressedControl, initialDelay); - QTime time; + QTimestamp time; time.start(); repaint(style()->subControlRect(QStyle::CC_ScrollBar, &opt, d->pressedControl, this)); if (time.elapsed() >= initialDelay && d->repeatActionTimer.isActive()) { diff --git a/src/gui/widgets/qworkspace.cpp b/src/gui/widgets/qworkspace.cpp index 2a6a7da..b4e4cc4 100644 --- a/src/gui/widgets/qworkspace.cpp +++ b/src/gui/widgets/qworkspace.cpp @@ -44,7 +44,6 @@ #include "qapplication.h" #include "qbitmap.h" #include "qcursor.h" -#include "qdatetime.h" #include "qdesktopwidget.h" #include "qevent.h" #include "qhash.h" @@ -59,6 +58,7 @@ #include "qscrollbar.h" #include "qstyle.h" #include "qstyleoption.h" +#include "qtimestamp.h" #include "qtooltip.h" #include "qdebug.h" #include @@ -450,10 +450,10 @@ void QWorkspaceTitleBar::mousePressEvent(QMouseEvent *e) case QStyle::SC_TitleBarSysMenu: if (d->flags & Qt::WindowSystemMenuHint) { d->buttonDown = QStyle::SC_None; - static QTime *t = 0; + static QTimestamp *t = 0; static QWorkspaceTitleBar *tc = 0; if (!t) - t = new QTime; + t = new QTimestamp; if (tc != this || t->elapsed() > QApplication::doubleClickInterval()) { emit showOperationMenu(); t->start(); @@ -1839,7 +1839,7 @@ bool QWorkspace::event(QEvent *e) bool QWorkspace::eventFilter(QObject *o, QEvent * e) { Q_D(QWorkspace); - static QTime* t = 0; + static QTimestamp* t = 0; static QWorkspace* tc = 0; if (o == d->maxtools) { switch (e->type()) { @@ -1847,7 +1847,7 @@ bool QWorkspace::eventFilter(QObject *o, QEvent * e) { QMenuBar* b = (QMenuBar*)o->parent(); if (!t) - t = new QTime; + t = new QTimestamp; if (tc != this || t->elapsed() > QApplication::doubleClickInterval()) { if (isRightToLeft()) { QPoint p = b->mapToGlobal(QPoint(b->x() + b->width(), b->y() + b->height())); -- cgit v0.12 From 0e0ac26bc58626df780e0fc3bc0483d5b310db8b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 19 Feb 2010 10:08:19 +0100 Subject: Port QtMultimedia uses of QTime as a stopwatch to QTimestamp (unix code only) --- src/multimedia/audio/qaudioinput_alsa_p.h | 5 +++-- src/multimedia/audio/qaudiooutput_alsa_p.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/multimedia/audio/qaudioinput_alsa_p.h b/src/multimedia/audio/qaudioinput_alsa_p.h index 92cef83..9a87691 100644 --- a/src/multimedia/audio/qaudioinput_alsa_p.h +++ b/src/multimedia/audio/qaudioinput_alsa_p.h @@ -61,6 +61,7 @@ #include #include #include +#include #include #include @@ -116,8 +117,8 @@ private: void drain(); QTimer* timer; - QTime timeStamp; - QTime clockStamp; + QTimestamp timeStamp; + QTimestamp clockStamp; qint64 elapsedTimeOffset; int intervalTime; char* audioBuffer; diff --git a/src/multimedia/audio/qaudiooutput_alsa_p.h b/src/multimedia/audio/qaudiooutput_alsa_p.h index 802bc27..c655701 100644 --- a/src/multimedia/audio/qaudiooutput_alsa_p.h +++ b/src/multimedia/audio/qaudiooutput_alsa_p.h @@ -60,6 +60,7 @@ #include #include #include +#include #include #include @@ -133,8 +134,8 @@ private: QTimer* timer; QByteArray m_device; int bytesAvailable; - QTime timeStamp; - QTime clockStamp; + QTimestamp timeStamp; + QTimestamp clockStamp; qint64 elapsedTimeOffset; char* audioBuffer; snd_pcm_t* handle; -- cgit v0.12 From e0f654ceb4a46ed60351743090dbc13ea8b92106 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 19 Feb 2010 10:15:44 +0100 Subject: Port QTest::qWait also to use QTimestamp. To avoid using QTimestamp to test QTimestamp, use QTest::qSleep in QTimestamp's own testcase. --- src/testlib/qtestsystem.h | 4 ++-- tests/auto/qtimestamp/tst_qtimestamp.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/testlib/qtestsystem.h b/src/testlib/qtestsystem.h index 3c11cdd..54da114 100644 --- a/src/testlib/qtestsystem.h +++ b/src/testlib/qtestsystem.h @@ -44,7 +44,7 @@ #include #include -#include +#include QT_BEGIN_HEADER @@ -63,7 +63,7 @@ namespace QTest { Q_ASSERT(QCoreApplication::instance()); - QTime timer; + QTimestamp timer; timer.start(); do { QCoreApplication::processEvents(QEventLoop::AllEvents, ms); diff --git a/tests/auto/qtimestamp/tst_qtimestamp.cpp b/tests/auto/qtimestamp/tst_qtimestamp.cpp index ab1e959..79138ce 100644 --- a/tests/auto/qtimestamp/tst_qtimestamp.cpp +++ b/tests/auto/qtimestamp/tst_qtimestamp.cpp @@ -63,7 +63,7 @@ void tst_QTimestamp::elapsed() QTimestamp t1; t1.start(); - QTest::qWait(4*minResolution); + QTest::qSleep(4*minResolution); QTimestamp t2; t2.start(); -- cgit v0.12 From 500b55813c591c35a63d76cb0f6809578c9ec053 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 19 Feb 2010 14:08:17 +0100 Subject: Add support for 32-bit rollovers on Windows --- src/corelib/tools/qtimestamp_win.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/corelib/tools/qtimestamp_win.cpp b/src/corelib/tools/qtimestamp_win.cpp index 72d38d0..34bf7a7 100644 --- a/src/corelib/tools/qtimestamp_win.cpp +++ b/src/corelib/tools/qtimestamp_win.cpp @@ -76,6 +76,18 @@ static quint64 getTickCount() return GetTickCount(); } +static qint64 difference(qint64 a, qint64 b) +{ + qint64 retval = a - b; + // if we're not using GetTickCount64, then there can be 32-bit rollover + // assume there were rollovers if the difference is negative by more than + // 75% of the 32-bit range + + if (!ptrGetTickCount64 && retval < Q_INT64_C(-0xc0000000)) + retval += Q_UINT64_C(0x100000000); + return retval; +} + bool QTimestamp::isMonotonic() { return true; @@ -91,22 +103,26 @@ qint64 QTimestamp::restart() { qint64 oldt1 = t1; t1 = getTickCount(); - return t1 - oldt1; + return difference(t1, oldt1); } qint64 QTimestamp::elapsed() const { - return getTickCount() - t1; + return difference(getTickCount(), t1); } qint64 QTimestamp::msecsTo(const QTimestamp &other) const { - return other.t1 - t1; + return difference(other.t1, t1); } void QTimestamp::addMSecs(int ms) { t1 += ms; + + // do we need to simulate rolling over? + if (!ptrGetTickCount64) + t1 = quint32(t1); } qint64 QTimestamp::secsTo(const QTimestamp &other) const @@ -116,12 +132,12 @@ qint64 QTimestamp::secsTo(const QTimestamp &other) const void QTimestamp::addSecs(int secs) { - t1 += secs * 1000; + addMSecs(secs * 1000); } bool operator<(const QTimestamp &v1, const QTimestamp &v2) { - return v1.t1 < v2.t1; + return difference(v1.t1, v2.t1) < 0; } QT_END_NAMESPACE -- cgit v0.12 From e0c97f943e80488c7e674075d40a27822b7e8c78 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 19 Feb 2010 17:04:55 +0100 Subject: Remove unnecessary functions from the QTimestamp API. If necesary, we can add them back later. But let's not add functions we don't need right now. --- src/corelib/tools/qtimestamp.h | 13 ------------- src/corelib/tools/qtimestamp_generic.cpp | 10 ---------- src/corelib/tools/qtimestamp_mac.cpp | 17 ----------------- src/corelib/tools/qtimestamp_symbian.cpp | 11 ----------- src/corelib/tools/qtimestamp_unix.cpp | 11 ----------- src/corelib/tools/qtimestamp_win.cpp | 14 -------------- 6 files changed, 76 deletions(-) diff --git a/src/corelib/tools/qtimestamp.h b/src/corelib/tools/qtimestamp.h index 1e913f0..de87ad8 100644 --- a/src/corelib/tools/qtimestamp.h +++ b/src/corelib/tools/qtimestamp.h @@ -64,9 +64,7 @@ public: bool hasExpired(qint64 timeout) const; qint64 msecsTo(const QTimestamp &other) const; - void addMSecs(int ms); qint64 secsTo(const QTimestamp &other) const; - void addSecs(int secs); bool operator==(const QTimestamp &other) const { return t1 == other.t1 && t2 == other.t2; } @@ -74,17 +72,6 @@ public: { return !(*this == other); } friend bool Q_CORE_EXPORT operator<(const QTimestamp &v1, const QTimestamp &v2); - friend qint64 operator-(const QTimestamp &v1, const QTimestamp &v2) - { return v2.msecsTo(v1); } - - friend QTimestamp &operator+=(QTimestamp &ts, qint64 ms) - { ts.addMSecs(ms); return ts; } - friend QTimestamp operator+(const QTimestamp &ts, qint64 ms) - { QTimestamp copy(ts); return copy += ms; } - friend QTimestamp &operator-=(QTimestamp &ts, qint64 ms) - { ts.addMSecs(-ms); return ts; } - friend QTimestamp operator-(const QTimestamp &ts, qint64 ms) - { QTimestamp copy(ts); return copy -= ms; } private: qint64 t1; diff --git a/src/corelib/tools/qtimestamp_generic.cpp b/src/corelib/tools/qtimestamp_generic.cpp index 9930932..c80ac34 100644 --- a/src/corelib/tools/qtimestamp_generic.cpp +++ b/src/corelib/tools/qtimestamp_generic.cpp @@ -78,21 +78,11 @@ qint64 QTimestamp::msecsTo(const QTimestamp &other) const return diff; } -void QTimestamp::addMSecs(int ms) -{ - t1 += ms; -} - qint64 QTimestamp::secsTo(const QTimestamp &other) const { return msecsTo(other) / 1000; } -void QTimestamp::addSecs(int secs) -{ - t1 += secs * 1000; -} - bool operator<(const QTimestamp &v1, const QTimestamp &v2) { return v1.t1 < v2.t1; diff --git a/src/corelib/tools/qtimestamp_mac.cpp b/src/corelib/tools/qtimestamp_mac.cpp index a80e7ee..02f0fa7 100644 --- a/src/corelib/tools/qtimestamp_mac.cpp +++ b/src/corelib/tools/qtimestamp_mac.cpp @@ -66,13 +66,6 @@ static qint64 absoluteToMSecs(qint64 cpuTime) return absoluteToNSecs(cpuTime) / 1000000; } -static qint64 msecsToAbsolute(qint64 ms) -{ - if (info.denom == 0) - mach_timebase_info(&info); - return ms * 1000000 * info.denom / info.numer; -} - timeval qt_gettime() { timeval tv; @@ -109,21 +102,11 @@ qint64 QTimestamp::msecsTo(const QTimestamp &other) const return absoluteToMSecs(other.t1 - t1); } -void QTimestamp::addMSecs(int ms) -{ - t1 += msecsToAbsolute(ms); -} - qint64 QTimestamp::secsTo(const QTimestamp &other) const { return msecsTo(other) / 1000; } -void QTimestamp::addSecs(int secs) -{ - t1 += msecsToAbsolute(secs * 1000); -} - bool operator<(const QTimestamp &v1, const QTimestamp &v2) { return v1.t1 < v2.t1; diff --git a/src/corelib/tools/qtimestamp_symbian.cpp b/src/corelib/tools/qtimestamp_symbian.cpp index e78597c..1d7b6ff 100644 --- a/src/corelib/tools/qtimestamp_symbian.cpp +++ b/src/corelib/tools/qtimestamp_symbian.cpp @@ -93,22 +93,11 @@ qint64 QTimestamp::msecsTo(const QTimestamp &other) const return difference(other.t1, t1); } -void QTimestamp::addMSecs(int ms) -{ - // simulate a 32-bit rollover - t1 = quint32(t1 + ms); -} - qint64 QTimestamp::secsTo(const QTimestamp &other) const { return msecsTo(other) / 1000; } -void QTimestamp::addSecs(int secs) -{ - addMSecs(secs * 1000); -} - bool operator<(const QTimestamp &v1, const QTimestamp &v2) { return difference(v1.t1, v2.t1) < 0; diff --git a/src/corelib/tools/qtimestamp_unix.cpp b/src/corelib/tools/qtimestamp_unix.cpp index 75371e7..507c861 100644 --- a/src/corelib/tools/qtimestamp_unix.cpp +++ b/src/corelib/tools/qtimestamp_unix.cpp @@ -156,22 +156,11 @@ qint64 QTimestamp::msecsTo(const QTimestamp &other) const return secs * 1000 + fraction / fractionAdjustment(); } -void QTimestamp::addMSecs(int ms) -{ - t1 += ms / 1000; - t2 += ms % 1000 * fractionAdjustment(); -} - qint64 QTimestamp::secsTo(const QTimestamp &other) const { return other.t1 - t1; } -void QTimestamp::addSecs(int secs) -{ - t1 += secs; -} - bool operator<(const QTimestamp &v1, const QTimestamp &v2) { return v1.t1 < v2.t1 || (v1.t1 == v2.t1 && v1.t2 < v2.t2); diff --git a/src/corelib/tools/qtimestamp_win.cpp b/src/corelib/tools/qtimestamp_win.cpp index 34bf7a7..1aea5cf 100644 --- a/src/corelib/tools/qtimestamp_win.cpp +++ b/src/corelib/tools/qtimestamp_win.cpp @@ -116,25 +116,11 @@ qint64 QTimestamp::msecsTo(const QTimestamp &other) const return difference(other.t1, t1); } -void QTimestamp::addMSecs(int ms) -{ - t1 += ms; - - // do we need to simulate rolling over? - if (!ptrGetTickCount64) - t1 = quint32(t1); -} - qint64 QTimestamp::secsTo(const QTimestamp &other) const { return msecsTo(other) / 1000; } -void QTimestamp::addSecs(int secs) -{ - addMSecs(secs * 1000); -} - bool operator<(const QTimestamp &v1, const QTimestamp &v2) { return difference(v1.t1, v2.t1) < 0; -- cgit v0.12 From 21983be486af0d252b8d393ed36b15becb3c8824 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 26 Feb 2010 15:02:26 +0100 Subject: Rename QTimestamp to QElapsedTimer --- src/corelib/animation/qabstractanimation_p.h | 4 ++-- src/corelib/io/qprocess.cpp | 6 +++--- src/corelib/io/qprocess_unix.cpp | 8 ++++---- src/corelib/kernel/qcore_unix.cpp | 4 ++-- src/corelib/kernel/qcore_unix_p.h | 2 +- src/corelib/kernel/qcoreapplication.cpp | 4 ++-- src/corelib/kernel/qeventdispatcher_unix.cpp | 6 +++--- src/corelib/tools/qdatetime.h | 2 +- src/corelib/tools/qtimeline.cpp | 4 ++-- src/corelib/tools/qtimestamp.cpp | 8 ++++---- src/corelib/tools/qtimestamp.h | 12 ++++++------ src/corelib/tools/qtimestamp_generic.cpp | 16 ++++++++-------- src/corelib/tools/qtimestamp_mac.cpp | 16 ++++++++-------- src/corelib/tools/qtimestamp_symbian.cpp | 16 ++++++++-------- src/corelib/tools/qtimestamp_unix.cpp | 24 ++++++++++++------------ src/corelib/tools/qtimestamp_win.cpp | 16 ++++++++-------- src/corelib/tools/tools.pri | 12 ++++++------ src/gui/dialogs/qfileinfogatherer.cpp | 6 +++--- src/gui/dialogs/qfileinfogatherer_p.h | 4 ++-- src/gui/dialogs/qprogressdialog.cpp | 4 ++-- src/gui/itemviews/qabstractitemview.cpp | 2 +- src/gui/itemviews/qabstractitemview_p.h | 4 ++-- src/gui/itemviews/qtreeview.cpp | 2 +- src/gui/kernel/qclipboard_x11.cpp | 6 +++--- src/gui/kernel/qdnd_x11.cpp | 4 ++-- src/gui/kernel/qgesture_p.h | 4 ++-- src/gui/kernel/qwidget_x11.cpp | 4 ++-- src/gui/kernel/qx11embed_x11.cpp | 4 ++-- src/gui/styles/qplastiquestyle.cpp | 4 ++-- src/gui/styles/qwindowsstyle_p.h | 4 ++-- src/gui/text/qfontdatabase_x11.cpp | 6 +++--- src/gui/widgets/qabstractslider_p.h | 4 ++-- src/gui/widgets/qeffects.cpp | 6 +++--- src/gui/widgets/qscrollbar.cpp | 4 ++-- src/gui/widgets/qworkspace.cpp | 10 +++++----- src/multimedia/audio/qaudioinput_alsa_p.h | 6 +++--- src/multimedia/audio/qaudiooutput_alsa_p.h | 6 +++--- src/network/socket/qabstractsocket.cpp | 10 +++++----- src/network/socket/qhttpsocketengine.cpp | 6 +++--- src/network/socket/qlocalsocket_unix.cpp | 4 ++-- src/network/socket/qnativesocketengine_unix.cpp | 4 ++-- src/network/socket/qsocks5socketengine.cpp | 14 +++++++------- src/network/ssl/qsslsocket.cpp | 10 +++++----- src/testlib/qtestsystem.h | 4 ++-- 44 files changed, 153 insertions(+), 153 deletions(-) diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h index 3eb4948..2282cdb 100644 --- a/src/corelib/animation/qabstractanimation_p.h +++ b/src/corelib/animation/qabstractanimation_p.h @@ -56,7 +56,7 @@ #include #include #include -#include +#include #include #ifdef Q_OS_WIN @@ -114,7 +114,7 @@ private: Q_DECLARE_PUBLIC(QAbstractAnimation) }; -typedef QTimestamp ElapsedTimer; +typedef QElapsedTimer ElapsedTimer; class QUnifiedTimer : public QObject { diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 6250094..63c2ab8 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -88,7 +88,7 @@ QT_END_NAMESPACE #include "qprocess_p.h" #include -#include +#include #include #include #include @@ -1639,7 +1639,7 @@ bool QProcess::waitForBytesWritten(int msecs) if (d->processState == QProcess::NotRunning) return false; if (d->processState == QProcess::Starting) { - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); bool started = waitForStarted(msecs); if (!started) @@ -1676,7 +1676,7 @@ bool QProcess::waitForFinished(int msecs) if (d->processState == QProcess::NotRunning) return false; if (d->processState == QProcess::Starting) { - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); bool started = waitForStarted(msecs); if (!started) diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 511154a..216c382 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -100,7 +100,7 @@ QT_END_NAMESPACE #include #include #include -#include +#include #include #include @@ -933,7 +933,7 @@ bool QProcessPrivate::waitForReadyRead(int msecs) qDebug("QProcessPrivate::waitForReadyRead(%d)", msecs); #endif - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); forever { @@ -1005,7 +1005,7 @@ bool QProcessPrivate::waitForBytesWritten(int msecs) qDebug("QProcessPrivate::waitForBytesWritten(%d)", msecs); #endif - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); while (!writeBuffer.isEmpty()) { @@ -1072,7 +1072,7 @@ bool QProcessPrivate::waitForFinished(int msecs) qDebug("QProcessPrivate::waitForFinished(%d)", msecs); #endif - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); forever { diff --git a/src/corelib/kernel/qcore_unix.cpp b/src/corelib/kernel/qcore_unix.cpp index 9146923..e0d92c0 100644 --- a/src/corelib/kernel/qcore_unix.cpp +++ b/src/corelib/kernel/qcore_unix.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "qcore_unix_p.h" -#include "qtimestamp.h" +#include "qelapsedtimer.h" #ifndef Q_OS_VXWORKS # if !defined(Q_OS_HPUX) || defined(__ia64) @@ -62,7 +62,7 @@ QT_BEGIN_NAMESPACE static inline bool time_update(struct timeval *tv, const struct timeval &start, const struct timeval &timeout) { - if (!QTimestamp::isMonotonic()) { + if (!QElapsedTimer::isMonotonic()) { // we cannot recalculate the timeout without a monotonic clock as the time may have changed return false; } diff --git a/src/corelib/kernel/qcore_unix_p.h b/src/corelib/kernel/qcore_unix_p.h index 59d66f7..439ca5a 100644 --- a/src/corelib/kernel/qcore_unix_p.h +++ b/src/corelib/kernel/qcore_unix_p.h @@ -314,7 +314,7 @@ static inline pid_t qt_safe_waitpid(pid_t pid, int *status, int options) # define _POSIX_MONOTONIC_CLOCK -1 #endif -timeval qt_gettime(); // in qtimestamp_mac.cpp or qtimestamp_unix.cpp +timeval qt_gettime(); // in qelapsedtimer_mac.cpp or qtimestamp_unix.cpp Q_CORE_EXPORT int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept, const struct timeval *tv); diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 3d6364b..8fc3fb8 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -58,7 +58,7 @@ #include #include #include -#include +#include #include #include #include @@ -917,7 +917,7 @@ void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags, int m QThreadData *data = QThreadData::current(); if (!data->eventDispatcher) return; - QTimestamp start; + QElapsedTimer start; start.start(); if (flags & QEventLoop::DeferredDeletion) QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp index 7a671d1..f7d45ac 100644 --- a/src/corelib/kernel/qeventdispatcher_unix.cpp +++ b/src/corelib/kernel/qeventdispatcher_unix.cpp @@ -45,7 +45,7 @@ #include "qpair.h" #include "qsocketnotifier.h" #include "qthread.h" -#include "qtimestamp.h" +#include "qelapsedtimer.h" #include "qeventdispatcher_unix_p.h" #include @@ -313,7 +313,7 @@ int QEventDispatcherUNIXPrivate::doSelect(QEventLoop::ProcessEventsFlags flags, QTimerInfoList::QTimerInfoList() { #if (_POSIX_MONOTONIC_CLOCK-0 <= 0) && !defined(Q_OS_MAC) - if (!QTimestamp::isMonotonic()) { + if (!QElapsedTimer::isMonotonic()) { // not using monotonic timers, initialize the timeChanged() machinery previousTime = qt_gettime(); @@ -392,7 +392,7 @@ bool QTimerInfoList::timeChanged(timeval *delta) void QTimerInfoList::repairTimersIfNeeded() { - if (QTimestamp::isMonotonic()) + if (QElapsedTimer::isMonotonic()) return; timeval delta; if (timeChanged(&delta)) diff --git a/src/corelib/tools/qdatetime.h b/src/corelib/tools/qdatetime.h index 75b5985..cb7f5bd 100644 --- a/src/corelib/tools/qdatetime.h +++ b/src/corelib/tools/qdatetime.h @@ -204,7 +204,7 @@ private: friend class QDateTime; friend class QDateTimePrivate; - friend class QTimestamp; + friend class QElapsedTimer; #ifndef QT_NO_DATASTREAM friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QTime &); friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QTime &); diff --git a/src/corelib/tools/qtimeline.cpp b/src/corelib/tools/qtimeline.cpp index 57977bc..f413223 100644 --- a/src/corelib/tools/qtimeline.cpp +++ b/src/corelib/tools/qtimeline.cpp @@ -44,7 +44,7 @@ #include #include #include -#include +#include QT_BEGIN_NAMESPACE @@ -70,7 +70,7 @@ public: int currentTime; int timerId; - QTimestamp timer; + QElapsedTimer timer; QTimeLine::Direction direction; QEasingCurve easingCurve; diff --git a/src/corelib/tools/qtimestamp.cpp b/src/corelib/tools/qtimestamp.cpp index b861099..220b108 100644 --- a/src/corelib/tools/qtimestamp.cpp +++ b/src/corelib/tools/qtimestamp.cpp @@ -39,23 +39,23 @@ ** ****************************************************************************/ -#include "qtimestamp.h" +#include "qelapsedtimer.h" QT_BEGIN_NAMESPACE static const qint64 invalidData = Q_INT64_C(0x8000000000000000); -void QTimestamp::invalidate() +void QElapsedTimer::invalidate() { t1 = t2 = invalidData; } -bool QTimestamp::isValid() const +bool QElapsedTimer::isValid() const { return t1 != invalidData && t2 != invalidData; } -bool QTimestamp::hasExpired(qint64 timeout) const +bool QElapsedTimer::hasExpired(qint64 timeout) const { // if timeout is -1, quint64(timeout) is LLINT_MAX, so this will be // considered as never expired diff --git a/src/corelib/tools/qtimestamp.h b/src/corelib/tools/qtimestamp.h index de87ad8..4fa0ca5 100644 --- a/src/corelib/tools/qtimestamp.h +++ b/src/corelib/tools/qtimestamp.h @@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Core) -class Q_CORE_EXPORT QTimestamp +class Q_CORE_EXPORT QElapsedTimer { public: static bool isMonotonic(); @@ -63,15 +63,15 @@ public: qint64 elapsed() const; bool hasExpired(qint64 timeout) const; - qint64 msecsTo(const QTimestamp &other) const; - qint64 secsTo(const QTimestamp &other) const; + qint64 msecsTo(const QElapsedTimer &other) const; + qint64 secsTo(const QElapsedTimer &other) const; - bool operator==(const QTimestamp &other) const + bool operator==(const QElapsedTimer &other) const { return t1 == other.t1 && t2 == other.t2; } - bool operator!=(const QTimestamp &other) const + bool operator!=(const QElapsedTimer &other) const { return !(*this == other); } - friend bool Q_CORE_EXPORT operator<(const QTimestamp &v1, const QTimestamp &v2); + friend bool Q_CORE_EXPORT operator<(const QElapsedTimer &v1, const QElapsedTimer &v2); private: qint64 t1; diff --git a/src/corelib/tools/qtimestamp_generic.cpp b/src/corelib/tools/qtimestamp_generic.cpp index c80ac34..a9c2233 100644 --- a/src/corelib/tools/qtimestamp_generic.cpp +++ b/src/corelib/tools/qtimestamp_generic.cpp @@ -39,24 +39,24 @@ ** ****************************************************************************/ -#include "qtimestamp.h" +#include "qelapsedtimer.h" #include "qdatetime.h" QT_BEGIN_NAMESPACE -bool QTimestamp::isMonotonic() +bool QElapsedTimer::isMonotonic() { return false; } -void QTimestamp::start() +void QElapsedTimer::start() { QTime t = QTime::currentTime(); t1 = t.mds; t2 = 0; } -qint64 QTimestamp::restart() +qint64 QElapsedTimer::restart() { QTime t = QTime::currentTime(); qint64 old = t1; @@ -64,13 +64,13 @@ qint64 QTimestamp::restart() return t1 - old; } -qint64 QTimestamp::elapsed() const +qint64 QElapsedTimer::elapsed() const { QTime t = QTime::currentTime(); return t.mds - t1; } -qint64 QTimestamp::msecsTo(const QTimestamp &other) const +qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const { qint64 diff = other.t1 - t1; if (diff < 0) // passed midnight @@ -78,12 +78,12 @@ qint64 QTimestamp::msecsTo(const QTimestamp &other) const return diff; } -qint64 QTimestamp::secsTo(const QTimestamp &other) const +qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const { return msecsTo(other) / 1000; } -bool operator<(const QTimestamp &v1, const QTimestamp &v2) +bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) { return v1.t1 < v2.t1; } diff --git a/src/corelib/tools/qtimestamp_mac.cpp b/src/corelib/tools/qtimestamp_mac.cpp index 02f0fa7..21a6d1b 100644 --- a/src/corelib/tools/qtimestamp_mac.cpp +++ b/src/corelib/tools/qtimestamp_mac.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qtimestamp.h" +#include "qelapsedtimer.h" #include #include @@ -47,7 +47,7 @@ QT_BEGIN_NAMESPACE -bool QTimestamp::isMonotonic() +bool QElapsedTimer::isMonotonic() { return true; } @@ -77,13 +77,13 @@ timeval qt_gettime() return tv; } -void QTimestamp::start() +void QElapsedTimer::start() { t1 = mach_absolute_time(); t2 = 0; } -qint64 QTimestamp::restart() +qint64 QElapsedTimer::restart() { qint64 old = t1; t1 = mach_absolute_time(); @@ -91,23 +91,23 @@ qint64 QTimestamp::restart() return absoluteToMSecs(t1 - old); } -qint64 QTimestamp::elapsed() const +qint64 QElapsedTimer::elapsed() const { uint64_t cpu_time = mach_absolute_time(); return absoluteToMSecs(cpu_time - t1); } -qint64 QTimestamp::msecsTo(const QTimestamp &other) const +qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const { return absoluteToMSecs(other.t1 - t1); } -qint64 QTimestamp::secsTo(const QTimestamp &other) const +qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const { return msecsTo(other) / 1000; } -bool operator<(const QTimestamp &v1, const QTimestamp &v2) +bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) { return v1.t1 < v2.t1; } diff --git a/src/corelib/tools/qtimestamp_symbian.cpp b/src/corelib/tools/qtimestamp_symbian.cpp index 1d7b6ff..1fbba65 100644 --- a/src/corelib/tools/qtimestamp_symbian.cpp +++ b/src/corelib/tools/qtimestamp_symbian.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qtimestamp.h" +#include "qelapsedtimer.h" #include QT_BEGIN_NAMESPACE @@ -65,40 +65,40 @@ static qint64 difference(qint64 a, qint64 b) return retval; } -bool QTimestamp::isMonotonic() +bool QElapsedTimer::isMonotonic() { return true; } -void QTimestamp::start() +void QElapsedTimer::start() { t1 = getMillisecondFromTick(); t2 = 0; } -qint64 QTimestamp::restart() +qint64 QElapsedTimer::restart() { qint64 oldt1 = t1; t1 = getMillisecondFromTick(); return difference(t1, oldt1); } -qint64 QTimestamp::elapsed() const +qint64 QElapsedTimer::elapsed() const { return difference(getMillisecondFromTick(), t1); } -qint64 QTimestamp::msecsTo(const QTimestamp &other) const +qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const { return difference(other.t1, t1); } -qint64 QTimestamp::secsTo(const QTimestamp &other) const +qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const { return msecsTo(other) / 1000; } -bool operator<(const QTimestamp &v1, const QTimestamp &v2) +bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) { return difference(v1.t1, v2.t1) < 0; } diff --git a/src/corelib/tools/qtimestamp_unix.cpp b/src/corelib/tools/qtimestamp_unix.cpp index 507c861..b8215f4 100644 --- a/src/corelib/tools/qtimestamp_unix.cpp +++ b/src/corelib/tools/qtimestamp_unix.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qtimestamp.h" +#include "qelapsedtimer.h" #include "qpair.h" #include #include @@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE static qint64 fractionAdjustment() { - if (QTimestamp::isMonotonic()) { + if (QElapsedTimer::isMonotonic()) { // the monotonic timer is measured in nanoseconds // 1 ms = 1000000 ns return 1000*1000ull; @@ -66,7 +66,7 @@ static qint64 fractionAdjustment() } } -bool QTimestamp::isMonotonic() +bool QElapsedTimer::isMonotonic() { #if (_POSIX_MONOTONIC_CLOCK-0 > 0) return true; @@ -95,7 +95,7 @@ static inline QPair do_gettime() return qMakePair(ts.tv_sec, ts.tv_nsec); #else # if !defined(QT_NO_CLOCK_MONOTONIC) && !defined(QT_BOOTSTRAPPED) - if (QTimestamp::isMonotonic()) { + if (QElapsedTimer::isMonotonic()) { timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return qMakePair(ts.tv_sec, ts.tv_nsec); @@ -116,20 +116,20 @@ timeval qt_gettime() timeval tv; tv.tv_sec = r.first; tv.tv_usec = r.second; - if (QTimestamp::isMonotonic()) + if (QElapsedTimer::isMonotonic()) tv.tv_usec /= 1000; return tv; } -void QTimestamp::start() +void QElapsedTimer::start() { QPair r = do_gettime(); t1 = r.first; t2 = r.second; } -qint64 QTimestamp::restart() +qint64 QElapsedTimer::restart() { QPair r = do_gettime(); qint64 oldt1 = t1; @@ -142,26 +142,26 @@ qint64 QTimestamp::restart() return r.first * 1000 + r.second / fractionAdjustment(); } -qint64 QTimestamp::elapsed() const +qint64 QElapsedTimer::elapsed() const { - QTimestamp now; + QElapsedTimer now; now.start(); return msecsTo(now); } -qint64 QTimestamp::msecsTo(const QTimestamp &other) const +qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const { qint64 secs = other.t1 - t1; qint64 fraction = other.t2 - t2; return secs * 1000 + fraction / fractionAdjustment(); } -qint64 QTimestamp::secsTo(const QTimestamp &other) const +qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const { return other.t1 - t1; } -bool operator<(const QTimestamp &v1, const QTimestamp &v2) +bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) { return v1.t1 < v2.t1 || (v1.t1 == v2.t1 && v1.t2 < v2.t2); } diff --git a/src/corelib/tools/qtimestamp_win.cpp b/src/corelib/tools/qtimestamp_win.cpp index 1aea5cf..e384dd8 100644 --- a/src/corelib/tools/qtimestamp_win.cpp +++ b/src/corelib/tools/qtimestamp_win.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qtimestamp.h" +#include "qelapsedtimer.h" #include typedef ULONGLONG (WINAPI *PtrGetTickCount64)(void); @@ -88,40 +88,40 @@ static qint64 difference(qint64 a, qint64 b) return retval; } -bool QTimestamp::isMonotonic() +bool QElapsedTimer::isMonotonic() { return true; } -void QTimestamp::start() +void QElapsedTimer::start() { t1 = getTickCount(); t2 = 0; } -qint64 QTimestamp::restart() +qint64 QElapsedTimer::restart() { qint64 oldt1 = t1; t1 = getTickCount(); return difference(t1, oldt1); } -qint64 QTimestamp::elapsed() const +qint64 QElapsedTimer::elapsed() const { return difference(getTickCount(), t1); } -qint64 QTimestamp::msecsTo(const QTimestamp &other) const +qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const { return difference(other.t1, t1); } -qint64 QTimestamp::secsTo(const QTimestamp &other) const +qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const { return msecsTo(other) / 1000; } -bool operator<(const QTimestamp &v1, const QTimestamp &v2) +bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) { return difference(v1.t1, v2.t1) < 0; } diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index e1097c4..692fae9 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -42,7 +42,7 @@ HEADERS += \ tools/qstringmatcher.h \ tools/qtextboundaryfinder.h \ tools/qtimeline.h \ - tools/qtimestamp.h \ + tools/qelapsedtimer.h \ tools/qunicodetables_p.h \ tools/qvarlengtharray.h \ tools/qvector.h \ @@ -77,16 +77,16 @@ SOURCES += \ tools/qstringlist.cpp \ tools/qtextboundaryfinder.cpp \ tools/qtimeline.cpp \ - tools/qtimestamp.cpp \ + tools/qelapsedtimer.cpp \ tools/qvector.cpp \ tools/qvsnprintf.cpp symbian:SOURCES+=tools/qlocale_symbian.cpp -mac:SOURCES += tools/qtimestamp_mac.cpp -else:unix:SOURCES += tools/qtimestamp_unix.cpp -else:win32:SOURCES += tools/qtimestamp_win.cpp -else:SOURCES += tools/qtimestamp_generic.cpp +mac:SOURCES += tools/qelapsedtimer_mac.cpp +else:unix:SOURCES += tools/qelapsedtimer_unix.cpp +else:win32:SOURCES += tools/qelapsedtimer_win.cpp +else:SOURCES += tools/qelapsedtimer_generic.cpp #zlib support contains(QT_CONFIG, zlib) { diff --git a/src/gui/dialogs/qfileinfogatherer.cpp b/src/gui/dialogs/qfileinfogatherer.cpp index a565c45..3b279ae 100644 --- a/src/gui/dialogs/qfileinfogatherer.cpp +++ b/src/gui/dialogs/qfileinfogatherer.cpp @@ -297,7 +297,7 @@ void QFileInfoGatherer::getFileInfos(const QString &path, const QStringList &fil return; } - QTimestamp base; + QElapsedTimer base; base.start(); QFileInfo fileInfo; bool firstTime = true; @@ -327,9 +327,9 @@ void QFileInfoGatherer::getFileInfos(const QString &path, const QStringList &fil emit directoryLoaded(path); } -void QFileInfoGatherer::fetch(const QFileInfo &fileInfo, QTimestamp &base, bool &firstTime, QList > &updatedFiles, const QString &path) { +void QFileInfoGatherer::fetch(const QFileInfo &fileInfo, QElapsedTimer &base, bool &firstTime, QList > &updatedFiles, const QString &path) { updatedFiles.append(QPair(fileInfo.fileName(), fileInfo)); - QTimestamp current; + QElapsedTimer current; current.start(); if ((firstTime && updatedFiles.count() > 100) || base.msecsTo(current) > 1000) { emit updates(path, updatedFiles); diff --git a/src/gui/dialogs/qfileinfogatherer_p.h b/src/gui/dialogs/qfileinfogatherer_p.h index a2b9acd..5abcd94 100644 --- a/src/gui/dialogs/qfileinfogatherer_p.h +++ b/src/gui/dialogs/qfileinfogatherer_p.h @@ -63,7 +63,7 @@ #include #include #include -#include +#include QT_BEGIN_NAMESPACE @@ -175,7 +175,7 @@ protected: void getFileInfos(const QString &path, const QStringList &files); private: - void fetch(const QFileInfo &info, QTimestamp &base, bool &firstTime, QList > &updatedFiles, const QString &path); + void fetch(const QFileInfo &info, QElapsedTimer &base, bool &firstTime, QList > &updatedFiles, const QString &path); QString translateDriveName(const QFileInfo &drive) const; QMutex mutex; diff --git a/src/gui/dialogs/qprogressdialog.cpp b/src/gui/dialogs/qprogressdialog.cpp index 602f47c..a2d7b23 100644 --- a/src/gui/dialogs/qprogressdialog.cpp +++ b/src/gui/dialogs/qprogressdialog.cpp @@ -53,7 +53,7 @@ #include "qpushbutton.h" #include "qcursor.h" #include "qtimer.h" -#include "qtimestamp.h" +#include "qelapsedtimer.h" #include #include @@ -103,7 +103,7 @@ public: QTimer *forceTimer; bool shown_once; bool cancellation_flag; - QTimestamp starttime; + QElapsedTimer starttime; #ifndef QT_NO_CURSOR QCursor parentCursor; #endif diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 34b5e13..3738816 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -2839,7 +2839,7 @@ void QAbstractItemView::keyboardSearch(const QString &search) QModelIndex start = currentIndex().isValid() ? currentIndex() : d->model->index(0, 0, d->root); - QTimestamp now; + QElapsedTimer now; now.start(); bool skipRow = false; if (search.isEmpty() diff --git a/src/gui/itemviews/qabstractitemview_p.h b/src/gui/itemviews/qabstractitemview_p.h index 4af98b4..509459c 100644 --- a/src/gui/itemviews/qabstractitemview_p.h +++ b/src/gui/itemviews/qabstractitemview_p.h @@ -64,7 +64,7 @@ #include "QtCore/qdebug.h" #include "QtGui/qpainter.h" #include "QtCore/qbasictimer.h" -#include "QtCore/qtimestamp.h" +#include "QtCore/qelapsedtimer.h" #ifndef QT_NO_ITEMVIEWS @@ -390,7 +390,7 @@ public: #endif QString keyboardInput; - QTimestamp keyboardInputTime; + QElapsedTimer keyboardInputTime; bool autoScroll; QBasicTimer autoScrollTimer; diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index 9f8c322..fcdc429 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -958,7 +958,7 @@ void QTreeView::keyboardSearch(const QString &search) else start = d->model->index(0, 0, d->root); - QTimestamp now; + QElapsedTimer now; now.start(); bool skipRow = false; if (search.isEmpty() diff --git a/src/gui/kernel/qclipboard_x11.cpp b/src/gui/kernel/qclipboard_x11.cpp index 2a9706b..3bdc971 100644 --- a/src/gui/kernel/qclipboard_x11.cpp +++ b/src/gui/kernel/qclipboard_x11.cpp @@ -75,7 +75,7 @@ #include "qt_x11_p.h" #include "qx11info_x11.h" #include "qimagewriter.h" -#include "qtimestamp.h" +#include "qelapsedtimer.h" #include "qvariant.h" #include "qdnd_p.h" #include @@ -516,9 +516,9 @@ static Bool checkForClipboardEvents(Display *, XEvent *e, XPointer) bool QX11Data::clipboardWaitForEvent(Window win, int type, XEvent *event, int timeout) { - QTimestamp started; + QElapsedTimer started; started.start(); - QTimestamp now = started; + QElapsedTimer now = started; if (QAbstractEventDispatcher::instance()->inherits("QtMotif") || QApplication::clipboard()->property("useEventLoopWhenWaiting").toBool()) { diff --git a/src/gui/kernel/qdnd_x11.cpp b/src/gui/kernel/qdnd_x11.cpp index 0d24ed7..0a05d8e 100644 --- a/src/gui/kernel/qdnd_x11.cpp +++ b/src/gui/kernel/qdnd_x11.cpp @@ -54,7 +54,7 @@ #include "qiodevice.h" #include "qpointer.h" #include "qcursor.h" -#include "qtimestamp.h" +#include "qelapsedtimer.h" #include "qvariant.h" #include "qvector.h" #include "qurl.h" @@ -1911,7 +1911,7 @@ Qt::DropAction QDragManager::drag(QDrag * o) // then we could still have problems, but this is highly unlikely QApplication::flush(); - QTimestamp timer; + QElapsedTimer timer; timer.start(); do { XEvent event; diff --git a/src/gui/kernel/qgesture_p.h b/src/gui/kernel/qgesture_p.h index 84d8b7c..bf60f97 100644 --- a/src/gui/kernel/qgesture_p.h +++ b/src/gui/kernel/qgesture_p.h @@ -56,7 +56,7 @@ #include "qrect.h" #include "qpoint.h" #include "qgesture.h" -#include "qtimestamp.h" +#include "qelapsedtimer.h" #include "private/qobject_p.h" QT_BEGIN_NAMESPACE @@ -148,7 +148,7 @@ public: QPoint lastPositions[3]; bool started; qreal speed; - QTimestamp time; + QElapsedTimer time; }; class QTapGesturePrivate : public QGesturePrivate diff --git a/src/gui/kernel/qwidget_x11.cpp b/src/gui/kernel/qwidget_x11.cpp index 3fbb9ce..b4febc6 100644 --- a/src/gui/kernel/qwidget_x11.cpp +++ b/src/gui/kernel/qwidget_x11.cpp @@ -49,7 +49,7 @@ #include "qbitmap.h" #include "qlayout.h" #include "qtextcodec.h" -#include "qtimestamp.h" +#include "qelapsedtimer.h" #include "qcursor.h" #include "qstack.h" #include "qcolormap.h" @@ -352,7 +352,7 @@ Q_GUI_EXPORT void qt_x11_wait_for_window_manager(QWidget* w) return; QApplication::flush(); XEvent ev; - QTimestamp t; + QElapsedTimer t; t.start(); static const int maximumWaitTime = 2000; if (!w->testAttribute(Qt::WA_WState_Created)) diff --git a/src/gui/kernel/qx11embed_x11.cpp b/src/gui/kernel/qx11embed_x11.cpp index b92a5b1..b527e72 100644 --- a/src/gui/kernel/qx11embed_x11.cpp +++ b/src/gui/kernel/qx11embed_x11.cpp @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include #include #include @@ -1231,7 +1231,7 @@ void QX11EmbedContainer::embedClient(WId id) For safety, we will not wait more than 500 ms, so that we can preemptively workaround buggy window managers. */ - QTimestamp t; + QElapsedTimer t; t.start(); functorData data; diff --git a/src/gui/styles/qplastiquestyle.cpp b/src/gui/styles/qplastiquestyle.cpp index 9f4d48e..4ae9f79 100644 --- a/src/gui/styles/qplastiquestyle.cpp +++ b/src/gui/styles/qplastiquestyle.cpp @@ -80,7 +80,7 @@ static const int blueFrameWidth = 2; // with of line edit focus frame #include #include #include -#include +#include #include #include #include @@ -980,7 +980,7 @@ public: #ifndef QT_NO_PROGRESSBAR QList bars; int progressBarAnimateTimer; - QTimestamp timer; + QElapsedTimer timer; #endif }; diff --git a/src/gui/styles/qwindowsstyle_p.h b/src/gui/styles/qwindowsstyle_p.h index 92060d8..2a89b84 100644 --- a/src/gui/styles/qwindowsstyle_p.h +++ b/src/gui/styles/qwindowsstyle_p.h @@ -59,7 +59,7 @@ #ifndef QT_NO_STYLE_WINDOWS #include #include -#include +#include QT_BEGIN_NAMESPACE @@ -80,7 +80,7 @@ public: QList bars; int animationFps; int animateTimer; - QTimestamp startTime; + QElapsedTimer startTime; int animateStep; QColor inactiveCaptionText; QColor activeCaptionColor; diff --git a/src/gui/text/qfontdatabase_x11.cpp b/src/gui/text/qfontdatabase_x11.cpp index fd3cba8..b1ab478 100644 --- a/src/gui/text/qfontdatabase_x11.cpp +++ b/src/gui/text/qfontdatabase_x11.cpp @@ -43,7 +43,7 @@ #include #include -#include +#include #include #include "qx11info_x11.h" @@ -1218,7 +1218,7 @@ static void load(const QString &family = QString(), int script = -1, bool forceX } #ifdef QFONTDATABASE_DEBUG - QTimestamp t; + QElapsedTimer t; t.start(); #endif @@ -1301,7 +1301,7 @@ static void initializeDb() if (!db || db->count) return; - QTimestamp t; + QElapsedTimer t; t.start(); #ifndef QT_NO_FONTCONFIG diff --git a/src/gui/widgets/qabstractslider_p.h b/src/gui/widgets/qabstractslider_p.h index c8c29b5..19d1fca 100644 --- a/src/gui/widgets/qabstractslider_p.h +++ b/src/gui/widgets/qabstractslider_p.h @@ -54,7 +54,7 @@ // #include "QtCore/qbasictimer.h" -#include "QtCore/qtimestamp.h" +#include "QtCore/qelapsedtimer.h" #include "private/qwidget_p.h" #include "qstyle.h" @@ -104,7 +104,7 @@ public: /** * The time of when the first auto repeating key press event occurs. */ - QTimestamp firstRepeat; + QElapsedTimer firstRepeat; #endif diff --git a/src/gui/widgets/qeffects.cpp b/src/gui/widgets/qeffects.cpp index 9dd853f..a56d093 100644 --- a/src/gui/widgets/qeffects.cpp +++ b/src/gui/widgets/qeffects.cpp @@ -49,7 +49,7 @@ #include "qpixmap.h" #include "qpointer.h" #include "qtimer.h" -#include "qtimestamp.h" +#include "qelapsedtimer.h" #include "qdebug.h" QT_BEGIN_NAMESPACE @@ -103,7 +103,7 @@ private: int elapsed; bool showWidget; QTimer anim; - QTimestamp checkTime; + QElapsedTimer checkTime; double windowOpacity; }; @@ -384,7 +384,7 @@ private: int orientation; QTimer anim; - QTimestamp checkTime; + QElapsedTimer checkTime; QPixmap pm; }; diff --git a/src/gui/widgets/qscrollbar.cpp b/src/gui/widgets/qscrollbar.cpp index 894300d..4ee9f27 100644 --- a/src/gui/widgets/qscrollbar.cpp +++ b/src/gui/widgets/qscrollbar.cpp @@ -47,7 +47,7 @@ #include "qstyle.h" #include "qstyleoption.h" #include "qmenu.h" -#include +#include #ifndef QT_NO_SCROLLBAR @@ -613,7 +613,7 @@ void QScrollBar::mousePressEvent(QMouseEvent *e) } const int initialDelay = 500; // default threshold d->activateControl(d->pressedControl, initialDelay); - QTimestamp time; + QElapsedTimer time; time.start(); repaint(style()->subControlRect(QStyle::CC_ScrollBar, &opt, d->pressedControl, this)); if (time.elapsed() >= initialDelay && d->repeatActionTimer.isActive()) { diff --git a/src/gui/widgets/qworkspace.cpp b/src/gui/widgets/qworkspace.cpp index b4e4cc4..7180c4d 100644 --- a/src/gui/widgets/qworkspace.cpp +++ b/src/gui/widgets/qworkspace.cpp @@ -58,7 +58,7 @@ #include "qscrollbar.h" #include "qstyle.h" #include "qstyleoption.h" -#include "qtimestamp.h" +#include "qelapsedtimer.h" #include "qtooltip.h" #include "qdebug.h" #include @@ -450,10 +450,10 @@ void QWorkspaceTitleBar::mousePressEvent(QMouseEvent *e) case QStyle::SC_TitleBarSysMenu: if (d->flags & Qt::WindowSystemMenuHint) { d->buttonDown = QStyle::SC_None; - static QTimestamp *t = 0; + static QElapsedTimer *t = 0; static QWorkspaceTitleBar *tc = 0; if (!t) - t = new QTimestamp; + t = new QElapsedTimer; if (tc != this || t->elapsed() > QApplication::doubleClickInterval()) { emit showOperationMenu(); t->start(); @@ -1839,7 +1839,7 @@ bool QWorkspace::event(QEvent *e) bool QWorkspace::eventFilter(QObject *o, QEvent * e) { Q_D(QWorkspace); - static QTimestamp* t = 0; + static QElapsedTimer* t = 0; static QWorkspace* tc = 0; if (o == d->maxtools) { switch (e->type()) { @@ -1847,7 +1847,7 @@ bool QWorkspace::eventFilter(QObject *o, QEvent * e) { QMenuBar* b = (QMenuBar*)o->parent(); if (!t) - t = new QTimestamp; + t = new QElapsedTimer; if (tc != this || t->elapsed() > QApplication::doubleClickInterval()) { if (isRightToLeft()) { QPoint p = b->mapToGlobal(QPoint(b->x() + b->width(), b->y() + b->height())); diff --git a/src/multimedia/audio/qaudioinput_alsa_p.h b/src/multimedia/audio/qaudioinput_alsa_p.h index 9a87691..c907019 100644 --- a/src/multimedia/audio/qaudioinput_alsa_p.h +++ b/src/multimedia/audio/qaudioinput_alsa_p.h @@ -61,7 +61,7 @@ #include #include #include -#include +#include #include #include @@ -117,8 +117,8 @@ private: void drain(); QTimer* timer; - QTimestamp timeStamp; - QTimestamp clockStamp; + QElapsedTimer timeStamp; + QElapsedTimer clockStamp; qint64 elapsedTimeOffset; int intervalTime; char* audioBuffer; diff --git a/src/multimedia/audio/qaudiooutput_alsa_p.h b/src/multimedia/audio/qaudiooutput_alsa_p.h index c655701..e6ac231 100644 --- a/src/multimedia/audio/qaudiooutput_alsa_p.h +++ b/src/multimedia/audio/qaudiooutput_alsa_p.h @@ -60,7 +60,7 @@ #include #include #include -#include +#include #include #include @@ -134,8 +134,8 @@ private: QTimer* timer; QByteArray m_device; int bytesAvailable; - QTimestamp timeStamp; - QTimestamp clockStamp; + QElapsedTimer timeStamp; + QElapsedTimer clockStamp; qint64 elapsedTimeOffset; char* audioBuffer; snd_pcm_t* handle; diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index fc50ee5..21cd0fd 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -370,7 +370,7 @@ #include #include #include -#include +#include #ifndef QT_NO_OPENSSL #include @@ -1738,7 +1738,7 @@ bool QAbstractSocket::waitForConnected(int msecs) bool wasPendingClose = d->pendingClose; d->pendingClose = false; - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); if (d->state == HostLookupState) { @@ -1819,7 +1819,7 @@ bool QAbstractSocket::waitForReadyRead(int msecs) return false; } - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); // handle a socket in connecting state @@ -1878,7 +1878,7 @@ bool QAbstractSocket::waitForBytesWritten(int msecs) if (d->writeBuffer.isEmpty()) return false; - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); // handle a socket in connecting state @@ -1960,7 +1960,7 @@ bool QAbstractSocket::waitForDisconnected(int msecs) return false; } - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); // handle a socket in connecting state diff --git a/src/network/socket/qhttpsocketengine.cpp b/src/network/socket/qhttpsocketengine.cpp index 9d412ac..dfda257 100644 --- a/src/network/socket/qhttpsocketengine.cpp +++ b/src/network/socket/qhttpsocketengine.cpp @@ -44,7 +44,7 @@ #include "qhostaddress.h" #include "qurl.h" #include "qhttp.h" -#include "qtimestamp.h" +#include "qelapsedtimer.h" #if !defined(QT_NO_NETWORKPROXY) && !defined(QT_NO_HTTP) #include @@ -319,7 +319,7 @@ bool QHttpSocketEngine::waitForRead(int msecs, bool *timedOut) if (!d->socket || d->socket->state() == QAbstractSocket::UnconnectedState) return false; - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); // Wait for more data if nothing is available. @@ -366,7 +366,7 @@ bool QHttpSocketEngine::waitForWrite(int msecs, bool *timedOut) return true; } - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); // If we're not connected yet, wait until we are, and until bytes have diff --git a/src/network/socket/qlocalsocket_unix.cpp b/src/network/socket/qlocalsocket_unix.cpp index 20301ba..f14decc 100644 --- a/src/network/socket/qlocalsocket_unix.cpp +++ b/src/network/socket/qlocalsocket_unix.cpp @@ -54,7 +54,7 @@ #include #include -#include +#include #ifdef Q_OS_VXWORKS # include @@ -534,7 +534,7 @@ bool QLocalSocket::waitForConnected(int msec) int result = -1; // on Linux timeout will be updated by select, but _not_ on other systems. - QTimestamp timer; + QElapsedTimer timer; timer.start(); while (state() == ConnectingState && (-1 == msec || timer.elapsed() < msec)) { diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp index 7c1fc17..6c800fe 100644 --- a/src/network/socket/qnativesocketengine_unix.cpp +++ b/src/network/socket/qnativesocketengine_unix.cpp @@ -44,7 +44,7 @@ #include "private/qnet_unix_p.h" #include "qiodevice.h" #include "qhostaddress.h" -#include "qtimestamp.h" +#include "qelapsedtimer.h" #include "qvarlengtharray.h" #include #include @@ -1003,7 +1003,7 @@ int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool checkRead, bool c #ifndef Q_OS_SYMBIAN ret = qt_safe_select(socketDescriptor + 1, &fdread, &fdwrite, 0, timeout < 0 ? 0 : &tv); #else - QTimestamp timer; + QElapsedTimer timer; timer.start(); do { diff --git a/src/network/socket/qsocks5socketengine.cpp b/src/network/socket/qsocks5socketengine.cpp index 0c6a01a..f68edfe 100644 --- a/src/network/socket/qsocks5socketengine.cpp +++ b/src/network/socket/qsocks5socketengine.cpp @@ -49,7 +49,7 @@ #include "qdebug.h" #include "qhash.h" #include "qqueue.h" -#include "qtimestamp.h" +#include "qelapsedtimer.h" #include "qmutex.h" #include "qthread.h" #include "qcoreapplication.h" @@ -308,7 +308,7 @@ struct QSocks5BindData : public QSocks5Data quint16 localPort; QHostAddress peerAddress; quint16 peerPort; - QTimestamp timeStamp; + QElapsedTimer timeStamp; }; struct QSocks5RevivedDatagram @@ -1355,7 +1355,7 @@ bool QSocks5SocketEngine::bind(const QHostAddress &address, quint16 port) } int msecs = SOCKS5_BLOCKING_BIND_TIMEOUT; - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); d->data->controlSocket->connectToHost(d->proxyInfo.hostName(), d->proxyInfo.port()); if (!d->waitForConnected(msecs, 0) || @@ -1455,7 +1455,7 @@ void QSocks5SocketEngine::close() if (d->data && d->data->controlSocket) { if (d->data->controlSocket->state() == QAbstractSocket::ConnectedState) { int msecs = 100; - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); while (!d->data->controlSocket->bytesToWrite()) { if (!d->data->controlSocket->waitForBytesWritten(qt_timeout_value(msecs, stopWatch.elapsed()))) @@ -1674,7 +1674,7 @@ bool QSocks5SocketEnginePrivate::waitForConnected(int msecs, bool *timedOut) mode == BindMode ? BindSuccess : UdpAssociateSuccess; - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); while (socks5State != wantedState) { @@ -1699,7 +1699,7 @@ bool QSocks5SocketEngine::waitForRead(int msecs, bool *timedOut) d->readNotificationActivated = false; - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); // are we connected yet? @@ -1749,7 +1749,7 @@ bool QSocks5SocketEngine::waitForWrite(int msecs, bool *timedOut) Q_D(QSocks5SocketEngine); QSOCKS5_DEBUG << "waitForWrite" << msecs; - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); // are we connected yet? diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp index 895e32c..86b11b9 100644 --- a/src/network/ssl/qsslsocket.cpp +++ b/src/network/ssl/qsslsocket.cpp @@ -287,7 +287,7 @@ #include #include #include -#include +#include #include #include @@ -1393,7 +1393,7 @@ bool QSslSocket::waitForEncrypted(int msecs) if (d->mode == UnencryptedMode && !d->autoStartHandshake) return false; - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); if (d->plainSocket->state() != QAbstractSocket::ConnectedState) { @@ -1433,7 +1433,7 @@ bool QSslSocket::waitForReadyRead(int msecs) bool *previousReadyReadEmittedPointer = d->readyReadEmittedPointer; d->readyReadEmittedPointer = &readyReadEmitted; - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); if (!d->connectionEncrypted) { @@ -1470,7 +1470,7 @@ bool QSslSocket::waitForBytesWritten(int msecs) if (d->mode == UnencryptedMode) return d->plainSocket->waitForBytesWritten(msecs); - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); if (!d->connectionEncrypted) { @@ -1508,7 +1508,7 @@ bool QSslSocket::waitForDisconnected(int msecs) if (d->mode == UnencryptedMode) return d->plainSocket->waitForDisconnected(msecs); - QTimestamp stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); if (!d->connectionEncrypted) { diff --git a/src/testlib/qtestsystem.h b/src/testlib/qtestsystem.h index 54da114..82d69d6 100644 --- a/src/testlib/qtestsystem.h +++ b/src/testlib/qtestsystem.h @@ -44,7 +44,7 @@ #include #include -#include +#include QT_BEGIN_HEADER @@ -63,7 +63,7 @@ namespace QTest { Q_ASSERT(QCoreApplication::instance()); - QTimestamp timer; + QElapsedTimer timer; timer.start(); do { QCoreApplication::processEvents(QEventLoop::AllEvents, ms); -- cgit v0.12 From 7f3c9feaaf67ce7e89cd2f9df2155c61a58acaed Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 26 Feb 2010 15:02:56 +0100 Subject: Rename the files too --- src/corelib/tools/qelapsedtimer.cpp | 65 ++++++++++ src/corelib/tools/qelapsedtimer.h | 85 +++++++++++++ src/corelib/tools/qelapsedtimer_generic.cpp | 91 +++++++++++++ src/corelib/tools/qelapsedtimer_mac.cpp | 115 +++++++++++++++++ src/corelib/tools/qelapsedtimer_symbian.cpp | 106 ++++++++++++++++ src/corelib/tools/qelapsedtimer_unix.cpp | 169 +++++++++++++++++++++++++ src/corelib/tools/qelapsedtimer_win.cpp | 129 +++++++++++++++++++ src/corelib/tools/qtimestamp.cpp | 65 ---------- src/corelib/tools/qtimestamp.h | 85 ------------- src/corelib/tools/qtimestamp_generic.cpp | 91 ------------- src/corelib/tools/qtimestamp_mac.cpp | 115 ----------------- src/corelib/tools/qtimestamp_symbian.cpp | 106 ---------------- src/corelib/tools/qtimestamp_unix.cpp | 169 ------------------------- src/corelib/tools/qtimestamp_win.cpp | 129 ------------------- tests/auto/qelapsedtimer/qelapsedtimer.pro | 13 ++ tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp | 94 ++++++++++++++ tests/auto/qtimestamp/qtimestamp.pro | 13 -- tests/auto/qtimestamp/tst_qtimestamp.cpp | 94 -------------- 18 files changed, 867 insertions(+), 867 deletions(-) create mode 100644 src/corelib/tools/qelapsedtimer.cpp create mode 100644 src/corelib/tools/qelapsedtimer.h create mode 100644 src/corelib/tools/qelapsedtimer_generic.cpp create mode 100644 src/corelib/tools/qelapsedtimer_mac.cpp create mode 100644 src/corelib/tools/qelapsedtimer_symbian.cpp create mode 100644 src/corelib/tools/qelapsedtimer_unix.cpp create mode 100644 src/corelib/tools/qelapsedtimer_win.cpp delete mode 100644 src/corelib/tools/qtimestamp.cpp delete mode 100644 src/corelib/tools/qtimestamp.h delete mode 100644 src/corelib/tools/qtimestamp_generic.cpp delete mode 100644 src/corelib/tools/qtimestamp_mac.cpp delete mode 100644 src/corelib/tools/qtimestamp_symbian.cpp delete mode 100644 src/corelib/tools/qtimestamp_unix.cpp delete mode 100644 src/corelib/tools/qtimestamp_win.cpp create mode 100644 tests/auto/qelapsedtimer/qelapsedtimer.pro create mode 100644 tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp delete mode 100644 tests/auto/qtimestamp/qtimestamp.pro delete mode 100644 tests/auto/qtimestamp/tst_qtimestamp.cpp diff --git a/src/corelib/tools/qelapsedtimer.cpp b/src/corelib/tools/qelapsedtimer.cpp new file mode 100644 index 0000000..220b108 --- /dev/null +++ b/src/corelib/tools/qelapsedtimer.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qelapsedtimer.h" + +QT_BEGIN_NAMESPACE + +static const qint64 invalidData = Q_INT64_C(0x8000000000000000); + +void QElapsedTimer::invalidate() +{ + t1 = t2 = invalidData; +} + +bool QElapsedTimer::isValid() const +{ + return t1 != invalidData && t2 != invalidData; +} + +bool QElapsedTimer::hasExpired(qint64 timeout) const +{ + // if timeout is -1, quint64(timeout) is LLINT_MAX, so this will be + // considered as never expired + return quint64(elapsed()) > quint64(timeout); +} + +QT_END_NAMESPACE diff --git a/src/corelib/tools/qelapsedtimer.h b/src/corelib/tools/qelapsedtimer.h new file mode 100644 index 0000000..4fa0ca5 --- /dev/null +++ b/src/corelib/tools/qelapsedtimer.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTIMESTAMP_H +#define QTIMESTAMP_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Core) + +class Q_CORE_EXPORT QElapsedTimer +{ +public: + static bool isMonotonic(); + + void start(); + qint64 restart(); + void invalidate(); + bool isValid() const; + + qint64 elapsed() const; + bool hasExpired(qint64 timeout) const; + + qint64 msecsTo(const QElapsedTimer &other) const; + qint64 secsTo(const QElapsedTimer &other) const; + + bool operator==(const QElapsedTimer &other) const + { return t1 == other.t1 && t2 == other.t2; } + bool operator!=(const QElapsedTimer &other) const + { return !(*this == other); } + + friend bool Q_CORE_EXPORT operator<(const QElapsedTimer &v1, const QElapsedTimer &v2); + +private: + qint64 t1; + qint64 t2; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QTIMESTAMP_H diff --git a/src/corelib/tools/qelapsedtimer_generic.cpp b/src/corelib/tools/qelapsedtimer_generic.cpp new file mode 100644 index 0000000..a9c2233 --- /dev/null +++ b/src/corelib/tools/qelapsedtimer_generic.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qelapsedtimer.h" +#include "qdatetime.h" + +QT_BEGIN_NAMESPACE + +bool QElapsedTimer::isMonotonic() +{ + return false; +} + +void QElapsedTimer::start() +{ + QTime t = QTime::currentTime(); + t1 = t.mds; + t2 = 0; +} + +qint64 QElapsedTimer::restart() +{ + QTime t = QTime::currentTime(); + qint64 old = t1; + t1 = t.mds; + return t1 - old; +} + +qint64 QElapsedTimer::elapsed() const +{ + QTime t = QTime::currentTime(); + return t.mds - t1; +} + +qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const +{ + qint64 diff = other.t1 - t1; + if (diff < 0) // passed midnight + diff += 86400 * 1000; + return diff; +} + +qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const +{ + return msecsTo(other) / 1000; +} + +bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) +{ + return v1.t1 < v2.t1; +} + +QT_END_NAMESPACE diff --git a/src/corelib/tools/qelapsedtimer_mac.cpp b/src/corelib/tools/qelapsedtimer_mac.cpp new file mode 100644 index 0000000..21a6d1b --- /dev/null +++ b/src/corelib/tools/qelapsedtimer_mac.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qelapsedtimer.h" +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +bool QElapsedTimer::isMonotonic() +{ + return true; +} + +static mach_timebase_info_data_t info = {0,0}; +static qint64 absoluteToNSecs(qint64 cpuTime) +{ + if (info.denom == 0) + mach_timebase_info(&info); + qint64 nsecs = cpuTime * info.numer / info.denom; + return nsecs; +} + +static qint64 absoluteToMSecs(qint64 cpuTime) +{ + return absoluteToNSecs(cpuTime) / 1000000; +} + +timeval qt_gettime() +{ + timeval tv; + + uint64_t cpu_time = mach_absolute_time(); + uint64_t nsecs = absoluteToNSecs(cpu_time); + tv.tv_sec = nsecs / 1000000000ull; + tv.tv_usec = (nsecs / 1000) - (tv.tv_sec * 1000000); + return tv; +} + +void QElapsedTimer::start() +{ + t1 = mach_absolute_time(); + t2 = 0; +} + +qint64 QElapsedTimer::restart() +{ + qint64 old = t1; + t1 = mach_absolute_time(); + + return absoluteToMSecs(t1 - old); +} + +qint64 QElapsedTimer::elapsed() const +{ + uint64_t cpu_time = mach_absolute_time(); + return absoluteToMSecs(cpu_time - t1); +} + +qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const +{ + return absoluteToMSecs(other.t1 - t1); +} + +qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const +{ + return msecsTo(other) / 1000; +} + +bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) +{ + return v1.t1 < v2.t1; +} + +QT_END_NAMESPACE diff --git a/src/corelib/tools/qelapsedtimer_symbian.cpp b/src/corelib/tools/qelapsedtimer_symbian.cpp new file mode 100644 index 0000000..1fbba65 --- /dev/null +++ b/src/corelib/tools/qelapsedtimer_symbian.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qelapsedtimer.h" +#include + +QT_BEGIN_NAMESPACE + +// return quint64 to avoid sign-extension +static quint64 getMillisecondFromTick() +{ + static TInt nanokernel_tick_period; + if (!nanokernel_tick_period) + HAL::Get(HAL::ENanoTickPeriod, nanokernel_tick_period); + return nanokernel_tick_period * User::NTickCount(); +} + +static qint64 difference(qint64 a, qint64 b) +{ + qint64 retval = a - b; + // there can be 32-bit rollover + // assume there were rollovers if the difference is negative by more than + // 75% of the 32-bit range + + if (retval < Q_INT64_C(-0xc0000000)) + retval += Q_UINT64_C(0x100000000); + return retval; +} + +bool QElapsedTimer::isMonotonic() +{ + return true; +} + +void QElapsedTimer::start() +{ + t1 = getMillisecondFromTick(); + t2 = 0; +} + +qint64 QElapsedTimer::restart() +{ + qint64 oldt1 = t1; + t1 = getMillisecondFromTick(); + return difference(t1, oldt1); +} + +qint64 QElapsedTimer::elapsed() const +{ + return difference(getMillisecondFromTick(), t1); +} + +qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const +{ + return difference(other.t1, t1); +} + +qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const +{ + return msecsTo(other) / 1000; +} + +bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) +{ + return difference(v1.t1, v2.t1) < 0; +} + +QT_END_NAMESPACE diff --git a/src/corelib/tools/qelapsedtimer_unix.cpp b/src/corelib/tools/qelapsedtimer_unix.cpp new file mode 100644 index 0000000..b8215f4 --- /dev/null +++ b/src/corelib/tools/qelapsedtimer_unix.cpp @@ -0,0 +1,169 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qelapsedtimer.h" +#include "qpair.h" +#include +#include +#include + +#if !defined(QT_NO_CLOCK_MONOTONIC) +# if defined(QT_BOOTSTRAPPED) +# define QT_NO_CLOCK_MONOTONIC +# endif +#endif + +QT_BEGIN_NAMESPACE + +static qint64 fractionAdjustment() +{ + if (QElapsedTimer::isMonotonic()) { + // the monotonic timer is measured in nanoseconds + // 1 ms = 1000000 ns + return 1000*1000ull; + } else { + // gettimeofday is measured in microseconds + // 1 ms = 1000 us + return 1000; + } +} + +bool QElapsedTimer::isMonotonic() +{ +#if (_POSIX_MONOTONIC_CLOCK-0 > 0) + return true; +#else + static int returnValue = 0; + + if (returnValue == 0) { +# if (_POSIX_MONOTONIC_CLOCK-0 < 0) + returnValue = -1; +# elif (_POSIX_MONOTONIC_CLOCK == 0) + // detect if the system support monotonic timers + long x = sysconf(_SC_MONOTONIC_CLOCK); + returnValue = (x >= 200112L) ? 1 : -1; +# endif + } + + return returnValue != -1; +#endif +} + +static inline QPair do_gettime() +{ +#if (_POSIX_MONOTONIC_CLOCK-0 > 0) + timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return qMakePair(ts.tv_sec, ts.tv_nsec); +#else +# if !defined(QT_NO_CLOCK_MONOTONIC) && !defined(QT_BOOTSTRAPPED) + if (QElapsedTimer::isMonotonic()) { + timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return qMakePair(ts.tv_sec, ts.tv_nsec); + } +# endif + // use gettimeofday + timeval tv; + ::gettimeofday(&tv, 0); + return qMakePair(tv.tv_sec, tv.tv_usec); +#endif +} + +// used in qcore_unix.cpp and qeventdispatcher_unix.cpp +timeval qt_gettime() +{ + QPair r = do_gettime(); + + timeval tv; + tv.tv_sec = r.first; + tv.tv_usec = r.second; + if (QElapsedTimer::isMonotonic()) + tv.tv_usec /= 1000; + + return tv; +} + +void QElapsedTimer::start() +{ + QPair r = do_gettime(); + t1 = r.first; + t2 = r.second; +} + +qint64 QElapsedTimer::restart() +{ + QPair r = do_gettime(); + qint64 oldt1 = t1; + qint64 oldt2 = t2; + t1 = r.first; + t2 = r.second; + + r.first -= oldt1; + r.second -= oldt2; + return r.first * 1000 + r.second / fractionAdjustment(); +} + +qint64 QElapsedTimer::elapsed() const +{ + QElapsedTimer now; + now.start(); + return msecsTo(now); +} + +qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const +{ + qint64 secs = other.t1 - t1; + qint64 fraction = other.t2 - t2; + return secs * 1000 + fraction / fractionAdjustment(); +} + +qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const +{ + return other.t1 - t1; +} + +bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) +{ + return v1.t1 < v2.t1 || (v1.t1 == v2.t1 && v1.t2 < v2.t2); +} + +QT_END_NAMESPACE diff --git a/src/corelib/tools/qelapsedtimer_win.cpp b/src/corelib/tools/qelapsedtimer_win.cpp new file mode 100644 index 0000000..e384dd8 --- /dev/null +++ b/src/corelib/tools/qelapsedtimer_win.cpp @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qelapsedtimer.h" +#include + +typedef ULONGLONG (WINAPI *PtrGetTickCount64)(void); +static PtrGetTickCount64 ptrGetTickCount64 = 0; + +QT_BEGIN_NAMESPACE + +static void resolveLibs() +{ + static bool done = false; + if (done) + return; + + // try to get GetTickCount64 from the system + HMODULE kernel32 = GetModuleHandleW(L"kernel32"); + if (!kernel32) + return; + +#if defined(Q_OS_WINCE) + // does this function exist on WinCE, or will ever exist? + ptrGetTickCount64 = (PtrGetTickCount64)GetProcAddress(kernel32, L"GetTickCount64"); +#else + ptrGetTickCount64 = (PtrGetTickCount64)GetProcAddress(kernel32, "GetTickCount64"); +#endif + + done = true; +} + +static quint64 getTickCount() +{ + resolveLibs(); + if (ptrGetTickCount64) + return ptrGetTickCount64(); + return GetTickCount(); +} + +static qint64 difference(qint64 a, qint64 b) +{ + qint64 retval = a - b; + // if we're not using GetTickCount64, then there can be 32-bit rollover + // assume there were rollovers if the difference is negative by more than + // 75% of the 32-bit range + + if (!ptrGetTickCount64 && retval < Q_INT64_C(-0xc0000000)) + retval += Q_UINT64_C(0x100000000); + return retval; +} + +bool QElapsedTimer::isMonotonic() +{ + return true; +} + +void QElapsedTimer::start() +{ + t1 = getTickCount(); + t2 = 0; +} + +qint64 QElapsedTimer::restart() +{ + qint64 oldt1 = t1; + t1 = getTickCount(); + return difference(t1, oldt1); +} + +qint64 QElapsedTimer::elapsed() const +{ + return difference(getTickCount(), t1); +} + +qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const +{ + return difference(other.t1, t1); +} + +qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const +{ + return msecsTo(other) / 1000; +} + +bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) +{ + return difference(v1.t1, v2.t1) < 0; +} + +QT_END_NAMESPACE diff --git a/src/corelib/tools/qtimestamp.cpp b/src/corelib/tools/qtimestamp.cpp deleted file mode 100644 index 220b108..0000000 --- a/src/corelib/tools/qtimestamp.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qelapsedtimer.h" - -QT_BEGIN_NAMESPACE - -static const qint64 invalidData = Q_INT64_C(0x8000000000000000); - -void QElapsedTimer::invalidate() -{ - t1 = t2 = invalidData; -} - -bool QElapsedTimer::isValid() const -{ - return t1 != invalidData && t2 != invalidData; -} - -bool QElapsedTimer::hasExpired(qint64 timeout) const -{ - // if timeout is -1, quint64(timeout) is LLINT_MAX, so this will be - // considered as never expired - return quint64(elapsed()) > quint64(timeout); -} - -QT_END_NAMESPACE diff --git a/src/corelib/tools/qtimestamp.h b/src/corelib/tools/qtimestamp.h deleted file mode 100644 index 4fa0ca5..0000000 --- a/src/corelib/tools/qtimestamp.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTIMESTAMP_H -#define QTIMESTAMP_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Core) - -class Q_CORE_EXPORT QElapsedTimer -{ -public: - static bool isMonotonic(); - - void start(); - qint64 restart(); - void invalidate(); - bool isValid() const; - - qint64 elapsed() const; - bool hasExpired(qint64 timeout) const; - - qint64 msecsTo(const QElapsedTimer &other) const; - qint64 secsTo(const QElapsedTimer &other) const; - - bool operator==(const QElapsedTimer &other) const - { return t1 == other.t1 && t2 == other.t2; } - bool operator!=(const QElapsedTimer &other) const - { return !(*this == other); } - - friend bool Q_CORE_EXPORT operator<(const QElapsedTimer &v1, const QElapsedTimer &v2); - -private: - qint64 t1; - qint64 t2; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QTIMESTAMP_H diff --git a/src/corelib/tools/qtimestamp_generic.cpp b/src/corelib/tools/qtimestamp_generic.cpp deleted file mode 100644 index a9c2233..0000000 --- a/src/corelib/tools/qtimestamp_generic.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qelapsedtimer.h" -#include "qdatetime.h" - -QT_BEGIN_NAMESPACE - -bool QElapsedTimer::isMonotonic() -{ - return false; -} - -void QElapsedTimer::start() -{ - QTime t = QTime::currentTime(); - t1 = t.mds; - t2 = 0; -} - -qint64 QElapsedTimer::restart() -{ - QTime t = QTime::currentTime(); - qint64 old = t1; - t1 = t.mds; - return t1 - old; -} - -qint64 QElapsedTimer::elapsed() const -{ - QTime t = QTime::currentTime(); - return t.mds - t1; -} - -qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const -{ - qint64 diff = other.t1 - t1; - if (diff < 0) // passed midnight - diff += 86400 * 1000; - return diff; -} - -qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const -{ - return msecsTo(other) / 1000; -} - -bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) -{ - return v1.t1 < v2.t1; -} - -QT_END_NAMESPACE diff --git a/src/corelib/tools/qtimestamp_mac.cpp b/src/corelib/tools/qtimestamp_mac.cpp deleted file mode 100644 index 21a6d1b..0000000 --- a/src/corelib/tools/qtimestamp_mac.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qelapsedtimer.h" -#include -#include - -#include - -QT_BEGIN_NAMESPACE - -bool QElapsedTimer::isMonotonic() -{ - return true; -} - -static mach_timebase_info_data_t info = {0,0}; -static qint64 absoluteToNSecs(qint64 cpuTime) -{ - if (info.denom == 0) - mach_timebase_info(&info); - qint64 nsecs = cpuTime * info.numer / info.denom; - return nsecs; -} - -static qint64 absoluteToMSecs(qint64 cpuTime) -{ - return absoluteToNSecs(cpuTime) / 1000000; -} - -timeval qt_gettime() -{ - timeval tv; - - uint64_t cpu_time = mach_absolute_time(); - uint64_t nsecs = absoluteToNSecs(cpu_time); - tv.tv_sec = nsecs / 1000000000ull; - tv.tv_usec = (nsecs / 1000) - (tv.tv_sec * 1000000); - return tv; -} - -void QElapsedTimer::start() -{ - t1 = mach_absolute_time(); - t2 = 0; -} - -qint64 QElapsedTimer::restart() -{ - qint64 old = t1; - t1 = mach_absolute_time(); - - return absoluteToMSecs(t1 - old); -} - -qint64 QElapsedTimer::elapsed() const -{ - uint64_t cpu_time = mach_absolute_time(); - return absoluteToMSecs(cpu_time - t1); -} - -qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const -{ - return absoluteToMSecs(other.t1 - t1); -} - -qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const -{ - return msecsTo(other) / 1000; -} - -bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) -{ - return v1.t1 < v2.t1; -} - -QT_END_NAMESPACE diff --git a/src/corelib/tools/qtimestamp_symbian.cpp b/src/corelib/tools/qtimestamp_symbian.cpp deleted file mode 100644 index 1fbba65..0000000 --- a/src/corelib/tools/qtimestamp_symbian.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qelapsedtimer.h" -#include - -QT_BEGIN_NAMESPACE - -// return quint64 to avoid sign-extension -static quint64 getMillisecondFromTick() -{ - static TInt nanokernel_tick_period; - if (!nanokernel_tick_period) - HAL::Get(HAL::ENanoTickPeriod, nanokernel_tick_period); - return nanokernel_tick_period * User::NTickCount(); -} - -static qint64 difference(qint64 a, qint64 b) -{ - qint64 retval = a - b; - // there can be 32-bit rollover - // assume there were rollovers if the difference is negative by more than - // 75% of the 32-bit range - - if (retval < Q_INT64_C(-0xc0000000)) - retval += Q_UINT64_C(0x100000000); - return retval; -} - -bool QElapsedTimer::isMonotonic() -{ - return true; -} - -void QElapsedTimer::start() -{ - t1 = getMillisecondFromTick(); - t2 = 0; -} - -qint64 QElapsedTimer::restart() -{ - qint64 oldt1 = t1; - t1 = getMillisecondFromTick(); - return difference(t1, oldt1); -} - -qint64 QElapsedTimer::elapsed() const -{ - return difference(getMillisecondFromTick(), t1); -} - -qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const -{ - return difference(other.t1, t1); -} - -qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const -{ - return msecsTo(other) / 1000; -} - -bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) -{ - return difference(v1.t1, v2.t1) < 0; -} - -QT_END_NAMESPACE diff --git a/src/corelib/tools/qtimestamp_unix.cpp b/src/corelib/tools/qtimestamp_unix.cpp deleted file mode 100644 index b8215f4..0000000 --- a/src/corelib/tools/qtimestamp_unix.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qelapsedtimer.h" -#include "qpair.h" -#include -#include -#include - -#if !defined(QT_NO_CLOCK_MONOTONIC) -# if defined(QT_BOOTSTRAPPED) -# define QT_NO_CLOCK_MONOTONIC -# endif -#endif - -QT_BEGIN_NAMESPACE - -static qint64 fractionAdjustment() -{ - if (QElapsedTimer::isMonotonic()) { - // the monotonic timer is measured in nanoseconds - // 1 ms = 1000000 ns - return 1000*1000ull; - } else { - // gettimeofday is measured in microseconds - // 1 ms = 1000 us - return 1000; - } -} - -bool QElapsedTimer::isMonotonic() -{ -#if (_POSIX_MONOTONIC_CLOCK-0 > 0) - return true; -#else - static int returnValue = 0; - - if (returnValue == 0) { -# if (_POSIX_MONOTONIC_CLOCK-0 < 0) - returnValue = -1; -# elif (_POSIX_MONOTONIC_CLOCK == 0) - // detect if the system support monotonic timers - long x = sysconf(_SC_MONOTONIC_CLOCK); - returnValue = (x >= 200112L) ? 1 : -1; -# endif - } - - return returnValue != -1; -#endif -} - -static inline QPair do_gettime() -{ -#if (_POSIX_MONOTONIC_CLOCK-0 > 0) - timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - return qMakePair(ts.tv_sec, ts.tv_nsec); -#else -# if !defined(QT_NO_CLOCK_MONOTONIC) && !defined(QT_BOOTSTRAPPED) - if (QElapsedTimer::isMonotonic()) { - timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - return qMakePair(ts.tv_sec, ts.tv_nsec); - } -# endif - // use gettimeofday - timeval tv; - ::gettimeofday(&tv, 0); - return qMakePair(tv.tv_sec, tv.tv_usec); -#endif -} - -// used in qcore_unix.cpp and qeventdispatcher_unix.cpp -timeval qt_gettime() -{ - QPair r = do_gettime(); - - timeval tv; - tv.tv_sec = r.first; - tv.tv_usec = r.second; - if (QElapsedTimer::isMonotonic()) - tv.tv_usec /= 1000; - - return tv; -} - -void QElapsedTimer::start() -{ - QPair r = do_gettime(); - t1 = r.first; - t2 = r.second; -} - -qint64 QElapsedTimer::restart() -{ - QPair r = do_gettime(); - qint64 oldt1 = t1; - qint64 oldt2 = t2; - t1 = r.first; - t2 = r.second; - - r.first -= oldt1; - r.second -= oldt2; - return r.first * 1000 + r.second / fractionAdjustment(); -} - -qint64 QElapsedTimer::elapsed() const -{ - QElapsedTimer now; - now.start(); - return msecsTo(now); -} - -qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const -{ - qint64 secs = other.t1 - t1; - qint64 fraction = other.t2 - t2; - return secs * 1000 + fraction / fractionAdjustment(); -} - -qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const -{ - return other.t1 - t1; -} - -bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) -{ - return v1.t1 < v2.t1 || (v1.t1 == v2.t1 && v1.t2 < v2.t2); -} - -QT_END_NAMESPACE diff --git a/src/corelib/tools/qtimestamp_win.cpp b/src/corelib/tools/qtimestamp_win.cpp deleted file mode 100644 index e384dd8..0000000 --- a/src/corelib/tools/qtimestamp_win.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qelapsedtimer.h" -#include - -typedef ULONGLONG (WINAPI *PtrGetTickCount64)(void); -static PtrGetTickCount64 ptrGetTickCount64 = 0; - -QT_BEGIN_NAMESPACE - -static void resolveLibs() -{ - static bool done = false; - if (done) - return; - - // try to get GetTickCount64 from the system - HMODULE kernel32 = GetModuleHandleW(L"kernel32"); - if (!kernel32) - return; - -#if defined(Q_OS_WINCE) - // does this function exist on WinCE, or will ever exist? - ptrGetTickCount64 = (PtrGetTickCount64)GetProcAddress(kernel32, L"GetTickCount64"); -#else - ptrGetTickCount64 = (PtrGetTickCount64)GetProcAddress(kernel32, "GetTickCount64"); -#endif - - done = true; -} - -static quint64 getTickCount() -{ - resolveLibs(); - if (ptrGetTickCount64) - return ptrGetTickCount64(); - return GetTickCount(); -} - -static qint64 difference(qint64 a, qint64 b) -{ - qint64 retval = a - b; - // if we're not using GetTickCount64, then there can be 32-bit rollover - // assume there were rollovers if the difference is negative by more than - // 75% of the 32-bit range - - if (!ptrGetTickCount64 && retval < Q_INT64_C(-0xc0000000)) - retval += Q_UINT64_C(0x100000000); - return retval; -} - -bool QElapsedTimer::isMonotonic() -{ - return true; -} - -void QElapsedTimer::start() -{ - t1 = getTickCount(); - t2 = 0; -} - -qint64 QElapsedTimer::restart() -{ - qint64 oldt1 = t1; - t1 = getTickCount(); - return difference(t1, oldt1); -} - -qint64 QElapsedTimer::elapsed() const -{ - return difference(getTickCount(), t1); -} - -qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const -{ - return difference(other.t1, t1); -} - -qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const -{ - return msecsTo(other) / 1000; -} - -bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) -{ - return difference(v1.t1, v2.t1) < 0; -} - -QT_END_NAMESPACE diff --git a/tests/auto/qelapsedtimer/qelapsedtimer.pro b/tests/auto/qelapsedtimer/qelapsedtimer.pro new file mode 100644 index 0000000..3a06390 --- /dev/null +++ b/tests/auto/qelapsedtimer/qelapsedtimer.pro @@ -0,0 +1,13 @@ +load(qttest_p4) +QT -= gui + +SOURCES += tst_qtimestamp.cpp +wince* { + DEFINES += SRCDIR=\\\"\\\" +} else:symbian { + # do not define SRCDIR at all + TARGET.EPOCHEAPSIZE = 0x100000 0x3000000 +} else { + DEFINES += SRCDIR=\\\"$$PWD/\\\" +} + diff --git a/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp b/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp new file mode 100644 index 0000000..79138ce --- /dev/null +++ b/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp @@ -0,0 +1,94 @@ +#include +#include +#include +#include + +static const int minResolution = 50; // the minimum resolution for the tests + +class tst_QTimestamp : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void validity(); + void basics(); + void elapsed(); +}; + +void tst_QTimestamp::validity() +{ + QTimestamp t; + + t.invalidate(); + QVERIFY(!t.isValid()); + + t.start(); + QVERIFY(t.isValid()); + + t.invalidate(); + QVERIFY(!t.isValid()); +} + +void tst_QTimestamp::basics() +{ + QTimestamp t1; + t1.start(); + + QCOMPARE(t1, t1); + QVERIFY(!(t1 != t1)); + QVERIFY(!(t1 < t1)); + QCOMPARE(t1.msecsTo(t1), qint64(0)); + QCOMPARE(t1.secsTo(t1), qint64(0)); + QCOMPARE(t1 + 0, t1); + QCOMPARE(t1 - 0, t1); + + QTimestamp t2 = t1; + t2 += 1000; // so we can use secsTo + + QVERIFY(t1 != t2); + QVERIFY(!(t1 == t2)); + QVERIFY(t1 < t2); + QVERIFY(!(t2 < t1)); + QCOMPARE(t1.msecsTo(t2), qint64(1000)); + QCOMPARE(t1.secsTo(t2), qint64(1)); + QCOMPARE(t2 - t1, qint64(1000)); + QCOMPARE(t1 - t2, qint64(-1000)); + + qint64 elapsed = t1.restart(); + QVERIFY(elapsed < minResolution); +} + +void tst_QTimestamp::elapsed() +{ + QTimestamp t1; + t1.start(); + + QTest::qSleep(4*minResolution); + QTimestamp t2; + t2.start(); + + QVERIFY(t1 != t2); + QVERIFY(!(t1 == t2)); + QVERIFY(t1 < t2); + QVERIFY(t1.msecsTo(t2) > 0); + // don't check: t1.secsTo(t2) + QVERIFY(t1 - t2 < 0); + + QVERIFY(t1.elapsed() > 0); + QVERIFY(t1.hasExpired(minResolution)); + QVERIFY(!t1.hasExpired(8*minResolution)); + QVERIFY(!t2.hasExpired(minResolution)); + + QVERIFY(!t1.hasExpired(-1)); + QVERIFY(!t2.hasExpired(-1)); + + qint64 elapsed = t1.restart(); + QVERIFY(elapsed > 3*minResolution); + QVERIFY(elapsed < 5*minResolution); + qint64 diff = t1 - t2; + QVERIFY(diff < minResolution); +} + +QTEST_MAIN(tst_QTimestamp); + +#include "tst_qtimestamp.moc" diff --git a/tests/auto/qtimestamp/qtimestamp.pro b/tests/auto/qtimestamp/qtimestamp.pro deleted file mode 100644 index 3a06390..0000000 --- a/tests/auto/qtimestamp/qtimestamp.pro +++ /dev/null @@ -1,13 +0,0 @@ -load(qttest_p4) -QT -= gui - -SOURCES += tst_qtimestamp.cpp -wince* { - DEFINES += SRCDIR=\\\"\\\" -} else:symbian { - # do not define SRCDIR at all - TARGET.EPOCHEAPSIZE = 0x100000 0x3000000 -} else { - DEFINES += SRCDIR=\\\"$$PWD/\\\" -} - diff --git a/tests/auto/qtimestamp/tst_qtimestamp.cpp b/tests/auto/qtimestamp/tst_qtimestamp.cpp deleted file mode 100644 index 79138ce..0000000 --- a/tests/auto/qtimestamp/tst_qtimestamp.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include -#include -#include -#include - -static const int minResolution = 50; // the minimum resolution for the tests - -class tst_QTimestamp : public QObject -{ - Q_OBJECT - -private Q_SLOTS: - void validity(); - void basics(); - void elapsed(); -}; - -void tst_QTimestamp::validity() -{ - QTimestamp t; - - t.invalidate(); - QVERIFY(!t.isValid()); - - t.start(); - QVERIFY(t.isValid()); - - t.invalidate(); - QVERIFY(!t.isValid()); -} - -void tst_QTimestamp::basics() -{ - QTimestamp t1; - t1.start(); - - QCOMPARE(t1, t1); - QVERIFY(!(t1 != t1)); - QVERIFY(!(t1 < t1)); - QCOMPARE(t1.msecsTo(t1), qint64(0)); - QCOMPARE(t1.secsTo(t1), qint64(0)); - QCOMPARE(t1 + 0, t1); - QCOMPARE(t1 - 0, t1); - - QTimestamp t2 = t1; - t2 += 1000; // so we can use secsTo - - QVERIFY(t1 != t2); - QVERIFY(!(t1 == t2)); - QVERIFY(t1 < t2); - QVERIFY(!(t2 < t1)); - QCOMPARE(t1.msecsTo(t2), qint64(1000)); - QCOMPARE(t1.secsTo(t2), qint64(1)); - QCOMPARE(t2 - t1, qint64(1000)); - QCOMPARE(t1 - t2, qint64(-1000)); - - qint64 elapsed = t1.restart(); - QVERIFY(elapsed < minResolution); -} - -void tst_QTimestamp::elapsed() -{ - QTimestamp t1; - t1.start(); - - QTest::qSleep(4*minResolution); - QTimestamp t2; - t2.start(); - - QVERIFY(t1 != t2); - QVERIFY(!(t1 == t2)); - QVERIFY(t1 < t2); - QVERIFY(t1.msecsTo(t2) > 0); - // don't check: t1.secsTo(t2) - QVERIFY(t1 - t2 < 0); - - QVERIFY(t1.elapsed() > 0); - QVERIFY(t1.hasExpired(minResolution)); - QVERIFY(!t1.hasExpired(8*minResolution)); - QVERIFY(!t2.hasExpired(minResolution)); - - QVERIFY(!t1.hasExpired(-1)); - QVERIFY(!t2.hasExpired(-1)); - - qint64 elapsed = t1.restart(); - QVERIFY(elapsed > 3*minResolution); - QVERIFY(elapsed < 5*minResolution); - qint64 diff = t1 - t2; - QVERIFY(diff < minResolution); -} - -QTEST_MAIN(tst_QTimestamp); - -#include "tst_qtimestamp.moc" -- cgit v0.12 From bc88d38905a80b2a025acf5b52858264c0ef0d39 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 26 Feb 2010 15:10:19 +0100 Subject: Autotest: Rename the test to match the new class name --- tests/auto/qelapsedtimer/qelapsedtimer.pro | 2 +- tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/auto/qelapsedtimer/qelapsedtimer.pro b/tests/auto/qelapsedtimer/qelapsedtimer.pro index 3a06390..ed75228 100644 --- a/tests/auto/qelapsedtimer/qelapsedtimer.pro +++ b/tests/auto/qelapsedtimer/qelapsedtimer.pro @@ -1,7 +1,7 @@ load(qttest_p4) QT -= gui -SOURCES += tst_qtimestamp.cpp +SOURCES += tst_qelapsedtimer.cpp wince* { DEFINES += SRCDIR=\\\"\\\" } else:symbian { diff --git a/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp b/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp index 79138ce..d671d1b 100644 --- a/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp +++ b/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp @@ -1,11 +1,11 @@ #include #include -#include +#include #include static const int minResolution = 50; // the minimum resolution for the tests -class tst_QTimestamp : public QObject +class tst_QElapsedTimer : public QObject { Q_OBJECT @@ -15,9 +15,9 @@ private Q_SLOTS: void elapsed(); }; -void tst_QTimestamp::validity() +void tst_QElapsedTimer::validity() { - QTimestamp t; + QElapsedTimer t; t.invalidate(); QVERIFY(!t.isValid()); @@ -29,9 +29,9 @@ void tst_QTimestamp::validity() QVERIFY(!t.isValid()); } -void tst_QTimestamp::basics() +void tst_QElapsedTimer::basics() { - QTimestamp t1; + QElapsedTimer t1; t1.start(); QCOMPARE(t1, t1); @@ -42,7 +42,7 @@ void tst_QTimestamp::basics() QCOMPARE(t1 + 0, t1); QCOMPARE(t1 - 0, t1); - QTimestamp t2 = t1; + QElapsedTimer t2 = t1; t2 += 1000; // so we can use secsTo QVERIFY(t1 != t2); @@ -58,13 +58,13 @@ void tst_QTimestamp::basics() QVERIFY(elapsed < minResolution); } -void tst_QTimestamp::elapsed() +void tst_QElapsedTimer::elapsed() { - QTimestamp t1; + QElapsedTimer t1; t1.start(); QTest::qSleep(4*minResolution); - QTimestamp t2; + QElapsedTimer t2; t2.start(); QVERIFY(t1 != t2); @@ -89,6 +89,6 @@ void tst_QTimestamp::elapsed() QVERIFY(diff < minResolution); } -QTEST_MAIN(tst_QTimestamp); +QTEST_MAIN(tst_QElapsedTimer); -#include "tst_qtimestamp.moc" +#include "tst_qelapsedtimer.moc" -- cgit v0.12 From 047090b2b7af7e5a3b88615dafed9d4d957fbe6e Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 26 Feb 2010 16:29:47 +0100 Subject: Add a couple of extra functions to QElapsedTimer --- src/corelib/tools/qelapsedtimer.h | 13 ++++++++++ src/corelib/tools/qelapsedtimer_generic.cpp | 29 +++++++++++++++------- src/corelib/tools/qelapsedtimer_mac.cpp | 11 +++++++++ src/corelib/tools/qelapsedtimer_symbian.cpp | 10 ++++++++ src/corelib/tools/qelapsedtimer_unix.cpp | 14 +++++++++-- src/corelib/tools/qelapsedtimer_win.cpp | 10 ++++++++ tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp | 33 +++++++++++++++++++++----- 7 files changed, 103 insertions(+), 17 deletions(-) diff --git a/src/corelib/tools/qelapsedtimer.h b/src/corelib/tools/qelapsedtimer.h index 4fa0ca5..827359b 100644 --- a/src/corelib/tools/qelapsedtimer.h +++ b/src/corelib/tools/qelapsedtimer.h @@ -53,8 +53,20 @@ QT_MODULE(Core) class Q_CORE_EXPORT QElapsedTimer { public: + enum ClockType { + SystemTime, + MonotonicClock, + TickCounter, + MachAbsoluteTime + }; + static ClockType clockType(); static bool isMonotonic(); + static inline QElapsedTimer started() + { QElapsedTimer t; t.start(); return t; } + static inline QElapsedTimer invalid() + { QElapsedTimer t; t.invalidate(); return t; } + void start(); qint64 restart(); void invalidate(); @@ -63,6 +75,7 @@ public: qint64 elapsed() const; bool hasExpired(qint64 timeout) const; + qint64 msecsSinceReference() const; qint64 msecsTo(const QElapsedTimer &other) const; qint64 secsTo(const QElapsedTimer &other) const; diff --git a/src/corelib/tools/qelapsedtimer_generic.cpp b/src/corelib/tools/qelapsedtimer_generic.cpp index a9c2233..db6da46 100644 --- a/src/corelib/tools/qelapsedtimer_generic.cpp +++ b/src/corelib/tools/qelapsedtimer_generic.cpp @@ -44,6 +44,17 @@ QT_BEGIN_NAMESPACE +static qint64 currentDateTimeMsec() +{ + QDateTime t = QDateTime::currentDateTime(); + return t.toTime_t() * Q_INT64_C(1000) + t.time().msec(); +} + +QElapsedTimer::ClockType QElapsedTimer::clockType() +{ + return SystemTime; +} + bool QElapsedTimer::isMonotonic() { return false; @@ -51,30 +62,30 @@ bool QElapsedTimer::isMonotonic() void QElapsedTimer::start() { - QTime t = QTime::currentTime(); - t1 = t.mds; - t2 = 0; + restart(); } qint64 QElapsedTimer::restart() { - QTime t = QTime::currentTime(); qint64 old = t1; - t1 = t.mds; + t1 = currentDateTimeMsec(); + t2 = 0; return t1 - old; } qint64 QElapsedTimer::elapsed() const { - QTime t = QTime::currentTime(); - return t.mds - t1; + return currentDateTimeMsec() - t1; +} + +qint64 QElapsedTimer::msecsSinceReference() const +{ + return t1; } qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const { qint64 diff = other.t1 - t1; - if (diff < 0) // passed midnight - diff += 86400 * 1000; return diff; } diff --git a/src/corelib/tools/qelapsedtimer_mac.cpp b/src/corelib/tools/qelapsedtimer_mac.cpp index 21a6d1b..4a62761 100644 --- a/src/corelib/tools/qelapsedtimer_mac.cpp +++ b/src/corelib/tools/qelapsedtimer_mac.cpp @@ -47,6 +47,11 @@ QT_BEGIN_NAMESPACE +QElapsedTimer::ClockType QElapsedTimer::clockType() +{ + return MachAbsoluteTime; +} + bool QElapsedTimer::isMonotonic() { return true; @@ -87,6 +92,7 @@ qint64 QElapsedTimer::restart() { qint64 old = t1; t1 = mach_absolute_time(); + t2 = 0; return absoluteToMSecs(t1 - old); } @@ -97,6 +103,11 @@ qint64 QElapsedTimer::elapsed() const return absoluteToMSecs(cpu_time - t1); } +qint64 QElapsedTimer::msecsSinceReference() +{ + return absoluteToMSecs(t1); +} + qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const { return absoluteToMSecs(other.t1 - t1); diff --git a/src/corelib/tools/qelapsedtimer_symbian.cpp b/src/corelib/tools/qelapsedtimer_symbian.cpp index 1fbba65..06e6f99 100644 --- a/src/corelib/tools/qelapsedtimer_symbian.cpp +++ b/src/corelib/tools/qelapsedtimer_symbian.cpp @@ -53,6 +53,11 @@ static quint64 getMillisecondFromTick() return nanokernel_tick_period * User::NTickCount(); } +QElapsedTimer::ClockType QElapsedTimer::clockType() +{ + return TickCounter; +} + static qint64 difference(qint64 a, qint64 b) { qint64 retval = a - b; @@ -88,6 +93,11 @@ qint64 QElapsedTimer::elapsed() const return difference(getMillisecondFromTick(), t1); } +qint64 QElapsedTimer::msecsSinceReference() const +{ + return t1; +} + qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const { return difference(other.t1, t1); diff --git a/src/corelib/tools/qelapsedtimer_unix.cpp b/src/corelib/tools/qelapsedtimer_unix.cpp index b8215f4..85d7fa8 100644 --- a/src/corelib/tools/qelapsedtimer_unix.cpp +++ b/src/corelib/tools/qelapsedtimer_unix.cpp @@ -87,6 +87,11 @@ bool QElapsedTimer::isMonotonic() #endif } +QElapsedTimer::ClockType QElapsedTimer::clockType() +{ + return isMonotonic() ? MonotonicClock : SystemTime; +} + static inline QPair do_gettime() { #if (_POSIX_MONOTONIC_CLOCK-0 > 0) @@ -139,7 +144,7 @@ qint64 QElapsedTimer::restart() r.first -= oldt1; r.second -= oldt2; - return r.first * 1000 + r.second / fractionAdjustment(); + return r.first * Q_INT64_C(1000) + r.second / fractionAdjustment(); } qint64 QElapsedTimer::elapsed() const @@ -149,11 +154,16 @@ qint64 QElapsedTimer::elapsed() const return msecsTo(now); } +qint64 QElapsedTimer::msecsSinceReference() const +{ + return t1 * Q_INT64_C(1000) + t2 / fractionAdjustment(); +} + qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const { qint64 secs = other.t1 - t1; qint64 fraction = other.t2 - t2; - return secs * 1000 + fraction / fractionAdjustment(); + return secs * Q_INT64_C(1000) + fraction / fractionAdjustment(); } qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const diff --git a/src/corelib/tools/qelapsedtimer_win.cpp b/src/corelib/tools/qelapsedtimer_win.cpp index e384dd8..ce37fa2 100644 --- a/src/corelib/tools/qelapsedtimer_win.cpp +++ b/src/corelib/tools/qelapsedtimer_win.cpp @@ -76,6 +76,11 @@ static quint64 getTickCount() return GetTickCount(); } +QElapsedTimer::ClockType QElapsedTimer::clockType() +{ + return TickCounter; +} + static qint64 difference(qint64 a, qint64 b) { qint64 retval = a - b; @@ -111,6 +116,11 @@ qint64 QElapsedTimer::elapsed() const return difference(getTickCount(), t1); } +qint64 QElapsedTimer::msecsSinceReference() const +{ + return t1; +} + qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const { return difference(other.t1, t1); diff --git a/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp b/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp index d671d1b..5f797a3 100644 --- a/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp +++ b/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp @@ -10,11 +10,19 @@ class tst_QElapsedTimer : public QObject Q_OBJECT private Q_SLOTS: + void statics(); void validity(); void basics(); void elapsed(); }; +void tst_QElapsedTimer::statics() +{ + qDebug() << "Clock type is" << QElapsedTimer::clockType(); + qDebug() << "Said clock is" << (QElapsedTimer::isMonotonic() ? "monotonic" : "not monotonic"); + qDebug() << "Current time is" << QElapsedTimer::started().msecsSinceReference(); +} + void tst_QElapsedTimer::validity() { QElapsedTimer t; @@ -27,6 +35,12 @@ void tst_QElapsedTimer::validity() t.invalidate(); QVERIFY(!t.isValid()); + + t = QElapsedTimer::started(); + QVERIFY(t.isValid()); + + t = QElapsedTimer::invalid(); + QVERIFY(!t.isValid()); } void tst_QElapsedTimer::basics() @@ -34,14 +48,17 @@ void tst_QElapsedTimer::basics() QElapsedTimer t1; t1.start(); + QVERIFY(t1.msecsSinceReference() != 0); + QCOMPARE(t1, t1); QVERIFY(!(t1 != t1)); QVERIFY(!(t1 < t1)); QCOMPARE(t1.msecsTo(t1), qint64(0)); QCOMPARE(t1.secsTo(t1), qint64(0)); - QCOMPARE(t1 + 0, t1); - QCOMPARE(t1 - 0, t1); +// QCOMPARE(t1 + 0, t1); +// QCOMPARE(t1 - 0, t1); +#if 0 QElapsedTimer t2 = t1; t2 += 1000; // so we can use secsTo @@ -51,10 +68,14 @@ void tst_QElapsedTimer::basics() QVERIFY(!(t2 < t1)); QCOMPARE(t1.msecsTo(t2), qint64(1000)); QCOMPARE(t1.secsTo(t2), qint64(1)); - QCOMPARE(t2 - t1, qint64(1000)); - QCOMPARE(t1 - t2, qint64(-1000)); +// QCOMPARE(t2 - t1, qint64(1000)); +// QCOMPARE(t1 - t2, qint64(-1000)); +#endif + quint64 value1 = t1.msecsSinceReference(); qint64 elapsed = t1.restart(); + quint64 value2 = t1.msecsSinceReference(); + QCOMPARE(elapsed, qint64(value2 - value1)); QVERIFY(elapsed < minResolution); } @@ -72,7 +93,7 @@ void tst_QElapsedTimer::elapsed() QVERIFY(t1 < t2); QVERIFY(t1.msecsTo(t2) > 0); // don't check: t1.secsTo(t2) - QVERIFY(t1 - t2 < 0); +// QVERIFY(t1 - t2 < 0); QVERIFY(t1.elapsed() > 0); QVERIFY(t1.hasExpired(minResolution)); @@ -85,7 +106,7 @@ void tst_QElapsedTimer::elapsed() qint64 elapsed = t1.restart(); QVERIFY(elapsed > 3*minResolution); QVERIFY(elapsed < 5*minResolution); - qint64 diff = t1 - t2; + qint64 diff = t2.msecsTo(t1); QVERIFY(diff < minResolution); } -- cgit v0.12 From 873305b9d85de44fc9e2150697822c8d3ccdef65 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 26 Feb 2010 16:30:43 +0100 Subject: Change the 32-bit rollover on Windows and Symbian to be more efficient. If it rolls over, then the newer value will be lower than the older one. So just add 2^32 to the value and we'll have proper calculations. --- src/corelib/tools/qelapsedtimer_symbian.cpp | 31 +++++++++++++---------------- src/corelib/tools/qelapsedtimer_win.cpp | 30 ++++++++++++---------------- 2 files changed, 27 insertions(+), 34 deletions(-) diff --git a/src/corelib/tools/qelapsedtimer_symbian.cpp b/src/corelib/tools/qelapsedtimer_symbian.cpp index 06e6f99..6360dbf 100644 --- a/src/corelib/tools/qelapsedtimer_symbian.cpp +++ b/src/corelib/tools/qelapsedtimer_symbian.cpp @@ -50,7 +50,15 @@ static quint64 getMillisecondFromTick() static TInt nanokernel_tick_period; if (!nanokernel_tick_period) HAL::Get(HAL::ENanoTickPeriod, nanokernel_tick_period); - return nanokernel_tick_period * User::NTickCount(); + + static quint32 highdword = 0; + static quint32 lastval = 0; + quint32 val = User::NTickCount(); + if (val < lastval) + ++highdword; + lastval = val; + + return nanokernel_tick_period * (val | (quint64(highdword) << 32)); } QElapsedTimer::ClockType QElapsedTimer::clockType() @@ -58,18 +66,6 @@ QElapsedTimer::ClockType QElapsedTimer::clockType() return TickCounter; } -static qint64 difference(qint64 a, qint64 b) -{ - qint64 retval = a - b; - // there can be 32-bit rollover - // assume there were rollovers if the difference is negative by more than - // 75% of the 32-bit range - - if (retval < Q_INT64_C(-0xc0000000)) - retval += Q_UINT64_C(0x100000000); - return retval; -} - bool QElapsedTimer::isMonotonic() { return true; @@ -85,12 +81,13 @@ qint64 QElapsedTimer::restart() { qint64 oldt1 = t1; t1 = getMillisecondFromTick(); - return difference(t1, oldt1); + t2 = 0; + return t1 - oldt1; } qint64 QElapsedTimer::elapsed() const { - return difference(getMillisecondFromTick(), t1); + return getMillisecondFromTick() - t1; } qint64 QElapsedTimer::msecsSinceReference() const @@ -100,7 +97,7 @@ qint64 QElapsedTimer::msecsSinceReference() const qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const { - return difference(other.t1, t1); + return other.t1 - t1; } qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const @@ -110,7 +107,7 @@ qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) { - return difference(v1.t1, v2.t1) < 0; + return (v1.t1 - v2.t1) < 0; } QT_END_NAMESPACE diff --git a/src/corelib/tools/qelapsedtimer_win.cpp b/src/corelib/tools/qelapsedtimer_win.cpp index ce37fa2..135196a 100644 --- a/src/corelib/tools/qelapsedtimer_win.cpp +++ b/src/corelib/tools/qelapsedtimer_win.cpp @@ -73,7 +73,14 @@ static quint64 getTickCount() resolveLibs(); if (ptrGetTickCount64) return ptrGetTickCount64(); - return GetTickCount(); + + static quint32 highdword = 0; + static quint32 lastval = 0; + quint32 val = GetTickCount(); + if (val < lastval) + ++highdword; + lastval = val; + return val | (quint64(highdword) << 32); } QElapsedTimer::ClockType QElapsedTimer::clockType() @@ -81,18 +88,6 @@ QElapsedTimer::ClockType QElapsedTimer::clockType() return TickCounter; } -static qint64 difference(qint64 a, qint64 b) -{ - qint64 retval = a - b; - // if we're not using GetTickCount64, then there can be 32-bit rollover - // assume there were rollovers if the difference is negative by more than - // 75% of the 32-bit range - - if (!ptrGetTickCount64 && retval < Q_INT64_C(-0xc0000000)) - retval += Q_UINT64_C(0x100000000); - return retval; -} - bool QElapsedTimer::isMonotonic() { return true; @@ -108,12 +103,13 @@ qint64 QElapsedTimer::restart() { qint64 oldt1 = t1; t1 = getTickCount(); - return difference(t1, oldt1); + t2 = 0; + return t1 - oldt1; } qint64 QElapsedTimer::elapsed() const { - return difference(getTickCount(), t1); + return getTickCount() - t1; } qint64 QElapsedTimer::msecsSinceReference() const @@ -123,7 +119,7 @@ qint64 QElapsedTimer::msecsSinceReference() const qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const { - return difference(other.t1, t1); + return other.t1 - t1; } qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const @@ -133,7 +129,7 @@ qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) { - return difference(v1.t1, v2.t1) < 0; + return (v1.t1 - v2.t1) < 0; } QT_END_NAMESPACE -- cgit v0.12 From 06ffa232f1920fa5aa857e644df08ef52b62a0b3 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 1 Mar 2010 16:51:09 +0100 Subject: remove, fixup --- src/corelib/tools/qelapsedtimer.h | 5 ----- tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp | 10 +++------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/corelib/tools/qelapsedtimer.h b/src/corelib/tools/qelapsedtimer.h index 827359b..0d6f0be 100644 --- a/src/corelib/tools/qelapsedtimer.h +++ b/src/corelib/tools/qelapsedtimer.h @@ -62,11 +62,6 @@ public: static ClockType clockType(); static bool isMonotonic(); - static inline QElapsedTimer started() - { QElapsedTimer t; t.start(); return t; } - static inline QElapsedTimer invalid() - { QElapsedTimer t; t.invalidate(); return t; } - void start(); qint64 restart(); void invalidate(); diff --git a/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp b/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp index 5f797a3..5c3d4f8 100644 --- a/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp +++ b/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp @@ -20,7 +20,9 @@ void tst_QElapsedTimer::statics() { qDebug() << "Clock type is" << QElapsedTimer::clockType(); qDebug() << "Said clock is" << (QElapsedTimer::isMonotonic() ? "monotonic" : "not monotonic"); - qDebug() << "Current time is" << QElapsedTimer::started().msecsSinceReference(); + QElapsedTimer t; + t.start(); + qDebug() << "Current time is" << t.msecsSinceReference(); } void tst_QElapsedTimer::validity() @@ -35,12 +37,6 @@ void tst_QElapsedTimer::validity() t.invalidate(); QVERIFY(!t.isValid()); - - t = QElapsedTimer::started(); - QVERIFY(t.isValid()); - - t = QElapsedTimer::invalid(); - QVERIFY(!t.isValid()); } void tst_QElapsedTimer::basics() -- cgit v0.12 From 73d10fd0813b19ad71e76419d78bf6e2dfd312d7 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 1 Mar 2010 16:52:36 +0100 Subject: Add QDateTime::currentDateTimeUtc and QDateTime::currentMsecsSinceEpoch --- src/corelib/tools/qdatetime.cpp | 353 +++++++++++++++++++--------- src/corelib/tools/qdatetime.h | 3 +- src/corelib/tools/qelapsedtimer_generic.cpp | 10 +- src/corelib/tools/tools.pri | 3 +- tests/auto/qdatetime/tst_qdatetime.cpp | 75 ++++++ 5 files changed, 328 insertions(+), 116 deletions(-) diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index c1027ed..7e03777 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -98,18 +98,23 @@ static inline QDate fixedDate(int y, int m, int d) return result; } +static inline uint julianDayFromGregorianDate(int year, int month, int day) +{ + // Gregorian calendar starting from October 15, 1582 + // Algorithm from Henry F. Fliegel and Thomas C. Van Flandern + return (1461 * (year + 4800 + (month - 14) / 12)) / 4 + + (367 * (month - 2 - 12 * ((month - 14) / 12))) / 12 + - (3 * ((year + 4900 + (month - 14) / 12) / 100)) / 4 + + day - 32075; +} + static uint julianDayFromDate(int year, int month, int day) { if (year < 0) ++year; if (year > 1582 || (year == 1582 && (month > 10 || (month == 10 && day >= 15)))) { - // Gregorian calendar starting from October 15, 1582 - // Algorithm from Henry F. Fliegel and Thomas C. Van Flandern - return (1461 * (year + 4800 + (month - 14) / 12)) / 4 - + (367 * (month - 2 - 12 * ((month - 14) / 12))) / 12 - - (3 * ((year + 4900 + (month - 14) / 12) / 100)) / 4 - + day - 32075; + return julianDayFromGregorianDate(year, month, day); } else if (year < 1582 || (year == 1582 && (month < 10 || (month == 10 && day <= 4)))) { // Julian calendar until October 4, 1582 // Algorithm from Frequently Asked Questions about Calendars by Claus Toendering @@ -1118,46 +1123,12 @@ int QDate::daysTo(const QDate &d) const */ /*! - \overload + \fn QDate::currentDate() Returns the current date, as reported by the system clock. \sa QTime::currentTime(), QDateTime::currentDateTime() */ -QDate QDate::currentDate() -{ - QDate d; -#if defined(Q_OS_WIN) - SYSTEMTIME st; - memset(&st, 0, sizeof(SYSTEMTIME)); - GetLocalTime(&st); - d.jd = julianDayFromDate(st.wYear, st.wMonth, st.wDay); -#elif defined(Q_OS_SYMBIAN) - TTime localTime; - localTime.HomeTime(); - TDateTime localDateTime = localTime.DateTime(); - // months and days are zero indexed - d.jd = julianDayFromDate(localDateTime.Year(), localDateTime.Month() + 1, localDateTime.Day() + 1 ); -#else - // posix compliant system - time_t ltime; - time(<ime); - tm *t = 0; - -#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) - // use the reentrant version of localtime() where available - tzset(); - tm res; - t = localtime_r(<ime, &res); -#else - t = localtime(<ime); -#endif // !QT_NO_THREAD && _POSIX_THREAD_SAFE_FUNCTIONS - - d.jd = julianDayFromDate(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday); -#endif - return d; -} - #ifndef QT_NO_DATESTRING /*! \fn QDate QDate::fromString(const QString &string, Qt::DateFormat format) @@ -1812,7 +1783,7 @@ int QTime::msecsTo(const QTime &t) const */ /*! - \overload + \fn QTime::currentTime() Returns the current time as reported by the system clock. @@ -1820,53 +1791,6 @@ int QTime::msecsTo(const QTime &t) const operating system; not all systems provide 1-millisecond accuracy. */ -QTime QTime::currentTime() -{ - QTime ct; - -#if defined(Q_OS_WIN) - SYSTEMTIME st; - memset(&st, 0, sizeof(SYSTEMTIME)); - GetLocalTime(&st); - ct.mds = MSECS_PER_HOUR * st.wHour + MSECS_PER_MIN * st.wMinute + 1000 * st.wSecond - + st.wMilliseconds; -#if defined(Q_OS_WINCE) - ct.startTick = GetTickCount() % MSECS_PER_DAY; -#endif -#elif defined(Q_OS_SYMBIAN) - TTime localTime; - localTime.HomeTime(); - TDateTime localDateTime = localTime.DateTime(); - ct.mds = MSECS_PER_HOUR * localDateTime.Hour() + MSECS_PER_MIN * localDateTime.Minute() - + 1000 * localDateTime.Second() + (localDateTime.MicroSecond() / 1000); -#elif defined(Q_OS_UNIX) - // posix compliant system - struct timeval tv; - gettimeofday(&tv, 0); - time_t ltime = tv.tv_sec; - tm *t = 0; - -#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) - // use the reentrant version of localtime() where available - tzset(); - tm res; - t = localtime_r(<ime, &res); -#else - t = localtime(<ime); -#endif - Q_CHECK_PTR(t); - - ct.mds = MSECS_PER_HOUR * t->tm_hour + MSECS_PER_MIN * t->tm_min + 1000 * t->tm_sec - + tv.tv_usec / 1000; -#else - time_t ltime; // no millisecond resolution - ::time(<ime); - const tm *const t = localtime(<ime); - ct.mds = MSECS_PER_HOUR * t->tm_hour + MSECS_PER_MIN * t->tm_min + 1000 * t->tm_sec; -#endif - return ct; -} - #ifndef QT_NO_DATESTRING /*! \fn QTime QTime::fromString(const QString &string, Qt::DateFormat format) @@ -2872,63 +2796,280 @@ bool QDateTime::operator<(const QDateTime &other) const */ /*! + \fn QDateTime QDateTime::currentDateTime() Returns the current datetime, as reported by the system clock, in the local time zone. - \sa QDate::currentDate(), QTime::currentTime(), toTimeSpec() + \sa currentDateTimeUtc(), QDate::currentDate(), QTime::currentTime(), toTimeSpec() */ -QDateTime QDateTime::currentDateTime() +/*! + \fn QDateTime QDateTime::currentDateTimeUtc() + \since 4.7 + Returns the current datetime, as reported by the system clock, in + UTC. + + \sa currentDateTime(), QDate::currentDate(), QTime::currentTime(), toTimeSpec() +*/ + +/*! + \fn qint64 QDateTime::currentMsecsSinceEpoch() + \since 4.7 + + Returns the number of milliseconds since 1970-01-01T00:00:00 Universal + Coordinated Time. This number is like the POSIX time_t variable, but + expressed in milliseconds instead. + + \sa currentDateTime(), currentDateTimeUtc(), toTime_t(), toTimeSpec() +*/ + +static inline uint msecsFromDecomposed(int hour, int minute, int sec, int msec = 0) { + return MSECS_PER_HOUR * hour + MSECS_PER_MIN * minute + 1000 * sec + msec; +} + #if defined(Q_OS_WIN) +QDate QDate::currentDate() +{ + QDate d; + SYSTEMTIME st; + memset(&st, 0, sizeof(SYSTEMTIME)); + GetLocalTime(&st); + d.jd = julianDayFromDate(st.wYear, st.wMonth, st.wDay); + return d; +} + +QTime QTime::currentTime() +{ + QTime ct; + SYSTEMTIME st; + memset(&st, 0, sizeof(SYSTEMTIME)); + GetLocalTime(&st); + ct.mds = msecsFromDecomposed(st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); +#if defined(Q_OS_WINCE) + ct.startTick = GetTickCount() % MSECS_PER_DAY; +#endif + return ct; +} + +QDateTime QDateTime::currentDateTime() +{ QDate d; QTime t; SYSTEMTIME st; memset(&st, 0, sizeof(SYSTEMTIME)); GetLocalTime(&st); d.jd = julianDayFromDate(st.wYear, st.wMonth, st.wDay); - t.mds = MSECS_PER_HOUR * st.wHour + MSECS_PER_MIN * st.wMinute + 1000 * st.wSecond - + st.wMilliseconds; + t.mds = msecsFromDecomposed(st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); return QDateTime(d, t); +} + +QDateTime QDateTime::currentDateTimeUtc() +{ + QDate d; + QTime t; + SYSTEMTIME st; + memset(&st, 0, sizeof(SYSTEMTIME)); + GetSystemTime(&st); + d.jd = julianDayFromDate(st.wYear, st.wMonth, st.wDay); + t.mds = msecsFromDecomposed(st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); + return QDateTime(d, t, Qt::UTC); +} + +qint64 QDateTime::currentMsecsSinceEpoch() +{ + QDate d; + QTime t; + SYSTEMTIME st; + memset(&st, 0, sizeof(SYSTEMTIME)); + GetSystemTime(&st); + + return msecsFromDecomposed(st.wHour, st.wMinute, st.wSecond, st.wMilliseconds) + + qint64(julianDayFromGregorianDate(st.wYear, st.wMonth, st.wDay) + - julianDayFromGregorianDate(1970, 1, 1)) * Q_INT64_C(86400000); +} + #elif defined(Q_OS_SYMBIAN) - return QDateTime(QDate::currentDate(), QTime::currentTime()); +QDate QDate::currentDate() +{ + QDate d; + TTime localTime; + localTime.HomeTime(); + TDateTime localDateTime = localTime.DateTime(); + // months and days are zero indexed + d.jd = julianDayFromDate(localDateTime.Year(), localDateTime.Month() + 1, localDateTime.Day() + 1 ); + return d; +} + +QTime QTime::currentTime() +{ + QTime ct; + TTime localTime; + localTime.HomeTime(); + TDateTime localDateTime = localTime.DateTime(); + ct.mds = msecsFromDecomposed(localDateTime.Hour(), localDateTime.Minute(), + localDateTime.Second(), localDateTime.MicroSecond() / 1000); + return ct; +} + +QDateTime QDateTime::currentDateTime() +{ + QDate d; + QTime ct; + TTime localTime; + localTime.HomeTime(); + TDateTime localDateTime = localTime.DateTime(); + // months and days are zero indexed + d.jd = julianDayFromDate(localDateTime.Year(), localDateTime.Month() + 1, localDateTime.Day() + 1); + ct.mds = msecsFromDecomposed(localDateTime.Hour(), localDateTime.Minute(), + localDateTime.Second(), localDateTime.MicroSecond() / 1000); + return QDateTime(d, ct); +} + +QDateTime QDateTime::currentDateTimeUtc() +{ + QDate d; + QTime ct; + TTime gmTime; + gmTime.UniversalTime(); + TDateTime gmtDateTime = gmTime.DateTime(); + // months and days are zero indexed + d.jd = julianDayFromDate(gmtDateTime.Year(), gmtDateTime.Month() + 1, gmtDateTime.Day() + 1); + ct.mds = msecsFromDecomposed(gmtDateTime.Hour(), gmtDateTime.Minute(), + gmtDateTime.Second(), gmtDateTime.MicroSecond() / 1000); + return QDateTime(d, ct, Qt::UTC); +} + +qint64 QDateTime::currentMsecsSinceEpoch() +{ + QDate d; + QTime ct; + TTime gmTime; + gmTime.UniversalTime(); + TDateTime gmtDateTime = gmTime.DateTime(); + + // according to the documentation, the value is: + // "a date and time as a number of microseconds since midnight, January 1st, 0 AD nominal Gregorian" + qint64 value = gmTime.Int64(); + + // whereas 1970-01-01T00:00:00 is (in the same representation): + static const qint64 unixEpoch = qint64(1970 * 365 + 1970 / 4 - 1970 / 100 + 1970 / 400) * Q_INT64_C(86400) + * Q_INT64_C(1000000); + + return (value - unixEpoch) / 1000; +} + +#elif defined(Q_OS_UNIX) +QDate QDate::currentDate() +{ + QDate d; + // posix compliant system + time_t ltime; + time(<ime); + struct tm *t = 0; + +#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) + // use the reentrant version of localtime() where available + tzset(); + struct tm res; + t = localtime_r(<ime, &res); #else -#if defined(Q_OS_UNIX) + t = localtime(<ime); +#endif // !QT_NO_THREAD && _POSIX_THREAD_SAFE_FUNCTIONS + + d.jd = julianDayFromDate(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday); + return d; +} + +QTime QTime::currentTime() +{ + QTime ct; + // posix compliant system + struct timeval tv; + gettimeofday(&tv, 0); + time_t ltime = tv.tv_sec; + struct tm *t = 0; + +#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) + // use the reentrant version of localtime() where available + tzset(); + struct tm res; + t = localtime_r(<ime, &res); +#else + t = localtime(<ime); +#endif + Q_CHECK_PTR(t); + + ct.mds = msecsFromDecomposed(t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec / 1000); + return ct; +} + +QDateTime QDateTime::currentDateTime() +{ // posix compliant system // we have milliseconds struct timeval tv; gettimeofday(&tv, 0); time_t ltime = tv.tv_sec; - tm *t = 0; + struct tm *t = 0; #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) // use the reentrant version of localtime() where available tzset(); - tm res; + struct tm res; t = localtime_r(<ime, &res); #else t = localtime(<ime); #endif QDateTime dt; - dt.d->time.mds = MSECS_PER_HOUR * t->tm_hour + MSECS_PER_MIN * t->tm_min + 1000 * t->tm_sec - + tv.tv_usec / 1000; -#else - time_t ltime; // no millisecond resolution - ::time(<ime); - tm *t = 0; - localtime(<ime); - dt.d->time.mds = MSECS_PER_HOUR * t->tm_hour + MSECS_PER_MIN * t->tm_min + 1000 * t->tm_sec; -#endif // Q_OS_UNIX + dt.d->time.mds = msecsFromDecomposed(t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec / 1000); dt.d->date.jd = julianDayFromDate(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday); dt.d->spec = t->tm_isdst > 0 ? QDateTimePrivate::LocalDST : t->tm_isdst == 0 ? QDateTimePrivate::LocalStandard : QDateTimePrivate::LocalUnknown; return dt; +} + +QDateTime QDateTime::currentDateTimeUtc() +{ + // posix compliant system + // we have milliseconds + struct timeval tv; + gettimeofday(&tv, 0); + time_t ltime = tv.tv_sec; + struct tm *t = 0; + +#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) + // use the reentrant version of localtime() where available + struct tm res; + t = gmtime_r(<ime, &res); +#else + t = gmtime(<ime); #endif + + QDateTime dt; + dt.d->time.mds = msecsFromDecomposed(t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec / 1000); + + dt.d->date.jd = julianDayFromDate(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday); + dt.d->spec = QDateTimePrivate::UTC; + return dt; } +qint64 QDateTime::currentMsecsSinceEpoch() +{ + // posix compliant system + // we have milliseconds + struct timeval tv; + gettimeofday(&tv, 0); + return qint64(tv.tv_sec) * Q_INT64_C(1000) + tv.tv_usec / 1000; +} + +#else +#error "What system is this?" +#endif + /*! \since 4.2 diff --git a/src/corelib/tools/qdatetime.h b/src/corelib/tools/qdatetime.h index cb7f5bd..ef5968e 100644 --- a/src/corelib/tools/qdatetime.h +++ b/src/corelib/tools/qdatetime.h @@ -204,7 +204,6 @@ private: friend class QDateTime; friend class QDateTimePrivate; - friend class QElapsedTimer; #ifndef QT_NO_DATASTREAM friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QTime &); friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QTime &); @@ -262,11 +261,13 @@ public: int utcOffset() const; static QDateTime currentDateTime(); + static QDateTime currentDateTimeUtc(); #ifndef QT_NO_DATESTRING static QDateTime fromString(const QString &s, Qt::DateFormat f = Qt::TextDate); static QDateTime fromString(const QString &s, const QString &format); #endif static QDateTime fromTime_t(uint secsSince1Jan1970UTC); + static qint64 currentMsecsSinceEpoch(); #ifdef QT3_SUPPORT inline QT3_SUPPORT void setTime_t(uint secsSince1Jan1970UTC, Qt::TimeSpec spec) { diff --git a/src/corelib/tools/qelapsedtimer_generic.cpp b/src/corelib/tools/qelapsedtimer_generic.cpp index db6da46..3feecd6 100644 --- a/src/corelib/tools/qelapsedtimer_generic.cpp +++ b/src/corelib/tools/qelapsedtimer_generic.cpp @@ -44,12 +44,6 @@ QT_BEGIN_NAMESPACE -static qint64 currentDateTimeMsec() -{ - QDateTime t = QDateTime::currentDateTime(); - return t.toTime_t() * Q_INT64_C(1000) + t.time().msec(); -} - QElapsedTimer::ClockType QElapsedTimer::clockType() { return SystemTime; @@ -68,14 +62,14 @@ void QElapsedTimer::start() qint64 QElapsedTimer::restart() { qint64 old = t1; - t1 = currentDateTimeMsec(); + t1 = QDateTime::currentMsecsSinceEpoch(); t2 = 0; return t1 - old; } qint64 QElapsedTimer::elapsed() const { - return currentDateTimeMsec() - t1; + return QDateTime::currentMsecsSinceEpoch() - t1; } qint64 QElapsedTimer::msecsSinceReference() const diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index 692fae9..73dae7a 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -57,6 +57,7 @@ SOURCES += \ tools/qcryptographichash.cpp \ tools/qdatetime.cpp \ tools/qeasingcurve.cpp \ + tools/qelapsedtimer.cpp \ tools/qhash.cpp \ tools/qline.cpp \ tools/qlinkedlist.cpp \ @@ -77,13 +78,13 @@ SOURCES += \ tools/qstringlist.cpp \ tools/qtextboundaryfinder.cpp \ tools/qtimeline.cpp \ - tools/qelapsedtimer.cpp \ tools/qvector.cpp \ tools/qvsnprintf.cpp symbian:SOURCES+=tools/qlocale_symbian.cpp mac:SOURCES += tools/qelapsedtimer_mac.cpp +else:symbian:SOURCES += tools/qelapsedtimer_generic.cpp else:unix:SOURCES += tools/qelapsedtimer_unix.cpp else:win32:SOURCES += tools/qelapsedtimer_win.cpp else:SOURCES += tools/qelapsedtimer_generic.cpp diff --git a/tests/auto/qdatetime/tst_qdatetime.cpp b/tests/auto/qdatetime/tst_qdatetime.cpp index 86a4c80..a6b9a5f 100644 --- a/tests/auto/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/qdatetime/tst_qdatetime.cpp @@ -106,6 +106,8 @@ private slots: void secsTo(); void operator_eqeq(); void currentDateTime(); + void currentDateTimeUtc(); + void currentDateTimeUtc2(); void fromStringTextDate_data(); void fromStringTextDate(); @@ -880,6 +882,79 @@ void tst_QDateTime::currentDateTime() QVERIFY(dt3.timeSpec() == Qt::UTC); } +void tst_QDateTime::currentDateTimeUtc() +{ +#if defined(Q_OS_WINCE) + __time64_t buf1, buf2; + ::_time64(&buf1); +#else + time_t buf1, buf2; + ::time(&buf1); +#endif + QDateTime lowerBound; + lowerBound.setTime_t(buf1); + + QDateTime dt1 = QDateTime::currentDateTimeUtc(); + QDateTime dt2 = QDateTime::currentDateTimeUtc().toLocalTime(); + QDateTime dt3 = QDateTime::currentDateTimeUtc().toUTC(); + +#if defined(Q_OS_WINCE) + ::_time64(&buf2); +#else + ::time(&buf2); +#endif + QDateTime upperBound; + upperBound.setTime_t(buf2); + upperBound = upperBound.addSecs(1); + + QVERIFY(lowerBound < upperBound); + + QVERIFY(lowerBound <= dt1); + QVERIFY(dt1 < upperBound); + QVERIFY(lowerBound <= dt2); + QVERIFY(dt2 < upperBound); + QVERIFY(lowerBound <= dt3); + QVERIFY(dt3 < upperBound); + + QVERIFY(dt1.timeSpec() == Qt::UTC); + QVERIFY(dt2.timeSpec() == Qt::LocalTime); + QVERIFY(dt3.timeSpec() == Qt::UTC); +} + +void tst_QDateTime::currentDateTimeUtc2() +{ + QDateTime local, utc; + qint64 msec; + + // check that we got all down to the same milliseconds + int i = 2; + bool ok = false; + do { + local = QDateTime::currentDateTime(); + utc = QDateTime::currentDateTimeUtc(); + msec = QDateTime::currentMsecsSinceEpoch(); + ok = local.time().msec() == utc.time().msec() + && utc.time().msec() == (msec % 1000); + } while (--i && !ok); + + if (!i) + QSKIP("Failed to get the dates within 1 ms of each other", SkipAll); + + // seconds and milliseconds should be the same: + QCOMPARE(utc.time().second(), local.time().second()); + QCOMPARE(utc.time().msec(), local.time().msec()); + QCOMPARE(msec % 1000, qint64(local.time().msec())); + QCOMPARE(msec / 1000 % 60, qint64(local.time().second())); + + // the two dates should be equal, actually + QCOMPARE(local.toUTC(), utc); + QCOMPARE(utc.toLocalTime(), local); + + // and finally, the time_t should equal our number + QCOMPARE(qint64(utc.toTime_t()), msec / 1000); + QCOMPARE(qint64(local.toTime_t()), msec / 1000); +} + void tst_QDateTime::toTime_t_data() { QTest::addColumn("dateTimeStr"); -- cgit v0.12 From e62a99d588eaf2b7443250f36c42762a0631c02a Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 5 Mar 2010 19:03:51 +0100 Subject: Bugfix the Symbian implementation --- mkspecs/common/symbian/symbian.conf | 4 ++-- src/corelib/tools/qdatetime.cpp | 4 ++-- src/corelib/tools/qelapsedtimer_symbian.cpp | 20 +++++++++++++++++++- src/corelib/tools/tools.pri | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/mkspecs/common/symbian/symbian.conf b/mkspecs/common/symbian/symbian.conf index 16b9a28..239b998 100644 --- a/mkspecs/common/symbian/symbian.conf +++ b/mkspecs/common/symbian/symbian.conf @@ -74,8 +74,8 @@ QMAKE_LINK_OBJECT_MAX = QMAKE_LINK_OBJECT_SCRIPT= QMAKE_LIBS = -llibc -llibm -leuser -llibdl -QMAKE_LIBS_CORE = $$QMAKE_LIBS -llibpthread -lefsrv -QMAKE_LIBS_GUI = $$QMAKE_LIBS_CORE -lfbscli -lbitgdi -lhal -lgdi -lws32 -lapgrfx -lcone -leikcore -lmediaclientaudio -leikcoctl -leiksrv -lapparc -lcentralrepository +QMAKE_LIBS_CORE = $$QMAKE_LIBS -llibpthread -lefsrv -lhal +QMAKE_LIBS_GUI = $$QMAKE_LIBS_CORE -lfbscli -lbitgdi -lgdi -lws32 -lapgrfx -lcone -leikcore -lmediaclientaudio -leikcoctl -leiksrv -lapparc -lcentralrepository QMAKE_LIBS_NETWORK = QMAKE_LIBS_EGL = -llibEGL QMAKE_LIBS_OPENGL = diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 7e03777..54a4205 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -2953,8 +2953,8 @@ qint64 QDateTime::currentMsecsSinceEpoch() qint64 value = gmTime.Int64(); // whereas 1970-01-01T00:00:00 is (in the same representation): - static const qint64 unixEpoch = qint64(1970 * 365 + 1970 / 4 - 1970 / 100 + 1970 / 400) * Q_INT64_C(86400) - * Q_INT64_C(1000000); + // ((1970 * 365) + (1970 / 4) - (1970 / 100) + (1970 / 400) - 13) * 86400 * 1000000 + static const qint64 unixEpoch = Q_INT64_C(0xdcddb30f2f8000); return (value - unixEpoch) / 1000; } diff --git a/src/corelib/tools/qelapsedtimer_symbian.cpp b/src/corelib/tools/qelapsedtimer_symbian.cpp index 6360dbf..038b102 100644 --- a/src/corelib/tools/qelapsedtimer_symbian.cpp +++ b/src/corelib/tools/qelapsedtimer_symbian.cpp @@ -40,12 +40,15 @@ ****************************************************************************/ #include "qelapsedtimer.h" +#include "qpair.h" #include +#include +#include QT_BEGIN_NAMESPACE // return quint64 to avoid sign-extension -static quint64 getMillisecondFromTick() +static quint64 getMicrosecondFromTick() { static TInt nanokernel_tick_period; if (!nanokernel_tick_period) @@ -61,6 +64,21 @@ static quint64 getMillisecondFromTick() return nanokernel_tick_period * (val | (quint64(highdword) << 32)); } +static quint64 getMillisecondFromTick() +{ + return getMicrosecondFromTick() / 1000; +} + +timeval qt_gettime() +{ + timeval tv; + quint64 now = getMicrosecondFromTick(); + tv.tv_sec = now / 1000000; + tv.tv_usec = now % 1000000; + + return tv; +} + QElapsedTimer::ClockType QElapsedTimer::clockType() { return TickCounter; diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index 73dae7a..4e0ebbc 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -84,7 +84,7 @@ SOURCES += \ symbian:SOURCES+=tools/qlocale_symbian.cpp mac:SOURCES += tools/qelapsedtimer_mac.cpp -else:symbian:SOURCES += tools/qelapsedtimer_generic.cpp +else:symbian:SOURCES += tools/qelapsedtimer_symbian.cpp else:unix:SOURCES += tools/qelapsedtimer_unix.cpp else:win32:SOURCES += tools/qelapsedtimer_win.cpp else:SOURCES += tools/qelapsedtimer_generic.cpp -- cgit v0.12 From c8b999d9d1eaf3379233169ccd4e9ea8c86a1702 Mon Sep 17 00:00:00 2001 From: Carlos Manuel Duclos Vergara Date: Wed, 17 Mar 2010 12:03:50 +0100 Subject: "Strictly" Fullscreen Application in Mac OS Full screen in OSX is achieved by using the Kiosk Mode. Therefore it is not a real full screen but an emulation since we basically disable the dock and the menubar. Previous to this patch we were autoshowing the menubar all the time even when we didn't have a menubar. The problem with that is the fact that in OSX there is always a system menubar, so the menubar appeared the moment somebody hovered over the menubar region. With this patch we check if we have created a menubar and if so we autoshow the menubar, otherwise the menubar will remain hidden in full screen mode. Task-number: QTBUG-8933 Reviewed-by: Richard Moe Gustavsen --- src/gui/widgets/qmenu_mac.mm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/gui/widgets/qmenu_mac.mm b/src/gui/widgets/qmenu_mac.mm index 43722a1..627043d 100644 --- a/src/gui/widgets/qmenu_mac.mm +++ b/src/gui/widgets/qmenu_mac.mm @@ -2060,6 +2060,22 @@ bool QMenuBarPrivate::macUpdateMenuBarImmediatly() QWidget *w = findWindowThatShouldDisplayMenubar(); QMenuBar *mb = findMenubarForWindow(w); + // We need to see if we are in full screen mode, if so we need to + // switch the full screen mode to be able to show or hide the menubar. + if(w && mb) { + // This case means we are creating a menubar, check if full screen + if(w->isFullScreen()) { + // Ok, switch to showing the menubar when hovering over it. + SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar); + } + } else if(w) { + // Removing a menubar + if(w->isFullScreen()) { + // Ok, switch to not showing the menubar when hovering on it + SetSystemUIMode(kUIModeAllHidden, 0); + } + } + if (mb && mb->isNativeMenuBar()) { bool modal = QApplicationPrivate::modalState(); #ifdef QT_MAC_USE_COCOA -- cgit v0.12 From f8d5f2594a9b268b9eeecf95b24b23fc940c71ce Mon Sep 17 00:00:00 2001 From: Carlos Manuel Duclos Vergara Date: Wed, 17 Mar 2010 12:09:03 +0100 Subject: Cocoa: minisplitter has only 1px wide grab area The problem was that in Cocoa we were ignoring the WA_MouseNoMask attribute, therefore the mask was being applied to the mouse movements. This in turn caused the cursor not to change accordingly. Task-number: QTCREATORBUG-361 Reviewed-by: Prasanth --- src/gui/kernel/qcocoaview_mac.mm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm index 4f71681..a627616 100644 --- a/src/gui/kernel/qcocoaview_mac.mm +++ b/src/gui/kernel/qcocoaview_mac.mm @@ -241,7 +241,8 @@ static int qCocoaViewCount = 0; QRegion mask = qt_widget_private(cursorWidget)->extra->mask; NSCursor *nscursor = static_cast(qt_mac_nsCursorForQCursor(cursorWidget->cursor())); - if (mask.isEmpty()) { + // The mask could have the WA_MouseNoMask attribute set and that means that we have to ignore the mask. + if (mask.isEmpty() || cursorWidget->testAttribute(Qt::WA_MouseNoMask)) { [self addCursorRect:[qt_mac_nativeview_for(cursorWidget) visibleRect] cursor:nscursor]; } else { const QVector &rects = mask.rects(); @@ -490,7 +491,9 @@ static int qCocoaViewCount = 0; CGContextRef cg = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; qwidgetprivate->hd = cg; CGContextSaveGState(cg); - + CGFloat components[] = {1,0,0,1}; + CGContextSetFillColor(cg, components); + CGContextFillRect(cg, aRect); if (qwidget->isVisible() && qwidget->updatesEnabled()) { //process the actual paint event. if (qwidget->testAttribute(Qt::WA_WState_InPaintEvent)) qWarning("QWidget::repaint: Recursive repaint detected"); -- cgit v0.12 From 7e9052cc1f16b3eeabb73ada9492d91620df796d Mon Sep 17 00:00:00 2001 From: Carlos Manuel Duclos Vergara Date: Wed, 17 Mar 2010 12:15:59 +0100 Subject: Manual test for QTBUG-8933. See the readme file. Reviewed-by: TrustMe --- tests/manual/qtbug-8933/README | 7 ++++ tests/manual/qtbug-8933/main.cpp | 10 ++++++ tests/manual/qtbug-8933/qtbug-8933.pro | 16 ++++++++++ tests/manual/qtbug-8933/widget.cpp | 58 ++++++++++++++++++++++++++++++++++ tests/manual/qtbug-8933/widget.h | 32 +++++++++++++++++++ tests/manual/qtbug-8933/widget.ui | 33 +++++++++++++++++++ 6 files changed, 156 insertions(+) create mode 100644 tests/manual/qtbug-8933/README create mode 100644 tests/manual/qtbug-8933/main.cpp create mode 100644 tests/manual/qtbug-8933/qtbug-8933.pro create mode 100644 tests/manual/qtbug-8933/widget.cpp create mode 100644 tests/manual/qtbug-8933/widget.h create mode 100644 tests/manual/qtbug-8933/widget.ui diff --git a/tests/manual/qtbug-8933/README b/tests/manual/qtbug-8933/README new file mode 100644 index 0000000..b3ce407 --- /dev/null +++ b/tests/manual/qtbug-8933/README @@ -0,0 +1,7 @@ +The purpose of this test is to check if the full screen mode in OSX is working properly or not. +This test creates a widget and 5 seconds later enters full screen mode. If you hover over the area +where the menubar should be you will get no menubar. After 5 more seconds (i.e. 10 seconds since +start) a menubar is created. At that point, if you hover over the menubar area you will get the +menubar. 5 seconds later the menubar is destroyed and if you hover over there will be no menubar. +After 5 more seconds the widget goes back to normal mode and the test is finished. + diff --git a/tests/manual/qtbug-8933/main.cpp b/tests/manual/qtbug-8933/main.cpp new file mode 100644 index 0000000..841b7c3 --- /dev/null +++ b/tests/manual/qtbug-8933/main.cpp @@ -0,0 +1,10 @@ +#include +#include "widget.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Widget w; + w.show(); + return a.exec(); +} diff --git a/tests/manual/qtbug-8933/qtbug-8933.pro b/tests/manual/qtbug-8933/qtbug-8933.pro new file mode 100644 index 0000000..8b87c83 --- /dev/null +++ b/tests/manual/qtbug-8933/qtbug-8933.pro @@ -0,0 +1,16 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2010-03-16T14:40:16 +# +#------------------------------------------------- + +TARGET = qtbug-8933 +TEMPLATE = app + + +SOURCES += main.cpp\ + widget.cpp + +HEADERS += widget.h + +FORMS += widget.ui diff --git a/tests/manual/qtbug-8933/widget.cpp b/tests/manual/qtbug-8933/widget.cpp new file mode 100644 index 0000000..47a440b --- /dev/null +++ b/tests/manual/qtbug-8933/widget.cpp @@ -0,0 +1,58 @@ +#include "widget.h" +#include "ui_widget.h" + +#include +#include + +Widget::Widget(QWidget *parent) : + QWidget(parent), + ui(new Ui::Widget) +{ + ui->setupUi(this); + QTimer::singleShot(5000, this, SLOT(switchToFullScreen())); + QTimer::singleShot(10000, this, SLOT(addMenuBar())); + QTimer::singleShot(15000, this, SLOT(removeMenuBar())); + QTimer::singleShot(20000, this, SLOT(switchToNormalScreen())); +} + +Widget::~Widget() +{ + delete ui; +} + +void Widget::changeEvent(QEvent *e) +{ + QWidget::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + +void Widget::switchToFullScreen() +{ + ui->label->setText("entering full screen"); + showFullScreen(); +} + +void Widget::switchToNormalScreen() +{ + ui->label->setText("leaving full screen"); + showNormal(); +} + +void Widget::addMenuBar() +{ + ui->label->setText("adding menu bar"); + menuBar = new QMenuBar(this); + menuBar->setVisible(true); +} + +void Widget::removeMenuBar() +{ + ui->label->setText("removing menu bar"); + delete menuBar; +} diff --git a/tests/manual/qtbug-8933/widget.h b/tests/manual/qtbug-8933/widget.h new file mode 100644 index 0000000..f6afa8f --- /dev/null +++ b/tests/manual/qtbug-8933/widget.h @@ -0,0 +1,32 @@ +#ifndef WIDGET_H +#define WIDGET_H + +#include +#include +#include + +namespace Ui { + class Widget; +} + +class Widget : public QWidget { + Q_OBJECT +public: + Widget(QWidget *parent = 0); + ~Widget(); + +public slots: + void switchToFullScreen(); + void switchToNormalScreen(); + void addMenuBar(); + void removeMenuBar(); + +protected: + void changeEvent(QEvent *e); + +private: + Ui::Widget *ui; + QMenuBar *menuBar; +}; + +#endif // WIDGET_H diff --git a/tests/manual/qtbug-8933/widget.ui b/tests/manual/qtbug-8933/widget.ui new file mode 100644 index 0000000..e0ded3f --- /dev/null +++ b/tests/manual/qtbug-8933/widget.ui @@ -0,0 +1,33 @@ + + + Widget + + + + 0 + 0 + 600 + 400 + + + + Widget + + + + + 110 + 60 + 311 + 16 + + + + TextLabel + + + + + + + -- cgit v0.12