This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-Qt/doric/DoricContext.cpp

73 lines
2.0 KiB
C++
Raw Normal View History

2021-02-04 16:59:58 +08:00
#include "DoricContext.h"
#include "DoricContextManager.h"
#include "DoricNativeDriver.h"
2021-02-05 18:12:25 +08:00
2021-02-04 16:59:58 +08:00
#include "utils/DoricConstant.h"
2021-02-05 18:12:25 +08:00
#include "utils/DoricContextHolder.h"
2021-02-04 16:59:58 +08:00
DoricContext::DoricContext(QString contextId, QString source, QString extra) {
this->mRootNode = new DoricRootNode();
this->mContextId = contextId;
this->source = source;
this->extra = extra;
}
DoricContext *DoricContext::create(QString script, QString source,
QString extra) {
DoricContext *context =
DoricContextManager::getInstance()->createContext(script, source, extra);
context->script = script;
context->init(extra);
QVariantList args;
context->callEntity(DoricConstant::DORIC_ENTITY_CREATE, args);
return context;
}
void DoricContext::init(QString initData) {
this->extra = initData;
if (!initData.isEmpty()) {
QVariantList args;
args.push_back(initData);
callEntity(DoricConstant::DORIC_ENTITY_INIT, args);
}
}
void DoricContext::build(int width, int height) {
QMap<QString, QVariant> map;
map.insert("width", QVariant(width));
map.insert("height", QVariant(height));
QVariant jsValue(map);
this->initParams = jsValue;
QVariantList args;
args.push_back(this->initParams);
callEntity(DoricConstant::DORIC_ENTITY_BUILD, args);
}
void DoricContext::callEntity(QString methodName, QVariantList args) {
return getDriver()->invokeContextEntityMethod(this->mContextId, methodName,
args);
}
DoricInterfaceDriver *DoricContext::getDriver() {
if (driver == NULL) {
driver = DoricNativeDriver::getInstance();
return driver;
}
return driver;
}
QObject *DoricContext::obtainPlugin(QString name) {
if (mPluginMap.keys().contains(name)) {
return mPluginMap.value(name);
} else {
QObject *plugin =
getDriver()->getRegistry()->pluginInfoMap.createObject(name);
2021-02-05 18:12:25 +08:00
dynamic_cast<DoricContextHolder *>(plugin)->setContext(this);
2021-02-04 16:59:58 +08:00
mPluginMap.insert(name, plugin);
return plugin;
}
}