1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
// SPDX-FileContributor: Andrew Hayzen <andrew.hayzen@kdab.com>
//
// SPDX-License-Identifier: MIT OR Apache-2.0
use cxx::{type_id, ExternType};
use std::fmt;
use std::mem::MaybeUninit;

#[cxx::bridge]
mod ffi {
    unsafe extern "C++" {
        include!("cxx-qt-lib/qpersistentmodelindex.h");
        include!("cxx-qt-lib/qstring.h");

        type QPersistentModelIndex = super::QPersistentModelIndex;
        type QString = crate::QString;

        include!("cxx-qt-lib/qmodelindex.h");
        type QModelIndex = crate::QModelIndex;

        /// Returns the column this persistent model index refers to.
        fn column(self: &QPersistentModelIndex) -> i32;
        /// Returns true if this persistent model index is valid; otherwise returns false.
        ///
        /// A valid index belongs to a model, and has non-negative row and column numbers.
        #[rust_name = "is_valid"]
        fn isValid(self: &QPersistentModelIndex) -> bool;
        /// Returns the parent QModelIndex for this persistent index, or an invalid QModelIndex if it has no parent.
        fn parent(self: &QPersistentModelIndex) -> QModelIndex;
        /// Returns the row this persistent model index refers to.
        fn row(self: &QPersistentModelIndex) -> i32;
        /// Returns the sibling at row and column or an invalid QModelIndex if there is no sibling at this position.
        fn sibling(self: &QPersistentModelIndex, row: i32, column: i32) -> QModelIndex;
    }

    #[namespace = "rust::cxxqtlib1"]
    unsafe extern "C++" {
        include!("cxx-qt-lib/common.h");

        #[doc(hidden)]
        #[rust_name = "qpersistentmodelindex_drop"]
        fn drop(string: &mut QPersistentModelIndex);

        #[doc(hidden)]
        #[rust_name = "qpersistentmodelindex_from_qmodelindex"]
        fn construct(index: &QModelIndex) -> QPersistentModelIndex;
        #[doc(hidden)]
        #[rust_name = "qpersistentmodelindex_clone"]
        fn construct(other: &QPersistentModelIndex) -> QPersistentModelIndex;
        #[doc(hidden)]
        #[rust_name = "qpersistentmodelindex_eq"]
        fn operatorEq(a: &QPersistentModelIndex, b: &QPersistentModelIndex) -> bool;
        #[doc(hidden)]
        #[rust_name = "qpersistentmodelindex_to_qstring"]
        fn toQString(value: &QPersistentModelIndex) -> QString;
    }
}

/// The QPersistentModelIndex class is used to locate data in a data model.
#[repr(C)]
pub struct QPersistentModelIndex {
    _space: MaybeUninit<usize>,
}

impl Clone for QPersistentModelIndex {
    /// Creates a new QPersistentModelIndex that is a copy of the other persistent model index.
    fn clone(&self) -> Self {
        ffi::qpersistentmodelindex_clone(self)
    }
}

impl Drop for QPersistentModelIndex {
    /// Destroys the persistent model index.
    fn drop(&mut self) {
        ffi::qpersistentmodelindex_drop(self)
    }
}

impl From<&crate::QModelIndex> for QPersistentModelIndex {
    /// Creates a new QPersistentModelIndex that is a copy of the model index.
    fn from(index: &crate::QModelIndex) -> Self {
        ffi::qpersistentmodelindex_from_qmodelindex(index)
    }
}

impl std::cmp::PartialEq for QPersistentModelIndex {
    fn eq(&self, other: &Self) -> bool {
        ffi::qpersistentmodelindex_eq(self, other)
    }
}

impl std::cmp::Eq for QPersistentModelIndex {}

impl fmt::Display for QPersistentModelIndex {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", ffi::qpersistentmodelindex_to_qstring(self))
    }
}

impl fmt::Debug for QPersistentModelIndex {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{self}")
    }
}

// Safety:
//
// Static checks on the C++ side to ensure the size is the same.
unsafe impl ExternType for QPersistentModelIndex {
    type Id = type_id!("QPersistentModelIndex");
    type Kind = cxx::kind::Trivial;
}