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

55 lines
1.2 KiB
C
Raw Normal View History

2019-12-04 15:51:46 +08:00
#ifndef CONTEXT_H
#define CONTEXT_H
#include <QString>
2019-12-04 16:44:30 +08:00
#include <QJsonObject>
#include <QJsonDocument>
#include "constant.h"
2019-12-04 15:51:46 +08:00
#include "driver/driver.h"
#include "driver/native_driver.h"
class Context
{
private:
int contextId;
2019-12-13 17:48:37 +08:00
QString *source;
2019-12-04 15:51:46 +08:00
public:
2019-12-13 17:48:37 +08:00
Driver *driver = NativeDriver::getInstance();
2019-12-04 15:51:46 +08:00
2019-12-13 17:48:37 +08:00
Context(int contextId, QString *source) {
2019-12-04 15:51:46 +08:00
this->contextId = contextId;
this->source = source;
}
2019-12-04 16:44:30 +08:00
void show() {
2019-12-13 17:48:37 +08:00
QString *method = new QString(Constant::DORIC_ENTITY_SHOW);
QVector<QString*> *arguments = new QVector<QString*>();
driver->invokeContextEntityMethod(contextId, method, nullptr);
delete arguments;
delete method;
}
2019-12-04 16:44:30 +08:00
void init(double width, double height) {
2019-12-13 17:48:37 +08:00
QJsonObject *jsonObject = new QJsonObject();
jsonObject->insert("width", width);
jsonObject->insert("height", height);
2019-12-13 17:48:37 +08:00
QString *method = new QString(Constant::DORIC_ENTITY_INIT);
QVariant *variant = new QVariant();
variant->setValue(*jsonObject);
driver->invokeContextEntityMethod(contextId, method, variant, nullptr);
delete variant;
delete method;
delete jsonObject;
2019-12-04 16:44:30 +08:00
}
2019-12-04 15:51:46 +08:00
};
#endif // CONTEXT_H