Skip to content

Commit 7db4d04

Browse files
authored
Merge branch 'main' into support_qmake_scripts
2 parents 031f080 + cb64b22 commit 7db4d04

6 files changed

Lines changed: 87 additions & 33 deletions

File tree

crates/cxx-qt-lib/Cargo.toml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
[package]
77
name = "cxx-qt-lib"
88
version.workspace = true
9-
authors = ["Andrew Hayzen <andrew.hayzen@kdab.com>", "Gerhard de Clercq <gerhard.declercq@kdab.com>", "Leon Matthes <leon.matthes@kdab.com>"]
9+
authors = [
10+
"Andrew Hayzen <andrew.hayzen@kdab.com>",
11+
"Gerhard de Clercq <gerhard.declercq@kdab.com>",
12+
"Leon Matthes <leon.matthes@kdab.com>",
13+
]
1014
edition.workspace = true
1115
license.workspace = true
1216
description = "Qt types for integrating `cxx-qt` crate with `cxx`"
1317
repository.workspace = true
14-
exclude = [ "**/generate.sh" ]
18+
exclude = ["**/generate.sh"]
1519

1620
# When creating a library with cxx-qt-build, we need to set a fake "links" key
1721
# to make sure the build scripts are run in the correct order and the build scripts
@@ -20,6 +24,10 @@ exclude = [ "**/generate.sh" ]
2024
links = "cxx-qt-lib"
2125
rust-version.workspace = true
2226

27+
[package.metadata.docs.rs]
28+
all-features = true
29+
rustdoc-args = ["--cfg", "docsrs"]
30+
2331
[dependencies]
2432
cxx.workspace = true
2533
cxx-qt.workspace = true
@@ -30,7 +38,7 @@ rgb = { version = "0.8", optional = true }
3038
time = { version = "0.3.20", optional = true }
3139
url = { version = "2.3", optional = true }
3240
uuid = { version = "1.1.0", optional = true }
33-
serde = { version = "1", features=["derive"], optional = true }
41+
serde = { version = "1", features = ["derive"], optional = true }
3442
# Note: The image crate is not yet at 1.0 and a new version is released regularly.
3543
# To avoid a breaking change at each update, we don't specify a default version, and make the versions explicit.
3644
# Once 1.0 is released, we can add a dependency on `image`, which would then be `image = "1"`
@@ -46,7 +54,19 @@ qt-build-utils.workspace = true
4654
serde_json = "1.0.135"
4755

4856
[features]
49-
full = ["qt_full", "serde", "url", "uuid", "time", "rgb", "http", "chrono", "bytes", "image-v0-24", "image-v0-25"]
57+
full = [
58+
"qt_full",
59+
"serde",
60+
"url",
61+
"uuid",
62+
"time",
63+
"rgb",
64+
"http",
65+
"chrono",
66+
"bytes",
67+
"image-v0-24",
68+
"image-v0-25",
69+
]
5070
default = []
5171

5272
qt_full = ["qt_gui", "qt_qml", "qt_quickcontrols"]

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ impl QDate {
167167
/// Returns the number of days from this date to d (which is negative if d is earlier than this date).
168168
///
169169
/// Returns 0 if either date is invalid.
170-
pub fn days_to(&self, date: Self) -> ffi::qint64 {
171-
ffi::qdate_days_to(self, date)
170+
pub fn days_to(&self, date: Self) -> i64 {
171+
ffi::qdate_days_to(self, date).into()
172172
}
173173

174174
/// Returns the time as a string. The format parameter determines the format of the result string.
@@ -277,14 +277,14 @@ mod test {
277277
fn qdate_current_date() {
278278
let date_a = QDate::current_date();
279279
let date_b = date_a.add_days(100.into());
280-
assert_eq!(i64::from(date_a.days_to(date_b)), 100);
280+
assert_eq!(date_a.days_to(date_b), 100);
281281
}
282282

283283
#[test]
284284
fn qdate_julian_day() {
285285
let date_a = QDate::from_julian_day(1000);
286286
let date_b = QDate::from_julian_day(1010);
287-
assert_eq!(i64::from(date_a.days_to(date_b)), 10);
287+
assert_eq!(date_a.days_to(date_b), 10);
288288
}
289289

290290
#[cfg(feature = "chrono")]

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

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ mod ffi {
5757
/// Returns the date part of the datetime.
5858
fn date(self: &QDateTime) -> QDate;
5959

60-
/// Returns the number of days from this datetime to the other datetime.
61-
/// The number of days is counted as the number of times midnight is reached between this datetime to the other datetime.
62-
/// This means that a 10 minute difference from 23:55 to 0:05 the next day counts as one day.
63-
#[rust_name = "days_to"]
60+
#[doc(hidden)]
61+
#[rust_name = "days_to_qint64"]
6462
fn daysTo(self: &QDateTime, other: &QDateTime) -> qint64;
6563

6664
/// Returns if this datetime falls in Daylight-Saving Time.
@@ -79,14 +77,12 @@ mod ffi {
7977
#[rust_name = "offset_from_utc"]
8078
fn offsetFromUtc(self: &QDateTime) -> i32;
8179

82-
/// Returns the number of milliseconds from this datetime to the other datetime.
83-
/// If the other datetime is earlier than this datetime, the value returned is negative.
84-
#[rust_name = "msecs_to"]
80+
#[doc(hidden)]
81+
#[rust_name = "msecs_to_qint64"]
8582
fn msecsTo(self: &QDateTime, other: &QDateTime) -> qint64;
8683

87-
/// Returns the number of seconds from this datetime to the other datetime.
88-
/// If the other datetime is earlier than this datetime, the value returned is negative.
89-
#[rust_name = "secs_to"]
84+
#[doc(hidden)]
85+
#[rust_name = "secs_to_qint64"]
9086
fn secsTo(self: &QDateTime, other: &QDateTime) -> qint64;
9187

9288
#[doc(hidden)]
@@ -126,16 +122,16 @@ mod ffi {
126122
#[rust_name = "to_local_time"]
127123
fn toLocalTime(self: &QDateTime) -> QDateTime;
128124

129-
/// Returns the datetime as the number of milliseconds that have passed since 1970-01-01T00:00:00.000, Coordinated Universal Time (Qt::UTC).
130-
#[rust_name = "to_msecs_since_epoch"]
125+
#[doc(hidden)]
126+
#[rust_name = "to_msecs_since_epoch_qint64"]
131127
fn toMSecsSinceEpoch(self: &QDateTime) -> qint64;
132128

133129
/// Returns a copy of this datetime converted to a spec of Qt::OffsetFromUTC with the given offsetSeconds.
134130
#[rust_name = "to_offset_from_utc"]
135131
fn toOffsetFromUtc(self: &QDateTime, offset_seconds: i32) -> QDateTime;
136132

137-
/// Returns the datetime as the number of seconds that have passed since 1970-01-01T00:00:00.000, Coordinated Universal Time (Qt::UTC).
138-
#[rust_name = "to_secs_since_epoch"]
133+
#[doc(hidden)]
134+
#[rust_name = "to_secs_since_epoch_qint64"]
139135
fn toSecsSinceEpoch(self: &QDateTime) -> qint64;
140136

141137
/// Returns the time as a string. The format parameter determines the format of the string.
@@ -274,13 +270,20 @@ impl QDateTime {
274270

275271
/// Returns the number of milliseconds since 1970-01-01T00:00:00 Universal Coordinated Time.
276272
/// This number is like the POSIX time_t variable, but expressed in milliseconds instead.
277-
pub fn current_msecs_since_epoch() -> ffi::qint64 {
278-
ffi::qdatetime_current_msecs_since_epoch()
273+
pub fn current_msecs_since_epoch() -> i64 {
274+
ffi::qdatetime_current_msecs_since_epoch().into()
279275
}
280276

281277
/// Returns the number of seconds since 1970-01-01T00:00:00 Universal Coordinated Time.
282-
pub fn current_secs_since_epoch() -> ffi::qint64 {
283-
ffi::qdatetime_current_secs_since_epoch()
278+
pub fn current_secs_since_epoch() -> i64 {
279+
ffi::qdatetime_current_secs_since_epoch().into()
280+
}
281+
282+
/// Returns the number of days from this datetime to the other datetime.
283+
/// The number of days is counted as the number of times midnight is reached between this datetime to the other datetime.
284+
/// This means that a 10 minute difference from 23:55 to 0:05 the next day counts as one day.
285+
pub fn days_to(&self, other: &Self) -> i64 {
286+
self.days_to_qint64(other).into()
284287
}
285288

286289
/// Construct a Rust QDateTime from a given QDate, QTime, and QTimeZone
@@ -307,14 +310,14 @@ impl QDateTime {
307310

308311
/// Returns a datetime whose date and time are the number of milliseconds msecs that have passed since 1970-01-01T00:00:00.000,
309312
/// Coordinated Universal Time (Qt::UTC) and with the given timeZone.
310-
pub fn from_msecs_since_epoch(msecs: ffi::qint64, time_zone: &ffi::QTimeZone) -> Self {
311-
ffi::qdatetime_from_msecs_since_epoch(msecs, time_zone)
313+
pub fn from_msecs_since_epoch(msecs: i64, time_zone: &ffi::QTimeZone) -> Self {
314+
ffi::qdatetime_from_msecs_since_epoch(msecs.into(), time_zone)
312315
}
313316

314317
/// Returns a datetime whose date and time are the number of seconds secs that have passed since 1970-01-01T00:00:00.000,
315318
/// Coordinated Universal Time (Qt::UTC) and converted to the given spec.
316-
pub fn from_secs_since_epoch(secs: ffi::qint64, time_zone: &ffi::QTimeZone) -> Self {
317-
ffi::qdatetime_from_secs_since_epoch(secs, time_zone)
319+
pub fn from_secs_since_epoch(secs: i64, time_zone: &ffi::QTimeZone) -> Self {
320+
ffi::qdatetime_from_secs_since_epoch(secs.into(), time_zone)
318321
}
319322

320323
/// Returns the datetime represented in the string as a QDateTime using the format given, or None if this is not possible.
@@ -327,6 +330,18 @@ impl QDateTime {
327330
}
328331
}
329332

333+
/// Returns the number of milliseconds from this datetime to the other datetime.
334+
/// If the other datetime is earlier than this datetime, the value returned is negative.
335+
pub fn msecs_to(self: &QDateTime, other: &QDateTime) -> i64 {
336+
self.msecs_to_qint64(other).into()
337+
}
338+
339+
/// Returns the number of seconds from this datetime to the other datetime.
340+
/// If the other datetime is earlier than this datetime, the value returned is negative.
341+
pub fn secs_to(self: &QDateTime, other: &QDateTime) -> i64 {
342+
self.secs_to_qint64(other).into()
343+
}
344+
330345
/// Sets the date part of this datetime to date. If no time is set yet, it is set to midnight.
331346
/// If date is invalid, this QDateTime becomes invalid.
332347
pub fn set_date(&mut self, date: QDate) {
@@ -355,6 +370,16 @@ impl QDateTime {
355370
pub fn time_zone(&self) -> cxx::UniquePtr<ffi::QTimeZone> {
356371
ffi::qdatetime_time_zone(self)
357372
}
373+
374+
/// Returns the datetime as the number of milliseconds that have passed since 1970-01-01T00:00:00.000, Coordinated Universal Time (Qt::UTC).
375+
pub fn to_msecs_since_epoch(self: &QDateTime) -> i64 {
376+
self.to_msecs_since_epoch_qint64().into()
377+
}
378+
379+
/// Returns the datetime as the number of seconds that have passed since 1970-01-01T00:00:00.000, Coordinated Universal Time (Qt::UTC).
380+
pub fn to_secs_since_epoch(self: &QDateTime) -> i64 {
381+
self.to_secs_since_epoch_qint64().into()
382+
}
358383
}
359384

360385
impl Clone for QDateTime {

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ mod ffi {
3636
#[rust_name = "sibling_at_row"]
3737
fn siblingAtRow(self: &QModelIndex, row: i32) -> QModelIndex;
3838

39-
/// Returns a `quintptr` used by the model to associate the index with the internal data structure.
40-
#[rust_name = "internal_id"]
39+
#[doc(hidden)]
40+
#[rust_name = "internal_id_quintptr"]
4141
fn internalId(self: &QModelIndex) -> quintptr;
4242
/// Returns a `*mut c_void` pointer used by the model to associate the index with the internal data structure.
4343
#[rust_name = "internal_pointer_mut"]
@@ -98,6 +98,13 @@ impl fmt::Debug for QModelIndex {
9898
}
9999
}
100100

101+
impl QModelIndex {
102+
/// Returns a `usize` used by the model to associate the index with the internal data structure.
103+
pub fn internal_id(self: &QModelIndex) -> usize {
104+
self.internal_id_quintptr().into()
105+
}
106+
}
107+
101108
// Safety:
102109
//
103110
// Static checks on the C++ side to ensure the size is the same.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//
55
// SPDX-License-Identifier: MIT OR Apache-2.0
66

7+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
8+
79
#[cfg(not(any(cxxqt_qt_version_major = "5", cxxqt_qt_version_major = "6")))]
810
compile_error!("cxxqt_qt_version_major must be either \"5\" or \"6\"");
911

tests/qt_types_standalone/rust/src/qmodelindex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ fn internal_pointer_qmodelindex(i: &QModelIndex) -> *mut qmodelindex_cxx::c_void
4747
}
4848

4949
fn internal_id_qmodelindex(i: &QModelIndex) -> cxx_qt_lib::quintptr {
50-
i.internal_id()
50+
i.internal_id().into()
5151
}

0 commit comments

Comments
 (0)