Skip to content

Commit 6f2fc21

Browse files
authored
Merge pull request #43 from scratchcpp/library_info
Add library info to the about dialog
2 parents d6013f8 + 2a55509 commit 6f2fc21

File tree

6 files changed

+67
-2
lines changed

6 files changed

+67
-2
lines changed

src/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ qt_add_executable(${APP_TARGET}
66
app.h
77
appmenubar.cpp
88
appmenubar.h
9+
libraryinfo.cpp
10+
libraryinfo.h
911
)
1012

1113
qt_add_qml_module(${APP_TARGET}

src/app/libraryinfo.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
3+
#include <scratchcpp/scratchconfiguration.h>
4+
#include <scratchcpp-render/scratchcpp-render.h>
5+
6+
#include "libraryinfo.h"
7+
8+
using namespace scratchcpp;
9+
10+
LibraryInfo::LibraryInfo(QObject *parent) :
11+
QObject(parent)
12+
{
13+
}
14+
15+
QString LibraryInfo::libscratchcppVersion() const
16+
{
17+
return QString::fromStdString(libscratchcpp::ScratchConfiguration::version());
18+
}
19+
20+
QString LibraryInfo::scratchcppRenderVersion() const
21+
{
22+
return QString::fromStdString(scratchcpprender::version());
23+
}

src/app/libraryinfo.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
3+
#pragma once
4+
5+
#include <QQmlEngine>
6+
7+
namespace scratchcpp
8+
{
9+
10+
class LibraryInfo : public QObject
11+
{
12+
Q_OBJECT
13+
QML_ELEMENT
14+
QML_SINGLETON
15+
public:
16+
explicit LibraryInfo(QObject *parent = nullptr);
17+
18+
Q_INVOKABLE QString libscratchcppVersion() const;
19+
Q_INVOKABLE QString scratchcppRenderVersion() const;
20+
};
21+
22+
} // namespace scratchcpp

src/app/qml/dialogs/AboutDialog.qml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import QtQuick
44
import QtQuick.Controls
55
import QtQuick.Layouts
6+
import ScratchCPP
67
import ScratchCPP.Ui
78
import ScratchCPP.UiComponents
89

@@ -33,6 +34,16 @@ CustomDialog {
3334
text: qsTr("Version: %1").arg(Qt.application.version)
3435
}
3536

37+
Label {
38+
//: For example "SomeLibrary version: 0.1.0"
39+
text: qsTr("%1 version: %2").arg("libscratchcpp").arg(LibraryInfo.libscratchcppVersion())
40+
}
41+
42+
Label {
43+
//: For example "SomeLibrary version: 0.1.0"
44+
text: qsTr("%1 version: %2").arg("ScratchCPP Render").arg(LibraryInfo.scratchcppRenderVersion())
45+
}
46+
3647
Label {
3748
text: qsTr("Revision: %1").arg(AppInfo.revision())
3849
}

src/global/internal/appinfo.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ AppInfo::AppInfo(QObject *parent) :
1313

1414
QString scratchcpp::AppInfo::revision() const
1515
{
16-
return git_CommitSHA1();
16+
QString rev = git_CommitSHA1();
17+
18+
if (rev.size() >= 8)
19+
return rev.first(8);
20+
21+
return "";
1722
}
1823

1924
int scratchcpp::AppInfo::buildYear() const

src/global/test/appinfo.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ using namespace scratchcpp::test;
1515
TEST(AppInfoTest, Revision)
1616
{
1717
AppInfo info;
18-
ASSERT_EQ(info.revision(), git_CommitSHA1());
18+
QString rev = git_CommitSHA1();
19+
ASSERT_GE(rev.size(), 8);
20+
ASSERT_EQ(info.revision(), rev.first(8));
1921
}
2022

2123
TEST(AppInfoTest, BuildYear)

0 commit comments

Comments
 (0)