History

fix interactive window crash

dante ruiz committed 7 years ago

Commit 7c024b41 parent 57c820f3 files · +45 −90Browse files

Showing the changes to interface/src/ui/InteractiveWindow.cpp (1 of 3 files). Show all

Unified · Split

interface/src/ui/InteractiveWindow.cpp+26−88
@@ -85,13 +85,13 @@ void InteractiveWindow::forwardKeyReleaseEvent(int key, int modifiers) { · 84 unmodified lines
8585 * @property {string} [title="InteractiveWindow] - The title of the window.
8686 * @property {Vec2} [position] - The initial position of the window, in pixels.
8787 * @property {Vec2} [size] - The initial size of the window, in pixels
88− * @property {boolean} [visible=true] - <code>true</code> to make the window visible when created, <code>false</code> to make
88+ * @property {boolean} [visible=true] - <code>true</code> to make the window visible when created, <code>false</code> to make
8989 * it invisible.
90− * @property {InteractiveWindow.PresentationMode} [presentationMode=Desktop.PresentationMode.VIRTUAL] -
91− * <code>Desktop.PresentationMode.VIRTUAL</code> to display the window inside Interface, <code>.NATIVE</code> to display it
90+ * @property {InteractiveWindow.PresentationMode} [presentationMode=Desktop.PresentationMode.VIRTUAL] -
91+ * <code>Desktop.PresentationMode.VIRTUAL</code> to display the window inside Interface, <code>.NATIVE</code> to display it
9292 * as its own separate window.
93− * @property {InteractiveWindow.PresentationWindowInfo} [presentationWindowInfo] - Controls how a <code>NATIVE</code> window is
94− * displayed. If used, the window is docked to the specified edge of the Interface window, otherwise the window is
93+ * @property {InteractiveWindow.PresentationWindowInfo} [presentationWindowInfo] - Controls how a <code>NATIVE</code> window is
94+ * displayed. If used, the window is docked to the specified edge of the Interface window, otherwise the window is
9595 * displayed as its own separate window.
9696 * @property {InteractiveWindow.AdditionalFlags} [additionalFlags=0] - Window behavior flags in addition to "native window flags" (minimize/maximize/close),
9797 * set at window creation. Possible flag values are provided as {@link Desktop|Desktop.ALWAYS_ON_TOP} and {@link Desktop|Desktop.CLOSE_BUTTON_HIDES}.
@@ -124,7 +124,7 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap · 26 unmodified lines
124124 auto mainWindow = qApp->getWindow();
125125 _dockWidget = std::shared_ptr<DockWidget>(new DockWidget(title, mainWindow), dockWidgetDeleter);
126126 auto quickView = _dockWidget->getQuickView();
127−
127+
128128 Application::setupQmlSurface(quickView->rootContext() , true);
129129
130130 //add any whitelisted callbacks
@@ -176,7 +176,6 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap · 45 unmodified lines
176176 });
177177
178178 _dockWidget->setSource(QUrl(sourceUrl));
179−
180179 mainWindow->addDockWidget(dockArea, _dockWidget.get());
181180 } else {
182181 auto offscreenUi = DependencyManager::get<OffscreenUi>();
@@ -254,55 +253,35 @@ void InteractiveWindow::sendToQml(const QVariant& message) { · 71 unmodified lines
254253 }
255254
256255 void InteractiveWindow::emitScriptEvent(const QVariant& scriptMessage) {
257− if (QThread::currentThread() != thread()) {
258− QMetaObject::invokeMethod(this, "emitScriptEvent", Qt::QueuedConnection, Q_ARG(QVariant, scriptMessage));
259− } else {
260− emit scriptEventReceived(scriptMessage);
261− }
256+ emit scriptEventReceived(scriptMessage);
262257 }
263258
264259 void InteractiveWindow::emitWebEvent(const QVariant& webMessage) {
265− if (QThread::currentThread() != thread()) {
266− QMetaObject::invokeMethod(this, "emitWebEvent", Qt::QueuedConnection, Q_ARG(QVariant, webMessage));
267− } else {
268− emit webEventReceived(webMessage);
269− }
260+ emit webEventReceived(webMessage);
270261 }
271262
272263 void InteractiveWindow::close() {
273− if (QThread::currentThread() != thread()) {
274− QMetaObject::invokeMethod(this, "close");
275− return;
276− }
277−
278264 if (_qmlWindow) {
279265 _qmlWindow->deleteLater();
280266 }
281267
282− qApp->getWindow()->removeDockWidget(_dockWidget.get());
268+ if (_dockWidget) {
269+ auto window = qApp->getWindow();
270+ BLOCKING_INVOKE_METHOD(window, "removeDockWidget", Q_ARG(QDockWidget*, _dockWidget.get()));
271+ }
283272 _dockWidget = nullptr;
284273 _qmlWindow = nullptr;
285274 }
286275
287276 void InteractiveWindow::show() {
288− if (QThread::currentThread() != thread()) {
289− QMetaObject::invokeMethod(this, "show");
290− return;
291− }
292−
293277 if (_qmlWindow) {
294− QMetaObject::invokeMethod(_qmlWindow, "show", Qt::DirectConnection);
278+ QMetaObject::invokeMethod(_qmlWindow, "show");
295279 }
296280 }
297281
298282 void InteractiveWindow::raise() {
299− if (QThread::currentThread() != thread()) {
300− QMetaObject::invokeMethod(this, "raise");
301− return;
302− }
303−
304283 if (_qmlWindow) {
305− QMetaObject::invokeMethod(_qmlWindow, "raiseWindow", Qt::DirectConnection);
284+ QMetaObject::invokeMethod(_qmlWindow, "raiseWindow");
306285 }
307286 }
308287
@@ -323,17 +302,12 @@ void InteractiveWindow::setVisible(bool visible) { · 14 unmodified lines
323302 }
324303
325304 if (!_qmlWindow.isNull()) {
326− _qmlWindow->setProperty(INTERACTIVE_WINDOW_VISIBLE_PROPERTY, visible);
305+ QMetaObject::invokeMethod(_qmlWindow, "setProperty", Q_ARG(const char*, INTERACTIVE_WINDOW_VISIBLE_PROPERTY),
306+ Q_ARG(bool, visible));
327307 }
328308 }
329309
330310 bool InteractiveWindow::isVisible() const {
331− if (QThread::currentThread() != thread()) {
332− bool result = false;
333− BLOCKING_INVOKE_METHOD(const_cast<InteractiveWindow*>(this), "isVisible", Q_RETURN_ARG(bool, result));
334− return result;
335− }
336−
337311 if (_qmlWindow.isNull()) {
338312 return false;
339313 }
@@ -342,12 +316,6 @@ bool InteractiveWindow::isVisible() const { · 2 unmodified lines
342316 }
343317
344318 glm::vec2 InteractiveWindow::getPosition() const {
345− if (QThread::currentThread() != thread()) {
346− glm::vec2 result;
347− BLOCKING_INVOKE_METHOD(const_cast<InteractiveWindow*>(this), "getPosition", Q_RETURN_ARG(glm::vec2, result));
348− return result;
349− }
350−
351319 if (_qmlWindow.isNull()) {
352320 return {};
353321 }
@@ -362,18 +330,13 @@ void InteractiveWindow::setPosition(const glm::vec2& position) { · 8 unmodified lines
362330 }
363331
364332 if (!_qmlWindow.isNull()) {
365− _qmlWindow->setProperty(INTERACTIVE_WINDOW_POSITION_PROPERTY, QPointF(position.x, position.y));
366− QMetaObject::invokeMethod(_qmlWindow, "updateInteractiveWindowPositionForMode", Qt::DirectConnection);
333+ QMetaObject::invokeMethod(_qmlWindow, "setProperty", Q_ARG(const char*, INTERACTIVE_WINDOW_POSITION_PROPERTY),
334+ Q_ARG(QPointF, QPointF(position.x, position.y)));
335+ QMetaObject::invokeMethod(_qmlWindow, "updateInteractiveWindowPositionForMode");
367336 }
368337 }
369338
370339 glm::vec2 InteractiveWindow::getSize() const {
371− if (QThread::currentThread() != thread()) {
372− glm::vec2 result;
373− BLOCKING_INVOKE_METHOD(const_cast<InteractiveWindow*>(this), "getSize", Q_RETURN_ARG(glm::vec2, result));
374− return result;
375− }
376−
377340 if (_qmlWindow.isNull()) {
378341 return {};
379342 }
@@ -381,24 +344,14 @@ glm::vec2 InteractiveWindow::getSize() const { · 1 unmodified line
381344 }
382345
383346 void InteractiveWindow::setSize(const glm::vec2& size) {
384− if (QThread::currentThread() != thread()) {
385− QMetaObject::invokeMethod(this, "setSize", Q_ARG(const glm::vec2&, size));
386− return;
387− }
388−
389347 if (!_qmlWindow.isNull()) {
390− _qmlWindow->setProperty(INTERACTIVE_WINDOW_SIZE_PROPERTY, QSize(size.x, size.y));
391− QMetaObject::invokeMethod(_qmlWindow, "updateInteractiveWindowSizeForMode", Qt::DirectConnection);
348+ QMetaObject::invokeMethod(_qmlWindow, "setProperty", Q_ARG(const char*, INTERACTIVE_WINDOW_SIZE_PROPERTY),
349+ Q_ARG(QSize, QSize(size.x, size.y)));
350+ QMetaObject::invokeMethod(_qmlWindow, "updateInteractiveWindowSizeForMode");
392351 }
393352 }
394353
395354 QString InteractiveWindow::getTitle() const {
396− if (QThread::currentThread() != thread()) {
397− QString result;
398− BLOCKING_INVOKE_METHOD(const_cast<InteractiveWindow*>(this), "getTitle", Q_RETURN_ARG(QString, result));
399− return result;
400− }
401−
402355 if (_qmlWindow.isNull()) {
403356 return QString();
404357 }
@@ -406,24 +359,13 @@ QString InteractiveWindow::getTitle() const { · 1 unmodified line
406359 }
407360
408361 void InteractiveWindow::setTitle(const QString& title) {
409− if (QThread::currentThread() != thread()) {
410− QMetaObject::invokeMethod(this, "setTitle", Q_ARG(const QString&, title));
411− return;
412− }
413−
414362 if (!_qmlWindow.isNull()) {
415− _qmlWindow->setProperty(TITLE_PROPERTY, title);
363+ QMetaObject::invokeMethod(_qmlWindow, "setProperty", Q_ARG(const char*, TITLE_PROPERTY),
364+ Q_ARG(QString, title));
416365 }
417366 }
418367
419368 int InteractiveWindow::getPresentationMode() const {
420− if (QThread::currentThread() != thread()) {
421− int result;
422− BLOCKING_INVOKE_METHOD(const_cast<InteractiveWindow*>(this), "getPresentationMode",
423− Q_RETURN_ARG(int, result));
424− return result;
425− }
426−
427369 if (_qmlWindow.isNull()) {
428370 return Virtual;
429371 }
@@ -449,12 +391,8 @@ void InteractiveWindow::parentNativeWindowToMainWindow() { · 19 unmodified lines
449391 }
450392
451393 void InteractiveWindow::setPresentationMode(int presentationMode) {
452− if (QThread::currentThread() != thread()) {
453− QMetaObject::invokeMethod(this, "setPresentationMode", Q_ARG(int, presentationMode));
454− return;
455− }
456−
457394 if (!_qmlWindow.isNull()) {
458− _qmlWindow->setProperty(PRESENTATION_MODE_PROPERTY, presentationMode);
395+ QMetaObject::invokeMethod(_qmlWindow, "setProperty", Q_ARG(const char*, PRESENTATION_MODE_PROPERTY),
396+ Q_ARG(int, presentationMode));
459397 }
460398 }