Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
aboutsummaryrefslogtreecommitdiffstats
blob: b53f7ce826bf3d735504f5536ee8521f5b4b3119 (plain)
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
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef PYSIDEVARIANTUTILS_H
#define PYSIDEVARIANTUTILS_H

#include <sbkpython.h>

#include <pysidemacros.h>

#include <QtCore/qvariant.h>
#include <QtCore/qvariantlist.h>

#include <optional>

namespace PySide::Variant
{

/// Return a QMetaType for a PyTypeObject for purposes of
/// converting to a QVariant.
PYSIDE_API QMetaType resolveMetaType(PyTypeObject *type);

/// Convert a heterogenous Python list to a QVariantList by converting each
/// item using the QVariant converter.
PYSIDE_API std::optional<QVariantList> pyListToVariantList(PyObject *list);

/// Converts a list to a QVariant following the PySide semantics:
/// - A list of strings is returned as QVariant<QStringList>
/// - A list of convertible values is returned as QVariant<QList<Value>>
/// - Remaining types are returned as QVariant(QVariantList)
PYSIDE_API QVariant convertToVariantList(PyObject *list);

/// Converts a map to a QVariantMap (string keys and QVariant values)
PYSIDE_API QVariant convertToVariantMap(PyObject *map);
} // namespace PySide::Variant

#endif // PYSIDEVARIANTUTILS_H