diff --git a/tests/qt_types_standalone/CMakeLists.txt b/tests/qt_types_standalone/CMakeLists.txt index bd2e1cd07..48bdd982b 100644 --- a/tests/qt_types_standalone/CMakeLists.txt +++ b/tests/qt_types_standalone/CMakeLists.txt @@ -53,6 +53,7 @@ add_executable(${APP_NAME} cpp/qcoreapplication.h cpp/qdate.h cpp/qdatetime.h + cpp/qfontmetrics.h cpp/qguiapplication.h cpp/qhash.h cpp/qline.h diff --git a/tests/qt_types_standalone/cpp/main.cpp b/tests/qt_types_standalone/cpp/main.cpp index beae4764d..83dac5405 100644 --- a/tests/qt_types_standalone/cpp/main.cpp +++ b/tests/qt_types_standalone/cpp/main.cpp @@ -12,6 +12,7 @@ #include "qcoreapplication.h" #include "qdate.h" #include "qdatetime.h" +#include "qfontmetrics.h" #include "qguiapplication.h" #include "qhash.h" #include "qline.h" @@ -92,6 +93,7 @@ main(int argc, char* argv[]) runTest(QScopedPointer(new QVector3DTest)); runTest(QScopedPointer(new QVector4DTest)); runTest(QScopedPointer(new QPolygonTest)); + runTest(QScopedPointer(new QFontMetricsTest)); return status; } diff --git a/tests/qt_types_standalone/cpp/qfontmetrics.h b/tests/qt_types_standalone/cpp/qfontmetrics.h new file mode 100644 index 000000000..35ac31983 --- /dev/null +++ b/tests/qt_types_standalone/cpp/qfontmetrics.h @@ -0,0 +1,34 @@ +// clang-format off +// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company +// clang-format on +// SPDX-FileContributor: Laurent Montel +// +// SPDX-License-Identifier: MIT OR Apache-2.0 +#pragma once + +#include +#include +#include + +#include "cxx-qt-gen/qfontmetrics.cxx.h" + +class QFontMetricsTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void construct() + { + } + void clone() + { + QFont f; + f.setBold(true); + f.setPointSize(30); + const auto m = QFontMetrics(f); + + const auto c = clone_qfontmetrics(m); + QCOMPARE(m.ascent(), c.ascent()); + QCOMPARE(m.height(), c.height()); + } +}; diff --git a/tests/qt_types_standalone/rust/build.rs b/tests/qt_types_standalone/rust/build.rs index ae458ce59..35740496e 100644 --- a/tests/qt_types_standalone/rust/build.rs +++ b/tests/qt_types_standalone/rust/build.rs @@ -12,6 +12,7 @@ fn main() { .file("src/qcoreapplication.rs") .file("src/qdate.rs") .file("src/qdatetime.rs") + .file("src/qfontmetrics.rs") .file("src/qguiapplication.rs") .file("src/qhash.rs") .file("src/qline.rs") diff --git a/tests/qt_types_standalone/rust/src/lib.rs b/tests/qt_types_standalone/rust/src/lib.rs index d81d4ccb3..88a91d80e 100644 --- a/tests/qt_types_standalone/rust/src/lib.rs +++ b/tests/qt_types_standalone/rust/src/lib.rs @@ -9,6 +9,7 @@ mod qcolor; mod qcoreapplication; mod qdate; mod qdatetime; +mod qfontmetrics; mod qguiapplication; mod qhash; mod qline; diff --git a/tests/qt_types_standalone/rust/src/qfontmetrics.rs b/tests/qt_types_standalone/rust/src/qfontmetrics.rs new file mode 100644 index 000000000..ad3e50f59 --- /dev/null +++ b/tests/qt_types_standalone/rust/src/qfontmetrics.rs @@ -0,0 +1,23 @@ +// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company +// SPDX-FileContributor: Laurent Montel +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use cxx_qt_lib::QFontMetrics; + +#[cxx::bridge] +mod qfontmetrics_cxx { + unsafe extern "C++" { + include!("cxx-qt-lib/qfontmetrics.h"); + + type QFontMetrics = cxx_qt_lib::QFontMetrics; + } + + extern "Rust" { + fn clone_qfontmetrics(f: &QFontMetrics) -> QFontMetrics; + } +} + +fn clone_qfontmetrics(p: &QFontMetrics) -> QFontMetrics { + p.clone() +}