aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Kampas <martin.kampas@jolla.com>2016-11-16 16:24:44 +0100
committerJuergen Bocklage-Ryannel <juergen.bocklage-ryannel@pelagicore.com>2016-11-23 07:17:44 +0000
commit50c7a98eb0e4126e7d05af74134b50cd583f3301 (patch)
treeea47e47cd4c3afb17472229ebef261936332d03a
parenta5851207bb3c606ec46e3683da1d0c6befbe7138 (diff)
Allow to take over a document preloaded beyond LiveNodeEngine's control
Change-Id: I1f17c811818a843d3d58961520e2b8b40400e10f Reviewed-by: Juergen Bocklage-Ryannel <juergen.bocklage-ryannel@pelagicore.com>
-rw-r--r--src/bench/mainwindow.cpp2
-rw-r--r--src/livenodeengine.cpp96
-rw-r--r--src/livenodeengine.h6
-rw-r--r--src/remotereceiver.cpp8
4 files changed, 98 insertions, 14 deletions
diff --git a/src/bench/mainwindow.cpp b/src/bench/mainwindow.cpp
index 44b0436..62a29e5 100644
--- a/src/bench/mainwindow.cpp
+++ b/src/bench/mainwindow.cpp
@@ -80,7 +80,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(m_workspace, SIGNAL(pathActivated(LiveDocument)), m_hub, SLOT(setActivePath(LiveDocument)));
connect(m_workspace, SIGNAL(pathActivated(LiveDocument)), m_hostManager, SLOT(followTreeSelection(LiveDocument)));
connect(m_hub, SIGNAL(activateDocument(LiveDocument)), this, SLOT(updateWindowTitle()));
- connect(m_hub, SIGNAL(activateDocument(LiveDocument)), m_node, SLOT(setActiveDocument(LiveDocument)));
+ connect(m_hub, SIGNAL(activateDocument(LiveDocument)), m_node, SLOT(loadDocument(LiveDocument)));
connect(m_node, SIGNAL(activeWindowChanged(QQuickWindow*)), this, SLOT(onActiveWindowChanged(QQuickWindow*)));
connect(m_node->qmlEngine(), SIGNAL(quit()), this, SLOT(logQuitEvent()));
connect(m_allHosts, SIGNAL(publishAll()), m_hostManager, SLOT(publishAll()));
diff --git a/src/livenodeengine.cpp b/src/livenodeengine.cpp
index b72917b..8bc26ff 100644
--- a/src/livenodeengine.cpp
+++ b/src/livenodeengine.cpp
@@ -285,13 +285,92 @@ int LiveNodeEngine::rotation() const
}
/*!
- * Loads the given \a document onto the QML view. Clears any caches.
+ * Allows to initialize active document with an instance preloaded beyond
+ * LiveNodeEngine's control.
+ *
+ * This can be called at most once and only before a document has been loaded
+ * with loadDocument().
+ *
+ * \a document is the source of the component that was used to instantiate the
+ * \a object. \a window should be either the \a object itself or the
+ * fallbackView(). \a errors (if any) will be added to log.
+ *
+ * Note that \a window will be destroyed on next loadDocument() call unless it
+ * is the fallbackView(). \a object will be destroyed unconditionally.
+ */
+void LiveNodeEngine::usePreloadedDocument(const LiveDocument &document, QObject *object,
+ QQuickWindow *window, const QList<QQmlError> &errors)
+{
+ LIVE_ASSERT(m_activeFile.isNull(), return);
+ LIVE_ASSERT(!document.isNull(), return);
+
+ m_activeFile = document;
+
+ if (!m_activeFile.existsIn(m_workspace)) {
+ QQmlError error;
+ error.setUrl(QUrl::fromLocalFile(m_activeFile.absoluteFilePathIn(m_workspace)));
+ error.setDescription(tr("File not found"));
+ emit logErrors(QList<QQmlError>() << error);
+ }
+
+ m_object = object;
+ m_activeWindow = window;
+
+ if (m_activeWindow) {
+ m_activeWindowConnections << connect(m_activeWindow.data(), &QWindow::widthChanged,
+ this, &LiveNodeEngine::onSizeChanged);
+ m_activeWindowConnections << connect(m_activeWindow.data(), &QWindow::heightChanged,
+ this, &LiveNodeEngine::onSizeChanged);
+ onSizeChanged();
+ }
+
+ emit activeDocumentChanged(m_activeFile);
+ emit documentLoaded();
+ emit activeWindowChanged(m_activeWindow);
+ emit logErrors(errors);
+}
+
+/*!
+ * This is an overloaded function provided for convenience. It is suitable for
+ * use with QQmlApplicationEngine.
+ *
+ * Tries to resolve \a document against current workspace(). \a window is the
+ * root object. \a errors (if any) will be added to log.
+ */
+void LiveNodeEngine::usePreloadedDocument(const QString &document, QQuickWindow *window,
+ const QList<QQmlError> &errors)
+{
+ LIVE_ASSERT(m_activeFile.isNull(), return);
+
+ LiveDocument resolved = LiveDocument::resolve(workspace(), document);
+ if (resolved.isNull()) {
+ qWarning() << "Failed to resolve preloaded document path:" << document
+ << "Workspace: " << workspace();
+ return;
+ }
+
+ usePreloadedDocument(resolved, window, window, errors);
+}
+
+/*!
+ * Loads or reloads the given \a document onto the QML view. Clears any caches.
+ *
+ * The activeDocumentChanged() signal is emitted when this results in change of
+ * the activeDocument().
+ *
+ * \sa documentLoaded()
*/
void LiveNodeEngine::loadDocument(const LiveDocument& document)
{
DEBUG << "LiveNodeEngine::loadDocument: " << document;
+
+ LiveDocument oldActiveFile = m_activeFile;
+
m_activeFile = document;
+ if (m_activeFile != oldActiveFile)
+ emit activeDocumentChanged(m_activeFile);
+
if (!m_activeFile.isNull())
reloadDocument();
}
@@ -495,15 +574,6 @@ QUrl LiveNodeEngine::queryDocumentViewer(const QUrl& url)
}
/*!
- * Sets the document \a document to be shown
- */
-void LiveNodeEngine::setActiveDocument(const LiveDocument &document)
-{
- loadDocument(document);
- emit activeDocumentChanged(document);
-}
-
-/*!
* Returns the current workspace path.
*/
QString LiveNodeEngine::workspace() const
@@ -649,7 +719,11 @@ void LiveNodeEngine::onSizeChanged()
/*!
* \fn void LiveNodeEngine::activeDocumentChanged(const LiveDocument& document)
*
- * The document \a document was activated
+ * The document \a document was loaded with loadDocument() and is now the
+ * activeDocument(). This signal is only emitted when the new document differs
+ * from the previously loaded one.
+ *
+ * \sa documentLoaded()
*/
/*!
diff --git a/src/livenodeengine.h b/src/livenodeengine.h
index c7ddc16..78eebfe 100644
--- a/src/livenodeengine.h
+++ b/src/livenodeengine.h
@@ -84,11 +84,15 @@ public:
ContentAdapterInterface *activePlugin() const;
QQuickWindow *activeWindow() const;
+ void usePreloadedDocument(const LiveDocument &document, QObject *object, QQuickWindow *window,
+ const QList<QQmlError> &errors);
+ void usePreloadedDocument(const QString &document, QQuickWindow *window,
+ const QList<QQmlError> &errors);
+
public Q_SLOTS:
void setXOffset(int offset);
void setYOffset(int offset);
void setRotation(int rotation);
- void setActiveDocument(const LiveDocument& document);
void loadDocument(const LiveDocument& document);
void delayReload();
virtual void reloadDocument();
diff --git a/src/remotereceiver.cpp b/src/remotereceiver.cpp
index e871399..4d57caf 100644
--- a/src/remotereceiver.cpp
+++ b/src/remotereceiver.cpp
@@ -252,7 +252,7 @@ void RemoteReceiver::registerNode(LiveNodeEngine *node)
connect(m_node, SIGNAL(logErrors(QList<QQmlError>)), this, SLOT(appendToLog(QList<QQmlError>)));
connect(m_node, SIGNAL(clearLog()), this, SLOT(clearLog()));
connect(m_node, SIGNAL(activeDocumentChanged(LiveDocument)), this, SLOT(onActiveDocumentChanged(LiveDocument)));
- connect(this, SIGNAL(activateDocument(LiveDocument)), m_node, SLOT(setActiveDocument(LiveDocument)));
+ connect(this, SIGNAL(activateDocument(LiveDocument)), m_node, SLOT(loadDocument(LiveDocument)));
connect(this, SIGNAL(updateDocument(LiveDocument,QByteArray)), m_node, SLOT(updateDocument(LiveDocument,QByteArray)));
connect(this, SIGNAL(xOffsetChanged(int)), m_node, SLOT(setXOffset(int)));
connect(this, SIGNAL(yOffsetChanged(int)), m_node, SLOT(setYOffset(int)));
@@ -363,6 +363,9 @@ void RemoteReceiver::clearLog()
m_log.clear();
m_logSentPosition = 0;
+ if (!m_client)
+ return;
+
m_client->send("clearLog()", QByteArray());
}
@@ -371,6 +374,9 @@ void RemoteReceiver::clearLog()
*/
void RemoteReceiver::onActiveDocumentChanged(const LiveDocument &document)
{
+ if (!m_client)
+ return;
+
QByteArray bytes;
QDataStream out(&bytes, QIODevice::WriteOnly);
out << document.relativeFilePath();