Skip to content

Commit e5daff8

Browse files
committed
cxx-qt-lib: use qint64 type to remove C++ methods
1 parent 85961d1 commit e5daff8

File tree

6 files changed

+90
-213
lines changed

6 files changed

+90
-213
lines changed

crates/cxx-qt-lib/include/core/qdate.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@
1515
namespace rust {
1616
namespace cxxqtlib1 {
1717

18-
QDate
19-
qdateAddDays(const QDate& date, ::std::int64_t ndays);
2018
QDate
2119
qdateCurrentDate();
2220
QDate
2321
qdateFromString(const QString& string, const QString& format);
2422
QDate
2523
qdateFromString(const QString& string, Qt::DateFormat format);
2624
// In Qt 5 d is const-ref, in Qt 6 it is value
27-
::std::int64_t
25+
qint64
2826
qdateDaysTo(const QDate& date, QDate d);
2927
bool
3028
qdateIsLeapYear(::std::int32_t year);

crates/cxx-qt-lib/include/core/qdatetime.h

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,44 +29,24 @@ struct IsRelocatable<QDateTime> : ::std::true_type
2929
namespace rust {
3030
namespace cxxqtlib1 {
3131

32-
QDateTime
33-
qdatetimeAddDays(const QDateTime& datetime, ::std::int64_t ndays);
34-
QDateTime
35-
qdatetimeAddMSecs(const QDateTime& datetime, ::std::int64_t msecs);
36-
QDateTime
37-
qdatetimeAddSecs(const QDateTime& datetime, ::std::int64_t secs);
3832
QDateTime
3933
qdatetimeCurrentDateTime();
4034
QDateTime
4135
qdatetimeCurrentDateTimeUtc();
42-
::std::int64_t
36+
qint64
4337
qdatetimeCurrentMSecsSinceEpoch();
44-
::std::int64_t
38+
qint64
4539
qdatetimeCurrentSecsSinceEpoch();
46-
::std::int64_t
47-
qdatetimeDaysTo(const QDateTime& datetime, const QDateTime& other);
4840
QDateTime
49-
qdatetimeFromMSecsSinceEpoch(::std::int64_t msecs, const QTimeZone& timeZone);
41+
qdatetimeFromMSecsSinceEpoch(qint64 msecs, const QTimeZone& timeZone);
5042
QDateTime
51-
qdatetimeFromSecsSinceEpoch(::std::int64_t secs, const QTimeZone& timeZone);
52-
::std::int64_t
53-
qdatetimeMSecsTo(const QDateTime& datetime, const QDateTime& other);
54-
::std::int64_t
55-
qdatetimeSecsTo(const QDateTime& datetime, const QDateTime& other);
43+
qdatetimeFromSecsSinceEpoch(qint64 secs, const QTimeZone& timeZone);
5644
void
5745
qdatetimeSetDate(QDateTime& datetime, QDate date);
5846
void
59-
qdatetimeSetMSecsSinceEpoch(QDateTime& datetime, ::std::int64_t msecs);
60-
void
61-
qdatetimeSetSecsSinceEpoch(QDateTime& datetime, ::std::int64_t secs);
62-
void
6347
qdatetimeSetTime(QDateTime& datetime, QTime time);
6448
::std::unique_ptr<QTimeZone>
6549
qdatetimeTimeZone(const QDateTime& datetime);
66-
::std::int64_t
67-
qdatetimeToMSecsSinceEpoch(const QDateTime& datetime);
68-
::std::int64_t
69-
qdatetimeToSecsSinceEpoch(const QDateTime& datetime);
7050
void
7151
qdatetimeSetTimeZone(QDateTime& datetime, const QTimeZone& timeZone);
7252
}

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,17 @@ static_assert(::std::is_trivially_copyable<QDate>::value,
2222
namespace rust {
2323
namespace cxxqtlib1 {
2424

25-
QDate
26-
qdateAddDays(const QDate& date, ::std::int64_t ndays)
27-
{
28-
return date.addDays(static_cast<qint64>(ndays));
29-
}
30-
3125
QDate
3226
qdateCurrentDate()
3327
{
3428
return QDate::currentDate();
3529
}
3630

37-
::std::int64_t
31+
qint64
3832
qdateDaysTo(const QDate& date, QDate d)
3933
{
4034
// In Qt 5 d is const-ref, in Qt 6 it is value
41-
return static_cast<::std::int64_t>(date.daysTo(d));
35+
return date.daysTo(d);
4236
}
4337

4438
QDate

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,25 @@ mod ffi {
1414
type DateFormat = crate::DateFormat;
1515
}
1616

17+
unsafe extern "C++" {
18+
include!("cxx-qt-lib/qtypes.h");
19+
#[cxx_name = "qint64"]
20+
type QInt64 = crate::QInt64;
21+
}
22+
1723
unsafe extern "C++" {
1824
include!("cxx-qt-lib/qstring.h");
1925
type QString = crate::QString;
2026

2127
include!("cxx-qt-lib/qdate.h");
2228
type QDate = super::QDate;
2329

30+
/// Returns a QDate object containing a date ndays later than the date of this object (or earlier if ndays is negative).
31+
///
32+
/// Returns a null date if the current date is invalid or the new date is out of range.
33+
#[rust_name = "add_days"]
34+
fn addDays(self: &QDate, ndays: QInt64) -> QDate;
35+
2436
/// Returns a QDate object containing a date nmonths later than the date of this object (or earlier if nmonths is negative).
2537
#[rust_name = "add_months"]
2638
fn addMonths(self: &QDate, nmonths: i32) -> QDate;
@@ -76,17 +88,13 @@ mod ffi {
7688

7789
#[namespace = "rust::cxxqtlib1"]
7890
unsafe extern "C++" {
79-
#[doc(hidden)]
80-
#[rust_name = "qdate_add_days"]
81-
fn qdateAddDays(date: &QDate, ndays: i64) -> QDate;
82-
8391
#[doc(hidden)]
8492
#[rust_name = "qdate_current_date"]
8593
fn qdateCurrentDate() -> QDate;
8694

8795
#[doc(hidden)]
8896
#[rust_name = "qdate_days_to"]
89-
fn qdateDaysTo(date: &QDate, d: QDate) -> i64;
97+
fn qdateDaysTo(date: &QDate, d: QDate) -> QInt64;
9098

9199
#[doc(hidden)]
92100
#[rust_name = "qdate_from_string"]
@@ -147,13 +155,6 @@ impl fmt::Debug for QDate {
147155
}
148156

149157
impl QDate {
150-
/// Returns a QDate object containing a date ndays later than the date of this object (or earlier if ndays is negative).
151-
///
152-
/// Returns a null date if the current date is invalid or the new date is out of range.
153-
pub fn add_days(&self, ndays: i64) -> Self {
154-
ffi::qdate_add_days(self, ndays)
155-
}
156-
157158
// Returns the current date, as reported by the system clock.
158159
pub fn current_date() -> Self {
159160
ffi::qdate_current_date()
@@ -162,7 +163,7 @@ impl QDate {
162163
/// Returns the number of days from this date to d (which is negative if d is earlier than this date).
163164
///
164165
/// Returns 0 if either date is invalid.
165-
pub fn days_to(&self, date: Self) -> i64 {
166+
pub fn days_to(&self, date: Self) -> ffi::QInt64 {
166167
ffi::qdate_days_to(self, date)
167168
}
168169

@@ -271,15 +272,15 @@ mod test {
271272
#[test]
272273
fn qdate_current_date() {
273274
let date_a = QDate::current_date();
274-
let date_b = date_a.add_days(100);
275-
assert_eq!(date_a.days_to(date_b), 100);
275+
let date_b = date_a.add_days(100.into());
276+
assert_eq!(i64::from(date_a.days_to(date_b)), 100);
276277
}
277278

278279
#[test]
279280
fn qdate_julian_day() {
280281
let date_a = QDate::from_julian_day(1000);
281282
let date_b = QDate::from_julian_day(1010);
282-
assert_eq!(date_a.days_to(date_b), 10);
283+
assert_eq!(i64::from(date_a.days_to(date_b)), 10);
283284
}
284285

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

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

Lines changed: 6 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,6 @@ static_assert(QTypeInfo<QDateTime>::isRelocatable);
2828
namespace rust {
2929
namespace cxxqtlib1 {
3030

31-
QDateTime
32-
qdatetimeAddDays(const QDateTime& datetime, ::std::int64_t ndays)
33-
{
34-
return datetime.addDays(static_cast<qint64>(ndays));
35-
}
36-
37-
QDateTime
38-
qdatetimeAddMSecs(const QDateTime& datetime, ::std::int64_t msecs)
39-
{
40-
return datetime.addMSecs(static_cast<qint64>(msecs));
41-
}
42-
43-
QDateTime
44-
qdatetimeAddSecs(const QDateTime& datetime, ::std::int64_t secs)
45-
{
46-
return datetime.addSecs(static_cast<qint64>(secs));
47-
}
48-
4931
QDateTime
5032
qdatetimeCurrentDateTime()
5133
{
@@ -58,48 +40,28 @@ qdatetimeCurrentDateTimeUtc()
5840
return QDateTime::currentDateTimeUtc();
5941
}
6042

61-
::std::int64_t
43+
qint64
6244
qdatetimeCurrentMSecsSinceEpoch()
6345
{
6446
return QDateTime::currentMSecsSinceEpoch();
6547
}
6648

67-
::std::int64_t
49+
qint64
6850
qdatetimeCurrentSecsSinceEpoch()
6951
{
7052
return QDateTime::currentSecsSinceEpoch();
7153
}
7254

73-
::std::int64_t
74-
qdatetimeDaysTo(const QDateTime& datetime, const QDateTime& other)
75-
{
76-
return static_cast<::std::int64_t>(datetime.daysTo(other));
77-
}
78-
7955
QDateTime
80-
qdatetimeFromMSecsSinceEpoch(::std::int64_t msecs, const QTimeZone& timeZone)
56+
qdatetimeFromMSecsSinceEpoch(qint64 msecs, const QTimeZone& timeZone)
8157
{
82-
return QDateTime::fromMSecsSinceEpoch(static_cast<qint64>(msecs), timeZone);
58+
return QDateTime::fromMSecsSinceEpoch(msecs, timeZone);
8359
}
8460

8561
QDateTime
86-
qdatetimeFromSecsSinceEpoch(::std::int64_t secs, const QTimeZone& timeZone)
62+
qdatetimeFromSecsSinceEpoch(qint64 secs, const QTimeZone& timeZone)
8763
{
88-
return QDateTime::fromSecsSinceEpoch(static_cast<qint64>(secs), timeZone);
89-
}
90-
91-
::std::int64_t
92-
qdatetimeMSecsTo(const QDateTime& datetime, const QDateTime& other)
93-
{
94-
95-
return static_cast<::std::int64_t>(datetime.msecsTo(other));
96-
}
97-
98-
::std::int64_t
99-
qdatetimeSecsTo(const QDateTime& datetime, const QDateTime& other)
100-
{
101-
102-
return static_cast<::std::int64_t>(datetime.secsTo(other));
64+
return QDateTime::fromSecsSinceEpoch(secs, timeZone);
10365
}
10466

10567
void
@@ -108,18 +70,6 @@ qdatetimeSetDate(QDateTime& datetime, QDate date)
10870
datetime.setDate(date);
10971
}
11072

111-
void
112-
qdatetimeSetMSecsSinceEpoch(QDateTime& datetime, ::std::int64_t msecs)
113-
{
114-
datetime.setMSecsSinceEpoch(static_cast<qint64>(msecs));
115-
}
116-
117-
void
118-
qdatetimeSetSecsSinceEpoch(QDateTime& datetime, ::std::int64_t secs)
119-
{
120-
datetime.setSecsSinceEpoch(static_cast<qint64>(secs));
121-
}
122-
12373
void
12474
qdatetimeSetTime(QDateTime& datetime, QTime time)
12575
{
@@ -132,18 +82,6 @@ qdatetimeTimeZone(const QDateTime& datetime)
13282
return ::std::make_unique<QTimeZone>(datetime.timeZone());
13383
}
13484

135-
::std::int64_t
136-
qdatetimeToMSecsSinceEpoch(const QDateTime& datetime)
137-
{
138-
return static_cast<::std::int64_t>(datetime.toMSecsSinceEpoch());
139-
}
140-
141-
::std::int64_t
142-
qdatetimeToSecsSinceEpoch(const QDateTime& datetime)
143-
{
144-
return static_cast<::std::int64_t>(datetime.toSecsSinceEpoch());
145-
}
146-
14785
void
14886
qdatetimeSetTimeZone(QDateTime& datetime, const QTimeZone& timeZone)
14987
{

0 commit comments

Comments
 (0)