From 2e5868cb827e9dde6976fea2bf22b9335ecc11f3 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Mon, 21 Mar 2016 13:47:14 +0100 Subject: [PATCH] Removed separators from profilesmodel Profile menu now inserts separators in QML CURA-855 --- resources/qml/Cura.qml | 42 +++++++++++++++++++++++----------- resources/qml/ProfileSetup.qml | 40 ++++++++++++++++++++++---------- 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index af73c66c87..eb1a3886c8 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -215,26 +215,42 @@ UM.MainWindow Instantiator { id: profileMenuInstantiator - model: UM.ProfilesModel { addSeparators: true } + model: UM.ProfilesModel {} + property int separatorIndex: -1 + Loader { property QtObject model_data: model property int model_index: index - sourceComponent: model.separator ? profileMenuSeparatorDelegate : profileMenuItemDelegate + sourceComponent: profileMenuItemDelegate + } + + onObjectAdded: + { + //Insert a separator between readonly and custom profiles + if(separatorIndex < 0 && index > 0) { + if(model.getItem(index-1).readOnly != model.getItem(index).readOnly) { + profileMenu.addSeparator(); + separatorIndex = index; + } + } + //Because of the separator, custom profiles move one index lower + profileMenu.insertItem((model.getItem(index).readOnly) ? index : index + 1, object.item); + } + onObjectRemoved: + { + //When adding a profile, the menu is rebuild by removing all items. + //If a separator was added, we need to remove that too. + if(separatorIndex >= 0) + { + profileMenu.removeItem(profileMenu.items[separatorIndex]) + separatorIndex = -1; + } + profileMenu.removeItem(object.item); } - onObjectAdded: profileMenu.insertItem(index, object.item) - onObjectRemoved: profileMenu.removeItem(object.item) } ExclusiveGroup { id: profileMenuGroup; } - Component - { - id: profileMenuSeparatorDelegate - MenuSeparator { - id: item - } - } - Component { id: profileMenuItemDelegate @@ -259,7 +275,7 @@ UM.MainWindow } } - MenuSeparator { } + MenuSeparator { id: profileMenuSeparator } MenuItem { action: actions.addProfile; } MenuItem { action: actions.manageProfiles; } diff --git a/resources/qml/ProfileSetup.qml b/resources/qml/ProfileSetup.qml index c0337f3b26..194ffce807 100644 --- a/resources/qml/ProfileSetup.qml +++ b/resources/qml/ProfileSetup.qml @@ -51,23 +51,40 @@ Item{ Instantiator { id: profileSelectionInstantiator - model: UM.ProfilesModel { addSeparators: true } + model: UM.ProfilesModel {} + property int separatorIndex: -1 + Loader { property QtObject model_data: model property int model_index: index - sourceComponent: model.separator ? menuSeparatorDelegate : menuItemDelegate + sourceComponent: menuItemDelegate + } + onObjectAdded: + { + //Insert a separator between readonly and custom profiles + if(separatorIndex < 0 && index > 0) { + if(model.getItem(index-1).readOnly != model.getItem(index).readOnly) { + profileSelectionMenu.addSeparator(); + separatorIndex = index; + } + } + //Because of the separator, custom profiles move one index lower + profileSelectionMenu.insertItem((model.getItem(index).readOnly) ? index : index + 1, object.item); + } + onObjectRemoved: + { + //When adding a profile, the menu is rebuild by removing all items. + //If a separator was added, we need to remove that too. + if(separatorIndex >= 0) + { + profileSelectionMenu.removeItem(profileSelectionMenu.items[separatorIndex]) + separatorIndex = -1; + } + profileSelectionMenu.removeItem(object.item); } - onObjectAdded: profileSelectionMenu.insertItem(index, object.item) - onObjectRemoved: profileSelectionMenu.removeItem(object.item) } ExclusiveGroup { id: profileSelectionMenuGroup; } - Component - { - id: menuSeparatorDelegate - MenuSeparator { - id: item - } - } + Component { id: menuItemDelegate @@ -92,7 +109,6 @@ Item{ } } - MenuSeparator { } MenuItem { action: base.addProfileAction;