Skip to content

Commit 541afe1

Browse files
authored
Merge branch 'main' into improve_qimage_support
2 parents 2851a79 + ffd346d commit 541afe1

30 files changed

+555
-3
lines changed

.clangd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
2+
# SPDX-FileContributor: Leon Matthes <[email protected]>
3+
#
4+
# SPDX-License-Identifier: MIT OR Apache-2.0
5+
CompileFlags:
6+
Add: [-DCXX_QT_GUI_FEATURE=1]

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ compile_commands.json
2020
# cmps (https://github.com/leonmatthes/cmps)
2121
.cmps/
2222

23+
# clangd cache
24+
.cache/

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ CXX-Qt is tested on CI on Linux, Windows, and macOS (all on x86_64). It should w
4141
Rust both support, however, these are not tested regularly.
4242

4343
CXX-Qt is in early development and the API changes frequently. For the latest documentation between releases, [install mdBook](https://rust-lang.github.io/mdBook/guide/installation.html)
44-
and run `mdbook serve` in the [book folder](./book).
44+
and run `mdbook serve --open` in the [book folder](./book). It will open your own browser.
45+
If you need to open it in another browser goto url [http://localhost:3000](http://localhost:3000).
4546

4647
## Comparison to other Rust Qt bindings
4748

@@ -130,7 +131,7 @@ ctest --test-dir build
130131

131132
## Licensing
132133

133-
CXX-Qt is Copyright (C) 2022, Klarälvdalens Datakonsult AB, and is available under
134+
CXX-Qt is Copyright (C) Klarälvdalens Datakonsult AB, and is available under
134135
the terms of the [MIT](https://github.com/KDAB/cxx-qt/blob/main/LICENSES/MIT.txt)
135136
or the [Apache-2.0](https://github.com/KDAB/cxx-qt/blob/main/LICENSES/Apache-2.0.txt)
136137
licenses.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// clang-format off
2+
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
3+
// clang-format on
4+
// SPDX-FileContributor: Laurent Montel <[email protected]>
5+
//
6+
// SPDX-License-Identifier: MIT OR Apache-2.0
7+
#pragma once
8+
9+
#include <QtCore/QLine>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// clang-format off
2+
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
3+
// clang-format on
4+
// SPDX-FileContributor: Laurent Montel <[email protected]>
5+
//
6+
// SPDX-License-Identifier: MIT OR Apache-2.0
7+
#pragma once
8+
9+
#include <QtCore/QLineF>

crates/cxx-qt-lib-headers/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub fn write_headers(directory: impl AsRef<Path>) {
2525
(include_str!("../include/core/qdate.h"), "qdate.h"),
2626
(include_str!("../include/core/qdatetime.h"), "qdatetime.h"),
2727
(include_str!("../include/core/qhash.h"), "qhash.h"),
28+
(include_str!("../include/core/qline.h"), "qline.h"),
29+
(include_str!("../include/core/qlinef.h"), "qlinef.h"),
2830
(include_str!("../include/core/qlist.h"), "qlist.h"),
2931
(
3032
include_str!("../include/core/qlist_qvector.h"),

crates/cxx-qt-lib/build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ fn main() {
3737
"core/qdate",
3838
"core/qhash/qhash_i32_qbytearray",
3939
"core/qhash/qhash_qstring_qvariant",
40+
"core/qline",
41+
"core/qlinef",
4042
"core/qlist/qlist_bool",
4143
"core/qlist/qlist_f32",
4244
"core/qlist/qlist_f64",
@@ -200,6 +202,8 @@ fn main() {
200202
"core/qcoreapplication",
201203
"core/qdate",
202204
"core/qhash/qhash",
205+
"core/qline",
206+
"core/qlinef",
203207
"core/qlist/qlist",
204208
"core/qmap/qmap",
205209
"core/qmargins",

crates/cxx-qt-lib/src/core/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ pub use qdatetime::QDateTime;
2020
mod qhash;
2121
pub use qhash::{QHash, QHashPair, QHashPair_QString_QVariant, QHashPair_i32_QByteArray};
2222

23+
mod qline;
24+
pub use qline::QLine;
25+
26+
mod qlinef;
27+
pub use qlinef::QLineF;
28+
2329
mod qlist;
2430
pub use qlist::{QList, QListElement};
2531

crates/cxx-qt-lib/src/core/qline.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// clang-format off
2+
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
3+
// clang-format on
4+
// SPDX-FileContributor: Laurent Montel <[email protected]>
5+
//
6+
// SPDX-License-Identifier: MIT OR Apache-2.0
7+
#include "cxx-qt-lib/qline.h"
8+
9+
#include "../assertion_utils.h"
10+
11+
#include <cstdint>
12+
13+
// QLine has "QPoint" members - pt1, pt2
14+
// Rust represents these as 32-bit integer types.
15+
// https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/tools/qline.h?h=v5.15.6-lts-lgpl#n90
16+
//
17+
// https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/tools/qline.h?h=v6.2.4#n90
18+
assert_alignment_and_size(QLine,
19+
alignof(::std::int32_t),
20+
sizeof(::std::int32_t[4]));
21+
22+
static_assert(::std::is_trivially_copyable<QLine>::value);

crates/cxx-qt-lib/src/core/qline.rs

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
2+
// SPDX-FileContributor: Laurent Montel <[email protected]>
3+
//
4+
// SPDX-License-Identifier: MIT OR Apache-2.0
5+
6+
use crate::QPoint;
7+
use cxx::{type_id, ExternType};
8+
9+
#[cxx::bridge]
10+
mod ffi {
11+
unsafe extern "C++" {
12+
include!("cxx-qt-lib/qline.h");
13+
type QLine = super::QLine;
14+
include!("cxx-qt-lib/qpoint.h");
15+
type QPoint = crate::QPoint;
16+
17+
/// Returns the line's start point.
18+
fn p1(self: &QLine) -> QPoint;
19+
20+
/// Returns the line's end point.
21+
fn p2(self: &QLine) -> QPoint;
22+
23+
/// Returns the x-coordinate of the line's start point.
24+
fn x1(self: &QLine) -> i32;
25+
26+
/// Returns the x-coordinate of the line's end point.
27+
fn x2(self: &QLine) -> i32;
28+
29+
/// Returns the y-coordinate of the line's start point.
30+
fn y1(self: &QLine) -> i32;
31+
32+
/// Returns the y-coordinate of the line's end point.
33+
fn y2(self: &QLine) -> i32;
34+
35+
/// Returns the center point of this line. This is equivalent to (p1() + p2()) / 2, except it will never overflow.
36+
fn center(self: &QLine) -> QPoint;
37+
38+
/// Returns the horizontal component of the line's vector.
39+
fn dx(self: &QLine) -> i32;
40+
41+
/// Returns the vertical component of the line's vector.
42+
fn dy(self: &QLine) -> i32;
43+
44+
/// Returns true if the line does not have distinct start and end points; otherwise returns false.
45+
#[rust_name = "is_null"]
46+
fn isNull(self: &QLine) -> bool;
47+
48+
/// Sets the starting point of this line to p1.
49+
#[rust_name = "set_p1"]
50+
fn setP1(self: &mut QLine, p1: &QPoint);
51+
52+
/// Sets the end point of this line to p2.
53+
#[rust_name = "set_p2"]
54+
fn setP2(self: &mut QLine, p1: &QPoint);
55+
56+
/// Sets this line to the start in x1, y1 and end in x2, y2.
57+
#[rust_name = "set_line"]
58+
fn setLine(self: &mut QLine, x1: i32, y1: i32, x2: i32, y2: i32);
59+
60+
/// Sets the start point of this line to p1 and the end point of this line to p2.
61+
#[rust_name = "set_points"]
62+
fn setPoints(self: &mut QLine, p1: &QPoint, p2: &QPoint);
63+
64+
/// Translates this line by the given offset.
65+
fn translate(self: &mut QLine, offset: &QPoint);
66+
67+
/// Returns this line translated by the given offset.
68+
fn translated(self: &QLine, offset: &QPoint) -> QLine;
69+
}
70+
71+
#[namespace = "rust::cxxqtlib1"]
72+
unsafe extern "C++" {
73+
include!("cxx-qt-lib/common.h");
74+
75+
#[doc(hidden)]
76+
#[rust_name = "qline_default"]
77+
fn construct() -> QLine;
78+
79+
#[doc(hidden)]
80+
#[rust_name = "qline_new"]
81+
fn construct(pt1: QPoint, pt2: QPoint) -> QLine;
82+
}
83+
}
84+
85+
/// The QLine class provides a two-dimensional vector using integer precision
86+
#[derive(Debug, Clone, PartialEq, Eq)]
87+
#[repr(C)]
88+
pub struct QLine {
89+
pt1: QPoint,
90+
pt2: QPoint,
91+
}
92+
93+
impl QLine {
94+
/// Constructs a line object that represents the line between p1 and p2.
95+
pub fn new(pt1: QPoint, pt2: QPoint) -> Self {
96+
ffi::qline_new(pt1, pt2)
97+
}
98+
}
99+
100+
impl Default for QLine {
101+
/// Constructs a null line.
102+
fn default() -> Self {
103+
ffi::qline_default()
104+
}
105+
}
106+
107+
// Safety:
108+
//
109+
// Static checks on the C++ side ensure that QLine is trivial.
110+
unsafe impl ExternType for QLine {
111+
type Id = type_id!("QLine");
112+
type Kind = cxx::kind::Trivial;
113+
}

crates/cxx-qt-lib/src/core/qlinef.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// clang-format off
2+
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
3+
// clang-format on
4+
// SPDX-FileContributor: Laurent Montel <[email protected]>
5+
//
6+
// SPDX-License-Identifier: MIT OR Apache-2.0
7+
#include "cxx-qt-lib/qlinef.h"
8+
9+
#include "../assertion_utils.h"
10+
11+
#include <cstdint>
12+
13+
// QLineF has "QPointF" members - pt1, pt2
14+
// Rust represents these as double types.
15+
// https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/tools/qline.h?h=v5.15.6-lts-lgpl#n281
16+
//
17+
// https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/tools/qline.h?h=v6.2.4#n295
18+
assert_alignment_and_size(QLineF, alignof(double), sizeof(double[4]));
19+
20+
static_assert(::std::is_trivially_copyable<QLineF>::value);

crates/cxx-qt-lib/src/core/qlinef.rs

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
2+
// SPDX-FileContributor: Laurent Montel <[email protected]>
3+
//
4+
// SPDX-License-Identifier: MIT OR Apache-2.0
5+
6+
use crate::QLine;
7+
use crate::QPointF;
8+
use cxx::{type_id, ExternType};
9+
10+
#[cxx::bridge]
11+
mod ffi {
12+
unsafe extern "C++" {
13+
include!("cxx-qt-lib/qlinef.h");
14+
type QLineF = super::QLineF;
15+
include!("cxx-qt-lib/qline.h");
16+
type QLine = crate::QLine;
17+
include!("cxx-qt-lib/qpointf.h");
18+
type QPointF = crate::QPointF;
19+
20+
/// Returns the line's start point.
21+
fn p1(self: &QLineF) -> QPointF;
22+
23+
/// Returns the line's end point.
24+
fn p2(self: &QLineF) -> QPointF;
25+
26+
/// Returns the x-coordinate of the line's start point.
27+
fn x1(self: &QLineF) -> f64;
28+
29+
/// Returns the x-coordinate of the line's end point.
30+
fn x2(self: &QLineF) -> f64;
31+
32+
/// Returns the y-coordinate of the line's start point.
33+
fn y1(self: &QLineF) -> f64;
34+
35+
/// Returns the y-coordinate of the line's end point.
36+
fn y2(self: &QLineF) -> f64;
37+
38+
/// Returns the center point of this line. This is equivalent to (p1() + p2()) / 2, except it will never overflow.
39+
fn center(self: &QLineF) -> QPointF;
40+
41+
/// Returns the horizontal component of the line's vector.
42+
fn dx(self: &QLineF) -> f64;
43+
44+
/// Returns the vertical component of the line's vector.
45+
fn dy(self: &QLineF) -> f64;
46+
47+
/// Returns true if the line does not have distinct start and end points; otherwise returns false.
48+
#[rust_name = "is_null"]
49+
fn isNull(self: &QLineF) -> bool;
50+
51+
/// Sets the starting point of this line to p1.
52+
#[rust_name = "set_p1"]
53+
fn setP1(self: &mut QLineF, p1: &QPointF);
54+
55+
/// Sets the end point of this line to p2.
56+
#[rust_name = "set_p2"]
57+
fn setP2(self: &mut QLineF, p1: &QPointF);
58+
59+
/// Sets this line to the start in x1, y1 and end in x2, y2.
60+
#[rust_name = "set_line"]
61+
fn setLine(self: &mut QLineF, x1: f64, y1: f64, x2: f64, y2: f64);
62+
63+
/// Sets the start point of this line to p1 and the end point of this line to p2.
64+
#[rust_name = "set_points"]
65+
fn setPoints(self: &mut QLineF, p1: &QPointF, p2: &QPointF);
66+
67+
/// Translates this line by the given offset.
68+
fn translate(self: &mut QLineF, offset: &QPointF);
69+
70+
/// Returns this line translated by the given offset.
71+
fn translated(self: &QLineF, offset: &QPointF) -> QLineF;
72+
}
73+
74+
#[namespace = "rust::cxxqtlib1"]
75+
unsafe extern "C++" {
76+
include!("cxx-qt-lib/common.h");
77+
78+
#[doc(hidden)]
79+
#[rust_name = "qlinef_default"]
80+
fn construct() -> QLineF;
81+
82+
#[doc(hidden)]
83+
#[rust_name = "qlinef_new"]
84+
fn construct(pt1: QPointF, pt2: QPointF) -> QLineF;
85+
#[doc(hidden)]
86+
#[rust_name = "qlinef_from_qline"]
87+
fn construct(line: &QLine) -> QLineF;
88+
}
89+
}
90+
91+
/// The QLineF class provides a two-dimensional vector using floating point precision.
92+
#[derive(Debug, Clone, PartialEq)]
93+
#[repr(C)]
94+
pub struct QLineF {
95+
pt1: QPointF,
96+
pt2: QPointF,
97+
}
98+
99+
impl QLineF {
100+
/// Constructs a line object that represents the line between pt1 and pt2.
101+
pub fn new(pt1: QPointF, pt2: QPointF) -> Self {
102+
ffi::qlinef_new(pt1, pt2)
103+
}
104+
}
105+
106+
impl Default for QLineF {
107+
/// Constructs a default qlinef
108+
fn default() -> Self {
109+
ffi::qlinef_default()
110+
}
111+
}
112+
113+
impl From<&ffi::QLine> for QLineF {
114+
/// Construct a QLineF object from the given integer-based line.
115+
fn from(line: &QLine) -> Self {
116+
ffi::qlinef_from_qline(line)
117+
}
118+
}
119+
120+
// Safety:
121+
//
122+
// Static checks on the C++ side ensure that QLineF is trivial.
123+
unsafe impl ExternType for QLineF {
124+
type Id = type_id!("QLineF");
125+
type Kind = cxx::kind::Trivial;
126+
}

crates/cxx-qt-lib/src/core/qpersistentmodelindex.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ mod ffi {
3131
fn row(self: &QPersistentModelIndex) -> i32;
3232
/// Returns the sibling at row and column or an invalid QModelIndex if there is no sibling at this position.
3333
fn sibling(self: &QPersistentModelIndex, row: i32, column: i32) -> QModelIndex;
34+
35+
/// Swaps this persistent modelindex with other. This function is very fast and never fails.
36+
fn swap(self: &mut QPersistentModelIndex, other: &mut QPersistentModelIndex);
3437
}
3538

3639
#[namespace = "rust::cxxqtlib1"]

crates/cxx-qt-lib/src/core/qstring.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ mod ffi {
8181
/// Returns true if the string starts with s; otherwise returns false.
8282
#[rust_name = "starts_with"]
8383
fn startsWith(self: &QString, s: &QString, cs: CaseSensitivity) -> bool;
84+
85+
/// Converts a plain text string to an HTML string with HTML metacharacters <, >, &, and " replaced by HTML entities.
86+
#[rust_name = "to_html_escaped"]
87+
fn toHtmlEscaped(self: &QString) -> QString;
8488
}
8589

8690
#[namespace = "rust::cxxqtlib1"]

0 commit comments

Comments
 (0)