h & cpp split
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#ifndef NATIVE_BRIDGE_H
|
||||
#define NATIVE_BRIDGE_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QJSValue>
|
||||
#include <QObject>
|
||||
|
||||
|
7
doric/native/native_empty.cpp
Normal file
7
doric/native/native_empty.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <QDebug>
|
||||
|
||||
#include "native_empty.h"
|
||||
|
||||
void NativeEmpty::function() {
|
||||
qDebug() << "nativeEmpty";
|
||||
}
|
@@ -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
|
||||
|
13
doric/native/native_log.cpp
Normal file
13
doric/native/native_log.cpp
Normal 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;
|
||||
}
|
||||
}
|
@@ -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
|
||||
|
30
doric/native/native_timer.cpp
Normal file
30
doric/native/native_timer.cpp
Normal 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);
|
||||
}
|
@@ -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
|
||||
|
Reference in New Issue
Block a user