diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 158e4faad97..e218f3e770b 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -179,6 +179,7 @@ ENDIF(WITH_QSCIAPI) SET(PY_FILES __init__.py utils.py + customwidgets.py ) ADD_CUSTOM_TARGET(pyutils ALL) diff --git a/python/__init__.py b/python/__init__.py index 31207a67ec3..37e0b29064a 100755 --- a/python/__init__.py +++ b/python/__init__.py @@ -24,6 +24,8 @@ __copyright__ = '(C) 2007, Martin Dobias' __revision__ = '$Format:%H$' import sip +from customwidgets import referenceCustomWidgets + try: apis = ["QDate", "QDateTime", "QString", "QTextStream", "QTime", "QUrl", "QVariant"] for api in apis: @@ -34,6 +36,8 @@ except ValueError: from qgis.core import QgsFeature, QgsGeometry +referenceCustomWidgets() + try: # Add a __nonzero__ method onto QPyNullVariant so we can check for null values easier. # >>> value = QPyNullVariant("int") diff --git a/python/customwidgets.py b/python/customwidgets.py new file mode 100644 index 00000000000..45836d91b1e --- /dev/null +++ b/python/customwidgets.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + customwidgets.py + --------------------- + Date : May 2014 + Copyright : (C) 2014 by Denis Rouzaud + Email : denis.rouzaud@gmail.com +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +import sys +import qgis +from qgis import gui + +""" + This allow to redirect the custom widget include header file to qgis.gui +""" + +def referenceCustomWidgets(): + sys.modules["qgscollapsiblegroupboxplugin"] = qgis.gui + sys.modules["qgsfieldcomboboxplugin"] = qgis.gui + sys.modules["qgsfieldexpressionwidgetplugin"] = qgis.gui + sys.modules["qgsmaplayercomboboxplugin"] = qgis.gui + sys.modules["qgsscalevisibilitywidgetplugin"] = qgis.gui diff --git a/src/customwidgets/qgiscustomwidgets.cpp b/src/customwidgets/qgiscustomwidgets.cpp index 69bfdeaeaec..26f17153f01 100644 --- a/src/customwidgets/qgiscustomwidgets.cpp +++ b/src/customwidgets/qgiscustomwidgets.cpp @@ -27,6 +27,12 @@ QgisCustomWidgets::QgisCustomWidgets( QObject *parent ) : QObject( parent ) { + + // !!!!!!!!!!!!!!!!!!!!! + // do not forget to add the corresponding line in python/customwidgets.py + // to make the custom widget available from python + // !!!!!!!!!!!!!!!!!!!!! + mWidgets.append( new QgsCollapsibleGroupBoxPlugin ); mWidgets.append( new QgsFieldComboBoxPlugin ); mWidgets.append( new QgsFieldExpressionWidgetPlugin );