contains(QT_CONFIG, accessibility) {
SUBDIRS += accessible
}
+!contains(QT_CONFIG, no-widgets) {
+ SUBDIRS += widgets
+}
--- /dev/null
+TARGET = qmlwidgethandler
+QT = qml-private core-private v8-private widgets
+
+PLUGIN_TYPE = qmlwidgets
+PLUGIN_CLASS_NAME = QQmlWidgetHandler
+load(qt_plugin)
+
+SOURCES += \
+ qqmlwidgethandler.cpp
+
+HEADERS += \
+ qqmlwidgethandler.h
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2013 Konrad Rosenbaum <konrad@silmor.de>.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qqmlwidgethandler.h"
+
+#include <QtCore/qplugin.h>
+#include <QtWidgets/qwidget.h>
+
+QT_BEGIN_NAMESPACE
+
+QQmlWidgetHandler::QQmlWidgetHandler()
+{
+}
+
+QQmlWidgetHandler::~QQmlWidgetHandler()
+{
+}
+
+bool QQmlWidgetHandler::setWidgetParent(QObject*widget, QObject*parent)
+{
+ //see if both objects are widgets, if so: reparent and return success
+ if (widget->isWidgetType() && parent->isWidgetType()) {
+ static_cast<QWidget*>(widget)->setParent(static_cast<QWidget*>(parent));
+ return true;
+ }
+ return false;
+}
+
+QT_END_NAMESPACE
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2013 Konrad Rosenbaum <konrad@silmor.de>.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQMLWIDGETHANDLER_H
+#define QQMLWIDGETHANDLER_H
+
+#include <QtQml/private/qqmlwidgethandlerplugin_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQmlWidgetHandler : public QObject, public QQmlWidgetHandlerPlugin
+{
+ Q_OBJECT
+ Q_DISABLE_COPY(QQmlWidgetHandler)
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlWidgetHandlerPlugin")
+ Q_INTERFACES(QQmlWidgetHandlerPlugin)
+
+public:
+ QQmlWidgetHandler();
+ ~QQmlWidgetHandler();
+
+ virtual bool setWidgetParent(QObject*widget, QObject*parent);
+};
+
+QT_END_NAMESPACE
+
+#endif // QQMLWIDGETHANDLER_H
--- /dev/null
+TEMPLATE = subdirs
+
+SUBDIRS += qmlwidgethandler
\ No newline at end of file
****************************************************************************/
#include <private/qqmlglobal_p.h>
+#include <private/qqmlwidgethandlerplugin_p.h>
#include <QtCore/qvariant.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qdebug.h>
#include <QtCore/QCoreApplication>
+#include <QtCore/qpluginloader.h>
+#include <QtCore/qfileinfo.h>
+#include <QtCore/qdir.h>
QT_BEGIN_NAMESPACE
emit versionChanged(); //Note that we don't get notified if it's changed from C++
}
+DEFINE_BOOL_CONFIG_OPTION(qmlWidgetHandlerVerbose, QML_WIDGETHANDLER_VERBOSE)
+
+void QQml_setParent_widget(QObject *object, QObject *parent)
+{
+ Q_ASSERT(object);
+ Q_ASSERT(parent);
+ static QQmlWidgetHandlerPlugin*plugin=0;
+#ifndef QT_NO_LIBRARY
+ if(plugin==0) {
+ QStringList pluginCandidates;
+ static const QString pluginName="qmlwidgethandler";
+
+ const QStringList paths = QCoreApplication::libraryPaths();
+ foreach (const QString &libPath, paths) {
+ const QDir dir(libPath + QLatin1String("/qmlwidgets"));
+ if (dir.exists()) {
+ QStringList plugins(dir.entryList(QDir::Files));
+ foreach (const QString &pluginPath, plugins) {
+ if (QFileInfo(pluginPath).fileName().contains(pluginName))
+ pluginCandidates << dir.absoluteFilePath(pluginPath);
+ }
+ }
+ }
+
+ foreach (const QString &pluginPath, pluginCandidates) {
+ QPluginLoader loader(pluginPath);
+ if (!loader.load()) {
+ if (qmlWidgetHandlerVerbose())
+ qDebug() << "QML: Error while loading: " << loader.errorString();
+ continue;
+ }
+ if (QObject *instance = loader.instance())
+ plugin = qobject_cast<QQmlWidgetHandlerPlugin*>(instance);
+
+ if (plugin) {
+ if (qmlWidgetHandlerVerbose())
+ qDebug() << "QML: WidgetHandlerPlugin successfully loaded.";
+ break;
+ } else {
+ loader.unload();
+ }
+ }
+
+ if (!plugin && qmlWidgetHandlerVerbose())
+ qWarning("QML: unable to load the widget handler while trying to reparent a QML controlled widget!");
+ }
+#endif
+ Q_ASSERT_X(plugin, "QQml_setParent_widget", "Cannot reparent QML owned widgets without qmlwidgethandler plugin.");
+ if (!plugin->setWidgetParent(object, parent))
+ qWarning("QML: failed to reparent widget");
+}
+
QT_END_NAMESPACE
static_cast<QQmlGraphics_DerivedObject *>(object)->setParent_noEvent(parent);
}
+/*!
+ Assuming the \a object and \a parent are widgets, this calls the QWidget::setParent
+ method. If necessary first loading the plugin that handles this case.
+*/
+void QQml_setParent_widget(QObject *object, QObject *parent);
class QQmlValueType;
class QV8Engine;
}
if (!objects.isEmpty()) {
QObject *parent = objects.at(objects.count() - 1 - (instr.parentToSuper?1:0));
-#if 0 // ### refactor
- if (o->isWidgetType() && parent->isWidgetType())
- static_cast<QWidget*>(o)->setParent(static_cast<QWidget*>(parent));
- else
-#endif
+ if (o->isWidgetType()) {
+ if (parent->isWidgetType())
+ QQml_setParent_widget(o, parent);
+ //else: parent is probably a layout
+ } else {
QQml_setParent_noEvent(o, parent);
+ }
ddata->parentFrozen = true;
}
objects.push(o);
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2013 Konrad Rosenbaum <konrad@silmor.de>.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQMLWIDGETHANDLERPLUGIN_H
+#define QQMLWIDGETHANDLERPLUGIN_H
+
+#include <QtQml/qtqmlglobal.h>
+#include <private/qqmlglobal_p.h>
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+
+class Q_QML_PRIVATE_EXPORT QQmlWidgetHandlerPlugin
+{
+public:
+ QQmlWidgetHandlerPlugin() {}
+ virtual ~QQmlWidgetHandlerPlugin() {}
+
+ virtual bool setWidgetParent(QObject*widget, QObject*parent)=0;
+};
+
+#define QQmlWidgetHandlerPlugin_iid "org.qt-project.Qt.QQmlWidgetHandlerPlugin"
+
+Q_DECLARE_INTERFACE(QQmlWidgetHandlerPlugin, QQmlWidgetHandlerPlugin_iid)
+
+QT_END_NAMESPACE
+
+#endif // QQMLWIDGETHANDLERPLUGIN_H