diff options
| author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2020-01-06 01:00:08 +0100 |
|---|---|---|
| committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-01-06 20:13:31 +0000 |
| commit | 68c30e372b01561e8809fcfa5426ae896da70b8e (patch) | |
| tree | 68245df2a3616ff0ebf9e132cab0d3c22a586755 /src/tools/uic/python/pythonwriteimports.cpp | |
| parent | bd4a1b98b813dfbbb4a9db35a380bed8dd5f0ce3 (diff) | |
| parent | 3a010f72b81d530df96bfb04e0dd2f13a527cc18 (diff) | |
Merge "Merge remote-tracking branch 'origin/5.14' into 5.15"
Diffstat (limited to 'src/tools/uic/python/pythonwriteimports.cpp')
| -rw-r--r-- | src/tools/uic/python/pythonwriteimports.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/tools/uic/python/pythonwriteimports.cpp b/src/tools/uic/python/pythonwriteimports.cpp index 303615f77b4..be556966834 100644 --- a/src/tools/uic/python/pythonwriteimports.cpp +++ b/src/tools/uic/python/pythonwriteimports.cpp @@ -29,6 +29,7 @@ #include "pythonwriteimports.h" #include <customwidgetsinfo.h> +#include <option.h> #include <uic.h> #include <ui4.h> @@ -46,6 +47,20 @@ from PySide2.QtGui import (QBrush, QColor, QConicalGradient, QFont, from PySide2.QtWidgets import * )I"; +// Change the name of a qrc file "dir/foo.qrc" file to the Python +// module name "foo_rc" according to project conventions. +static QString pythonResource(QString resource) +{ + const int lastSlash = resource.lastIndexOf(QLatin1Char('/')); + if (lastSlash != -1) + resource.remove(0, lastSlash + 1); + if (resource.endsWith(QLatin1String(".qrc"))) { + resource.chop(4); + resource.append(QLatin1String("_rc")); + } + return resource; +} + namespace Python { WriteImports::WriteImports(Uic *uic) : m_uic(uic) @@ -60,6 +75,23 @@ void WriteImports::acceptUI(DomUI *node) TreeWalker::acceptCustomWidgets(customWidgets); output << '\n'; } + + if (auto resources = node->elementResources()) { + const auto includes = resources->elementInclude(); + for (auto include : includes) { + if (include->hasAttributeLocation()) + writeImport(pythonResource(include->attributeLocation())); + } + output << '\n'; + } +} + +void WriteImports::writeImport(const QString &module) +{ + + if (m_uic->option().fromImports) + m_uic->output() << "from . "; + m_uic->output() << "import " << module << '\n'; } QString WriteImports::qtModuleOf(const DomCustomWidget *node) const |
