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,15 +83,12 @@ 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
delegate: Rectangle { function getSource(index) : string {
Column {
anchors.centerIn: parent
Text {
text: {
switch (index) { switch (index) {
case 0: case 0:
return "ComponetDemo.js" return "ComponetDemo.js"
@ -141,6 +138,14 @@ ApplicationWindow {
return "TextDemo.js" return "TextDemo.js"
} }
} }
delegate: Rectangle {
Column {
anchors.centerIn: parent
Text {
text: {
return list.getSource(index)
}
} }
} }
width: parent.width width: parent.width
@ -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)
} }
} }
} }