File indexing completed on 2024-04-28 16:21:22

0001 /* This file is part of the KDE project
0002    Copyright (C) 2012 Philip Van Hoof <philip@codeminded.be>
0003              (C) 2005-2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0004              (C) 2006 Fredrik Edemar <f_edemar@linux.se>
0005              (C) 2005-2006 Raphael Langerhorst <raphael.langerhorst@kdemail.net>
0006              (C) 2004 Tomas Mecir <mecirt@gmail.com>
0007              (C) 2003 Norbert Andres <nandres@web.de>
0008              (C) 2002 Philipp Mueller <philipp.mueller@gmx.de>
0009              (C) 2000 David Faure <faure@kde.org>
0010              (C) 2000 Werner Trobin <trobin@kde.org>
0011              (C) 2000-2006 Laurent Montel <montel@kde.org>
0012              (C) 1999, 2000 Torben Weis <weis@kde.org>
0013              (C) 1999 Stephan Kulow <coolo@kde.org>
0014 
0015    This library is free software; you can redistribute it and/or
0016    modify it under the terms of the GNU Library General Public
0017    License as published by the Free Software Foundation; either
0018    version 2 of the License, or (at your option) any later version.
0019 
0020    This library is distributed in the hope that it will be useful,
0021    but WITHOUT ANY WARRANTY; without even the implied warranty of
0022    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0023    Library General Public License for more details.
0024 
0025    You should have received a copy of the GNU Library General Public License
0026    along with this library; see the file COPYING.LIB.  If not, write to
0027    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0028    Boston, MA 02110-1301, USA.
0029 */
0030 
0031 
0032 #ifndef ELAPSED_TIME_P_H
0033 #define ELAPSED_TIME_P_H
0034 
0035 #include "SheetsDebug.h"
0036 #include <QTime>
0037 
0038 namespace Calligra
0039 {
0040 namespace Sheets
0041 {
0042 
0043 class ElapsedTime
0044 {
0045 public:
0046     enum OutputMode { Default, PrintOnlyTime };
0047 
0048 #ifdef NDEBUG
0049 
0050     ElapsedTime() {}
0051     explicit ElapsedTime(const QString &, OutputMode = Default) {}
0052 
0053 #else // NDEBUG
0054 
0055     ElapsedTime() {
0056         m_time.start();
0057     }
0058 
0059     explicit ElapsedTime(const QString &name, OutputMode mode = Default)
0060             : m_name(name) {
0061         m_time.start();
0062         if (mode != PrintOnlyTime) {
0063             debugSheets << QString("*** (" + name + ")... Starting measuring...");
0064         }
0065     }
0066 
0067     ~ElapsedTime() {
0068         uint milliSec = m_time.elapsed();
0069         uint min = static_cast<uint>(milliSec / (1000 * 60));
0070         milliSec -= (min * 60 * 1000);
0071         uint sec = static_cast<uint>(milliSec / 1000);
0072         milliSec -= sec * 1000;
0073 
0074         if (m_name.isNull())
0075             debugSheets << QString("*** Elapsed time: %1 min %2 sec %3 msec").arg(min).arg(sec).arg(milliSec);
0076         else
0077             debugSheets << QString("*** (%1) Elapsed time: %2 min %3 sec %4 msec").arg(m_name).arg(min).arg(sec).arg(milliSec);
0078     }
0079 
0080 private:
0081     QTime   m_time;
0082     QString m_name;
0083 
0084 #endif // NDEBUG
0085 };
0086 
0087 } // namespace Sheets
0088 } // namespace Calligra
0089 
0090 #endif