Skip to content

Commit 3c5e1ad

Browse files
Just-Kielcbentejac
authored andcommitted
[ui] Format GB to string for occupied cache size
1 parent ac7aedd commit 3c5e1ad

File tree

2 files changed

+50
-17
lines changed

2 files changed

+50
-17
lines changed

meshroom/ui/qml/Utils/format.js

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ function intToString(v) {
1010

1111
// Convert a plain text to an html escaped string.
1212
function plainToHtml(t) {
13-
var escaped = t.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;') // escape text
14-
return escaped.replace(/\n/g, '<br>') // replace line breaks
13+
var escaped = t.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;') // escape text
14+
return escaped.replace(/\n/g, '<br>') // replace line breaks
1515
}
1616

1717
function divmod(x, y) {
1818
// Perform the division and get the quotient
19-
const quotient = Math.floor(x / y);
19+
const quotient = Math.floor(x / y)
2020
// Compute the remainder
21-
const remainder = x % y;
22-
return [quotient, remainder];
21+
const remainder = x % y
22+
return [quotient, remainder]
2323
}
2424

2525
function sec2timeHMS(totalSeconds) {
@@ -30,7 +30,7 @@ function sec2timeHMS(totalSeconds) {
3030
hours: hours,
3131
minutes: minutes,
3232
seconds: seconds
33-
};
33+
}
3434
}
3535

3636
function sec2timecode(timeSeconds) {
@@ -43,22 +43,22 @@ function sec2timecode(timeSeconds) {
4343
function sec2timeStr(timeSeconds) {
4444
// Need to decide the rounding precision first
4545
// to propagate the right values
46-
if(timeSeconds >= 60.0) {
46+
if (timeSeconds >= 60.0) {
4747
timeSeconds = Math.round(timeSeconds)
4848
} else {
4949
timeSeconds = parseFloat(timeSeconds.toFixed(2))
5050
}
5151
var timeObj = sec2timeHMS(timeSeconds)
5252
var timeStr = ""
53-
if(timeObj.hours > 0) {
53+
if (timeObj.hours > 0) {
5454
timeStr += timeObj.hours + "h"
5555
}
56-
if(timeObj.hours > 0 || timeObj.minutes > 0) {
56+
if (timeObj.hours > 0 || timeObj.minutes > 0) {
5757
timeStr += timeObj.minutes + "m"
5858
}
59-
if(timeObj.hours === 0) {
59+
if (timeObj.hours === 0) {
6060
// seconds only matter if the elapsed time is less than 1 hour
61-
if(timeObj.minutes === 0) {
61+
if (timeObj.minutes === 0) {
6262
// If less than a minute, keep millisecond precision
6363
timeStr += timeObj.seconds.toFixed(2) + "s"
6464
} else {
@@ -68,3 +68,39 @@ function sec2timeStr(timeSeconds) {
6868
}
6969
return timeStr
7070
}
71+
72+
function GB2GBMBKB(GB) {
73+
// Convert GB to GB, MB, KB
74+
var GBInt = Math.floor(GB)
75+
var MB = Math.floor((GB - GBInt) * 1024)
76+
var KB = Math.floor(((GB - GBInt) * 1024 - MB) * 1024)
77+
return {
78+
GB: GBInt,
79+
MB: MB,
80+
KB: KB
81+
}
82+
}
83+
84+
function GB2SizeStr(GB) {
85+
// Convert GB to a human readable size string
86+
// e.g. 1.23GB, 456MB, 789KB
87+
// We only use one unit at a time
88+
var sizeObj = GB2GBMBKB(GB)
89+
var sizeStr = ""
90+
if (sizeObj.GB > 0) {
91+
sizeStr += sizeObj.GB
92+
if (sizeObj.MB > 0 && sizeObj.GB < 10) {
93+
sizeStr += "." + Math.floor(sizeObj.MB / 1024 * 1000)
94+
}
95+
sizeStr += "GB"
96+
} else if (sizeObj.MB > 0) {
97+
sizeStr = sizeObj.MB
98+
if (sizeObj.KB > 0 && sizeObj.MB < 10) {
99+
sizeStr += "." + Math.floor(sizeObj.KB / 1024 * 1000)
100+
}
101+
sizeStr += "MB"
102+
} else if (sizeObj.GB === 0 && sizeObj.MB === 0) {
103+
sizeStr += sizeObj.KB + "KB"
104+
}
105+
return sizeStr
106+
}

meshroom/ui/qml/Viewer/SequencePlayer.qml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,18 +485,15 @@ FloatingPane {
485485
ProgressBar {
486486
id: occupiedCacheProgressBar
487487

488+
property string occupiedCache: viewer.ramInfo ? Format.GB2SizeStr(viewer.ramInfo.y) : 0
489+
488490
width: parent.width
489491

490492
from: 0
491493
to: settings_SequencePlayer.maxCacheMemory
492494
value: viewer && viewer.ramInfo != undefined ? viewer.ramInfo.y : 0
493495

494-
ToolTip.text: {
495-
if (viewer && viewer.ramInfo != undefined) {
496-
return "Occupied cache: "+ viewer.ramInfo.y + " GB" + "\n" + "On max cache memory set: " + settings_SequencePlayer.maxCacheMemory + " GB"
497-
}
498-
return "Unknown occupied cache (max cache memory set: " + settings_SequencePlayer.maxCacheMemory + ")"
499-
}
496+
ToolTip.text: "Occupied cache: " + occupiedCache + "\n" + "On max cache memory set: " + settings_SequencePlayer.maxCacheMemory + " GB"
500497
ToolTip.visible: hovered
501498
ToolTip.delay: 100
502499
}

0 commit comments

Comments
 (0)