1 | /* This file is part of the KDE project |
2 | Copyright (C) 2012 Philip Van Hoof <philip@codeminded.be> |
3 | (C) 2005-2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net> |
4 | (C) 2006 Fredrik Edemar <f_edemar@linux.se> |
5 | (C) 2005-2006 Raphael Langerhorst <raphael.langerhorst@kdemail.net> |
6 | (C) 2004 Tomas Mecir <mecirt@gmail.com> |
7 | (C) 2003 Norbert Andres <nandres@web.de> |
8 | (C) 2002 Philipp Mueller <philipp.mueller@gmx.de> |
9 | (C) 2000 David Faure <faure@kde.org> |
10 | (C) 2000 Werner Trobin <trobin@kde.org> |
11 | (C) 2000-2006 Laurent Montel <montel@kde.org> |
12 | (C) 1999, 2000 Torben Weis <weis@kde.org> |
13 | (C) 1999 Stephan Kulow <coolo@kde.org> |
14 | |
15 | This library is free software; you can redistribute it and/or |
16 | modify it under the terms of the GNU Library General Public |
17 | License as published by the Free Software Foundation; either |
18 | version 2 of the License, or (at your option) any later version. |
19 | |
20 | This library is distributed in the hope that it will be useful, |
21 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
23 | Library General Public License for more details. |
24 | |
25 | You should have received a copy of the GNU Library General Public License |
26 | along with this library; see the file COPYING.LIB. If not, write to |
27 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
28 | Boston, MA 02110-1301, USA. |
29 | */ |
30 | |
31 | |
32 | #ifndef ELAPSED_TIME_P_H |
33 | #define ELAPSED_TIME_P_H |
34 | |
35 | #include <kdebug.h> |
36 | #include <QTime> |
37 | |
38 | namespace Calligra |
39 | { |
40 | namespace Sheets |
41 | { |
42 | |
43 | class ElapsedTime |
44 | { |
45 | public: |
46 | enum OutputMode { Default, PrintOnlyTime }; |
47 | |
48 | #ifdef NDEBUG |
49 | |
50 | ElapsedTime() {} |
51 | explicit ElapsedTime(const QString &, OutputMode = Default) {} |
52 | |
53 | #else // NDEBUG |
54 | |
55 | ElapsedTime() { |
56 | m_time.start(); |
57 | } |
58 | |
59 | explicit ElapsedTime(const QString &name, OutputMode mode = Default) |
60 | : m_name(name) { |
61 | m_time.start(); |
62 | if (mode != PrintOnlyTime) { |
63 | kDebug(36001) << QString("*** (" + name + ")... Starting measuring..." ); |
64 | } |
65 | } |
66 | |
67 | ~ElapsedTime() { |
68 | uint milliSec = m_time.elapsed(); |
69 | uint min = static_cast<uint>(milliSec / (1000 * 60)); |
70 | milliSec -= (min * 60 * 1000); |
71 | uint sec = static_cast<uint>(milliSec / 1000); |
72 | milliSec -= sec * 1000; |
73 | |
74 | if (m_name.isNull()) |
75 | kDebug(36001) << QString("*** Elapsed time: %1 min %2 sec %3 msec" ).arg(min).arg(sec).arg(milliSec); |
76 | else |
77 | kDebug(36001) << QString("*** (%1) Elapsed time: %2 min %3 sec %4 msec" ).arg(m_name).arg(min).arg(sec).arg(milliSec); |
78 | } |
79 | |
80 | private: |
81 | QTime m_time; |
82 | QString m_name; |
83 | |
84 | #endif // NDEBUG |
85 | }; |
86 | |
87 | } // namespace Sheets |
88 | } // namespace Calligra |
89 | |
90 | #endif |
91 | |