context holder & generic
This commit is contained in:
parent
41640c1399
commit
24f7bb2498
@ -1,7 +1,9 @@
|
||||
#include "DoricContext.h"
|
||||
#include "DoricContextManager.h"
|
||||
#include "DoricNativeDriver.h"
|
||||
|
||||
#include "utils/DoricConstant.h"
|
||||
#include "utils/DoricContextHolder.h"
|
||||
|
||||
DoricContext::DoricContext(QString contextId, QString source, QString extra) {
|
||||
this->mRootNode = new DoricRootNode();
|
||||
@ -63,6 +65,7 @@ QObject *DoricContext::obtainPlugin(QString name) {
|
||||
} else {
|
||||
QObject *plugin =
|
||||
getDriver()->getRegistry()->pluginInfoMap.createObject(name);
|
||||
dynamic_cast<DoricContextHolder *>(plugin)->setContext(this);
|
||||
mPluginMap.insert(name, plugin);
|
||||
return plugin;
|
||||
}
|
||||
|
@ -32,7 +32,8 @@ SOURCES += \
|
||||
main.cpp \
|
||||
plugin/DoricShaderPlugin.cpp \
|
||||
shader/DoricRootNode.cpp \
|
||||
utils/DoricConstant.cpp
|
||||
utils/DoricConstant.cpp \
|
||||
utils/DoricContextHolder.cpp
|
||||
|
||||
RESOURCES += qml.qrc
|
||||
|
||||
@ -67,10 +68,12 @@ HEADERS += \
|
||||
engine/DoricNativeLog.h \
|
||||
engine/DoricNativeRequire.h \
|
||||
engine/DoricTimerExtension.h \
|
||||
plugin/DoricNativePlugin.h \
|
||||
plugin/DoricShaderPlugin.h \
|
||||
shader/DoricRootNode.h \
|
||||
template/DoricSingleton.h \
|
||||
utils/DoricConstant.h \
|
||||
utils/DoricContextHolder.h \
|
||||
utils/DoricCountDownLatch.h \
|
||||
utils/DoricObjectFactory.h \
|
||||
utils/DoricUtils.h
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.11.1, 2021-02-04T16:22:10. -->
|
||||
<!-- Written by QtCreator 4.11.1, 2021-02-05T15:58:19. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
@ -19,7 +19,6 @@ void DoricBridgeExtension::callNative(QString contextId, QString module,
|
||||
Qt::DirectConnection, QGenericReturnArgument(),
|
||||
Q_ARG(QJSValue, jsValue),
|
||||
Q_ARG(QString, callbackId));
|
||||
qDebug() << plugin;
|
||||
}
|
||||
qDebug() << "contextId: " + contextId;
|
||||
qDebug() << "module: " + module;
|
||||
|
11
doric-Qt/doric/plugin/DoricNativePlugin.h
Normal file
11
doric-Qt/doric/plugin/DoricNativePlugin.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef DORICNATIVEPLUGIN_H
|
||||
#define DORICNATIVEPLUGIN_H
|
||||
|
||||
#include "../utils/DoricContextHolder.h"
|
||||
|
||||
class DoricNativePlugin : public DoricContextHolder {
|
||||
public:
|
||||
using DoricContextHolder::DoricContextHolder;
|
||||
};
|
||||
|
||||
#endif // DORICNATIVEPLUGIN_H
|
@ -2,8 +2,6 @@
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
DoricShaderPlugin::DoricShaderPlugin(QObject *parent) : QObject(parent) {}
|
||||
|
||||
void DoricShaderPlugin::render(QJSValue jsValue, QString callbackId) {
|
||||
qDebug() << "";
|
||||
qDebug() << getContext();
|
||||
}
|
||||
|
@ -4,10 +4,12 @@
|
||||
#include <QJSValue>
|
||||
#include <QObject>
|
||||
|
||||
class DoricShaderPlugin : public QObject {
|
||||
#include "DoricNativePlugin.h"
|
||||
|
||||
class DoricShaderPlugin : public DoricNativePlugin {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DoricShaderPlugin(QObject *parent);
|
||||
using DoricNativePlugin::DoricNativePlugin;
|
||||
|
||||
Q_INVOKABLE void render(QJSValue jsValue, QString callbackId);
|
||||
};
|
||||
|
9
doric-Qt/doric/utils/DoricContextHolder.cpp
Normal file
9
doric-Qt/doric/utils/DoricContextHolder.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include "DoricContextHolder.h"
|
||||
|
||||
DoricContextHolder::DoricContextHolder(QObject *parent) { mContext = NULL; }
|
||||
|
||||
void DoricContextHolder::setContext(DoricContext *context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
DoricContext *DoricContextHolder::getContext() { return mContext; }
|
18
doric-Qt/doric/utils/DoricContextHolder.h
Normal file
18
doric-Qt/doric/utils/DoricContextHolder.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef DORICCONTEXTHOLDER_H
|
||||
#define DORICCONTEXTHOLDER_H
|
||||
|
||||
#include "../DoricContext.h"
|
||||
|
||||
class DoricContextHolder : public QObject {
|
||||
protected:
|
||||
DoricContext *mContext = NULL;
|
||||
|
||||
public:
|
||||
explicit DoricContextHolder(QObject *parent = nullptr);
|
||||
|
||||
void setContext(DoricContext *context);
|
||||
|
||||
DoricContext *getContext();
|
||||
};
|
||||
|
||||
#endif // DORICCONTEXTHOLDER_H
|
Reference in New Issue
Block a user