Skip to content

Commit

Permalink
Add QVector of QLine(F)
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderVocke committed Sep 13, 2024
1 parent ab982e1 commit f789a0d
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 7 deletions.
2 changes: 2 additions & 0 deletions crates/cxx-qt-lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ fn main() {
"core/qvector/qvector_i64",
"core/qvector/qvector_qbytearray",
"core/qvector/qvector_qdate",
"core/qvector/qvector_qline",
"core/qvector/qvector_qlinef",
"core/qvector/qvector_qmargins",
"core/qvector/qvector_qmarginsf",
"core/qvector/qvector_qpersistentmodelindex",
Expand Down
2 changes: 2 additions & 0 deletions crates/cxx-qt-lib/include/core/qvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ using QVector_QColor = QVector<::QColor>;
#endif
using QVector_QDate = QVector<::QDate>;
using QVector_QDateTime = QVector<::QDateTime>;
using QVector_QLine = QVector<::QLine>;
using QVector_QLineF = QVector<::QLineF>;
using QVector_QMargins = QVector<::QMargins>;
using QVector_QMarginsF = QVector<::QMarginsF>;
using QVector_QPersistentModelIndex = QVector<::QPersistentModelIndex>;
Expand Down
8 changes: 8 additions & 0 deletions crates/cxx-qt-lib/src/core/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ static const int register_QList_QDate =
qRegisterMetaType<::QList_QDate>("QList_QDate");
static const int register_QList_QDateTime =
qRegisterMetaType<::QList_QDateTime>("QList_QDateTime");
static const int register_QList_QLine =
qRegisterMetaType<::QList_QLine>("QList_QLine");
static const int register_QList_QLineF =
qRegisterMetaType<::QList_QLineF>("QList_QLineF");
static const int register_QList_QMargins =
qRegisterMetaType<::QList_QMargins>("QList_QMargins");
static const int register_QList_QMarginsF =
Expand Down Expand Up @@ -126,6 +130,10 @@ static const int register_QVector_QDate =
qRegisterMetaType<::QVector_QDate>("QVector_QDate");
static const int register_QVector_QDateTime =
qRegisterMetaType<::QVector_QDateTime>("QVector_QDateTime");
static const int register_QVector_QLine =
qRegisterMetaType<::QVector_QLine>("QVector_QLine");
static const int register_QVector_QLineF =
qRegisterMetaType<::QVector_QLineF>("QVector_QLineF");
static const int register_QVector_QMargins =
qRegisterMetaType<::QVector_QMargins>("QVector_QMargins");
static const int register_QVector_QMarginsF =
Expand Down
2 changes: 2 additions & 0 deletions crates/cxx-qt-lib/src/core/qvector/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ generate_bridge_qt "QByteArray" "qbytearray"
generate_bridge_qt "QColor" "qcolor"
generate_bridge_qt "QDate" "qdate"
generate_bridge_qt "QDateTime" "qdatetime"
generate_bridge_qt "QLine" "qline"
generate_bridge_qt "QLineF" "qlinef"
generate_bridge_qt "QMargins" "qmargins"
generate_bridge_qt "QMarginsF" "qmarginsf"
generate_bridge_qt "QPersistentModelIndex" "qpersistentmodelindex"
Expand Down
6 changes: 4 additions & 2 deletions crates/cxx-qt-lib/src/core/qvector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::QColor;
#[cfg(not(target_os = "emscripten"))]
use crate::QDateTime;
use crate::{
QByteArray, QDate, QMargins, QMarginsF, QPersistentModelIndex, QPoint, QPointF, QRect, QRectF,
QSize, QSizeF, QString, QTime, QUrl, QVariant,
QByteArray, QDate, QLine, QLineF, QMargins, QMarginsF, QPersistentModelIndex, QPoint, QPointF,
QRect, QRectF, QSize, QSizeF, QString, QTime, QUrl, QVariant,
};
use core::{marker::PhantomData, mem::MaybeUninit};
use cxx::{type_id, ExternType};
Expand Down Expand Up @@ -355,6 +355,8 @@ impl_qvector_element!(QColor, qvector_qcolor, "QVector_QColor");
impl_qvector_element!(QDate, qvector_qdate, "QVector_QDate");
#[cfg(not(target_os = "emscripten"))]
impl_qvector_element!(QDateTime, qvector_qdatetime, "QVector_QDateTime");
impl_qvector_element!(QLine, qvector_qline, "QVector_QLine");
impl_qvector_element!(QLineF, qvector_qlinef, "QVector_QLineF");
impl_qvector_element!(QMargins, qvector_qmargins, "QVector_QMargins");
impl_qvector_element!(QMarginsF, qvector_qmarginsf, "QVector_QMarginsF");
impl_qvector_element!(
Expand Down
92 changes: 92 additions & 0 deletions crates/cxx-qt-lib/src/core/qvector/qvector_qline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
// SPDX-FileContributor: Andrew Hayzen <[email protected]>
//
// SPDX-License-Identifier: MIT OR Apache-2.0

#[cxx::bridge]
pub mod ffi {
unsafe extern "C++" {
include!("cxx-qt-lib/qline.h");
type QLine = crate::QLine;

include!("cxx-qt-lib/qvector.h");
type QVector_QLine = crate::QVector<QLine>;
}

unsafe extern "C++" {
#[rust_name = "cxx_clear"]
fn clear(self: &mut QVector_QLine);
#[rust_name = "cxx_contains"]
fn contains(self: &QVector_QLine, _: &QLine) -> bool;
}

#[namespace = "rust::cxxqtlib1"]
unsafe extern "C++" {
include!("cxx-qt-lib/common.h");

#[rust_name = "qvector_clone_QLine"]
fn construct(_: &QVector_QLine) -> QVector_QLine;
#[rust_name = "qvector_default_QLine"]
fn construct() -> QVector_QLine;
#[rust_name = "qvector_drop_QLine"]
fn drop(_: &mut QVector_QLine);
}

#[namespace = "rust::cxxqtlib1::qvector"]
unsafe extern "C++" {
#[rust_name = "reserve_QLine"]
fn qvectorReserve(_: &mut QVector_QLine, size: isize);
#[rust_name = "append_QLine"]
fn qvectorAppend(_: &mut QVector_QLine, _: &QLine);
#[rust_name = "get_unchecked_QLine"]
unsafe fn qvectorGetUnchecked(set: &QVector_QLine, pos: isize) -> &QLine;
#[rust_name = "index_of_QLine"]
fn qvectorIndexOf(_: &QVector_QLine, _: &QLine) -> isize;
#[rust_name = "insert_QLine"]
fn qvectorInsert(_: &mut QVector_QLine, _: isize, _: &QLine);
#[rust_name = "remove_QLine"]
fn qvectorRemove(_: &mut QVector_QLine, _: isize);
#[rust_name = "len_QLine"]
fn qvectorLen(_: &QVector_QLine) -> isize;
}
}

pub(crate) fn append(v: &mut ffi::QVector_QLine, value: &ffi::QLine) {
ffi::append_QLine(v, value);
}

pub(crate) fn clone(s: &ffi::QVector_QLine) -> ffi::QVector_QLine {
ffi::qvector_clone_QLine(s)
}

pub(crate) fn reserve(v: &mut ffi::QVector_QLine, size: isize) {
ffi::reserve_QLine(v, size);
}

pub(crate) fn default() -> ffi::QVector_QLine {
ffi::qvector_default_QLine()
}

pub(crate) fn drop(s: &mut ffi::QVector_QLine) {
ffi::qvector_drop_QLine(s);
}

pub(crate) unsafe fn get_unchecked(s: &ffi::QVector_QLine, pos: isize) -> &ffi::QLine {
ffi::get_unchecked_QLine(s, pos)
}

pub(crate) fn index_of(v: &ffi::QVector_QLine, value: &ffi::QLine) -> isize {
ffi::index_of_QLine(v, value)
}

pub(crate) fn insert(s: &mut ffi::QVector_QLine, pos: isize, value: &ffi::QLine) {
ffi::insert_QLine(s, pos, value);
}

pub(crate) fn len(s: &ffi::QVector_QLine) -> isize {
ffi::len_QLine(s)
}

pub(crate) fn remove(s: &mut ffi::QVector_QLine, pos: isize) {
ffi::remove_QLine(s, pos);
}
92 changes: 92 additions & 0 deletions crates/cxx-qt-lib/src/core/qvector/qvector_qlinef.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
// SPDX-FileContributor: Andrew Hayzen <[email protected]>
//
// SPDX-License-Identifier: MIT OR Apache-2.0

#[cxx::bridge]
pub mod ffi {
unsafe extern "C++" {
include!("cxx-qt-lib/qlinef.h");
type QLineF = crate::QLineF;

include!("cxx-qt-lib/qvector.h");
type QVector_QLineF = crate::QVector<QLineF>;
}

unsafe extern "C++" {
#[rust_name = "cxx_clear"]
fn clear(self: &mut QVector_QLineF);
#[rust_name = "cxx_contains"]
fn contains(self: &QVector_QLineF, _: &QLineF) -> bool;
}

#[namespace = "rust::cxxqtlib1"]
unsafe extern "C++" {
include!("cxx-qt-lib/common.h");

#[rust_name = "qvector_clone_QLineF"]
fn construct(_: &QVector_QLineF) -> QVector_QLineF;
#[rust_name = "qvector_default_QLineF"]
fn construct() -> QVector_QLineF;
#[rust_name = "qvector_drop_QLineF"]
fn drop(_: &mut QVector_QLineF);
}

#[namespace = "rust::cxxqtlib1::qvector"]
unsafe extern "C++" {
#[rust_name = "reserve_QLineF"]
fn qvectorReserve(_: &mut QVector_QLineF, size: isize);
#[rust_name = "append_QLineF"]
fn qvectorAppend(_: &mut QVector_QLineF, _: &QLineF);
#[rust_name = "get_unchecked_QLineF"]
unsafe fn qvectorGetUnchecked(set: &QVector_QLineF, pos: isize) -> &QLineF;
#[rust_name = "index_of_QLineF"]
fn qvectorIndexOf(_: &QVector_QLineF, _: &QLineF) -> isize;
#[rust_name = "insert_QLineF"]
fn qvectorInsert(_: &mut QVector_QLineF, _: isize, _: &QLineF);
#[rust_name = "remove_QLineF"]
fn qvectorRemove(_: &mut QVector_QLineF, _: isize);
#[rust_name = "len_QLineF"]
fn qvectorLen(_: &QVector_QLineF) -> isize;
}
}

pub(crate) fn append(v: &mut ffi::QVector_QLineF, value: &ffi::QLineF) {
ffi::append_QLineF(v, value);
}

pub(crate) fn clone(s: &ffi::QVector_QLineF) -> ffi::QVector_QLineF {
ffi::qvector_clone_QLineF(s)
}

pub(crate) fn reserve(v: &mut ffi::QVector_QLineF, size: isize) {
ffi::reserve_QLineF(v, size);
}

pub(crate) fn default() -> ffi::QVector_QLineF {
ffi::qvector_default_QLineF()
}

pub(crate) fn drop(s: &mut ffi::QVector_QLineF) {
ffi::qvector_drop_QLineF(s);
}

pub(crate) unsafe fn get_unchecked(s: &ffi::QVector_QLineF, pos: isize) -> &ffi::QLineF {
ffi::get_unchecked_QLineF(s, pos)
}

pub(crate) fn index_of(v: &ffi::QVector_QLineF, value: &ffi::QLineF) -> isize {
ffi::index_of_QLineF(v, value)
}

pub(crate) fn insert(s: &mut ffi::QVector_QLineF, pos: isize, value: &ffi::QLineF) {
ffi::insert_QLineF(s, pos, value);
}

pub(crate) fn len(s: &ffi::QVector_QLineF) -> isize {
ffi::len_QLineF(s)
}

pub(crate) fn remove(s: &mut ffi::QVector_QLineF, pos: isize) {
ffi::remove_QLineF(s, pos);
}
10 changes: 5 additions & 5 deletions crates/cxx-qt-lib/src/gui/qpainter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ mod ffi {
type QPolygon = crate::QPolygon;
include!("cxx-qt-lib/qregion.h");
type QRegion = crate::QRegion;
include!("cxx-qt-lib/qlist.h");
type QList_QLine = crate::QList<QLine>;
type QList_QLineF = crate::QList<QLineF>;
include!("cxx-qt-lib/qvector.h");
type QVector_QLine = crate::QVector<QLine>;
type QVector_QLineF = crate::QVector<QLineF>;

/// Returns the current background mode.
#[rust_name = "background_mode"]
Expand Down Expand Up @@ -250,11 +250,11 @@ mod ffi {

/// Draws the set of lines defined by the list lines using the current pen and brush.
#[rust_name = "draw_lines"]
fn drawLines(self: Pin<&mut QPainter>, lines: &QList_QLine);
fn drawLines(self: Pin<&mut QPainter>, lines: &QVector_QLine);

/// Draws the set of lines defined by the list lines using the current pen and brush.
#[rust_name = "draw_linefs"]
fn drawLines(self: Pin<&mut QPainter>, lines: &QList_QLineF);
fn drawLines(self: Pin<&mut QPainter>, lines: &QVector_QLineF);

/// Draws the given painter path using the current pen for outline and the current brush for filling.
#[rust_name = "draw_path"]
Expand Down

0 comments on commit f789a0d

Please sign in to comment.