Skip to content

Commit d6b03db

Browse files
committed
Add display for qlinef/qline
1 parent 7b9a6ee commit d6b03db

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use crate::QPoint;
77
use cxx::{type_id, ExternType};
8+
use std::fmt;
89

910
#[cxx::bridge]
1011
mod ffi {
@@ -13,6 +14,8 @@ mod ffi {
1314
type QLine = super::QLine;
1415
include!("cxx-qt-lib/qpoint.h");
1516
type QPoint = crate::QPoint;
17+
include!("cxx-qt-lib/qstring.h");
18+
type QString = crate::QString;
1619

1720
/// Returns the line's start point.
1821
fn p1(self: &QLine) -> QPoint;
@@ -79,6 +82,10 @@ mod ffi {
7982
#[doc(hidden)]
8083
#[rust_name = "qline_new"]
8184
fn construct(pt1: QPoint, pt2: QPoint) -> QLine;
85+
86+
#[doc(hidden)]
87+
#[rust_name = "qline_to_qstring"]
88+
fn toQString(value: &QLine) -> QString;
8289
}
8390
}
8491

@@ -104,6 +111,12 @@ impl Default for QLine {
104111
}
105112
}
106113

114+
impl fmt::Display for QLine {
115+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
116+
write!(f, "{}", ffi::qline_to_qstring(self))
117+
}
118+
}
119+
107120
// Safety:
108121
//
109122
// Static checks on the C++ side ensure that QLine is trivial.

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use crate::QLine;
77
use crate::QPointF;
88
use cxx::{type_id, ExternType};
9+
use std::fmt;
910

1011
#[cxx::bridge]
1112
mod ffi {
@@ -16,6 +17,8 @@ mod ffi {
1617
type QLine = crate::QLine;
1718
include!("cxx-qt-lib/qpointf.h");
1819
type QPointF = crate::QPointF;
20+
include!("cxx-qt-lib/qstring.h");
21+
type QString = crate::QString;
1922

2023
/// Returns the angle of the line in degrees.
2124
fn angle(self: &QLineF) -> f64;
@@ -121,6 +124,10 @@ mod ffi {
121124
#[doc(hidden)]
122125
#[rust_name = "qlinef_from_qline"]
123126
fn construct(line: &QLine) -> QLineF;
127+
128+
#[doc(hidden)]
129+
#[rust_name = "qlinef_to_qstring"]
130+
fn toQString(value: &QLineF) -> QString;
124131
}
125132
}
126133

@@ -161,6 +168,12 @@ impl From<QLineF> for ffi::QLine {
161168
}
162169
}
163170

171+
impl fmt::Display for QLineF {
172+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
173+
write!(f, "{}", ffi::qlinef_to_qstring(self))
174+
}
175+
}
176+
164177
// Safety:
165178
//
166179
// Static checks on the C++ side ensure that QLineF is trivial.

0 commit comments

Comments
 (0)