Skip to content

Add support for QQuaternion #1314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `QSet::reserve` to reserve capacity up-front.
- Support for further types: `QUuid`
- New example: Basic greeter app
- Support for further types: `qreal`, `qint64`, `qintptr`, `qsizetype`, `quint64`, `quintptr`
- Support for further types: `qreal`, `qint64`, `qintptr`, `qsizetype`, `quint64`, `quintptr`, `QQuaternion`
- Support for `cfg` attributes through to C++ generation
- CXX-Qt-build: Improved compile time and propagation of initializers between crates
- CXX-Qt-build: Multi-crate projects are now possible with Cargo and CMake (see `examples/qml_multi_crates`)
Expand Down
3 changes: 3 additions & 0 deletions crates/cxx-qt-lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ fn main() {
rust_bridges.extend([
"core/qlist/qlist_qcolor",
"core/qvariant/qvariant_qcolor",
"core/qvariant/qvariant_qquaternion",
"core/qvariant/qvariant_qvector2d",
"core/qvariant/qvariant_qvector3d",
"core/qvariant/qvariant_qvector4d",
Expand All @@ -209,6 +210,7 @@ fn main() {
"gui/qfont",
"gui/qguiapplication",
"gui/qimage",
"gui/qquaternion",
"gui/qpainterpath",
"gui/qpainter",
"gui/qpen",
Expand Down Expand Up @@ -286,6 +288,7 @@ fn main() {
"gui/qpen",
"gui/qpolygon",
"gui/qpolygonf",
"gui/qquaternion",
"gui/qregion",
"gui/qvector2d",
"gui/qvector3d",
Expand Down
7 changes: 7 additions & 0 deletions crates/cxx-qt-lib/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ operatorDiv(const S scalar, const T& t)
return t / scalar;
}

template<typename T>
T
operatorNeg(const T& t)
{
return -t;
}

template<typename T, typename... Args>
std::unique_ptr<T>
make_unique(Args... args)
Expand Down
2 changes: 2 additions & 0 deletions crates/cxx-qt-lib/include/core/qvariant.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#ifdef CXX_QT_GUI_FEATURE
#include <QtGui/QColor>
#include <QtGui/QQuaternion>
#include <QtGui/QVector2D>
#include <QtGui/QVector3D>
#include <QtGui/QVector4D>
Expand Down Expand Up @@ -83,6 +84,7 @@ CXX_QT_QVARIANT_CAN_CONVERT(I64)
CXX_QT_QVARIANT_CAN_CONVERT(QByteArray)
#ifdef CXX_QT_GUI_FEATURE
CXX_QT_QVARIANT_CAN_CONVERT(QColor)
CXX_QT_QVARIANT_CAN_CONVERT(QQuaternion)
CXX_QT_QVARIANT_CAN_CONVERT(QVector2D)
CXX_QT_QVARIANT_CAN_CONVERT(QVector3D)
CXX_QT_QVARIANT_CAN_CONVERT(QVector4D)
Expand Down
9 changes: 9 additions & 0 deletions crates/cxx-qt-lib/include/gui/qgenericmatrix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// clang-format off
// SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
// clang-format on
// SPDX-FileContributor: Joshua Booth <[email protected]>
//
// SPDX-License-Identifier: MIT OR Apache-2.0
#pragma once

#include <QtGui/QGenericMatrix>
48 changes: 48 additions & 0 deletions crates/cxx-qt-lib/include/gui/qquaternion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// clang-format off
// SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
// clang-format on
// SPDX-FileContributor: Joshua Booth <[email protected]>
//
// SPDX-License-Identifier: MIT OR Apache-2.0
#pragma once

#include <QtGui/QQuaternion>

namespace rust {
namespace cxxqtlib1 {

inline float (*qquaternionDotProduct)(const QQuaternion&, const QQuaternion&) =
QQuaternion::dotProduct;

inline QQuaternion (*qquaternionFromAxes)(const QVector3D&,
const QVector3D&,
const QVector3D&) =
QQuaternion::fromAxes;

inline QQuaternion (*qquaternionFromAxisAndAngle)(float, float, float, float) =
QQuaternion::fromAxisAndAngle;

inline QQuaternion (*qquaternionFromDirection)(const QVector3D&,
const QVector3D&) =
QQuaternion::fromDirection;

inline QQuaternion (*qquaternionFromEulerAngles)(float, float, float) =
QQuaternion::fromEulerAngles;

inline QQuaternion (*qquaternionFromRotationMatrix)(const QMatrix3x3&) =
QQuaternion::fromRotationMatrix;

inline QQuaternion (*qquaternionNlerp)(const QQuaternion&,
const QQuaternion&,
float) = QQuaternion::nlerp;

inline QQuaternion (*qquaternionRotationTo)(const QVector3D&,
const QVector3D&) =
QQuaternion::rotationTo;

inline QQuaternion (*qquaternionSlerp)(const QQuaternion&,
const QQuaternion&,
float) = QQuaternion::slerp;

}
}
9 changes: 9 additions & 0 deletions crates/cxx-qt-lib/include/qgenericmatrix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// clang-format off
// SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
// clang-format on
// SPDX-FileContributor: Joshua Booth <[email protected]>
//
// SPDX-License-Identifier: MIT OR Apache-2.0
#pragma once

#include "gui/qgenericmatrix.h"
9 changes: 9 additions & 0 deletions crates/cxx-qt-lib/include/qquaternion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// clang-format off
// SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
// clang-format on
// SPDX-FileContributor: Joshua Booth <[email protected]>
//
// SPDX-License-Identifier: MIT OR Apache-2.0
#pragma once

#include "gui/qquaternion.h"
1 change: 1 addition & 0 deletions crates/cxx-qt-lib/src/core/qvariant/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ generate_bridge_qt "QModelIndex" "qmodelindex"
generate_bridge_qt "QPersistentModelIndex" "qpersistentmodelindex"
generate_bridge_qt "QPoint" "qpoint"
generate_bridge_qt "QPointF" "qpointf"
generate_bridge_qt "QQuaternion" "qquaternion"
generate_bridge_qt "QRect" "qrect"
generate_bridge_qt "QRectF" "qrectf"
generate_bridge_qt "QSize" "qsize"
Expand Down
2 changes: 2 additions & 0 deletions crates/cxx-qt-lib/src/core/qvariant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ impl_qvariant_value!(crate::QModelIndex, qvariant_qmodelindex);
impl_qvariant_value!(crate::QPersistentModelIndex, qvariant_qpersistentmodelindex);
impl_qvariant_value!(crate::QPoint, qvariant_qpoint);
impl_qvariant_value!(crate::QPointF, qvariant_qpointf);
#[cfg(feature = "qt_gui")]
impl_qvariant_value!(crate::QQuaternion, qvariant_qquaternion);
impl_qvariant_value!(crate::QRect, qvariant_qrect);
impl_qvariant_value!(crate::QRectF, qvariant_qrectf);
impl_qvariant_value!(crate::QSize, qvariant_qsize);
Expand Down
1 change: 1 addition & 0 deletions crates/cxx-qt-lib/src/core/qvariant/qvariant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ CXX_QT_QVARIANT_CAN_CONVERT_IMPL(::std::int64_t, I64)
CXX_QT_QVARIANT_CAN_CONVERT_IMPL(::QByteArray, QByteArray)
#ifdef CXX_QT_GUI_FEATURE
CXX_QT_QVARIANT_CAN_CONVERT_IMPL(::QColor, QColor)
CXX_QT_QVARIANT_CAN_CONVERT_IMPL(::QQuaternion, QQuaternion)
CXX_QT_QVARIANT_CAN_CONVERT_IMPL(::QVector2D, QVector2D)
CXX_QT_QVARIANT_CAN_CONVERT_IMPL(::QVector3D, QVector3D)
CXX_QT_QVARIANT_CAN_CONVERT_IMPL(::QVector4D, QVector4D)
Expand Down
37 changes: 37 additions & 0 deletions crates/cxx-qt-lib/src/core/qvariant/qvariant_qquaternion.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions crates/cxx-qt-lib/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
mod qcolor;
pub use qcolor::{QColor, QColorNameFormat, QColorSpec};

mod qgenericmatrix;
pub use qgenericmatrix::{
QGenericMatrix, QMatrix2x2, QMatrix2x3, QMatrix2x4, QMatrix3x2, QMatrix3x3, QMatrix3x4,
QMatrix4x2, QMatrix4x3,
};

mod qguiapplication;
pub use qguiapplication::QGuiApplication;

mod qquaternion;
pub use qquaternion::QQuaternion;

mod qvector2d;
pub use qvector2d::QVector2D;

Expand Down
Loading
Loading