diff options
Diffstat (limited to 'sources/pyside6/PySide6/glue/qtuitools.cpp')
-rw-r--r-- | sources/pyside6/PySide6/glue/qtuitools.cpp | 92 |
1 files changed, 33 insertions, 59 deletions
diff --git a/sources/pyside6/PySide6/glue/qtuitools.cpp b/sources/pyside6/PySide6/glue/qtuitools.cpp index 40646e74b..1835ed096 100644 --- a/sources/pyside6/PySide6/glue/qtuitools.cpp +++ b/sources/pyside6/PySide6/glue/qtuitools.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt for Python. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 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 // @snippet uitools-loadui /* * Based on code provided by: @@ -44,9 +8,10 @@ */ #include <shiboken.h> -#include <QUiLoader> -#include <QFile> -#include <QWidget> + +#include <QtUiTools/QUiLoader> +#include <QtWidgets/QWidget> +#include <QtCore/QFile> static void createChildrenNameAttributes(PyObject *root, QObject *object) { @@ -80,7 +45,7 @@ static PyObject *QUiLoadedLoadUiFromDevice(QUiLoader *self, QIODevice *dev, QWid } if (!PyErr_Occurred()) - PyErr_SetString(PyExc_RuntimeError, "Unable to open/read ui device"); + PyErr_Format(PyExc_RuntimeError, "Unable to open/read ui device"); return nullptr; } @@ -97,7 +62,7 @@ Q_IMPORT_PLUGIN(PyCustomWidgets); // @snippet quiloader-registercustomwidget registerCustomWidget(%PYARG_1); -%CPPSELF.addPluginPath(""); // force reload widgets +%CPPSELF.addPluginPath(QString{}); // force reload widgets // @snippet quiloader-registercustomwidget // @snippet quiloader-load-1 @@ -107,7 +72,8 @@ registerCustomWidget(%PYARG_1); // @snippet quiloader-load-2 // Avoid calling the original function: %CPPSELF.%FUNCTION_NAME() -%PYARG_0 = QUiLoaderLoadUiFromFileName(%CPPSELF, %1, %2); +auto str = PySide::pyPathToQString(%1); +%PYARG_0 = QUiLoaderLoadUiFromFileName(%CPPSELF, str, %2); // @snippet quiloader-load-2 // @snippet loaduitype @@ -121,38 +87,46 @@ char *arg1 = PyBytes_AsString(strObj); QByteArray uiFileName(arg1); Py_DECREF(strObj); -QFile uiFile(uiFileName); - -if (!uiFile.exists()) { - qCritical().noquote() << "File" << uiFileName << "does not exists"; +if (uiFileName.isEmpty()) { + qCritical() << "Error converting the UI filename to QByteArray"; Py_RETURN_NONE; } -if (uiFileName.isEmpty()) { - qCritical() << "Error converting the UI filename to QByteArray"; +QFile uiFile(QString::fromUtf8(uiFileName)); + +if (!uiFile.exists()) { + qCritical().noquote() << "File" << uiFileName << "does not exist"; Py_RETURN_NONE; } // Use the 'pyside6-uic' wrapper instead of 'uic' // This approach is better than rely on 'uic' since installing // the wheels cover this case. -QString uicBin("pyside6-uic"); +QString uicBin(QStringLiteral("pyside6-uic")); QStringList uicArgs = {QString::fromUtf8(uiFileName)}; QProcess uicProcess; uicProcess.start(uicBin, uicArgs); -if (!uicProcess.waitForFinished()) { - qCritical() << "Cannot run 'pyside6-uic': " << uicProcess.errorString() << " - " - << "Exit status " << uicProcess.exitStatus() - << " (" << uicProcess.exitCode() << ")\n" - << "Check if 'pyside6-uic' is in PATH"; +if (!uicProcess.waitForStarted()) { + qCritical().noquote() << "Cannot run '" << uicBin << "': " + << uicProcess.errorString() << " - Check if 'pyside6-uic' is in PATH"; + Py_RETURN_NONE; +} + +if (!uicProcess.waitForFinished() + || uicProcess.exitStatus() != QProcess::NormalExit + || uicProcess.exitCode() != 0) { + qCritical().noquote() << '\'' << uicBin << "' failed: " + << uicProcess.errorString() << " - Exit status " << uicProcess.exitStatus() + << " (" << uicProcess.exitCode() << ")\n"; Py_RETURN_NONE; } + QByteArray uiFileContent = uicProcess.readAllStandardOutput(); QByteArray errorOutput = uicProcess.readAllStandardError(); if (!errorOutput.isEmpty()) { - qCritical().noquote() << errorOutput; + qCritical().noquote() << '\'' << uicBin << "' failed: " << errorOutput; Py_RETURN_NONE; } @@ -176,8 +150,8 @@ QXmlStreamReader reader(&uiFile); while (!reader.atEnd() && baseClassName.isEmpty() && className.isEmpty()) { auto token = reader.readNext(); if (token == QXmlStreamReader::StartElement && reader.name() == u"widget") { - baseClassName = reader.attributes().value(QLatin1String("class")).toUtf8(); - className = reader.attributes().value(QLatin1String("name")).toUtf8(); + baseClassName = reader.attributes().value(QLatin1StringView("class")).toUtf8(); + className = reader.attributes().value(QLatin1StringView("name")).toUtf8(); } } |