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
use qvariant::*;

/// A wrapper around `Vec<QVariant>`, that is supposed to be used in [`Q_OBJECT!`](macro.Q_OBJECT.html) properties.
/// It is only needed because of macro restrictions in current stable Rust.
/// # Examples
/// ```
/// # #[macro_use] extern crate qml;
/// # use qml::*;
/// # #[allow(unused_variables)]
/// # fn main() {
/// let shortcut: QVariantList = qvarlist![["John", [2, 2]], ["Ivan", [10, 0]], ["Mary", [0, 1]]].into();
/// # }
/// ```
/// ```
/// # #[macro_use] extern crate qml;
/// # use qml::*;
/// pub struct Example;
///
/// Q_OBJECT!(
/// pub Example as QExample{
///     signals:
///     slots:
///     properties:
///         list: QVariantList; read: get_list, write: set_list, notify: list_changed;
/// });
///
/// # fn main() {
///     let mut qobj = QExample::new(Example, qvarlist![["John", [2, 2]]].into());
/// # }
/// ```
/// #See
/// [`qvarlist!`](macro.qvarlist.html), [`Q_OBJECT!`](macro.Q_OBJECT.html)

pub struct QVariantList {
    vec: Vec<QVariant>,
}

impl Default for QVariantList {
    fn default() -> Self {
        QVariantList { vec: vec![] }
    }
}

impl From<QVariantList> for QVariant {
    fn from(i: QVariantList) -> Self {
        i.vec.into()
    }
}

impl From<Vec<QVariant>> for QVariantList {
    fn from(i: Vec<QVariant>) -> Self {
        QVariantList { vec: i }
    }
}

impl From<QVariantList> for Vec<QVariant> {
    fn from(i: QVariantList) -> Self {
        i.vec
    }
}

impl From<QVariant> for QVariantList {
    fn from(i: QVariant) -> Self {
        <Vec<QVariant>>::from(i).into()
    }
}