qdbusargument.sip 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // qdbusargument.sip generated by MetaSIP
  2. //
  3. // This file is part of the QtDBus Python extension module.
  4. //
  5. // Copyright (c) 2026 Riverbank Computing Limited <info@riverbankcomputing.com>
  6. //
  7. // This file is part of PyQt6.
  8. //
  9. // This file may be used under the terms of the GNU General Public License
  10. // version 3.0 as published by the Free Software Foundation and appearing in
  11. // the file LICENSE included in the packaging of this file. Please review the
  12. // following information to ensure the GNU General Public License version 3.0
  13. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  14. //
  15. // If you do not wish to use this file under the terms of the GPL version 3.0
  16. // then you may purchase a commercial license. For more information contact
  17. // info@riverbankcomputing.com.
  18. //
  19. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  20. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21. class QDBusArgument
  22. {
  23. %TypeHeaderCode
  24. #include <qdbusargument.h>
  25. %End
  26. %TypeCode
  27. #include <QStringList>
  28. static PyObject *qdbusargument_add(QDBusArgument *arg, PyObject *obj, int mtype)
  29. {
  30. int iserr = 0;
  31. if (PyLong_CheckExact(obj))
  32. {
  33. if (mtype == QMetaType::UChar || mtype == QMetaType::UShort || mtype == QMetaType::UInt || mtype == QMetaType::ULongLong)
  34. {
  35. // Handle the unsigned values.
  36. unsigned long long v = PyLong_AsUnsignedLongLongMask(obj);
  37. switch (mtype)
  38. {
  39. case QMetaType::UChar:
  40. *arg << (uchar)v;
  41. break;
  42. case QMetaType::UShort:
  43. *arg << (ushort)v;
  44. break;
  45. case QMetaType::UInt:
  46. *arg << (uint)v;
  47. break;
  48. case QMetaType::ULongLong:
  49. *arg << (qulonglong)v;
  50. break;
  51. }
  52. }
  53. else if (mtype == QMetaType::Short || mtype == QMetaType::Int || mtype == QMetaType::LongLong)
  54. {
  55. // Handle the signed values.
  56. long long v = PyLong_AsLongLong(obj);
  57. switch (mtype)
  58. {
  59. case QMetaType::Short:
  60. *arg << (short)v;
  61. break;
  62. case QMetaType::Int:
  63. *arg << (int)v;
  64. break;
  65. case QMetaType::LongLong:
  66. *arg << (qlonglong)v;
  67. break;
  68. }
  69. }
  70. else
  71. {
  72. PyErr_Format(PyExc_ValueError,
  73. "%d is an invalid QMetaType::Type for an integer object",
  74. mtype);
  75. iserr = 1;
  76. }
  77. }
  78. else if (mtype == QMetaType::QStringList)
  79. {
  80. // A QStringList has to be handled explicitly to prevent it being seen
  81. // as a vialiant list.
  82. int value_state;
  83. QStringList *qsl = reinterpret_cast<QStringList *>(
  84. sipForceConvertToType(obj, sipType_QStringList, 0,
  85. SIP_NOT_NONE, &value_state, &iserr));
  86. if (!iserr)
  87. {
  88. arg->beginArray(QMetaType::QString);
  89. for (int i = 0; i < qsl->count(); ++i)
  90. *arg << qsl->at(i);
  91. arg->endArray();
  92. sipReleaseType(qsl, sipType_QStringList, value_state);
  93. }
  94. }
  95. else
  96. {
  97. int value_state;
  98. QVariant *qv = reinterpret_cast<QVariant *>(
  99. sipForceConvertToType(obj, sipType_QVariant, 0, SIP_NOT_NONE,
  100. &value_state, &iserr));
  101. if (!iserr)
  102. {
  103. // This is an internal method. If it proves to be a problem then we
  104. // will have to handle each type explicitly.
  105. arg->appendVariant(*qv);
  106. sipReleaseType(qv, sipType_QVariant, value_state);
  107. }
  108. }
  109. if (iserr)
  110. return 0;
  111. Py_INCREF(Py_None);
  112. return Py_None;
  113. }
  114. %End
  115. public:
  116. QDBusArgument();
  117. QDBusArgument(const QDBusArgument &other);
  118. QDBusArgument(SIP_PYOBJECT arg, int id = QMetaType::Int);
  119. %MethodCode
  120. sipCpp = new QDBusArgument();
  121. PyObject *res = qdbusargument_add(sipCpp, a0, a1);
  122. if (res)
  123. {
  124. Py_DECREF(res);
  125. }
  126. else
  127. {
  128. delete sipCpp;
  129. sipCpp = 0;
  130. }
  131. %End
  132. ~QDBusArgument();
  133. SIP_PYOBJECT add(SIP_PYOBJECT arg, int id = QMetaType::Int) /TypeHint=""/;
  134. %MethodCode
  135. sipRes = qdbusargument_add(sipCpp, a0, a1);
  136. %End
  137. void beginStructure();
  138. void endStructure();
  139. void beginArray(QMetaType elementMetaType);
  140. void beginArray(int id);
  141. void endArray();
  142. void beginMap(QMetaType keyMetaType, QMetaType valueMetaType);
  143. void beginMap(int kid, int vid);
  144. void endMap();
  145. void beginMapEntry();
  146. void endMapEntry();
  147. void swap(QDBusArgument &other /Constrained/);
  148. };