Skip to content

Commit 741741f

Browse files
ahayzen-kdabLeonMatthesKDAB
authored andcommitted
cxx-qt-lib: use quintptr for QModelIndex
1 parent 89ba58e commit 741741f

File tree

4 files changed

+9
-37
lines changed

4 files changed

+9
-37
lines changed

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

-9
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,3 @@
99
#include <cinttypes>
1010

1111
#include <QtCore/QModelIndex>
12-
13-
namespace rust {
14-
namespace cxxqtlib1 {
15-
16-
::std::size_t
17-
qmodelindexInternalId(const QModelIndex& index);
18-
19-
}
20-
}

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

-13
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,3 @@ assert_alignment_and_size(QModelIndex, {
1919
});
2020

2121
static_assert(::std::is_trivially_copyable<QModelIndex>::value);
22-
23-
namespace rust {
24-
namespace cxxqtlib1 {
25-
26-
::std::size_t
27-
qmodelindexInternalId(const QModelIndex& index)
28-
{
29-
// TODO: need to add support for quintptr
30-
return static_cast<::std::size_t>(index.internalId());
31-
}
32-
33-
}
34-
}

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

+4-13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ mod ffi {
1414

1515
type QModelIndex = super::QModelIndex;
1616
type QString = crate::QString;
17+
type quintptr = crate::quintptr;
1718

1819
/// Returns the column this model index refers to.
1920
fn column(self: &QModelIndex) -> i32;
@@ -35,6 +36,9 @@ mod ffi {
3536
#[rust_name = "sibling_at_row"]
3637
fn siblingAtRow(self: &QModelIndex, row: i32) -> QModelIndex;
3738

39+
/// Returns a `quintptr` used by the model to associate the index with the internal data structure.
40+
#[rust_name = "internal_id"]
41+
fn internalId(self: &QModelIndex) -> quintptr;
3842
/// Returns a `*mut c_void` pointer used by the model to associate the index with the internal data structure.
3943
#[rust_name = "internal_pointer_mut"]
4044
fn internalPointer(self: &QModelIndex) -> *mut c_void;
@@ -54,10 +58,6 @@ mod ffi {
5458
#[doc(hidden)]
5559
#[rust_name = "qmodelindex_to_qstring"]
5660
fn toQString(value: &QModelIndex) -> QString;
57-
58-
#[doc(hidden)]
59-
#[rust_name = "qmodelindex_internal_id"]
60-
fn qmodelindexInternalId(index: &QModelIndex) -> usize;
6161
}
6262
}
6363

@@ -71,15 +71,6 @@ pub struct QModelIndex {
7171
_m: MaybeUninit<usize>,
7272
}
7373

74-
impl QModelIndex {
75-
/// Returns a `usize` used by the model to associate the index with the internal data structure.
76-
//
77-
// TODO: need to add support for quintptr
78-
pub fn internal_id(&self) -> usize {
79-
ffi::qmodelindex_internal_id(self)
80-
}
81-
}
82-
8374
impl Default for QModelIndex {
8475
/// Creates a new empty model index. This type of model index is used to indicate that the position in the model is invalid.
8576
fn default() -> Self {

tests/qt_types_standalone/rust/src/qmodelindex.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ mod qmodelindex_cxx {
1010
unsafe extern "C++" {
1111
include!("cxx-qt-lib/qmodelindex.h");
1212
type QModelIndex = cxx_qt_lib::QModelIndex;
13+
14+
include!("cxx-qt-lib/qtypes.h");
15+
type quintptr = cxx_qt_lib::quintptr;
1316
}
1417

1518
#[namespace = "rust::cxxqtlib1"]
@@ -23,7 +26,7 @@ mod qmodelindex_cxx {
2326
fn read_qmodelindex(i: &QModelIndex) -> bool;
2427
fn clone_qmodelindex(i: &QModelIndex) -> QModelIndex;
2528
fn internal_pointer_qmodelindex(i: &QModelIndex) -> *mut c_void;
26-
fn internal_id_qmodelindex(i: &QModelIndex) -> usize;
29+
fn internal_id_qmodelindex(i: &QModelIndex) -> quintptr;
2730
}
2831
}
2932

@@ -43,6 +46,6 @@ fn internal_pointer_qmodelindex(i: &QModelIndex) -> *mut qmodelindex_cxx::c_void
4346
i.internal_pointer_mut()
4447
}
4548

46-
fn internal_id_qmodelindex(i: &QModelIndex) -> usize {
49+
fn internal_id_qmodelindex(i: &QModelIndex) -> cxx_qt_lib::quintptr {
4750
i.internal_id()
4851
}

0 commit comments

Comments
 (0)