Skip to content

Commit ab98bb8

Browse files
committed
Use QString to safely pass int64_t to qml in viewer
1 parent 7b952db commit ab98bb8

File tree

9 files changed

+93
-71
lines changed

9 files changed

+93
-71
lines changed

viewer/qml/Main.qml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,7 @@ PAGWindow {
294294
}
295295

296296
function updateProgress() {
297-
let duration = mainForm.pagView.duration;
298-
let displayedTime = duration * mainForm.pagView.progress;
299-
mainForm.controlForm.timeDisplayedText.text = Utils.msToTime(displayedTime);
297+
mainForm.controlForm.timeDisplayedText.text = mainForm.pagView.displayedTime;
300298
mainForm.controlForm.currentFrameText.text = mainForm.pagView.currentFrame;
301299
mainForm.controlForm.totalFrameText.text = mainForm.pagView.totalFrame;
302300
}

viewer/src/profiling/PAGFrameDisplayInfoModel.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
namespace pag {
2222

23-
FrameDisplayInfo::FrameDisplayInfo(const QString& name, const QString& color, int current, int avg,
24-
int max)
23+
FrameDisplayInfo::FrameDisplayInfo(const QString& name, const QString& color, int64_t current,
24+
int64_t avg, int64_t max)
2525
: name(name), color(color), current(current), avg(avg), max(max) {
2626
}
2727

@@ -42,13 +42,13 @@ auto PAGFrameDisplayInfoModel::data(const QModelIndex& index, int role) const ->
4242
return item.color;
4343
}
4444
case PAGFrameDisplayInfoRoles::CurrentRole: {
45-
return item.current;
45+
return QString::number(item.current);
4646
}
4747
case PAGFrameDisplayInfoRoles::AvgRole: {
48-
return item.avg;
48+
return QString::number(item.avg);
4949
}
5050
case PAGFrameDisplayInfoRoles::MaxRole: {
51-
return item.max;
51+
return QString::number(item.max);
5252
}
5353
default:
5454
return {};

viewer/src/profiling/PAGFrameDisplayInfoModel.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ namespace pag {
2525

2626
class FrameDisplayInfo {
2727
public:
28-
FrameDisplayInfo(const QString& name, const QString& color, int current, int avg, int max);
28+
FrameDisplayInfo(const QString& name, const QString& color, int64_t current, int64_t avg,
29+
int64_t max);
2930

3031
QString name{};
3132
QString color{};
32-
int current{0};
33-
int avg{0};
34-
int max{0};
33+
int64_t current{0};
34+
int64_t avg{0};
35+
int64_t max{0};
3536
};
3637

3738
class PAGFrameDisplayInfoModel : public QAbstractListModel {

viewer/src/profiling/PAGRunTimeModelManager.cpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ FrameTimeMetrics::FrameTimeMetrics(const FrameTimeMetrics& data) {
3030
imageDecodeTime = data.imageDecodeTime;
3131
}
3232

33-
FrameTimeMetrics::FrameTimeMetrics(int renderTime, int presentTime, int imageDecodeTime) {
33+
FrameTimeMetrics::FrameTimeMetrics(int64_t renderTime, int64_t presentTime,
34+
int64_t imageDecodeTime) {
3435
this->renderTime = renderTime;
3536
this->presentTime = presentTime;
3637
this->imageDecodeTime = imageDecodeTime;
@@ -41,12 +42,12 @@ auto FrameTimeMetrics::operator=(const FrameTimeMetrics& other) -> FrameTimeMetr
4142
PAGRunTimeModelManager::PAGRunTimeModelManager(QObject* parent) : QObject(parent) {
4243
}
4344

44-
auto PAGRunTimeModelManager::getTotalFrame() const -> int {
45-
return totalFrame;
45+
auto PAGRunTimeModelManager::getTotalFrame() const -> QString {
46+
return QString::number(totalFrame);
4647
}
4748

48-
auto PAGRunTimeModelManager::getCurrentFrame() const -> int {
49-
return currentFrame;
49+
auto PAGRunTimeModelManager::getCurrentFrame() const -> QString {
50+
return QString::number(currentFrame);
5051
}
5152

5253
auto PAGRunTimeModelManager::getFileInfoModel() const -> const PAGFileInfoModel* {
@@ -57,16 +58,16 @@ auto PAGRunTimeModelManager::getFrameDisplayInfoModel() const -> const PAGFrameD
5758
return &frameDisplayInfoModel;
5859
}
5960

60-
auto PAGRunTimeModelManager::setCurrentFrame(int currentFrame) -> void {
61-
if (this->currentFrame == currentFrame) {
61+
auto PAGRunTimeModelManager::setCurrentFrame(const QString& currentFrame) -> void {
62+
if (this->currentFrame == currentFrame.toLongLong()) {
6263
return;
6364
}
64-
this->currentFrame = currentFrame;
65+
this->currentFrame = currentFrame.toLongLong();
6566
Q_EMIT dataChanged();
6667
}
6768

68-
auto PAGRunTimeModelManager::updateData(int currentFrame, int renderTime, int presentTime,
69-
int imageDecodeTime) -> void {
69+
auto PAGRunTimeModelManager::updateData(int64_t currentFrame, int64_t renderTime,
70+
int64_t presentTime, int64_t imageDecodeTime) -> void {
7071
if (this->currentFrame == currentFrame) {
7172
return;
7273
}
@@ -78,26 +79,26 @@ auto PAGRunTimeModelManager::updateData(int currentFrame, int renderTime, int pr
7879

7980
auto PAGRunTimeModelManager::resetFile(const std::shared_ptr<PAGFile>& pagFile,
8081
const std::string& filePath) -> void {
81-
totalFrame = static_cast<int>(TimeToFrame(pagFile->duration(), pagFile->frameRate()));
82+
totalFrame = TimeToFrame(pagFile->duration(), pagFile->frameRate());
8283
currentFrame = -1;
8384
frameTimeMetricsMap.clear();
8485
fileInfoModel.resetFile(pagFile, filePath);
8586
updateFrameDisplayInfo(0, 0, 0);
8687
Q_EMIT dataChanged();
8788
}
8889

89-
auto PAGRunTimeModelManager::updateFrameDisplayInfo(int renderTime, int presentTime,
90-
int imageDecodeTime) -> void {
91-
int renderAvg = 0;
92-
int renderMax = 0;
93-
int renderTotal = 0;
94-
int presentAvg = 0;
95-
int presentMax = 0;
96-
int presentTotal = 0;
97-
int imageDecodeAvg = 0;
98-
int imageDecodeMax = 0;
99-
int imageDecodeTotal = 0;
100-
int size = static_cast<int>(frameTimeMetricsMap.size());
90+
auto PAGRunTimeModelManager::updateFrameDisplayInfo(int64_t renderTime, int64_t presentTime,
91+
int64_t imageDecodeTime) -> void {
92+
int64_t renderAvg = 0;
93+
int64_t renderMax = 0;
94+
int64_t renderTotal = 0;
95+
int64_t presentAvg = 0;
96+
int64_t presentMax = 0;
97+
int64_t presentTotal = 0;
98+
int64_t imageDecodeAvg = 0;
99+
int64_t imageDecodeMax = 0;
100+
int64_t imageDecodeTotal = 0;
101+
int64_t size = static_cast<int64_t>(frameTimeMetricsMap.size());
101102

102103
if (size > 0) {
103104
auto iter = frameTimeMetricsMap.begin();

viewer/src/profiling/PAGRunTimeModelManager.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,52 +28,55 @@ class FrameTimeMetrics {
2828
public:
2929
FrameTimeMetrics();
3030
FrameTimeMetrics(const FrameTimeMetrics& data);
31-
FrameTimeMetrics(int renderTime, int presentTime, int imageDecodeTime);
31+
FrameTimeMetrics(int64_t renderTime, int64_t presentTime, int64_t imageDecodeTime);
3232
auto operator=(const FrameTimeMetrics& other) -> FrameTimeMetrics&;
3333

3434
public:
35-
int renderTime{0};
36-
int presentTime{0};
37-
int imageDecodeTime{0};
35+
int64_t renderTime{0};
36+
int64_t presentTime{0};
37+
int64_t imageDecodeTime{0};
3838
};
3939

4040
class PAGRunTimeModelManager : public QObject {
4141
Q_OBJECT
4242
public:
4343
explicit PAGRunTimeModelManager(QObject* parent = nullptr);
4444

45-
Q_PROPERTY(int totalFrame READ getTotalFrame NOTIFY totalFrameChanged)
46-
Q_PROPERTY(int currentFrame READ getCurrentFrame WRITE setCurrentFrame NOTIFY currentFrameChanged)
45+
Q_PROPERTY(QString totalFrame READ getTotalFrame NOTIFY totalFrameChanged)
46+
Q_PROPERTY(
47+
QString currentFrame READ getCurrentFrame WRITE setCurrentFrame NOTIFY currentFrameChanged)
4748
Q_PROPERTY(
4849
const PAGFileInfoModel* fileInfoModel READ getFileInfoModel NOTIFY fileInfoModelChanged)
4950
Q_PROPERTY(const PAGFrameDisplayInfoModel* frameDisplayInfoModel READ getFrameDisplayInfoModel
5051
NOTIFY frameDisplayInfoModelChanged)
5152

52-
auto getTotalFrame() const -> int;
53-
auto getCurrentFrame() const -> int;
53+
auto getTotalFrame() const -> QString;
54+
auto getCurrentFrame() const -> QString;
5455
auto getFileInfoModel() const -> const PAGFileInfoModel*;
5556
auto getFrameDisplayInfoModel() const -> const PAGFrameDisplayInfoModel*;
5657

57-
auto setCurrentFrame(int currentFrame) -> void;
58+
auto setCurrentFrame(const QString& currentFrame) -> void;
5859

5960
Q_SIGNAL void totalFrameChanged();
6061
Q_SIGNAL void currentFrameChanged();
6162
Q_SIGNAL void fileInfoModelChanged();
6263
Q_SIGNAL void frameDisplayInfoModelChanged();
6364
Q_SIGNAL void dataChanged();
6465

65-
Q_SLOT void updateData(int currentFrame, int renderTime, int presentTime, int imageDecodeTime);
66+
Q_SLOT void updateData(int64_t currentFrame, int64_t renderTime, int64_t presentTime,
67+
int64_t imageDecodeTime);
6668

6769
auto resetFile(const std::shared_ptr<PAGFile>& pagFile, const std::string& filePath) -> void;
6870

6971
private:
70-
auto updateFrameDisplayInfo(int renderTime, int presentTime, int imageDecodeTime) -> void;
72+
auto updateFrameDisplayInfo(int64_t renderTime, int64_t presentTime, int64_t imageDecodeTime)
73+
-> void;
7174

7275
private:
73-
int totalFrame{-1};
74-
int currentFrame{-1};
76+
int64_t totalFrame{-1};
77+
int64_t currentFrame{-1};
7578
PAGFileInfoModel fileInfoModel{};
7679
PAGFrameDisplayInfoModel frameDisplayInfoModel{};
77-
QMap<int, FrameTimeMetrics> frameTimeMetricsMap{};
80+
QMap<int64_t, FrameTimeMetrics> frameTimeMetricsMap{};
7881
};
7982
} // namespace pag

viewer/src/rendering/PAGRenderThread.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ PAGRenderThread::PAGRenderThread(PAGView* pagView) : pagView(pagView) {
2828
auto PAGRenderThread::flush() -> void {
2929
pagView->pagPlayer->flush();
3030
double progress = pagView->pagFile->getProgress();
31-
int currentFrame = static_cast<int>(std::round((pagView->getTotalFrame() - 1) * progress));
32-
int renderingTime = static_cast<int>(pagView->pagPlayer->renderingTime());
33-
int presentingTime = static_cast<int>(pagView->pagPlayer->presentingTime());
34-
int imageDecodingTime = static_cast<int>(pagView->pagPlayer->imageDecodingTime());
31+
int64_t currentFrame =
32+
static_cast<int64_t>(std::round((pagView->getTotalFrame().toDouble() - 1) * progress));
33+
int64_t renderingTime = pagView->pagPlayer->renderingTime();
34+
int64_t presentingTime = pagView->pagPlayer->presentingTime();
35+
int64_t imageDecodingTime = pagView->pagPlayer->imageDecodingTime();
3536
Q_EMIT frameTimeMetricsReady(currentFrame, renderingTime, presentingTime, imageDecodingTime);
3637
QMetaObject::invokeMethod(pagView, "update", Qt::QueuedConnection);
3738
}

viewer/src/rendering/PAGRenderThread.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class PAGRenderThread : public QThread {
2929
public:
3030
explicit PAGRenderThread(PAGView* pagView);
3131

32-
Q_SIGNAL void frameTimeMetricsReady(int frame, int renderTime, int presentTime,
33-
int imageDecodeTime);
32+
Q_SIGNAL void frameTimeMetricsReady(int64_t frame, int64_t renderTime, int64_t presentTime,
33+
int64_t imageDecodeTime);
3434

3535
Q_SLOT void flush();
3636
Q_SLOT void shutDown();

viewer/src/rendering/PAGView.cpp

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,22 @@ auto PAGView::getPAGHeight() const -> int {
5959
return pagFile->height();
6060
}
6161

62-
auto PAGView::getTotalFrame() const -> int {
62+
auto PAGView::getTotalFrame() const -> QString {
6363
if (pagFile == nullptr) {
64-
return 0;
64+
return "0";
6565
}
66-
int totalFrames = static_cast<int>(std::round(getDuration() * pagFile->frameRate() / 1000.0));
66+
int64_t totalFrames =
67+
static_cast<int64_t>(std::round(getDuration().toLongLong() * pagFile->frameRate() / 1000.0));
6768
if (totalFrames < 1) {
6869
totalFrames = 0;
6970
}
70-
return totalFrames;
71+
return QString::number(totalFrames);
7172
}
7273

73-
auto PAGView::getCurrentFrame() const -> int {
74-
int totalFrames = getTotalFrame();
75-
return static_cast<int>(std::round(getProgress() * (totalFrames - 1)));
74+
auto PAGView::getCurrentFrame() const -> QString {
75+
int64_t totalFrames = getTotalFrame().toLongLong();
76+
int64_t currentFrame = static_cast<int64_t>(std::round(getProgress() * (totalFrames - 1)));
77+
return QString::number(currentFrame);
7678
}
7779

7880
auto PAGView::isPlaying() const -> bool {
@@ -86,11 +88,11 @@ auto PAGView::getShowVideoFrames() const -> bool {
8688
return pagPlayer->videoEnabled();
8789
}
8890

89-
auto PAGView::getDuration() const -> double {
91+
auto PAGView::getDuration() const -> QString {
9092
if (pagPlayer == nullptr) {
91-
return 0.0;
93+
return "0";
9294
}
93-
return static_cast<double>(pagPlayer->duration()) / 1000.0;
95+
return QString::number(pagPlayer->duration() / 1000);
9496
}
9597

9698
auto PAGView::getProgress() const -> double {
@@ -101,6 +103,19 @@ auto PAGView::getFilePath() const -> QString {
101103
return filePath;
102104
}
103105

106+
auto PAGView::getDisplayedTime() const -> QString {
107+
if (pagFile == nullptr) {
108+
return "00:00";
109+
}
110+
int64_t displayedTime =
111+
static_cast<int64_t>(std::round(getProgress() * getDuration().toLongLong() / 1000.0));
112+
int64_t displayedSeconds = displayedTime % 60;
113+
int64_t displayedMinutes = (displayedTime / 60) % 60;
114+
return QString("%1:%2")
115+
.arg(displayedMinutes, 2, 10, QChar('0'))
116+
.arg(displayedSeconds, 2, 10, QChar('0'));
117+
}
118+
104119
auto PAGView::getBackgroundColor() const -> QColor {
105120
if (pagFile == nullptr) {
106121
return QColorConstants::Black;

viewer/src/rendering/PAGView.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,28 @@ class PAGView : public QQuickItem {
3434

3535
Q_PROPERTY(int pagWidth READ getPAGWidth)
3636
Q_PROPERTY(int pagHeight READ getPAGHeight)
37-
Q_PROPERTY(int totalFrame READ getTotalFrame)
38-
Q_PROPERTY(int currentFrame READ getCurrentFrame)
3937
Q_PROPERTY(bool isPlaying READ isPlaying WRITE setIsPlaying NOTIFY isPlayingChanged)
4038
Q_PROPERTY(bool showVideoFrames READ getShowVideoFrames WRITE setShowVideoFrames)
41-
Q_PROPERTY(double duration READ getDuration)
4239
Q_PROPERTY(double progress READ getProgress WRITE setProgress NOTIFY progressChanged)
40+
Q_PROPERTY(QString totalFrame READ getTotalFrame)
41+
Q_PROPERTY(QString currentFrame READ getCurrentFrame)
42+
Q_PROPERTY(QString duration READ getDuration)
4343
Q_PROPERTY(QString filePath READ getFilePath NOTIFY fileChanged)
44+
Q_PROPERTY(QString displayedTime READ getDisplayedTime)
4445
Q_PROPERTY(QColor backgroundColor READ getBackgroundColor)
4546
Q_PROPERTY(QSizeF preferredSize READ getPreferredSize)
4647

4748
auto getPAGWidth() const -> int;
4849
auto getPAGHeight() const -> int;
49-
auto getTotalFrame() const -> int;
50-
auto getCurrentFrame() const -> int;
50+
5151
auto isPlaying() const -> bool;
5252
auto getShowVideoFrames() const -> bool;
53-
auto getDuration() const -> double;
5453
auto getProgress() const -> double;
54+
auto getTotalFrame() const -> QString;
55+
auto getCurrentFrame() const -> QString;
56+
auto getDuration() const -> QString;
5557
auto getFilePath() const -> QString;
58+
auto getDisplayedTime() const -> QString;
5659
auto getBackgroundColor() const -> QColor;
5760
auto getPreferredSize() const -> QSizeF;
5861

0 commit comments

Comments
 (0)