summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristián Maureira-Fredes <cristian.maureira-fredes@qt.io>2019-12-18 17:56:23 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-01-14 08:11:53 +0100
commit3f6275960c4da87a18f3740bc3fef68dcf8a65d1 (patch)
treef5eb21871cc39de1d893a85c1c95391c6ea451eb
parent6d545dedad6248d9ab2f28782940fc5709504315 (diff)
uic: add customwidget imports support for python
Fixes: QTBUG-81073 Change-Id: I29659481b14927ffcb8f2cb1829b577a67e4b937 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--src/tools/uic/python/pythonwriteimports.cpp26
-rw-r--r--tests/auto/tools/uic/baseline/config.ui.py2
2 files changed, 23 insertions, 5 deletions
diff --git a/src/tools/uic/python/pythonwriteimports.cpp b/src/tools/uic/python/pythonwriteimports.cpp
index be55696683..ce1df2284e 100644
--- a/src/tools/uic/python/pythonwriteimports.cpp
+++ b/src/tools/uic/python/pythonwriteimports.cpp
@@ -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
diff --git a/tests/auto/tools/uic/baseline/config.ui.py b/tests/auto/tools/uic/baseline/config.ui.py
index f7e1ffc773..8be5eae39f 100644
--- a/tests/auto/tools/uic/baseline/config.ui.py
+++ b/tests/auto/tools/uic/baseline/config.ui.py
@@ -43,7 +43,7 @@ from PySide2.QtGui import (QBrush, QColor, QConicalGradient, QFont,
QRadialGradient)
from PySide2.QtWidgets import *
-import GammaView
+from gammaview import GammaView
class Ui_Config(object):