aboutsummaryrefslogtreecommitdiffstats
path: root/PySide/QtUiTools/glue
diff options
context:
space:
mode:
authorrenatofilho <renato.filho@openbossa.org>2010-09-22 16:59:46 -0300
committerrenatofilho <renato.filho@openbossa.org>2010-09-22 17:21:18 -0300
commitbf4b2c7660adc99b6a8b83748787f0ea078ad13b (patch)
tree1c8e9cbe4548620ad8a8eb00808b004401aa740f /PySide/QtUiTools/glue
parent3525b77d69937938aa285f84b995a3a2d8685cce (diff)
Port old boost code used in QtUiTools.
fixes bug #376. Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Marcelo Lira <marcelo.lira@openbossa.org>
Diffstat (limited to 'PySide/QtUiTools/glue')
-rw-r--r--PySide/QtUiTools/glue/uitools_loadui.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/PySide/QtUiTools/glue/uitools_loadui.h b/PySide/QtUiTools/glue/uitools_loadui.h
new file mode 100644
index 000000000..da851c14c
--- /dev/null
+++ b/PySide/QtUiTools/glue/uitools_loadui.h
@@ -0,0 +1,68 @@
+/*
+ * Based on code provided by:
+ * Antonio Valentino <antonio.valentino at tiscali.it>
+ * Frédéric <frederic.mantegazza at gbiloba.org>
+ */
+
+#include <shiboken.h>
+
+static void
+_populate_parent(PyObject* pyParent, QWidget *parent)
+{
+ if (parent->children().isEmpty())
+ return;
+
+ 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::setParent(pyParent, pyChild);
+ _populate_parent(pyChild, qobject_cast<QWidget*>(child));
+ }
+ }
+}
+
+static PyObject*
+quiloader_load_ui_from_device(QUiLoader* self, QIODevice* dev, QWidget *parent)
+{
+ QWidget *w = self->load(dev, parent);
+ if (w) {
+ if (parent && parent->layout())
+ parent->layout()->deleteLater();
+
+ PyObject* pyParent = Shiboken::Converter<QWidget*>::toPython(w);
+ _populate_parent(pyParent, w);
+
+ return pyParent;
+ }
+
+ PyErr_SetString(PyExc_RuntimeError, "Unable to open ui file");
+ return 0;
+}
+
+static PyObject*
+quiloader_load_ui(QUiLoader* self, const QString &ui_file, 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) {
+ PyObject* pyParent = Shiboken::Converter<QWidget*>::toPython(w);
+
+ if (parent && parent->layout())
+ parent->layout()->deleteLater();
+
+ _populate_parent(pyParent, w);
+
+ return pyParent;
+ }
+ }
+ PyErr_SetString(PyExc_RuntimeError, "Unable to open ui file");
+ return 0;
+}