h & cpp split

This commit is contained in:
王劲鹏
2019-12-14 10:04:17 +08:00
parent 4610e71f42
commit ed2a1326fc
17 changed files with 210 additions and 159 deletions

View File

@@ -1,7 +1,6 @@
#ifndef NATIVE_BRIDGE_H
#define NATIVE_BRIDGE_H
#include <QDebug>
#include <QJSValue>
#include <QObject>

View File

@@ -0,0 +1,7 @@
#include <QDebug>
#include "native_empty.h"
void NativeEmpty::function() {
qDebug() << "nativeEmpty";
}

View File

@@ -2,7 +2,6 @@
#define NATIVE_EMPTY_H
#include <QObject>
#include <QDebug>
class NativeEmpty : public QObject {
Q_OBJECT
@@ -10,9 +9,7 @@ class NativeEmpty : public QObject {
public:
NativeEmpty(QObject *parent = nullptr) : QObject(parent) {}
Q_INVOKABLE void function() {
qDebug() << "nativeEmpty";
}
Q_INVOKABLE void function();
};
#endif // NATIVE_EMPTY_H

View File

@@ -0,0 +1,13 @@
#include <QDebug>
#include "native_log.h"
void NativeLog::function(QString level, QString content) {
if (level == 'w') {
qWarning() << content;
} else if (level == 'd') {
qDebug() << content;
} else if (level == 'e') {
qCritical() << content;
}
}

View File

@@ -2,7 +2,6 @@
#define NATIVELOG_H
#include <QObject>
#include <QDebug>
class NativeLog : public QObject {
Q_OBJECT
@@ -10,15 +9,7 @@ class NativeLog : public QObject {
public:
NativeLog(QObject *parent = nullptr) : QObject(parent) {}
Q_INVOKABLE void function(QString level, QString content) {
if (level == 'w') {
qWarning() << content;
} else if (level == 'd') {
qDebug() << content;
} else if (level == 'e') {
qCritical() << content;
}
}
Q_INVOKABLE void function(QString level, QString content);
};
#endif // NATIVELOG_H

View File

@@ -0,0 +1,30 @@
#include <QTimer>
#include "native_timer.h"
void NativeTimer::setTimer(long timerId, int time, bool repeat) {
QTimer *timer = new QTimer(this);
timer->setSingleShot(!repeat);
connect(timer, &QTimer::timeout, this, [=] () {
if (deletedTimerIds->contains(timerId)) {
deletedTimerIds->remove(timerId);
delete timer;
} else {
engine->evaluate(
Constant::GLOBAL_DORIC + "." +
Constant::DORIC_TIMER_CALLBACK + "(" +
QString::number(timerId) + ")"
);
if (!repeat) {
deletedTimerIds->remove(timerId);
delete timer;
}
}
});
timer->start(time);
}
void NativeTimer::clearTimer(long timerId) {
deletedTimerIds->insert(timerId);
}

View File

@@ -4,7 +4,6 @@
#include <QJSEngine>
#include <QObject>
#include <QSet>
#include <QTimer>
#include "constant.h"
@@ -20,32 +19,9 @@ public:
this->engine = engine;
}
Q_INVOKABLE void setTimer(long timerId, int time, bool repeat) {
QTimer *timer = new QTimer(this);
timer->setSingleShot(!repeat);
connect(timer, &QTimer::timeout, this, [=] () {
if (deletedTimerIds->contains(timerId)) {
deletedTimerIds->remove(timerId);
delete timer;
} else {
engine->evaluate(
Constant::GLOBAL_DORIC + "." +
Constant::DORIC_TIMER_CALLBACK + "(" +
QString::number(timerId) + ")"
);
Q_INVOKABLE void setTimer(long timerId, int time, bool repeat);
if (!repeat) {
deletedTimerIds->remove(timerId);
delete timer;
}
}
});
timer->start(time);
}
Q_INVOKABLE void clearTimer(long timerId) {
deletedTimerIds->insert(timerId);
}
Q_INVOKABLE void clearTimer(long timerId);
};
#endif // NATIVE_TIMER_H