code format
This commit is contained in:
parent
3fdedb6240
commit
4610e71f42
@ -14,19 +14,19 @@ class Context
|
||||
|
||||
private:
|
||||
int contextId;
|
||||
QString* source;
|
||||
QString *source;
|
||||
|
||||
public:
|
||||
Driver* driver = NativeDriver::getInstance();
|
||||
Driver *driver = NativeDriver::getInstance();
|
||||
|
||||
Context(int contextId, QString* source) {
|
||||
Context(int contextId, QString *source) {
|
||||
this->contextId = contextId;
|
||||
this->source = source;
|
||||
}
|
||||
|
||||
void show() {
|
||||
QString* method = new QString(Constant::DORIC_ENTITY_SHOW);
|
||||
QVector<QString*>* arguments = new QVector<QString*>();
|
||||
QString *method = new QString(Constant::DORIC_ENTITY_SHOW);
|
||||
QVector<QString*> *arguments = new QVector<QString*>();
|
||||
|
||||
driver->invokeContextEntityMethod(contextId, method, nullptr);
|
||||
|
||||
@ -35,12 +35,12 @@ public:
|
||||
}
|
||||
|
||||
void init(double width, double height) {
|
||||
QJsonObject* jsonObject = new QJsonObject();
|
||||
QJsonObject *jsonObject = new QJsonObject();
|
||||
jsonObject->insert("width", width);
|
||||
jsonObject->insert("height", height);
|
||||
|
||||
QString* method = new QString(Constant::DORIC_ENTITY_INIT);
|
||||
QVariant* variant = new QVariant();
|
||||
QString *method = new QString(Constant::DORIC_ENTITY_INIT);
|
||||
QVariant *variant = new QVariant();
|
||||
variant->setValue(*jsonObject);
|
||||
|
||||
driver->invokeContextEntityMethod(contextId, method, variant, nullptr);
|
||||
|
@ -15,8 +15,8 @@ void NativeDriver::destroyContext(int contextId) {
|
||||
jsEngine->destroyContext(contextId);
|
||||
}
|
||||
|
||||
void NativeDriver::invokeContextEntityMethod(int contextId, QString* method, ...) {
|
||||
QJSValueList* arguments = new QJSValueList();
|
||||
void NativeDriver::invokeContextEntityMethod(int contextId, QString *method, ...) {
|
||||
QJSValueList *arguments = new QJSValueList();
|
||||
arguments->append(QJSValue(QString::number(contextId)));
|
||||
arguments->append(QJSValue(*method));
|
||||
|
||||
@ -25,8 +25,8 @@ void NativeDriver::invokeContextEntityMethod(int contextId, QString* method, ...
|
||||
auto argument = va_arg(vaList, QVariant*);
|
||||
while (argument != nullptr) {
|
||||
if (QString(typeid(QJsonObject).name()).contains(QString(argument->typeName()))) {
|
||||
QJsonObject* jsonObject = static_cast<QJsonObject*>(argument->data());
|
||||
QJsonValue* jsonValue = new QJsonValue(*jsonObject);
|
||||
QJsonObject *jsonObject = static_cast<QJsonObject*>(argument->data());
|
||||
QJsonValue *jsonValue = new QJsonValue(*jsonObject);
|
||||
QJSValue jsValue = Utility::convert(jsEngine->engine, *jsonValue);
|
||||
delete jsonValue;
|
||||
arguments->append(jsValue);
|
||||
|
@ -44,10 +44,10 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
NativeLog* nativeLog = new NativeLog();
|
||||
NativeTimer* nativeTimer = new NativeTimer(engine);
|
||||
NativeEmpty* nativeEmpty = new NativeEmpty();
|
||||
NativeBridge* nativeBridge = new NativeBridge();
|
||||
NativeLog *nativeLog = new NativeLog();
|
||||
NativeTimer *nativeTimer = new NativeTimer(engine);
|
||||
NativeEmpty *nativeEmpty = new NativeEmpty();
|
||||
NativeBridge *nativeBridge = new NativeBridge();
|
||||
|
||||
void initJSEngine() {
|
||||
engine->installExtensions(QJSEngine::AllExtensions);
|
||||
|
@ -29,7 +29,7 @@ int main(int argc, char *argv[])
|
||||
file->close();
|
||||
delete file;
|
||||
|
||||
QString* source = new QString("Snake.js");
|
||||
QString *source = new QString("Snake.js");
|
||||
Context *context = ContextManager::getInstance()->createContext(&script, source);
|
||||
context->show();
|
||||
context->init(180, 320);
|
||||
|
@ -7,5 +7,5 @@ Q_INVOKABLE void NativeBridge::function(int contextId, QString module, QString m
|
||||
"methodName: " + methodName + ", " +
|
||||
"callbackId: " + callbackId + ", " +
|
||||
"arguments: " + jsValue.toString();
|
||||
Context* context = ContextManager::getInstance()->getContext(contextId);
|
||||
Context *context = ContextManager::getInstance()->getContext(contextId);
|
||||
}
|
||||
|
@ -13,15 +13,15 @@ class NativeTimer : public QObject {
|
||||
|
||||
private:
|
||||
QSet<long> *deletedTimerIds = new QSet<long>();
|
||||
QJSEngine* engine;
|
||||
QJSEngine *engine;
|
||||
|
||||
public:
|
||||
NativeTimer(QJSEngine* engine, QObject *parent = nullptr) : QObject(parent) {
|
||||
NativeTimer(QJSEngine *engine, QObject *parent = nullptr) : QObject(parent) {
|
||||
this->engine = engine;
|
||||
}
|
||||
|
||||
Q_INVOKABLE void setTimer(long timerId, int time, bool repeat) {
|
||||
QTimer* timer = new QTimer(this);
|
||||
QTimer *timer = new QTimer(this);
|
||||
timer->setSingleShot(!repeat);
|
||||
connect(timer, &QTimer::timeout, this, [=] () {
|
||||
if (deletedTimerIds->contains(timerId)) {
|
||||
|
@ -6,7 +6,7 @@
|
||||
class ShaderPlugin : public ContextHolder {
|
||||
|
||||
public:
|
||||
ShaderPlugin(Context* context) : ContextHolder(context) {}
|
||||
ShaderPlugin(Context *context) : ContextHolder(context) {}
|
||||
};
|
||||
|
||||
#endif // SHADER_PLUGIN_H
|
||||
|
@ -9,7 +9,7 @@
|
||||
class Utility {
|
||||
|
||||
public:
|
||||
static QJSValue convert(QJSEngine* jsEngine, QJsonValue jsonValue) {
|
||||
static QJSValue convert(QJSEngine *jsEngine, QJsonValue jsonValue) {
|
||||
if (jsonValue.isBool()) {
|
||||
return QJSValue(jsonValue.toBool());
|
||||
} else if (jsonValue.isString()) {
|
||||
|
Reference in New Issue
Block a user