Mantid
Loading...
Searching...
No Matches
QHashToDict.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9
11
13 auto mod = PyImport_ImportModule("qtpy.QtCore");
14 Py_DECREF(mod);
15
16 auto d = Python::Dict();
17
18 auto it = hash.constBegin();
19 auto end = hash.constEnd();
20 auto sipAPI = Detail::sipAPI();
21
22 while (it != end) {
23 auto *k = new KwArgs::key_type(it.key());
24 auto *kobj = sipAPI->api_convert_from_new_type(k, sipAPI->api_find_type("QString"), Py_None);
25
26 if (!kobj) {
27 delete k;
28 return Python::Dict();
29 }
30
31 auto *v = new KwArgs::mapped_type(it.value());
32 auto *vobj = sipAPI->api_convert_from_new_type(v, sipAPI->api_find_type("QVariant"), Py_None);
33
34 if (!vobj) {
35 delete v;
36 Py_DECREF(kobj);
37 return Python::Dict();
38 }
39
40 auto rc = PyDict_SetItem(d.ptr(), kobj, vobj);
41
42 Py_DECREF(vobj);
43 Py_DECREF(kobj);
44
45 if (rc < 0) {
46 return Python::Dict();
47 }
48
49 ++it;
50 }
51
52 return d;
53}
54
55} // namespace MantidQt::Widgets::Common::Python
EXPORT_OPT_MANTIDQT_COMMON const sipAPIDef * sipAPI()
Definition: Sip.cpp:15
boost::python::dict Dict
Definition: Object.h:30
EXPORT_OPT_MANTIDQT_COMMON Python::Dict qHashToDict(const KwArgs &hash)
Definition: QHashToDict.cpp:12