Skip to content

Commit

Permalink
cxx-qt-lib: use quintptr for QModelIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
ahayzen-kdab committed Nov 5, 2024
1 parent 724b060 commit aec4f39
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 37 deletions.
9 changes: 0 additions & 9 deletions crates/cxx-qt-lib/include/core/qmodelindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,3 @@
#include <cinttypes>

#include <QtCore/QModelIndex>

namespace rust {
namespace cxxqtlib1 {

::std::size_t
qmodelindexInternalId(const QModelIndex& index);

}
}
13 changes: 0 additions & 13 deletions crates/cxx-qt-lib/src/core/qmodelindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,3 @@ assert_alignment_and_size(QModelIndex, {
});

static_assert(::std::is_trivially_copyable<QModelIndex>::value);

namespace rust {
namespace cxxqtlib1 {

::std::size_t
qmodelindexInternalId(const QModelIndex& index)
{
// TODO: need to add support for quintptr
return static_cast<::std::size_t>(index.internalId());
}

}
}
17 changes: 4 additions & 13 deletions crates/cxx-qt-lib/src/core/qmodelindex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod ffi {

type QModelIndex = super::QModelIndex;
type QString = crate::QString;
type quintptr = crate::quintptr;

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

/// Returns a `quintptr` used by the model to associate the index with the internal data structure.
#[rust_name = "internal_id"]
fn internalId(self: &QModelIndex) -> quintptr;
/// Returns a `*mut c_void` pointer used by the model to associate the index with the internal data structure.
#[rust_name = "internal_pointer_mut"]
fn internalPointer(self: &QModelIndex) -> *mut c_void;
Expand All @@ -54,10 +58,6 @@ mod ffi {
#[doc(hidden)]
#[rust_name = "qmodelindex_to_qstring"]
fn toQString(value: &QModelIndex) -> QString;

#[doc(hidden)]
#[rust_name = "qmodelindex_internal_id"]
fn qmodelindexInternalId(index: &QModelIndex) -> usize;
}
}

Expand All @@ -71,15 +71,6 @@ pub struct QModelIndex {
_m: MaybeUninit<usize>,
}

impl QModelIndex {
/// Returns a `usize` used by the model to associate the index with the internal data structure.
//
// TODO: need to add support for quintptr
pub fn internal_id(&self) -> usize {
ffi::qmodelindex_internal_id(self)
}
}

impl Default for QModelIndex {
/// Creates a new empty model index. This type of model index is used to indicate that the position in the model is invalid.
fn default() -> Self {
Expand Down
7 changes: 5 additions & 2 deletions tests/qt_types_standalone/rust/src/qmodelindex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ mod qmodelindex_cxx {
unsafe extern "C++" {
include!("cxx-qt-lib/qmodelindex.h");
type QModelIndex = cxx_qt_lib::QModelIndex;

include!("cxx-qt-lib/qtypes.h");
type QUIntPtr = cxx_qt_lib::QUIntPtr;
}

#[namespace = "rust::cxxqtlib1"]
Expand All @@ -23,7 +26,7 @@ mod qmodelindex_cxx {
fn read_qmodelindex(i: &QModelIndex) -> bool;
fn clone_qmodelindex(i: &QModelIndex) -> QModelIndex;
fn internal_pointer_qmodelindex(i: &QModelIndex) -> *mut c_void;
fn internal_id_qmodelindex(i: &QModelIndex) -> usize;
fn internal_id_qmodelindex(i: &QModelIndex) -> QUIntPtr;
}
}

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

fn internal_id_qmodelindex(i: &QModelIndex) -> usize {
fn internal_id_qmodelindex(i: &QModelIndex) -> cxx_qt_lib::QUIntPtr {
i.internal_id()
}

0 comments on commit aec4f39

Please sign in to comment.