Skip to content

Commit

Permalink
Add Debug for QVariantList
Browse files Browse the repository at this point in the history
  • Loading branch information
direc85 committed Feb 23, 2024
1 parent 22c9bcc commit f4798d9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions qttypes/src/qtcore/qlist/qvariantlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ impl IndexMut<usize> for QVariantList {
}
}

impl std::fmt::Debug for QVariantList {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_map().entries(self.into_iter().enumerate()).finish()
}
}

impl<'a> IntoIterator for &'a QVariantList {
type Item = &'a QVariant;
type IntoIter = QListIterator<'a, QVariantList, QVariant>;
Expand Down Expand Up @@ -160,4 +166,16 @@ mod tests {
assert_eq!(qs2.to_string(), "hello");
assert_eq!(qba4.to_string(), "hello");
}

#[test]
fn qvariantlist_debug() {
let mut list = QVariantList::default();
list.push(42.into());
list.push(QString::from("String!").into());
list.push(QByteArray::from("Bytearray!").into());
assert_eq!(
format!("{:?}", list),
"{0: QVariant(int: \"42\"), 1: QVariant(QString: \"String!\"), 2: QVariant(QByteArray: \"Bytearray!\")}"
);
}
}

0 comments on commit f4798d9

Please sign in to comment.