@@ -94,7 +94,7 @@ QWindow* QQmlViewUtil::getQWindowView(Session* session, const ViewId& viewId) {
9494 return qobject_cast<QWindow*>(qViewHandle->get ());
9595}
9696
97- QQuickView * QQmlViewUtil::getQMLView (Session* session, const ViewId& viewId) {
97+ QQuickWindow * QQmlViewUtil::getQMLView (Session* session, const ViewId& viewId) {
9898 ViewHandle* viewHandle = session->GetViewHandle (viewId);
9999 if (NULL == viewHandle)
100100 return NULL ;
@@ -103,8 +103,69 @@ QQuickView* QQmlViewUtil::getQMLView(Session* session, const ViewId& viewId) {
103103 if (NULL == qViewHandle)
104104 return NULL ;
105105
106- return qobject_cast<QQuickView *>(qViewHandle->get ());
106+ return qobject_cast<QQuickWindow *>(qViewHandle->get ());
107107}
108+
109+ QQmlEngine* QQmlViewUtil::getQMLEngine (QQuickWindow* qquickWindow) {
110+ QQuickView* pView = qobject_cast<QQuickView*>(qquickWindow);
111+
112+ if (pView != NULL )
113+ return pView->engine ();
114+
115+ QQmlContext *rootContext = QQmlEngine::contextForObject (qquickWindow->contentItem ());
116+
117+ return rootContext->engine ();
118+ }
119+
120+ void QQmlViewUtil::setSource (const Logger& logger, const QUrl &url, bool sync, QQuickWindow* qquickWindow) {
121+ QQuickView* pView = qobject_cast<QQuickView*>(qquickWindow);
122+
123+ if (pView != NULL ) {
124+ if (sync) {
125+ QEventLoop loop;
126+ QObject::connect (pView, SIGNAL (statusChanged (QQuickView::Status)),&loop,SLOT (quit ()));
127+ pView->setSource (url);
128+
129+ if (QQuickView::Loading == pView->status ()) {
130+ loop.exec ();
131+ }
132+
133+ if (QQuickView::Ready != pView->status ()) {
134+ logger.Log (kWarningLogLevel , " QML sync load, smth wrong. View is not in READY state." );
135+ }
136+
137+ } else {
138+ pView->setSource (url);
139+ logger.Log (kFineLogLevel , " QML async load - " );
140+ }
141+ }
142+ else {
143+ // TODO async / sync mode
144+ QQmlEngine* engine = QQmlViewUtil::getQMLEngine (qquickWindow);
145+ QQmlApplicationEngine* appEngine = qobject_cast<QQmlApplicationEngine*>(engine);
146+
147+ if (appEngine != NULL ) {
148+ appEngine->load (url);
149+ }
150+ }
151+ }
152+
153+ const QUrl QQmlViewUtil::getSource (QQuickWindow* qquickWindow) {
154+ QQuickView* pView = qobject_cast<QQuickView*>(qquickWindow);
155+
156+ if (pView != NULL ) {
157+ return pView->source ();
158+ }
159+
160+ QQmlEngine* engine = QQmlViewUtil::getQMLEngine (qquickWindow);
161+ QQmlApplicationEngine* appEngine = qobject_cast<QQmlApplicationEngine*>(engine);
162+
163+ if (appEngine != NULL ) {
164+ return appEngine->baseUrl ();
165+ }
166+ return QUrl ();
167+ }
168+
108169#else
109170void QQmlViewUtil::removeInternalSuffixes (QString& str) {
110171 str.remove (QRegExp (QLatin1String (" _QMLTYPE_\\ d+" )));
0 commit comments