add storage demo & plugin
This commit is contained in:
parent
660d75d1ad
commit
394cbe5962
@ -47,6 +47,9 @@ void DoricDemoBridge::navigate(QVariant route) {
|
||||
case 10:
|
||||
name = "Snake.js";
|
||||
break;
|
||||
case 11:
|
||||
name = "StorageDemo.js";
|
||||
break;
|
||||
}
|
||||
QString script = DoricUtils::readAssetFile("/doric/bundles", name);
|
||||
|
||||
|
@ -14,7 +14,7 @@ int main(int argc, char *argv[]) {
|
||||
QQmlApplicationEngine engine;
|
||||
qmlRegisterType<FlexLayoutService>("pub.doric.widget", 1, 0,
|
||||
"FlexLayoutService");
|
||||
// const QUrl url(QStringLiteral("qrc:/doric/qml/test-layout.qml"));
|
||||
// const QUrl url(QStringLiteral("qrc:/test-layout.qml"));
|
||||
const QUrl url(QStringLiteral("qrc:/main.qml"));
|
||||
QObject::connect(
|
||||
&engine, &QQmlApplicationEngine::objectCreated, &app,
|
||||
|
@ -15,7 +15,7 @@ ApplicationWindow {
|
||||
|
||||
ListView {
|
||||
width: parent.width
|
||||
model: 11
|
||||
model: 12
|
||||
delegate: Rectangle {
|
||||
Column {
|
||||
anchors.centerIn: parent
|
||||
@ -44,6 +44,8 @@ ApplicationWindow {
|
||||
return "SimpleDemo.js"
|
||||
case 10:
|
||||
return "Snake.js"
|
||||
case 11:
|
||||
return "StorageDemo.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
<file alias="PopoverDemo.js">../../../doric-demo/bundle/src/PopoverDemo.js</file>
|
||||
<file alias="SimpleDemo.js">../../../doric-demo/bundle/src/SimpleDemo.js</file>
|
||||
<file alias="Snake.js">../../../doric-demo/bundle/src/Snake.js</file>
|
||||
<file alias="StorageDemo.js">../../../doric-demo/bundle/src/StorageDemo.js</file>
|
||||
</qresource>
|
||||
<qresource prefix="/doric">
|
||||
<file alias="doric-sandbox.js">../../../doric-js/bundle/doric-sandbox.js</file>
|
||||
|
@ -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