Skip to content

Commit e8826f5

Browse files
committed
cxx-qt-lib: use qint64 type to remove C++ methods
1 parent 440f45b commit e8826f5

File tree

6 files changed

+88
-211
lines changed

6 files changed

+88
-211
lines changed

crates/cxx-qt-lib-headers/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-headers/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
@@ -23,23 +23,17 @@ static_assert(::std::is_trivially_copyable<QDate>::value,
2323
namespace rust {
2424
namespace cxxqtlib1 {
2525

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

38-
::std::int64_t
32+
qint64
3933
qdateDaysTo(const QDate& date, QDate d)
4034
{
4135
// In Qt 5 d is const-ref, in Qt 6 it is value
42-
return static_cast<::std::int64_t>(date.daysTo(d));
36+
return date.daysTo(d);
4337
}
4438

4539
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: 4 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,6 @@ static_assert(QTypeInfo<QDateTime>::isRelocatable);
2929
namespace rust {
3030
namespace cxxqtlib1 {
3131

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

62-
::std::int64_t
44+
qint64
6345
qdatetimeCurrentMSecsSinceEpoch()
6446
{
6547
return QDateTime::currentMSecsSinceEpoch();
6648
}
6749

68-
::std::int64_t
50+
qint64
6951
qdatetimeCurrentSecsSinceEpoch()
7052
{
7153
return QDateTime::currentSecsSinceEpoch();
7254
}
7355

74-
::std::int64_t
75-
qdatetimeDaysTo(const QDateTime& datetime, const QDateTime& other)
76-
{
77-
return static_cast<::std::int64_t>(datetime.daysTo(other));
78-
}
79-
8056
QDateTime
81-
qdatetimeFromMSecsSinceEpoch(::std::int64_t msecs, const QTimeZone& timeZone)
57+
qdatetimeFromMSecsSinceEpoch(qint64 msecs, const QTimeZone& timeZone)
8258
{
8359
return QDateTime::fromMSecsSinceEpoch(static_cast<qint64>(msecs), timeZone);
8460
}
8561

8662
QDateTime
87-
qdatetimeFromSecsSinceEpoch(::std::int64_t secs, const QTimeZone& timeZone)
63+
qdatetimeFromSecsSinceEpoch(qint64 secs, const QTimeZone& timeZone)
8864
{
8965
return QDateTime::fromSecsSinceEpoch(static_cast<qint64>(secs), timeZone);
9066
}
9167

92-
::std::int64_t
93-
qdatetimeMSecsTo(const QDateTime& datetime, const QDateTime& other)
94-
{
95-
96-
return static_cast<::std::int64_t>(datetime.msecsTo(other));
97-
}
98-
99-
::std::int64_t
100-
qdatetimeSecsTo(const QDateTime& datetime, const QDateTime& other)
101-
{
102-
103-
return static_cast<::std::int64_t>(datetime.secsTo(other));
104-
}
105-
10668
void
10769
qdatetimeSetDate(QDateTime& datetime, QDate date)
10870
{
10971
datetime.setDate(date);
11072
}
11173

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

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

0 commit comments

Comments
 (0)