remove redundant code

This commit is contained in:
王劲鹏 2021-06-10 14:06:36 +08:00 committed by osborn
parent 7df3e61f9d
commit a62d0369c5
3 changed files with 59 additions and 127 deletions

View File

@ -37,83 +37,9 @@ DoricDemoBridge::DoricDemoBridge(QQmlApplicationEngine *engine, QObject *parent)
context->setContextProperty("draggableBridge", draggableBridge); context->setContextProperty("draggableBridge", draggableBridge);
} }
void DoricDemoBridge::navigate(QVariant path, QVariant index) { void DoricDemoBridge::navigate(QVariant source, QVariant alias) {
QString name;
switch (index.toInt()) {
case 0:
name = "ComponetDemo.js";
break;
case 1:
name = "Counter.js";
break;
case 2:
name = "DraggableDemo.js";
break;
case 3:
name = "EffectsDemo.js";
break;
case 4:
name = "FlexDemo.js";
break;
case 5:
name = "Gobang.js";
break;
case 6:
name = "ImageDemo.js";
break;
case 7:
name = "InputDemo.js";
break;
case 8:
name = "LayoutDemo.js";
break;
case 9:
name = "LayoutTestDemo.js";
break;
case 10:
name = "ModalDemo.js";
break;
case 11:
name = "ModularDemo.js";
break;
case 12:
name = "NavigatorDemo.js";
break;
case 13:
name = "NetworkDemo.js";
break;
case 14:
name = "NotificationDemo.js";
break;
case 15:
name = "PopoverDemo.js";
break;
case 16:
name = "ScrollerDemo.js";
break;
case 17:
name = "SimpleDemo.js";
break;
case 18:
name = "SliderDemo.js";
break;
case 19:
name = "Snake.js";
break;
case 20:
name = "StorageDemo.js";
break;
case 21:
name = "SwitchDemo.js";
break;
case 22:
name = "TextDemo.js";
break;
}
QString resourcePath = path.toString();
std::shared_ptr<DoricAsyncResult> asyncResult = std::shared_ptr<DoricAsyncResult> asyncResult =
DoricJSLoaderManager::getInstance()->request(resourcePath + name); DoricJSLoaderManager::getInstance()->request(source.toString());
QString script = asyncResult->getResult(); QString script = asyncResult->getResult();
@ -125,7 +51,7 @@ void DoricDemoBridge::navigate(QVariant path, QVariant index) {
DoricPanel *panel = new DoricPanel(mEngine, quickItem); DoricPanel *panel = new DoricPanel(mEngine, quickItem);
quickItem->setWidth(600); quickItem->setWidth(600);
quickItem->setHeight(800); quickItem->setHeight(800);
panel->config(script, name, NULL); panel->config(script, alias.toString(), NULL);
QObject *window = mEngine->rootObjects().at(0); QObject *window = mEngine->rootObjects().at(0);
QVariant arg = QVariant::fromValue(object); QVariant arg = QVariant::fromValue(object);

View File

@ -11,7 +11,7 @@ public:
QObject *parent = nullptr); QObject *parent = nullptr);
Q_INVOKABLE Q_INVOKABLE
void navigate(QVariant path, QVariant index); void navigate(QVariant source, QVariant alias);
private: private:
QQmlApplicationEngine *mEngine; QQmlApplicationEngine *mEngine;

View File

@ -83,63 +83,68 @@ ApplicationWindow {
ScrollBar.vertical.policy: ScrollBar.AlwaysOff ScrollBar.vertical.policy: ScrollBar.AlwaysOff
ListView { ListView {
id: list
width: parent.width width: parent.width
model: 23 model: 23
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
function getSource(index) : string {
switch (index) {
case 0:
return "ComponetDemo.js"
case 1:
return "Counter.js"
case 2:
return "DraggableDemo.js"
case 3:
return "EffectsDemo.js"
case 4:
return "FlexDemo.js"
case 5:
return "Gobang.js"
case 6:
return "ImageDemo.js"
case 7:
return "InputDemo.js"
case 8:
return "LayoutDemo.js"
case 9:
return "LayoutTestDemo.js"
case 10:
return "ModalDemo.js"
case 11:
return "ModularDemo.js"
case 12:
return "NavigatorDemo.js"
case 13:
return "NetworkDemo.js"
case 14:
return "NotificationDemo.js"
case 15:
return "PopoverDemo.js"
case 16:
return "ScrollerDemo.js"
case 17:
return "SimpleDemo.js"
case 18:
return "SliderDemo.js"
case 19:
return "Snake.js"
case 20:
return "StorageDemo.js"
case 21:
return "SwitchDemo.js"
case 22:
return "TextDemo.js"
}
}
delegate: Rectangle { delegate: Rectangle {
Column { Column {
anchors.centerIn: parent anchors.centerIn: parent
Text { Text {
text: { text: {
switch (index) { return list.getSource(index)
case 0:
return "ComponetDemo.js"
case 1:
return "Counter.js"
case 2:
return "DraggableDemo.js"
case 3:
return "EffectsDemo.js"
case 4:
return "FlexDemo.js"
case 5:
return "Gobang.js"
case 6:
return "ImageDemo.js"
case 7:
return "InputDemo.js"
case 8:
return "LayoutDemo.js"
case 9:
return "LayoutTestDemo.js"
case 10:
return "ModalDemo.js"
case 11:
return "ModularDemo.js"
case 12:
return "NavigatorDemo.js"
case 13:
return "NetworkDemo.js"
case 14:
return "NotificationDemo.js"
case 15:
return "PopoverDemo.js"
case 16:
return "ScrollerDemo.js"
case 17:
return "SimpleDemo.js"
case 18:
return "SliderDemo.js"
case 19:
return "Snake.js"
case 20:
return "StorageDemo.js"
case 21:
return "SwitchDemo.js"
case 22:
return "TextDemo.js"
}
} }
} }
} }
@ -148,7 +153,8 @@ ApplicationWindow {
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
demoBridge.navigate("assets://src/", index) let source = list.getSource(index)
demoBridge.navigate("assets://src/" + source, source)
} }
} }
} }