Skip to content

Commit 4b91445

Browse files
committed
WIP: cxx-qt-lib: use cfg for differing Qt 5 and Qt 6 types
1 parent 8c4ae69 commit 4b91445

File tree

4 files changed

+31
-35
lines changed

4 files changed

+31
-35
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,9 @@ syn = { version = "2.0", features = ["extra-traits", "full"] }
5656
quote = "1.0"
5757
serde = { version = "1.0", features = ["derive"] }
5858
serde_json = "1.0"
59+
60+
[patch.crates-io]
61+
# Use a patched cxx so that duplicate names with different cfg options don't fail
62+
cxx = { git = "https://github.com/ahayzen-kdab/cxx.git", branch = "duplicate-names-allow-custom-cfg" }
63+
cxx-build = { git = "https://github.com/ahayzen-kdab/cxx.git", branch = "duplicate-names-allow-custom-cfg" }
64+
cxx-gen = { git = "https://github.com/ahayzen-kdab/cxx.git", branch = "duplicate-names-allow-custom-cfg" }

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ qstringToRustString(const QString& string);
3333

3434
QString
3535
qstringArg(const QString& string, const QString& a);
36-
::rust::isize
37-
qstringIndexOf(const QString& string,
38-
const QString& str,
39-
::rust::isize from,
40-
Qt::CaseSensitivity cs);
4136
QString&
4237
qstringInsert(QString& string, ::rust::isize pos, const QString& str);
4338
QString

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,6 @@ qstringArg(const QString& string, const QString& a)
6161
return string.arg(a);
6262
}
6363

64-
::rust::isize
65-
qstringIndexOf(const QString& string,
66-
const QString& str,
67-
::rust::isize from,
68-
Qt::CaseSensitivity cs)
69-
{
70-
// Qt 5 has an int Qt 6 has a qsizetype
71-
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
72-
return static_cast<::rust::isize>(
73-
string.indexOf(str, static_cast<qsizetype>(from), cs));
74-
#else
75-
return static_cast<::rust::isize>(
76-
string.indexOf(str, static_cast<int>(from), cs));
77-
#endif
78-
}
79-
8064
QString&
8165
qstringInsert(QString& string, ::rust::isize pos, const QString& str)
8266
{

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ mod ffi {
1717
type SplitBehaviorFlags = crate::SplitBehaviorFlags;
1818
}
1919

20+
#[cfg(cxxqt_qt_version_major = "6")]
21+
unsafe extern "C++" {
22+
include!("cxx-qt-lib/qtypes.h");
23+
24+
#[cxx_name = "qsizetype"]
25+
type QSizeType = crate::QSizeType;
26+
}
27+
2028
unsafe extern "C++" {
2129
include!("cxx-qt-lib/qbytearray.h");
2230
type QByteArray = crate::QByteArray;
@@ -43,6 +51,23 @@ mod ffi {
4351
#[rust_name = "ends_with"]
4452
fn endsWith(self: &QString, s: &QString, cs: CaseSensitivity) -> bool;
4553

54+
/// Returns the index position of the first occurrence of the string str in this string,
55+
/// searching forward from index position from. Returns -1 if str is not found.
56+
#[cfg(cxxqt_qt_version_major = "5")]
57+
#[rust_name = "index_of"]
58+
fn indexOf(self: &QString, str: &QString, from: i32, cs: CaseSensitivity) -> i32;
59+
60+
/// Returns the index position of the first occurrence of the string str in this string,
61+
/// searching forward from index position from. Returns -1 if str is not found.
62+
#[cfg(cxxqt_qt_version_major = "6")]
63+
#[rust_name = "index_of"]
64+
fn indexOf(
65+
self: &QString,
66+
str: &QString,
67+
from: QSizeType,
68+
cs: CaseSensitivity,
69+
) -> QSizeType;
70+
4671
/// Returns true if the string has no characters; otherwise returns false.
4772
#[rust_name = "is_empty"]
4873
fn isEmpty(self: &QString) -> bool;
@@ -136,14 +161,6 @@ mod ffi {
136161
#[rust_name = "qstring_arg"]
137162
fn qstringArg(string: &QString, a: &QString) -> QString;
138163
#[doc(hidden)]
139-
#[rust_name = "qstring_index_of"]
140-
fn qstringIndexOf(
141-
string: &QString,
142-
str: &QString,
143-
from: isize,
144-
cs: CaseSensitivity,
145-
) -> isize;
146-
#[doc(hidden)]
147164
#[rust_name = "qstring_insert"]
148165
fn qstringInsert<'a>(string: &'a mut QString, pos: isize, str: &QString)
149166
-> &'a mut QString;
@@ -337,12 +354,6 @@ impl QString {
337354
self.compare_i32(other, cs).cmp(&0)
338355
}
339356

340-
/// Returns the index position of the first occurrence of the string str in this string,
341-
/// searching forward from index position from. Returns -1 if str is not found.
342-
pub fn index_of(&self, str: &QString, from: isize, cs: ffi::CaseSensitivity) -> isize {
343-
ffi::qstring_index_of(self, str, from, cs)
344-
}
345-
346357
/// Inserts the string str at the given index position and returns a mutable reference to this string.
347358
pub fn insert<'a>(&'a mut self, pos: isize, str: &Self) -> &'a mut Self {
348359
ffi::qstring_insert(self, pos, str)

0 commit comments

Comments
 (0)