Skip to content

Commit

Permalink
Merge 68e329e into f9b22d3
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Sep 13, 2018
2 parents f9b22d3 + 68e329e commit e62e6a7
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 4 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Expand Up @@ -157,6 +157,17 @@ elseif(CCACHE)
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
endif()

# Prevent long command lines on Windows

if(WIN32)
set(CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS TRUE)
set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS TRUE)

if("${CMAKE_GENERATOR}" STREQUAL "Ninja")
set(CMAKE_NINJA_FORCE_RESPONSE_FILE TRUE)
endif()
endif()

# Keep track of some basic information about Qt, after making sure that we have
# the version of Qt that we need

Expand Down
1 change: 1 addition & 0 deletions doc/downloads/index.js
Expand Up @@ -38,6 +38,7 @@ var jsonData = { "versions": [
],
"changes": [
{ "change": "<strong>General:</strong> only handle a URL when OpenCOR is visible and no modal dialog is active (see issue <a href=\"https://github.com/opencor/opencor/issues/1802\">#1802</a>)." },
{ "change": "<strong>Simulation Experiment view:</strong> provide more user-friendly simulation time information (see issue <a href=\"https://github.com/opencor/opencor/issues/1804\">#1804</a>)." },
{ "change": "<strong>Third-party libraries:</strong> upgraded <a href=\"https://libgit2.github.com/\">libgit2</a> to version 0.27.4 (see issue <a href=\"https://github.com/opencor/opencor/issues/1799\">#1799</a>)." }
]
},
Expand Down
20 changes: 20 additions & 0 deletions src/plugins/miscellaneous/Core/i18n/Core_fr.ts
Expand Up @@ -467,5 +467,25 @@
<source>Please choose an empty directory.</source>
<translation>Veuillez choisir un répertoire vide.</translation>
</message>
<message>
<source>d</source>
<translation>j</translation>
</message>
<message>
<source>h</source>
<translation></translation>
</message>
<message>
<source>m</source>
<translation></translation>
</message>
<message>
<source>s</source>
<translation></translation>
</message>
<message>
<source>ms</source>
<translation></translation>
</message>
</context>
</TS>
39 changes: 39 additions & 0 deletions src/plugins/miscellaneous/Core/src/corecliutils.cpp
Expand Up @@ -261,6 +261,45 @@ QString sizeAsString(quint64 pSize, int pPrecision)

//==============================================================================

QString formatTime(qint64 pTime)
{
// Convert the given time (in milliseconds) to a string and return it
// Note: normally, we would for example have something like
// int h = int(msToH*time);
// with msToH being
// static double msToH = 1.0/3600000.0;
// However, with pTime=3600000, h equals 0 due, I imagine, to the
// internal representation of the floating point number prior to its
// conversion to an int. So, instead, we explicitly divide things...

QString res = QString();
qint64 time = pTime;
int d = int(time/86400000.0); time -= 86400000*d;
int h = int(time/3600000.0); time -= 3600000*h;
int m = int(time/60000.0); time -= 60000*m;
int s = int(time/1000.0); time -= 1000*s;
int ms = int(time);

if (d || ((h || m || s || ms) && !res.isEmpty()))
res += (res.isEmpty()?QString():" ")+QString::number(d)+QObject::tr("d");

if (h || ((m || s || ms) && !res.isEmpty()))
res += (res.isEmpty()?QString():" ")+QString::number(h)+QObject::tr("h");

if (m || ((s || ms) && !res.isEmpty()))
res += (res.isEmpty()?QString():" ")+QString::number(m)+QObject::tr("m");

if (s || (ms && !res.isEmpty()))
res += (res.isEmpty()?QString():" ")+QString::number(s)+QObject::tr("s");

if (ms || res.isEmpty())
res += (res.isEmpty()?QString():" ")+QString::number(ms)+QObject::tr("ms");

return res;
}

//==============================================================================

QString sha1(const QByteArray &pByteArray)
{
// Return the SHA-1 value of the given byte array
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/miscellaneous/Core/src/corecliutils.h
Expand Up @@ -122,6 +122,8 @@ QString CORE_EXPORT digitGroupNumber(const QString &pNumber);

QString CORE_EXPORT sizeAsString(quint64 pSize, int pPrecision = 1);

QString CORE_EXPORT formatTime(qint64 pTime);

QString CORE_EXPORT sha1(const QByteArray &pByteArray);
QString CORE_EXPORT sha1(const QString &pString);

Expand Down
26 changes: 26 additions & 0 deletions src/plugins/miscellaneous/Core/tests/generaltests.cpp
Expand Up @@ -57,6 +57,32 @@ void GeneralTests::sizeAsStringTests()

//==============================================================================

void GeneralTests::formatTimeTests()
{
// Test the formatTime() method

QCOMPARE(OpenCOR::Core::formatTime(0), QString("0ms"));
QCOMPARE(OpenCOR::Core::formatTime(999), QString("999ms"));
QCOMPARE(OpenCOR::Core::formatTime(1000), QString("1s"));
QCOMPARE(OpenCOR::Core::formatTime(59999), QString("59s 999ms"));
QCOMPARE(OpenCOR::Core::formatTime(60000), QString("1m"));
QCOMPARE(OpenCOR::Core::formatTime(60999), QString("1m 0s 999ms"));
QCOMPARE(OpenCOR::Core::formatTime(61000), QString("1m 1s"));
QCOMPARE(OpenCOR::Core::formatTime(3599999), QString("59m 59s 999ms"));
QCOMPARE(OpenCOR::Core::formatTime(3600000), QString("1h"));
QCOMPARE(OpenCOR::Core::formatTime(3600999), QString("1h 0m 0s 999ms"));
QCOMPARE(OpenCOR::Core::formatTime(3601000), QString("1h 0m 1s"));
QCOMPARE(OpenCOR::Core::formatTime(3660000), QString("1h 1m"));
QCOMPARE(OpenCOR::Core::formatTime(86399999), QString("23h 59m 59s 999ms"));
QCOMPARE(OpenCOR::Core::formatTime(86400000), QString("1d"));
QCOMPARE(OpenCOR::Core::formatTime(86400999), QString("1d 0h 0m 0s 999ms"));
QCOMPARE(OpenCOR::Core::formatTime(86401000), QString("1d 0h 0m 1s"));
QCOMPARE(OpenCOR::Core::formatTime(86460000), QString("1d 0h 1m"));
QCOMPARE(OpenCOR::Core::formatTime(90000000), QString("1d 1h"));
}

//==============================================================================

void GeneralTests::sha1Tests()
{
// Test the sha1() method
Expand Down
1 change: 1 addition & 0 deletions src/plugins/miscellaneous/Core/tests/generaltests.h
Expand Up @@ -41,6 +41,7 @@ private slots:
void initTestCase();

void sizeAsStringTests();
void formatTimeTests();
void sha1Tests();
void stringPositionAsLineColumnTests();
void stringLineColumnAsPositionTests();
Expand Down
Expand Up @@ -617,8 +617,8 @@
<translation>Temps de simulation :</translation>
</message>
<message>
<source>%1 s using %2</source>
<translation>%1 s avec %2</translation>
<source>%1 using %2</source>
<translation>%1 avec %2</translation>
</message>
</context>
</TS>
Expand Up @@ -3258,8 +3258,8 @@ void SimulationExperimentViewSimulationWidget::simulationStopped(qint64 pElapsed
if (!mSimulation->data()->nlaSolverName().isEmpty())
solversInformation += "+"+mSimulation->data()->nlaSolverName();

output(QString(OutputTab+"<strong>"+tr("Simulation time:")+"</strong> <span"+OutputInfo+">"+tr("%1 s using %2").arg(QString::number(0.001*pElapsedTime, 'g', 3))
.arg(solversInformation)+"</span>."+OutputBrLn));
output(QString(OutputTab+"<strong>"+tr("Simulation time:")+"</strong> <span"+OutputInfo+">"+tr("%1 using %2").arg(Core::formatTime(pElapsedTime))
.arg(solversInformation)+"</span>."+OutputBrLn));
}

// Update our parameters and simulation mode
Expand Down

0 comments on commit e62e6a7

Please sign in to comment.