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/context.cpp

63 lines
1.5 KiB
C++
Raw Normal View History

2019-12-14 10:04:17 +08:00
#include "context.h"
2021-01-28 17:06:40 +08:00
#include "native_driver.h"
2021-01-28 20:31:06 +08:00
#include "context_manager.h"
2021-02-02 20:42:37 +08:00
#include "utils/constant.h"
2019-12-14 10:04:17 +08:00
2021-01-28 17:06:40 +08:00
Context::Context(QString contextId, QString source, QString extra)
{
2021-02-02 20:42:37 +08:00
this->mRootNode = new RootNode();
2021-01-28 17:06:40 +08:00
this->mContextId = contextId;
2019-12-14 10:04:17 +08:00
this->source = source;
2021-01-28 17:06:40 +08:00
this->extra = extra;
2019-12-14 10:04:17 +08:00
}
2021-01-28 20:31:06 +08:00
Context* Context::create(QString script, QString source, QString extra)
{
Context *context = ContextManager::getInstance()->createContext(script, source, extra);
context->script = script;
2021-02-02 20:42:37 +08:00
context->init(extra);
QVariantList args;
context->callEntity(Constant::DORIC_ENTITY_CREATE, args);
2021-01-28 20:31:06 +08:00
return context;
}
2021-02-02 20:42:37 +08:00
void Context::init(QString initData)
{
this->extra = initData;
if (!initData.isEmpty()) {
QVariantList args;
args.push_back(initData);
callEntity(Constant::DORIC_ENTITY_INIT, args);
}
}
void Context::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(Constant::DORIC_ENTITY_BUILD, args);
}
void Context::callEntity(QString methodName, QVariantList args)
{
return getDriver()->invokeContextEntityMethod(this->mContextId, methodName, args);
}
2021-01-28 17:06:40 +08:00
InterfaceDriver* Context::getDriver()
{
if (driver == NULL)
{
driver = NativeDriver::getInstance();
return driver;
}
return driver;
2019-12-14 10:04:17 +08:00
}