From 24cbdd8dfa3cd01184d0dae297c15547d4962293 Mon Sep 17 00:00:00 2001 From: renatofilho Date: Wed, 6 Oct 2010 18:55:42 -0300 Subject: Created uiloader plugin used to register new types before QUiLoader. This is used to register a new python type which can be used in ui description files. Reviewer: Hugo Parente Lima Luciano Wolf --- PySide/QtUiTools/CMakeLists.txt | 5 ++++ PySide/QtUiTools/glue/plugins.h | 47 +++++++++++++++++++++++++++++++++ PySide/QtUiTools/typesystem_uitools.xml | 12 +++++++++ 3 files changed, 64 insertions(+) create mode 100644 PySide/QtUiTools/glue/plugins.h (limited to 'PySide/QtUiTools') diff --git a/PySide/QtUiTools/CMakeLists.txt b/PySide/QtUiTools/CMakeLists.txt index 9922e9d10..4054ffc9b 100644 --- a/PySide/QtUiTools/CMakeLists.txt +++ b/PySide/QtUiTools/CMakeLists.txt @@ -10,18 +10,22 @@ set(QtUiTools_include_dirs ${CMAKE_CURRENT_SOURCE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} ${QT_QTXML_INCLUDE_DIR} + ${QT_QTDESIGNER_INCLUDE_DIR} ${QT_QTUITOOLS_INCLUDE_DIR} ${PYTHON_INCLUDE_PATH} ${SHIBOKEN_INCLUDE_DIR} ${libpyside_SOURCE_DIR} + ${plugins_SOURCE_DIR} ${QtCore_BINARY_DIR}/PySide/QtCore/ ${QtXml_BINARY_DIR}/PySide/QtXml/ ${QtGui_BINARY_DIR}/PySide/QtGui/ ${CMAKE_CURRENT_BINARY_DIR}/PySide/QtUiTools) set(QtUiTools_libraries pyside + uiplugin ${PYSIDE_PYTHON_LIBRARIES} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} + ${QT_QTDESIGNER_LIBRARY} ${QT_QTUITOOLS_LIBRARY}) set(QtUiTools_deps QtGui QtXml) create_pyside_module(QtUiTools @@ -31,3 +35,4 @@ create_pyside_module(QtUiTools QtUiTools_typesystem_path QtUiTools_SRC "") + diff --git a/PySide/QtUiTools/glue/plugins.h b/PySide/QtUiTools/glue/plugins.h new file mode 100644 index 000000000..09070bf19 --- /dev/null +++ b/PySide/QtUiTools/glue/plugins.h @@ -0,0 +1,47 @@ +/* + * This file is part of the PySide project. + * + * Copyright (C) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: PySide team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _PLUGIN_H_ +#define _PLUGIN_H_ + +#include +#include "customwidgets.h" + +inline void registerCustomWidget(PyObject* obj) +{ + static PyCustomWidgets* plugin = 0; + + if (plugin == 0) { + foreach(QObject* o, QPluginLoader::staticInstances()) { + plugin = qobject_cast(o); + if (o) + break; + } + } + + if (!plugin) + qDebug() << "Fail to load uiloader plugin"; + else + plugin->registerWidgetType(obj); +} + +#endif diff --git a/PySide/QtUiTools/typesystem_uitools.xml b/PySide/QtUiTools/typesystem_uitools.xml index a188aa34b..0abc6957c 100644 --- a/PySide/QtUiTools/typesystem_uitools.xml +++ b/PySide/QtUiTools/typesystem_uitools.xml @@ -23,6 +23,18 @@ + + + + + Q_IMPORT_PLUGIN(uiplugin); + + + + registerCustomWidget(%PYARG_1); + %CPPSELF.addPluginPath(""); // force reload widgets + + -- cgit v1.2.3