From 0c156fdf42b07b985654706efa1533a66093ce2d Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Fri, 17 Apr 2015 11:51:36 +0200 Subject: [PATCH] Pull mode list model out of SidebarHeader and put it into Sidebar This helps with code readability --- qml/Sidebar.qml | 9 ++++++++- qml/SidebarHeader.qml | 11 ++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/qml/Sidebar.qml b/qml/Sidebar.qml index c9f8307218..e21c917f21 100644 --- a/qml/Sidebar.qml +++ b/qml/Sidebar.qml @@ -48,6 +48,7 @@ UM.AngledCornerRectangle { addMachineAction: base.addMachineAction; configureMachinesAction: base.configureMachinesAction; + modesModel: modesListModel; } Loader { @@ -56,7 +57,7 @@ UM.AngledCornerRectangle { Layout.fillWidth: true; Layout.fillHeight: true; - source: header.currentModeFile; + source: modesListModel.get(header.currentModeIndex).file; property Item sidebar: base; @@ -86,4 +87,10 @@ UM.AngledCornerRectangle { SidebarTooltip { id: tooltip; } + + ListModel { + id: modesListModel; + ListElement { text: QT_TR_NOOP("Simple"); file: "SidebarSimple.qml" } + ListElement { text: QT_TR_NOOP("Advanced"); file: "SidebarAdvanced.qml" } + } } diff --git a/qml/SidebarHeader.qml b/qml/SidebarHeader.qml index 903f451403..085fce6e77 100644 --- a/qml/SidebarHeader.qml +++ b/qml/SidebarHeader.qml @@ -8,7 +8,8 @@ import UM 1.0 as UM Column { id: base; - property string currentModeFile: modeModel.get(modeMenu.currentIndex).file; + property variant modesModel; + property alias currentModeIndex: modeMenu.currentIndex; property Action addMachineAction; property Action configureMachinesAction; @@ -28,7 +29,7 @@ Column { } ToolButton { - text: qsTr(modeModel.get(modeMenu.currentIndex).text); + text: base.modesModel ? qsTr(base.modesModel.get(modeMenu.currentIndex).text) : ""; style: UM.Theme.styles.sidebar_header_button; @@ -40,11 +41,7 @@ Column { property int currentIndex: 0; Instantiator { - model: ListModel { - id: modeModel; - ListElement { text: QT_TR_NOOP("Simple"); file: "SidebarSimple.qml" } - ListElement { text: QT_TR_NOOP("Advanced"); file: "SidebarAdvanced.qml" } - } + model: base.modesModel; MenuItem { text: qsTr(model.text);