add storage demo & plugin
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "plugin/DoricNetworkPlugin.h"
|
||||
#include "plugin/DoricPopoverPlugin.h"
|
||||
#include "plugin/DoricShaderPlugin.h"
|
||||
#include "plugin/DoricStoragePlugin.h"
|
||||
|
||||
#include "shader/DoricHLayoutNode.h"
|
||||
#include "shader/DoricImageNode.h"
|
||||
@@ -18,6 +19,7 @@ DoricRegistry::DoricRegistry() {
|
||||
registerNativePlugin<DoricModalPlugin>("modal");
|
||||
registerNativePlugin<DoricPopoverPlugin>("popover");
|
||||
registerNativePlugin<DoricNetworkPlugin>("network");
|
||||
registerNativePlugin<DoricStoragePlugin>("storage");
|
||||
|
||||
registerViewNode<DoricRootNode>("Root");
|
||||
registerViewNode<DoricStackNode>("Stack");
|
||||
|
@@ -39,6 +39,7 @@ SOURCES += \
|
||||
plugin/DoricNetworkPlugin.cpp \
|
||||
plugin/DoricPopoverPlugin.cpp \
|
||||
plugin/DoricShaderPlugin.cpp \
|
||||
plugin/DoricStoragePlugin.cpp \
|
||||
shader/DoricGroupNode.cpp \
|
||||
shader/DoricHLayoutNode.cpp \
|
||||
shader/DoricImageNode.cpp \
|
||||
@@ -112,6 +113,7 @@ HEADERS += \
|
||||
plugin/DoricNetworkPlugin.h \
|
||||
plugin/DoricPopoverPlugin.h \
|
||||
plugin/DoricShaderPlugin.h \
|
||||
plugin/DoricStoragePlugin.h \
|
||||
shader/DoricGroupNode.h \
|
||||
shader/DoricHLayoutNode.h \
|
||||
shader/DoricImageNode.h \
|
||||
|
@@ -90,6 +90,8 @@ v8::Local<v8::Value> Variant2JS(QVariant variant) {
|
||||
jsValue = array;
|
||||
} else if (variant.type() == QVariant::Int) {
|
||||
jsValue = v8::Number::New(isolate, variant.toDouble());
|
||||
} else if (variant.type() == QVariant::Invalid) {
|
||||
jsValue = v8::Undefined(isolate);
|
||||
}
|
||||
return handle_scope.Escape(jsValue);
|
||||
}
|
||||
|
95
doric-Qt/example/doric/plugin/DoricStoragePlugin.cpp
Normal file
95
doric-Qt/example/doric/plugin/DoricStoragePlugin.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
#include "DoricStoragePlugin.h"
|
||||
#include "engine/DoricPromise.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QSettings>
|
||||
|
||||
const QString DoricStoragePlugin::PREF_NAME = "pref_doric";
|
||||
|
||||
void DoricStoragePlugin::setItem(QString jsValueString, QString callbackId) {
|
||||
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
|
||||
QJsonValue jsValue = document.object();
|
||||
|
||||
QJsonValue zone = jsValue["zone"];
|
||||
QString key = jsValue["key"].toString();
|
||||
QString value = jsValue["value"].toString();
|
||||
|
||||
QString prefName;
|
||||
if (zone.isString()) {
|
||||
prefName = PREF_NAME + "_" + zone.toString();
|
||||
} else {
|
||||
prefName = PREF_NAME;
|
||||
}
|
||||
|
||||
QSettings settings;
|
||||
settings.setValue(prefName + "/" + key, value);
|
||||
|
||||
QVariantList args;
|
||||
DoricPromise::resolve(getContext(), callbackId, args);
|
||||
}
|
||||
|
||||
void DoricStoragePlugin::getItem(QString jsValueString, QString callbackId) {
|
||||
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
|
||||
QJsonValue jsValue = document.object();
|
||||
|
||||
QJsonValue zone = jsValue["zone"];
|
||||
QString key = jsValue["key"].toString();
|
||||
|
||||
QString prefName;
|
||||
if (zone.isString()) {
|
||||
prefName = PREF_NAME + "_" + zone.toString();
|
||||
} else {
|
||||
prefName = PREF_NAME;
|
||||
}
|
||||
|
||||
QSettings settings;
|
||||
QVariant value = settings.value(prefName + "/" + key);
|
||||
|
||||
QVariantList args;
|
||||
args.append(value);
|
||||
DoricPromise::resolve(getContext(), callbackId, args);
|
||||
}
|
||||
|
||||
void DoricStoragePlugin::remove(QString jsValueString, QString callbackId) {
|
||||
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
|
||||
QJsonValue jsValue = document.object();
|
||||
|
||||
QJsonValue zone = jsValue["zone"];
|
||||
QString key = jsValue["key"].toString();
|
||||
|
||||
QString prefName;
|
||||
if (zone.isString()) {
|
||||
prefName = PREF_NAME + "_" + zone.toString();
|
||||
} else {
|
||||
prefName = PREF_NAME;
|
||||
}
|
||||
|
||||
QSettings settings;
|
||||
settings.remove(prefName + "/" + key);
|
||||
|
||||
QVariantList args;
|
||||
DoricPromise::resolve(getContext(), callbackId, args);
|
||||
}
|
||||
|
||||
void DoricStoragePlugin::clear(QString jsValueString, QString callbackId) {
|
||||
QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8());
|
||||
QJsonValue jsValue = document.object();
|
||||
|
||||
QJsonValue zone = jsValue["zone"];
|
||||
QString key = jsValue["key"].toString();
|
||||
|
||||
QString prefName;
|
||||
if (zone.isString()) {
|
||||
prefName = PREF_NAME + "_" + zone.toString();
|
||||
} else {
|
||||
prefName = PREF_NAME;
|
||||
}
|
||||
|
||||
QSettings settings;
|
||||
settings.clear();
|
||||
|
||||
QVariantList args;
|
||||
DoricPromise::resolve(getContext(), callbackId, args);
|
||||
}
|
23
doric-Qt/example/doric/plugin/DoricStoragePlugin.h
Normal file
23
doric-Qt/example/doric/plugin/DoricStoragePlugin.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef DORICSTORAGEPLUGIN_H
|
||||
#define DORICSTORAGEPLUGIN_H
|
||||
|
||||
#include "DoricNativePlugin.h"
|
||||
|
||||
class DoricStoragePlugin : public DoricNativePlugin {
|
||||
Q_OBJECT
|
||||
private:
|
||||
static const QString PREF_NAME;
|
||||
|
||||
public:
|
||||
using DoricNativePlugin::DoricNativePlugin;
|
||||
|
||||
Q_INVOKABLE void setItem(QString jsValueString, QString callbackId);
|
||||
|
||||
Q_INVOKABLE void getItem(QString jsValueString, QString callbackId);
|
||||
|
||||
Q_INVOKABLE void remove(QString jsValueString, QString callbackId);
|
||||
|
||||
Q_INVOKABLE void clear(QString jsValueString, QString callbackId);
|
||||
};
|
||||
|
||||
#endif // DORICSTORAGEPLUGIN_H
|
Reference in New Issue
Block a user