summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-07-04 18:29:46 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2011-07-11 15:11:56 -0300
commitf1a737a2207b57d8976d4b0dc64c33e378dfe302 (patch)
tree69cd2102f683c67c2756cc9139daf7747a86c9f5
parent505cf202fbf82dca6d3742166195273e103057fc (diff)
downloadpyside-f1a737a2207b57d8976d4b0dc64c33e378dfe302.tar.gz
pyside-f1a737a2207b57d8976d4b0dc64c33e378dfe302.tar.xz
pyside-f1a737a2207b57d8976d4b0dc64c33e378dfe302.zip
Fix bug 913 - "Widgets inside QTabWidget are not exported as members of the containing widget"
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org> Renato Ara├║jo <renato.filho@openbossa.org>
-rw-r--r--PySide/QtUiTools/glue/uitools_loadui.h81
-rw-r--r--PySide/QtUiTools/typesystem_uitools.xml6
-rw-r--r--tests/QtUiTools/CMakeLists.txt1
-rw-r--r--tests/QtUiTools/bug_392.py2
-rw-r--r--tests/QtUiTools/bug_913.py23
-rw-r--r--tests/QtUiTools/bug_913.ui57
6 files changed, 117 insertions, 53 deletions
diff --git a/PySide/QtUiTools/glue/uitools_loadui.h b/PySide/QtUiTools/glue/uitools_loadui.h
index a6e339a..18bb360 100644
--- a/PySide/QtUiTools/glue/uitools_loadui.h
+++ b/PySide/QtUiTools/glue/uitools_loadui.h
@@ -5,73 +5,56 @@
*/
#include <shiboken.h>
+#include <QUiLoader>
+#include <QFile>
+#include <QWidget>
-static void
-_populate_parent(PyObject* pyParent, QObject *parent)
+static void createChildrenNameAttributes(PyObject* root, QObject* object)
{
- if (parent->children().isEmpty())
- return;
+ foreach (QObject* child, object->children()) {
+ const QByteArray name = child->objectName().toLocal8Bit();
- foreach(QObject *child, parent->children()) {
- QString name(child->objectName());
if (!name.isEmpty() && !name.startsWith("_") && !name.startsWith("qt_")) {
- bool has_attr = PyObject_HasAttrString(pyParent, qPrintable(name));
- Shiboken::AutoDecRef pyChild(Shiboken::Converter<QObject*>::toPython(child));
- if (!has_attr)
- PyObject_SetAttrString(pyParent, qPrintable(name), pyChild);
-
- Shiboken::Object::setParent(pyParent, pyChild);
- _populate_parent(pyChild, qobject_cast<QObject*>(child));
+ bool hasAttr = PyObject_HasAttrString(root, name.constData());
+ if (!hasAttr) {
+ Shiboken::AutoDecRef pyChild(Shiboken::Converter<QObject*>::toPython(child));
+ PyObject_SetAttrString(root, name.constData(), pyChild);
+ }
+ createChildrenNameAttributes(root, child);
}
+ createChildrenNameAttributes(root, child);
}
}
-static PyObject*
-quiloader_load_ui_from_device(QUiLoader* self, QIODevice* dev, QWidget *parent)
+static PyObject* QUiLoadedLoadUiFromDevice(QUiLoader* self, QIODevice* dev, QWidget* parent)
{
- QWidget *w = self->load(dev, parent);
- if (w) {
- QObject* _parent = parent;
- if (!_parent)
- _parent = w;
+ QWidget* wdg = self->load(dev, parent);
+
+ if (wdg) {
+ PyObject* pyWdg = Shiboken::Converter<QWidget*>::toPython(wdg);
+
+ if (!parent)
+ parent = wdg;
- if (parent && parent->layout())
+ if (parent->layout())
parent->layout()->deleteLater();
- PyObject* pyParent = Shiboken::Converter<QWidget*>::toPython(w);
- _populate_parent(pyParent, _parent);
+ createChildrenNameAttributes(pyWdg, wdg);
+ if (parent) {
+ Shiboken::AutoDecRef pyParent(Shiboken::Converter<QWidget*>::toPython(parent));
+ Shiboken::Object::setParent(pyParent, pyWdg);
+ }
- return pyParent;
+ return pyWdg;
}
if (!PyErr_Occurred())
- PyErr_SetString(PyExc_RuntimeError, "Unable to open ui file");
+ PyErr_SetString(PyExc_RuntimeError, "Unable to open/read ui device");
return 0;
}
-static PyObject*
-quiloader_load_ui(QUiLoader* self, const QString &ui_file, QWidget *parent)
+static PyObject* QUiLoaderLoadUiFromFileName(QUiLoader* self, const QString& uiFile, QWidget* parent)
{
- QFile fd(ui_file);
-
- if (fd.exists(ui_file) && fd.open(QFile::ReadOnly)) {
- QWidget* w = self->load(&fd, parent);
- fd.close();
- if (w != 0) {
- QObject *_parent = parent;
- if (!_parent)
- _parent = w;
-
- Shiboken::AutoDecRef pyParent(Shiboken::Converter<QWidget*>::toPython(_parent));
- if (parent && parent->layout())
- parent->layout()->deleteLater();
-
- _populate_parent(pyParent, _parent);
-
- return Shiboken::Converter<QWidget*>::toPython(w);
- }
- }
- if (!PyErr_Occurred())
- PyErr_SetString(PyExc_RuntimeError, "Unable to open ui file");
- return 0;
+ QFile fd(uiFile);
+ return QUiLoadedLoadUiFromDevice(self, &fd, parent);
}
diff --git a/PySide/QtUiTools/typesystem_uitools.xml b/PySide/QtUiTools/typesystem_uitools.xml
index 9d36d3e..46c325c 100644
--- a/PySide/QtUiTools/typesystem_uitools.xml
+++ b/PySide/QtUiTools/typesystem_uitools.xml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
This file is part of PySide project.
- Copyright (C) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
+ Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies).
Contact: PySide team <contact@pyside.org>
This library is free software; you can redistribute it and/or
@@ -107,7 +107,7 @@
</modify-argument>
<inject-code>
// Avoid calling the original function: %CPPSELF.%FUNCTION_NAME()
- %PYARG_0 = quiloader_load_ui_from_device(%CPPSELF, %1, %2);
+ %PYARG_0 = QUiLoadedLoadUiFromDevice(%CPPSELF, %1, %2);
</inject-code>
</modify-function>
@@ -126,7 +126,7 @@
</modify-argument>
<inject-code>
// Avoid calling the original function: %CPPSELF.%FUNCTION_NAME()
- %PYARG_0 = quiloader_load_ui(%CPPSELF, %1, %2);
+ %PYARG_0 = QUiLoaderLoadUiFromFileName(%CPPSELF, %1, %2);
</inject-code>
</add-function>
</object-type>
diff --git a/tests/QtUiTools/CMakeLists.txt b/tests/QtUiTools/CMakeLists.txt
index 02fb89d..9acc9f3 100644
--- a/tests/QtUiTools/CMakeLists.txt
+++ b/tests/QtUiTools/CMakeLists.txt
@@ -5,5 +5,6 @@ PYSIDE_TEST(bug_426.py)
PYSIDE_TEST(bug_552.py)
PYSIDE_TEST(bug_797.py)
PYSIDE_TEST(bug_909.py)
+PYSIDE_TEST(bug_913.py)
PYSIDE_TEST(uiloader_test.py)
PYSIDE_TEST(ui_test.py)
diff --git a/tests/QtUiTools/bug_392.py b/tests/QtUiTools/bug_392.py
index 69817ff..c6e751f 100644
--- a/tests/QtUiTools/bug_392.py
+++ b/tests/QtUiTools/bug_392.py
@@ -19,7 +19,7 @@ class BugTest(UsesQApplication):
filePath = os.path.join(os.path.dirname(__file__), 'action.ui')
result = loader.load(filePath, w)
- self.assert_(isinstance(result.statusbar.actionFoo, QtGui.QAction))
+ self.assert_(isinstance(result.actionFoo, QtGui.QAction))
def testPythonCustomWidgets(self):
w = QtGui.QWidget()
diff --git a/tests/QtUiTools/bug_913.py b/tests/QtUiTools/bug_913.py
new file mode 100644
index 0000000..f42ce4a
--- /dev/null
+++ b/tests/QtUiTools/bug_913.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sys
+import unittest
+from helper import adjust_filename
+
+from PySide.QtCore import *
+from PySide.QtGui import *
+from PySide.QtUiTools import *
+
+class TestBug913 (unittest.TestCase):
+
+ def testIt(self):
+ app = QApplication([])
+
+ loader = QUiLoader()
+ widget = loader.load(adjust_filename('bug_913.ui', __file__))
+ widget.tabWidget.currentIndex() # direct child is available as member
+ widget.le_first.setText('foo') # child of QTabWidget must also be available!
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/QtUiTools/bug_913.ui b/tests/QtUiTools/bug_913.ui
new file mode 100644
index 0000000..0fc95fd
--- /dev/null
+++ b/tests/QtUiTools/bug_913.ui
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Form</class>
+ <widget class="QWidget" name="Form">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QTabWidget" name="tabWidget">
+ <widget class="QWidget" name="tab">
+ <attribute name="title">
+ <string>Tab 1</string>
+ </attribute>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>First name:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="le_first"/>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Last name:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="le_last"/>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tab_2">
+ <attribute name="title">
+ <string>Tab 2</string>
+ </attribute>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>