Move sorting of DefinitionContainerModel out of qml

Add printer dialog now has sections by a configurable metadata property. A prefered section is set to always show on top.
Add weights to the Ultimaker printer definitions to create a sensible list (newest on top).

CURA-1593
This commit is contained in:
fieldOfView 2016-08-01 19:17:08 +02:00
parent 0d9d4b88ce
commit 42fc25ab09
8 changed files with 20 additions and 30 deletions

View file

@ -8,6 +8,7 @@
"author": "Ultimaker", "author": "Ultimaker",
"manufacturer": "Ultimaker", "manufacturer": "Ultimaker",
"category": "Ultimaker", "category": "Ultimaker",
"weight": 3,
"file_formats": "text/x-gcode", "file_formats": "text/x-gcode",
"icon": "icon_ultimaker2.png", "icon": "icon_ultimaker2.png",
"platform": "ultimaker2_platform.obj", "platform": "ultimaker2_platform.obj",

View file

@ -7,6 +7,7 @@
"author": "Ultimaker", "author": "Ultimaker",
"manufacturer": "Ultimaker", "manufacturer": "Ultimaker",
"category": "Ultimaker", "category": "Ultimaker",
"weight": 3,
"file_formats": "text/x-gcode", "file_formats": "text/x-gcode",
"icon": "icon_ultimaker2.png", "icon": "icon_ultimaker2.png",
"platform": "ultimaker2_platform.obj", "platform": "ultimaker2_platform.obj",

View file

@ -7,6 +7,7 @@
"author": "Ultimaker", "author": "Ultimaker",
"manufacturer": "Ultimaker", "manufacturer": "Ultimaker",
"category": "Ultimaker", "category": "Ultimaker",
"weight": 2,
"file_formats": "text/x-gcode", "file_formats": "text/x-gcode",
"platform": "ultimaker2_platform.obj", "platform": "ultimaker2_platform.obj",
"platform_texture": "Ultimaker2ExtendedPlusbackplate.png", "platform_texture": "Ultimaker2ExtendedPlusbackplate.png",

View file

@ -7,6 +7,7 @@
"author": "Ultimaker", "author": "Ultimaker",
"manufacturer": "Ultimaker", "manufacturer": "Ultimaker",
"category": "Ultimaker", "category": "Ultimaker",
"weight": 3,
"file_formats": "text/x-gcode", "file_formats": "text/x-gcode",
"icon": "icon_ultimaker2.png", "icon": "icon_ultimaker2.png",
"platform": "ultimaker2go_platform.obj", "platform": "ultimaker2go_platform.obj",

View file

@ -7,6 +7,7 @@
"author": "Ultimaker", "author": "Ultimaker",
"manufacturer": "Ultimaker", "manufacturer": "Ultimaker",
"category": "Ultimaker", "category": "Ultimaker",
"weight": 1,
"file_formats": "text/x-gcode", "file_formats": "text/x-gcode",
"platform": "ultimaker2_platform.obj", "platform": "ultimaker2_platform.obj",
"platform_texture": "Ultimaker2Plusbackplate.png", "platform_texture": "Ultimaker2Plusbackplate.png",

View file

@ -8,6 +8,7 @@
"author": "Ultimaker", "author": "Ultimaker",
"manufacturer": "Ultimaker", "manufacturer": "Ultimaker",
"category": "Ultimaker", "category": "Ultimaker",
"weight": 4,
"file_formats": "text/x-gcode", "file_formats": "text/x-gcode",
"icon": "icon_ultimaker.png", "icon": "icon_ultimaker.png",
"platform": "ultimaker_platform.stl", "platform": "ultimaker_platform.stl",

View file

@ -7,6 +7,7 @@
"author": "Ultimaker", "author": "Ultimaker",
"manufacturer": "Ultimaker", "manufacturer": "Ultimaker",
"category": "Ultimaker", "category": "Ultimaker",
"weight": 4,
"file_formats": "text/x-gcode", "file_formats": "text/x-gcode",
"icon": "icon_ultimaker.png", "icon": "icon_ultimaker.png",
"platform": "ultimaker2_platform.obj", "platform": "ultimaker2_platform.obj",

View file

@ -33,7 +33,7 @@ UM.Dialog
signal machineAdded(string id) signal machineAdded(string id)
function getMachineName() function getMachineName()
{ {
var name = machineList.model.get(machineList.currentIndex) != undefined ? machineList.model.get(machineList.currentIndex).name : "" var name = machineList.model.getItem(machineList.currentIndex) != undefined ? machineList.model.getItem(machineList.currentIndex).name : ""
return name return name
} }
@ -53,27 +53,15 @@ UM.Dialog
{ {
id: machineList id: machineList
model: ListModel model: UM.DefinitionContainersModel
{ {
id: sortedMachineDefinitionsModel id: machineDefinitionsModel
Component.onCompleted: { filter: { "visible": true }
// DefinitionContainersModel is sorted alphabetically, but we want the preferred sectionProperty: "category"
// category on top so we create a custom-sorted ListModel from it. preferredSectionValue: preferredCategory
var items = [];
for(var i in machineDefinitionsModel.items) {
var item = machineDefinitionsModel.getItem(i);
if (item["category"] == preferredCategory)
sortedMachineDefinitionsModel.append(item);
else
items.push(item);
}
for(var i in items) {
sortedMachineDefinitionsModel.append(items[i]);
}
}
} }
section.property: "category" section.property: "section"
section.delegate: Button section.delegate: Button
{ {
text: section text: section
@ -112,11 +100,11 @@ UM.Dialog
onClicked: onClicked:
{ {
base.activeCategory = section; base.activeCategory = section;
if (machineList.model.get(machineList.currentIndex).category != section) { if (machineList.model.getItem(machineList.currentIndex).section != section) {
// Find the first machine from this category // Find the first machine from this section
for(var i = 0; i < sortedMachineDefinitionsModel.count; i++) { for(var i = 0; i < sortedMachineDefinitionsModel.count; i++) {
var item = sortedMachineDefinitionsModel.get(i); var item = sortedMachineDefinitionsModel.getItem(i);
if (item.category == section) { if (item.section == section) {
machineList.currentIndex = i; machineList.currentIndex = i;
break; break;
} }
@ -151,7 +139,7 @@ UM.Dialog
states: State states: State
{ {
name: "collapsed"; name: "collapsed";
when: base.activeCategory != model.category; when: base.activeCategory != model.section;
PropertyChanges { target: machineButton; opacity: 0; height: 0; } PropertyChanges { target: machineButton; opacity: 0; height: 0; }
} }
@ -198,7 +186,7 @@ UM.Dialog
onClicked: onClicked:
{ {
base.visible = false base.visible = false
var item = machineList.model.get(machineList.currentIndex); var item = machineList.model.getItem(machineList.currentIndex);
Cura.MachineManager.addMachine(machineName.text, item.id) Cura.MachineManager.addMachine(machineName.text, item.id)
base.machineAdded(item.id) // Emit signal that the user added a machine. base.machineAdded(item.id) // Emit signal that the user added a machine.
} }
@ -211,11 +199,6 @@ UM.Dialog
id: catalog; id: catalog;
name: "cura"; name: "cura";
} }
UM.DefinitionContainersModel
{
id: machineDefinitionsModel
filter: { "visible": true }
}
SystemPalette { id: palette } SystemPalette { id: palette }
ExclusiveGroup { id: printerGroup; } ExclusiveGroup { id: printerGroup; }
} }