Merge pull request from zfox23/dockedWindowEventBridge

Fix JS to QML event bridge messages with Docked Windows
This commit is contained in:
Zach Fox 2019-05-15 16:28:43 -07:00 committed by GitHub
commit ee9d3d3ae1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 5 deletions

View file

@ -86,7 +86,6 @@ void interactiveWindowPointerFromScriptValue(const QScriptValue& object, Interac
* provided as {@link Desktop|Desktop.ALWAYS_ON_TOP} and {@link Desktop|Desktop.CLOSE_BUTTON_HIDES}.
*/
InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap& properties) {
bool docked = false;
InteractiveWindowPresentationMode presentationMode = InteractiveWindowPresentationMode::Native;
if (properties.contains(PRESENTATION_MODE_PROPERTY)) {
@ -146,12 +145,12 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap
QObject::connect(quickView.get(), &QQuickView::statusChanged, [&, this] (QQuickView::Status status) {
if (status == QQuickView::Ready) {
QQuickItem* rootItem = _dockWidget->getRootItem();
_dockWidget->getQuickView()->rootContext()->setContextProperty(EVENT_BRIDGE_PROPERTY, this);
QObject::connect(rootItem, SIGNAL(sendToScript(QVariant)), this, SLOT(qmlToScript(const QVariant&)), Qt::QueuedConnection);
}
});
_dockWidget->setSource(QUrl(sourceUrl));
mainWindow->addDockWidget(dockArea, _dockWidget.get());
_dockedWindow = docked;
} else {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
// Build the event bridge and wrapper on the main thread
@ -210,10 +209,10 @@ InteractiveWindow::~InteractiveWindow() {
void InteractiveWindow::sendToQml(const QVariant& message) {
// Forward messages received from the script on to QML
if (_dockedWindow) {
if (_dockWidget) {
QQuickItem* rootItem = _dockWidget->getRootItem();
if (rootItem) {
QMetaObject::invokeMethod(_qmlWindow, "fromScript", Qt::QueuedConnection, Q_ARG(QVariant, message));
QMetaObject::invokeMethod(rootItem, "fromScript", Qt::QueuedConnection, Q_ARG(QVariant, message));
}
} else {
QMetaObject::invokeMethod(_qmlWindow, "fromScript", Qt::QueuedConnection, Q_ARG(QVariant, message));

View file

@ -288,7 +288,6 @@ protected slots:
void qmlToScript(const QVariant& message);
private:
bool _dockedWindow { false };
QPointer<QObject> _qmlWindow;
std::shared_ptr<DockWidget> _dockWidget { nullptr };
};