Add a remainingTime() method to the public interface of the QTimer class
authorLaszlo Papp <lpapp@kde.org>
Thu, 23 Feb 2012 05:41:30 +0000 (07:41 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 3 Apr 2012 13:10:05 +0000 (15:10 +0200)
commit8b56b8ed32cf6351047b21c80359f5f2b895a314
tree840ebb7726fd527684c38496bd6edcdf0712c06f
parent4b023e248747a589f2402b03f1967b999e3bb3b8
Add a remainingTime() method to the public interface of the QTimer class

It is an extension coming from the use case when you, for instance, need to
implement a countdown timer in client codes, and manually maintain a dedicated
variable for counting down with the help of yet another Timer. There might be
other use cases as well. The returned value is meant to be in milliseconds, as
the method documentation says, since it is reasonable, and consistent with the
rest (ie. the interval accessor).

The elapsed time is already being tracked inside the event dispatcher, thus the
effort is only exposing that for all platforms supported according to the
desired timer identifier, and propagating up to the QTimer public API. It is
done by using the QTimerInfoList class in the glib and unix dispatchers, and the
WinTimeInfo struct for the windows dispatcher.

It might be a good idea to to establish a QWinTimerInfo
(qtimerinfo_win{_p.h,cpp}) in the future for resembling the interface for
windows with the glib/unix management so that it would be consistent. That would
mean abstracting out a base class (~interface) for the timer info classes.
Something like that QAbstractTimerInfo.

Test: Build test only on (Arch)Linux, Windows and Mac. I have also run the unit
tests and they passed as well.

Change-Id: Ie37b3aff909313ebc92e511e27d029abb070f110
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
20 files changed:
src/corelib/kernel/qabstracteventdispatcher.cpp
src/corelib/kernel/qabstracteventdispatcher.h
src/corelib/kernel/qeventdispatcher_glib.cpp
src/corelib/kernel/qeventdispatcher_glib_p.h
src/corelib/kernel/qeventdispatcher_unix.cpp
src/corelib/kernel/qeventdispatcher_unix_p.h
src/corelib/kernel/qeventdispatcher_win.cpp
src/corelib/kernel/qeventdispatcher_win_p.h
src/corelib/kernel/qtimer.cpp
src/corelib/kernel/qtimer.h
src/corelib/kernel/qtimerinfo_unix.cpp
src/corelib/kernel/qtimerinfo_unix_p.h
src/corelib/tools/qelapsedtimer_win.cpp
src/plugins/platforms/cocoa/qcocoaeventdispatcher.h
src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm
tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp
tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
tests/auto/corelib/thread/qthread/tst_qthread.cpp
tests/auto/testlib/selftests/benchlibeventcounter/tst_benchlibeventcounter.cpp
tests/auto/testlib/selftests/benchliboptions/tst_benchliboptions.cpp