destroy context when qquickview hidden
This commit is contained in:
parent
7402fc2c0c
commit
d9828dca93
@ -15,6 +15,12 @@ DoricContext::DoricContext(QString contextId, QString source, QString extra) {
|
|||||||
this->extra = extra;
|
this->extra = extra;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DoricContext::~DoricContext() {
|
||||||
|
QVariantList args;
|
||||||
|
callEntity(DoricConstant::DORIC_ENTITY_DESTROY, args);
|
||||||
|
DoricContextManager::getInstance()->destroyContext(this);
|
||||||
|
}
|
||||||
|
|
||||||
DoricContext *DoricContext::create(QString script, QString source,
|
DoricContext *DoricContext::create(QString script, QString source,
|
||||||
QString extra) {
|
QString extra) {
|
||||||
DoricContext *context =
|
DoricContext *context =
|
||||||
@ -84,3 +90,5 @@ DoricViewNode *DoricContext::targetViewNode(QString id) {
|
|||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString DoricContext::getContextId() { return mContextId; }
|
||||||
|
@ -24,6 +24,8 @@ private:
|
|||||||
public:
|
public:
|
||||||
DoricContext(QString contextId, QString source, QString extra);
|
DoricContext(QString contextId, QString source, QString extra);
|
||||||
|
|
||||||
|
~DoricContext();
|
||||||
|
|
||||||
static DoricContext *create(QString script, QString source, QString extra);
|
static DoricContext *create(QString script, QString source, QString extra);
|
||||||
|
|
||||||
void init(QString initData);
|
void init(QString initData);
|
||||||
@ -43,6 +45,8 @@ public:
|
|||||||
QQmlEngine *getQmlEngine();
|
QQmlEngine *getQmlEngine();
|
||||||
|
|
||||||
DoricViewNode *targetViewNode(QString id);
|
DoricViewNode *targetViewNode(QString id);
|
||||||
|
|
||||||
|
QString getContextId();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTEXT_H
|
#endif // CONTEXT_H
|
||||||
|
@ -14,3 +14,8 @@ DoricContext *DoricContextManager::createContext(QString script, QString source,
|
|||||||
DoricContext *DoricContextManager::getContext(QString contextId) {
|
DoricContext *DoricContextManager::getContext(QString contextId) {
|
||||||
return contextMap->value(contextId);
|
return contextMap->value(contextId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DoricContextManager::destroyContext(DoricContext *context) {
|
||||||
|
context->getDriver()->destroyContext(context->getContextId());
|
||||||
|
contextMap->remove(context->getContextId());
|
||||||
|
}
|
||||||
|
@ -25,6 +25,8 @@ public:
|
|||||||
DoricContext *createContext(QString script, QString source, QString extra);
|
DoricContext *createContext(QString script, QString source, QString extra);
|
||||||
|
|
||||||
DoricContext *getContext(QString contextId);
|
DoricContext *getContext(QString contextId);
|
||||||
|
|
||||||
|
void destroyContext(DoricContext *context);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTEXTMANAGER_H
|
#endif // CONTEXTMANAGER_H
|
||||||
|
@ -14,9 +14,8 @@ void DoricNativeDriver::invokeContextEntityMethod(QString contextId,
|
|||||||
|
|
||||||
void DoricNativeDriver::invokeDoricMethod(QString method, QVariantList args) {
|
void DoricNativeDriver::invokeDoricMethod(QString method, QVariantList args) {
|
||||||
return DoricAsyncCall::ensureRunInThreadPool(
|
return DoricAsyncCall::ensureRunInThreadPool(
|
||||||
&jsEngine.mJSThreadPool, [this, method, args] {
|
&jsEngine.mJSThreadPool,
|
||||||
this->jsEngine.invokeDoricMethod(method, args);
|
[this, method, args] { this->jsEngine.invokeDoricMethod(method, args); });
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DoricAsyncResult *DoricNativeDriver::asyncCall(std::function<void()> lambda,
|
DoricAsyncResult *DoricNativeDriver::asyncCall(std::function<void()> lambda,
|
||||||
@ -40,7 +39,11 @@ void DoricNativeDriver::createContext(QString contextId, QString script,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoricNativeDriver::destroyContext(QString contextId) {}
|
void DoricNativeDriver::destroyContext(QString contextId) {
|
||||||
|
DoricAsyncCall::ensureRunInThreadPool(
|
||||||
|
&jsEngine.mJSThreadPool,
|
||||||
|
[this, contextId] { this->jsEngine.destroyContext(contextId); });
|
||||||
|
}
|
||||||
|
|
||||||
DoricRegistry *DoricNativeDriver::getRegistry() {
|
DoricRegistry *DoricNativeDriver::getRegistry() {
|
||||||
return this->jsEngine.getRegistry();
|
return this->jsEngine.getRegistry();
|
||||||
|
@ -6,6 +6,10 @@ DoricPanel::DoricPanel(QQmlEngine *qmlEngine, QQuickItem *quickItem) {
|
|||||||
mQuickItem = quickItem;
|
mQuickItem = quickItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DoricPanel::~DoricPanel() {
|
||||||
|
delete mContext;
|
||||||
|
}
|
||||||
|
|
||||||
void DoricPanel::config(QString script, QString alias, QString extra) {
|
void DoricPanel::config(QString script, QString alias, QString extra) {
|
||||||
DoricContext *context = DoricContext::create(script, alias, extra);
|
DoricContext *context = DoricContext::create(script, alias, extra);
|
||||||
config(context);
|
config(context);
|
||||||
|
@ -17,6 +17,8 @@ private:
|
|||||||
public:
|
public:
|
||||||
DoricPanel(QQmlEngine *qmlEngine, QQuickItem *quickItem);
|
DoricPanel(QQmlEngine *qmlEngine, QQuickItem *quickItem);
|
||||||
|
|
||||||
|
~DoricPanel();
|
||||||
|
|
||||||
void config(QString script, QString alias, QString extra);
|
void config(QString script, QString alias, QString extra);
|
||||||
|
|
||||||
void config(DoricContext *context);
|
void config(DoricContext *context);
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
#include "DoricDemoBridge.h"
|
#include "DoricDemoBridge.h"
|
||||||
#include "DoricPanel.h"
|
#include "DoricPanel.h"
|
||||||
#include "utils/DoricUtils.h"
|
|
||||||
#include "utils/DoricMouseAreaBridge.h"
|
#include "utils/DoricMouseAreaBridge.h"
|
||||||
|
#include "utils/DoricUtils.h"
|
||||||
|
|
||||||
DoricDemoBridge::DoricDemoBridge(QObject *parent) : QObject(parent) {}
|
DoricDemoBridge::DoricDemoBridge(QObject *parent) : QObject(parent) {}
|
||||||
|
|
||||||
@ -33,6 +33,10 @@ void DoricDemoBridge::navigate(QVariant route) {
|
|||||||
view->setSource(url);
|
view->setSource(url);
|
||||||
view->setWidth(405);
|
view->setWidth(405);
|
||||||
view->setHeight(720);
|
view->setHeight(720);
|
||||||
|
Qt::WindowFlags flag = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint |
|
||||||
|
Qt::WindowTitleHint | Qt::WindowCloseButtonHint |
|
||||||
|
Qt::CustomizeWindowHint | Qt::WindowSystemMenuHint;
|
||||||
|
view->setFlags(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -46,6 +50,12 @@ void DoricDemoBridge::navigate(QVariant route) {
|
|||||||
quickItem->setParentItem(view->rootObject());
|
quickItem->setParentItem(view->rootObject());
|
||||||
|
|
||||||
panel->config(script, name, NULL);
|
panel->config(script, name, NULL);
|
||||||
|
|
||||||
|
connect(view, &QQuickView::visibleChanged, this, [view, panel]() {
|
||||||
|
if (!view->isVisible()) {
|
||||||
|
delete panel;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
view->show();
|
view->show();
|
||||||
|
@ -100,6 +100,12 @@ void DoricJSEngine::prepareContext(QString contextId, QString script,
|
|||||||
mJSE->loadJS(packageContextScript(contextId, script), "Context://" + source);
|
mJSE->loadJS(packageContextScript(contextId, script), "Context://" + source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DoricJSEngine::destroyContext(QString contextId) {
|
||||||
|
QString script =
|
||||||
|
QString(DoricConstant::TEMPLATE_CONTEXT_DESTROY).replace("%s", contextId);
|
||||||
|
mJSE->loadJS(script, "_Context://" + contextId);
|
||||||
|
}
|
||||||
|
|
||||||
void DoricJSEngine::invokeDoricMethod(QString method, QVariantList arguments) {
|
void DoricJSEngine::invokeDoricMethod(QString method, QVariantList arguments) {
|
||||||
return mJSE->invokeObject(DoricConstant::GLOBAL_DORIC, method, arguments);
|
return mJSE->invokeObject(DoricConstant::GLOBAL_DORIC, method, arguments);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,11 @@ public:
|
|||||||
~DoricJSEngine();
|
~DoricJSEngine();
|
||||||
|
|
||||||
void prepareContext(QString contextId, QString script, QString source);
|
void prepareContext(QString contextId, QString script, QString source);
|
||||||
|
|
||||||
|
void destroyContext(QString contextId);
|
||||||
|
|
||||||
void invokeDoricMethod(QString method, QVariantList arguments);
|
void invokeDoricMethod(QString method, QVariantList arguments);
|
||||||
|
|
||||||
DoricRegistry *getRegistry();
|
DoricRegistry *getRegistry();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import QtQuick.Controls 2.5
|
|||||||
|
|
||||||
ApplicationWindow {
|
ApplicationWindow {
|
||||||
visible: true
|
visible: true
|
||||||
width: 960
|
width: 405
|
||||||
height: 720
|
height: 720
|
||||||
title: qsTr("Scroll")
|
title: qsTr("Scroll")
|
||||||
|
|
||||||
|
@ -33,3 +33,4 @@ const QString DoricConstant::DORIC_ENTITY_RESPONSE = "__response__";
|
|||||||
const QString DoricConstant::DORIC_ENTITY_INIT = "__init__";
|
const QString DoricConstant::DORIC_ENTITY_INIT = "__init__";
|
||||||
const QString DoricConstant::DORIC_ENTITY_CREATE = "__onCreate__";
|
const QString DoricConstant::DORIC_ENTITY_CREATE = "__onCreate__";
|
||||||
const QString DoricConstant::DORIC_ENTITY_BUILD = "__build__";
|
const QString DoricConstant::DORIC_ENTITY_BUILD = "__build__";
|
||||||
|
const QString DoricConstant::DORIC_ENTITY_DESTROY = "__onDestroy__";
|
||||||
|
@ -30,6 +30,7 @@ public:
|
|||||||
static const QString DORIC_ENTITY_CREATE;
|
static const QString DORIC_ENTITY_CREATE;
|
||||||
static const QString DORIC_ENTITY_INIT;
|
static const QString DORIC_ENTITY_INIT;
|
||||||
static const QString DORIC_ENTITY_BUILD;
|
static const QString DORIC_ENTITY_BUILD;
|
||||||
|
static const QString DORIC_ENTITY_DESTROY;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONSTANT_H
|
#endif // CONSTANT_H
|
||||||
|
Reference in New Issue
Block a user