diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2020-01-15 01:00:38 +0100 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2020-01-15 01:00:39 +0100 |
commit | c3123c757a2301445ac286ce2c8af20959151e21 (patch) | |
tree | c8f5421725d0fe0cfe8a29136937e54d6f3f95c2 /src/tools | |
parent | 2cbc5f6f7ae8ba580126a7cafc1898377c2a2407 (diff) | |
parent | 7a59d6f138ff8799170cc03d709525ab965d703a (diff) | |
download | qtbase-c3123c757a2301445ac286ce2c8af20959151e21.tar.gz |
Merge remote-tracking branch 'origin/5.14' into 5.15
Change-Id: I8dbcf23835d52d3aa7d018ed250814d60c68aa83
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/uic/python/pythonwriteimports.cpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/tools/uic/python/pythonwriteimports.cpp b/src/tools/uic/python/pythonwriteimports.cpp index be55696683..963244d450 100644 --- a/src/tools/uic/python/pythonwriteimports.cpp +++ b/src/tools/uic/python/pythonwriteimports.cpp @@ -41,7 +41,7 @@ QT_BEGIN_NAMESPACE static const char *standardImports = R"I(from PySide2.QtCore import (QCoreApplication, QMetaObject, QObject, QPoint, QRect, QSize, QUrl, Qt) -from PySide2.QtGui import (QBrush, QColor, QConicalGradient, QFont, +from PySide2.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont, QFontDatabase, QIcon, QLinearGradient, QPalette, QPainter, QPixmap, QRadialGradient) from PySide2.QtWidgets import * @@ -114,11 +114,29 @@ void WriteImports::acceptCustomWidget(DomCustomWidget *node) const auto &className = node->elementClass(); if (className.contains(QLatin1String("::"))) return; // Exclude namespaced names (just to make tests pass). - const QString &qtModule = qtModuleOf(node); + const QString &importModule = qtModuleOf(node); auto &output = m_uic->output(); - if (!qtModule.isEmpty()) - output << "from PySide2." << qtModule << ' '; - output << "import " << className << '\n'; + // For starting importing PySide2 modules + if (!importModule.isEmpty()) { + output << "from "; + if (importModule.startsWith(QLatin1String("Qt"))) + output << "PySide2."; + output << importModule; + if (!className.isEmpty()) + output << " import " << className << "\n\n"; + } else { + // When the elementHeader is not set, we know it's the continuation + // of a PySide2 import or a normal import of another module. + if (!node->elementHeader() || node->elementHeader()->text().isEmpty()) { + output << "import " << className << '\n'; + } else { // When we do have elementHeader, we know it's a relative import. + QString modulePath = node->elementHeader()->text(); + // '.h' is added by default on headers for <customwidget> + if (modulePath.endsWith(QLatin1String(".h"))) + modulePath.chop(2); + output << "from " << modulePath << " import " << className << '\n'; + } + } } } // namespace Python |