forked from qt-creator/qt-creator
Deduplicate elapsed time formatting
While it's nice to see my code spreading, I still prefer to have it at one place. Change-Id: I7bdb13c47ed7e96227deeb14b0a8070aa40148de Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
committed by
André Hartmann
parent
41cb713370
commit
d76a2f4fcd
@@ -30,11 +30,13 @@
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonValue>
|
||||
#include <QRegularExpression>
|
||||
#include <QSet>
|
||||
#include <QTime>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
@@ -383,4 +385,12 @@ QString quoteAmpersands(const QString &text)
|
||||
return result.replace("&", "&&");
|
||||
}
|
||||
|
||||
QString formatElapsedTime(qint64 elapsed)
|
||||
{
|
||||
elapsed += 500; // round up
|
||||
const QString format = QString::fromLatin1(elapsed >= 3600000 ? "h:mm:ss" : "mm:ss");
|
||||
const QString time = QTime(0, 0).addMSecs(elapsed).toString(format);
|
||||
return QCoreApplication::translate("StringUtils", "Elapsed time: %1.").arg(time);
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
@@ -100,6 +100,6 @@ T makeUniquelyNumbered(const T &preferred, const Container &reserved)
|
||||
return tryName;
|
||||
}
|
||||
|
||||
|
||||
QTCREATOR_UTILS_EXPORT QString formatElapsedTime(qint64 elapsed);
|
||||
|
||||
} // namespace Utils
|
||||
|
@@ -61,6 +61,7 @@
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/stringutils.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QLoggingCategory>
|
||||
@@ -345,11 +346,8 @@ void ClangToolRunWorker::stop()
|
||||
reportStopped();
|
||||
|
||||
// Print elapsed time since start
|
||||
const QTime format = QTime(0, 0, 0, 0).addMSecs(m_elapsed.elapsed() + 500);
|
||||
QString time = format.toString("h:mm:ss");
|
||||
if (time.startsWith("0:"))
|
||||
time.remove(0, 2); // Don't display zero hours
|
||||
appendMessage(tr("Elapsed time: %1.") .arg(time), NormalMessageFormat);
|
||||
const QString elapsedTime = Utils::formatElapsedTime(m_elapsed.elapsed());
|
||||
appendMessage(elapsedTime, NormalMessageFormat);
|
||||
}
|
||||
|
||||
void ClangToolRunWorker::analyzeNextFile()
|
||||
|
@@ -35,6 +35,7 @@
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/stringutils.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QObject>
|
||||
@@ -237,11 +238,8 @@ void CMakeProcess::handleProcessFinished(int code, QProcess::ExitStatus status)
|
||||
|
||||
emit finished(code, status);
|
||||
|
||||
const QTime format = QTime(0, 0, 0, 0).addMSecs(m_elapsed.elapsed() + 500);
|
||||
QString time = format.toString("h:mm:ss");
|
||||
if (time.startsWith("0:"))
|
||||
time.remove(0, 2); // Don't display zero hours
|
||||
Core::MessageManager::write(tr("Elapsed time: %1.") .arg(time));
|
||||
const QString elapsedTime = Utils::formatElapsedTime(m_elapsed.elapsed());
|
||||
Core::MessageManager::write(elapsedTime);
|
||||
}
|
||||
|
||||
void CMakeProcess::checkForCancelled()
|
||||
|
@@ -42,6 +42,7 @@
|
||||
#include <cplusplus/LookupContext.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/runextensions.h>
|
||||
#include <utils/stringutils.h>
|
||||
#include <utils/temporarydirectory.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
@@ -173,9 +174,8 @@ void indexFindErrors(QFutureInterface<void> &indexingFuture,
|
||||
indexingFuture.setProgressValue(files.size() - (files.size() - (i + 1)));
|
||||
}
|
||||
|
||||
const QTime format = QTime(0, 0, 0, 0).addMSecs(timer.elapsed() + 500);
|
||||
const QString time = format.toString(QLatin1String("hh:mm:ss"));
|
||||
qDebug("FindErrorsIndexing: Finished after %s.", qPrintable(time));
|
||||
const QString elapsedTime = Utils::formatElapsedTime(timer.elapsed());
|
||||
qDebug("FindErrorsIndexing: %s", qPrintable(elapsedTime));
|
||||
}
|
||||
|
||||
void index(QFutureInterface<void> &indexingFuture,
|
||||
|
@@ -47,6 +47,7 @@
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <utils/runextensions.h>
|
||||
#include <utils/stringutils.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QElapsedTimer>
|
||||
@@ -458,11 +459,8 @@ void BuildManager::updateTaskCount()
|
||||
|
||||
void BuildManager::finish()
|
||||
{
|
||||
const QTime format = QTime(0, 0, 0, 0).addMSecs(d->m_elapsed.elapsed() + 500);
|
||||
QString time = format.toString("h:mm:ss");
|
||||
if (time.startsWith("0:"))
|
||||
time.remove(0, 2); // Don't display zero hours
|
||||
m_instance->addToOutputWindow(tr("Elapsed time: %1.") .arg(time), BuildStep::OutputFormat::NormalMessage);
|
||||
const QString elapsedTime = Utils::formatElapsedTime(d->m_elapsed.elapsed());
|
||||
m_instance->addToOutputWindow(elapsedTime, BuildStep::OutputFormat::NormalMessage);
|
||||
|
||||
QApplication::alert(ICore::mainWindow(), 3000);
|
||||
}
|
||||
|
Reference in New Issue
Block a user