aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/libpysideqml
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6/libpysideqml')
-rw-r--r--sources/pyside6/libpysideqml/pysideqmlnamedelement.cpp2
-rw-r--r--sources/pyside6/libpysideqml/pysideqmlregistertype.cpp76
-rw-r--r--sources/pyside6/libpysideqml/pysideqmlregistertype_p.h4
-rw-r--r--sources/pyside6/libpysideqml/pysideqmltypeinfo.cpp4
-rw-r--r--sources/pyside6/libpysideqml/pysideqmltypeinfo_p.h4
5 files changed, 40 insertions, 50 deletions
diff --git a/sources/pyside6/libpysideqml/pysideqmlnamedelement.cpp b/sources/pyside6/libpysideqml/pysideqmlnamedelement.cpp
index f29638017..8d2c558cf 100644
--- a/sources/pyside6/libpysideqml/pysideqmlnamedelement.cpp
+++ b/sources/pyside6/libpysideqml/pysideqmlnamedelement.cpp
@@ -31,7 +31,7 @@ PyObject *PySideQmlNamedElementPrivate::tp_call(PyObject *self, PyObject *args,
return nullptr;
auto *data = DecoratorPrivate::get<PySideQmlNamedElementPrivate>(self);
- auto *result = PySide::Qml::qmlNamedElementMacro(klass, data->string().c_str());
+ auto *result = PySide::Qml::qmlNamedElementMacro(klass, data->string());
Py_XINCREF(result);
return result;
}
diff --git a/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp b/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp
index 1208220ca..cf3b4dc52 100644
--- a/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp
+++ b/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp
@@ -85,6 +85,32 @@ static inline bool isQmlParserStatus(const QMetaObject *o)
return inheritsFrom(o, "QPyQmlParserStatus");
}
+static QByteArray getGlobalString(const char *name)
+{
+ PyObject *globalVar = PyDict_GetItemString(PyEval_GetGlobals(), name);
+
+ if (globalVar == nullptr || PyUnicode_Check(globalVar) == 0)
+ return {};
+
+ const char *stringValue = _PepUnicode_AsString(globalVar);
+ return stringValue != nullptr ? QByteArray(stringValue) : QByteArray{};
+}
+
+static int getGlobalInt(const char *name)
+{
+ PyObject *globalVar = PyDict_GetItemString(PyEval_GetGlobals(), name);
+
+ if (globalVar == nullptr || PyLong_Check(globalVar) == 0)
+ return -1;
+
+ long value = PyLong_AsLong(globalVar);
+
+ if (value > std::numeric_limits<int>::max() || value < std::numeric_limits<int>::min())
+ return -1;
+
+ return value;
+}
+
namespace PySide::Qml {
int qmlRegisterType(PyObject *pyObj, const char *uri, int versionMajor,
@@ -334,44 +360,6 @@ int qmlRegisterSingletonInstance(PyObject *pyObj, const char *uri, int versionMa
} // namespace PySide::Qml
-static std::string getGlobalString(const char *name)
-{
- using Shiboken::AutoDecRef;
-
- PyObject *globals = PyEval_GetGlobals();
-
- AutoDecRef pyName(Py_BuildValue("s", name));
-
- PyObject *globalVar = PyDict_GetItem(globals, pyName);
-
- if (globalVar == nullptr || !PyUnicode_Check(globalVar))
- return "";
-
- const char *stringValue = _PepUnicode_AsString(globalVar);
- return stringValue != nullptr ? stringValue : "";
-}
-
-static int getGlobalInt(const char *name)
-{
- using Shiboken::AutoDecRef;
-
- PyObject *globals = PyEval_GetGlobals();
-
- AutoDecRef pyName(Py_BuildValue("s", name));
-
- PyObject *globalVar = PyDict_GetItem(globals, pyName);
-
- if (globalVar == nullptr || !PyLong_Check(globalVar))
- return -1;
-
- long value = PyLong_AsLong(globalVar);
-
- if (value > std::numeric_limits<int>::max() || value < std::numeric_limits<int>::min())
- return -1;
-
- return value;
-}
-
enum class RegisterMode {
Normal,
Anonymous,
@@ -399,11 +387,11 @@ static PyObject *qmlElementMacroHelper(PyObject *pyObj,
return nullptr;
}
- std::string importName = getGlobalString("QML_IMPORT_NAME");
+ const auto importName = getGlobalString("QML_IMPORT_NAME");
int majorVersion = getGlobalInt("QML_IMPORT_MAJOR_VERSION");
int minorVersion = getGlobalInt("QML_IMPORT_MINOR_VERSION");
- if (importName.empty()) {
+ if (importName.isEmpty()) {
PyErr_Format(PyExc_TypeError, "You need specify QML_IMPORT_NAME in order to use %s.",
decoratorName);
return nullptr;
@@ -419,7 +407,7 @@ static PyObject *qmlElementMacroHelper(PyObject *pyObj,
if (minorVersion == -1)
minorVersion = 0;
- const char *uri = importName.c_str();
+ const char *uri = importName.constData();
const int result = mode == RegisterMode::Singleton
? PySide::Qml::qmlRegisterSingletonType(pyObj, uri, majorVersion, minorVersion,
typeName, nullptr,
@@ -452,7 +440,7 @@ PyObject *qmlElementMacro(PyObject *pyObj, const char *decoratorName,
mode = RegisterMode::Singleton;
else if (info->flags.testFlag(PySide::Qml::QmlTypeFlag::Uncreatable))
mode = RegisterMode::Uncreatable;
- noCreationReason = info->noCreationReason.c_str();
+ noCreationReason = info->noCreationReason.constData();
if (info->foreignType)
registerObject = reinterpret_cast<PyObject *>(info->foreignType);
}
@@ -466,9 +454,9 @@ PyObject *qmlElementMacro(PyObject *pyObj)
return qmlElementMacro(pyObj, "QmlElement");
}
-PyObject *qmlNamedElementMacro(PyObject *pyObj, const char *typeName)
+PyObject *qmlNamedElementMacro(PyObject *pyObj, const QByteArray &typeName)
{
- return qmlElementMacro(pyObj, "QmlNamedElement", qstrdup(typeName));
+ return qmlElementMacro(pyObj, "QmlNamedElement", qstrdup(typeName.constData()));
}
PyObject *qmlAnonymousMacro(PyObject *pyObj)
diff --git a/sources/pyside6/libpysideqml/pysideqmlregistertype_p.h b/sources/pyside6/libpysideqml/pysideqmlregistertype_p.h
index 3f077ee2a..f11f92241 100644
--- a/sources/pyside6/libpysideqml/pysideqmlregistertype_p.h
+++ b/sources/pyside6/libpysideqml/pysideqmlregistertype_p.h
@@ -6,12 +6,14 @@
#include <sbkpython.h>
+#include <QtCore/QByteArray>
+
PyTypeObject *qObjectType();
namespace PySide::Qml {
-PyObject *qmlNamedElementMacro(PyObject *pyObj, const char *typeName);
+PyObject *qmlNamedElementMacro(PyObject *pyObj, const QByteArray &typeName);
}
diff --git a/sources/pyside6/libpysideqml/pysideqmltypeinfo.cpp b/sources/pyside6/libpysideqml/pysideqmltypeinfo.cpp
index 0304d33e3..0dc5d64c8 100644
--- a/sources/pyside6/libpysideqml/pysideqmltypeinfo.cpp
+++ b/sources/pyside6/libpysideqml/pysideqmltypeinfo.cpp
@@ -42,8 +42,8 @@ QDebug operator<<(QDebug d, const QmlTypeInfo &i)
d.noquote();
d.nospace();
d << "QmlTypeInfo(" << i.flags;
- if (!i.noCreationReason.empty())
- d << ", noCreationReason=\"" << i.noCreationReason.c_str() << '"';
+ if (!i.noCreationReason.isEmpty())
+ d << ", noCreationReason=\"" << i.noCreationReason << '"';
if (i.foreignType)
d << ", foreignType=" << i.foreignType->tp_name;
if (i.attachedType)
diff --git a/sources/pyside6/libpysideqml/pysideqmltypeinfo_p.h b/sources/pyside6/libpysideqml/pysideqmltypeinfo_p.h
index e10a2b38c..cf06bb304 100644
--- a/sources/pyside6/libpysideqml/pysideqmltypeinfo_p.h
+++ b/sources/pyside6/libpysideqml/pysideqmltypeinfo_p.h
@@ -6,10 +6,10 @@
#include <sbkpython.h>
+#include <QtCore/QByteArray>
#include <QtCore/QFlags>
#include <memory>
-#include <string>
QT_FORWARD_DECLARE_CLASS(QDebug)
QT_FORWARD_DECLARE_CLASS(QObject)
@@ -30,7 +30,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QmlTypeFlags)
struct QmlTypeInfo
{
QmlTypeFlags flags;
- std::string noCreationReason;
+ QByteArray noCreationReason;
PyTypeObject *foreignType = nullptr;
PyTypeObject *attachedType = nullptr;
PyTypeObject *extensionType = nullptr;