Rename AbstractStacksModel.py -> MachineListModel.py since this model includes both abstract machine stacks and regular machines

Add machineCount for displaying the number of machines of a type.

MachineSelectorButton is in use in other places, swapped it out for a new Component MachineListButton.

CURA-9514
This commit is contained in:
joeydelarago 2022-08-23 14:29:05 +02:00
parent bedb76d516
commit b18080c332
6 changed files with 104 additions and 11 deletions

View file

@ -115,7 +115,7 @@ from . import CuraActions
from . import PlatformPhysics from . import PlatformPhysics
from . import PrintJobPreviewImageProvider from . import PrintJobPreviewImageProvider
from .AutoSave import AutoSave from .AutoSave import AutoSave
from .Machines.Models.AbstractStacksModel import AbstractStacksModel from .Machines.Models.MachineListModel import MachineListModel
from .Machines.Models.ActiveIntentQualitiesModel import ActiveIntentQualitiesModel from .Machines.Models.ActiveIntentQualitiesModel import ActiveIntentQualitiesModel
from .Machines.Models.IntentSelectionModel import IntentSelectionModel from .Machines.Models.IntentSelectionModel import IntentSelectionModel
from .SingleInstance import SingleInstance from .SingleInstance import SingleInstance
@ -1195,7 +1195,7 @@ class CuraApplication(QtApplication):
qmlRegisterType(InstanceContainer, "Cura", 1, 0, "InstanceContainer") qmlRegisterType(InstanceContainer, "Cura", 1, 0, "InstanceContainer")
qmlRegisterType(ExtrudersModel, "Cura", 1, 0, "ExtrudersModel") qmlRegisterType(ExtrudersModel, "Cura", 1, 0, "ExtrudersModel")
qmlRegisterType(GlobalStacksModel, "Cura", 1, 0, "GlobalStacksModel") qmlRegisterType(GlobalStacksModel, "Cura", 1, 0, "GlobalStacksModel")
qmlRegisterType(AbstractStacksModel, "Cura", 1, 0, "AbstractStacksModel") qmlRegisterType(MachineListModel, "Cura", 1, 0, "MachineListModel")
self.processEvents() self.processEvents()
qmlRegisterType(FavoriteMaterialsModel, "Cura", 1, 0, "FavoriteMaterialsModel") qmlRegisterType(FavoriteMaterialsModel, "Cura", 1, 0, "FavoriteMaterialsModel")

View file

@ -14,7 +14,8 @@ from cura.Settings.AbstractMachine import AbstractMachine
from cura.Settings.CuraContainerRegistry import CuraContainerRegistry from cura.Settings.CuraContainerRegistry import CuraContainerRegistry
from cura.Settings.GlobalStack import GlobalStack from cura.Settings.GlobalStack import GlobalStack
class AbstractStacksModel(ListModel):
class MachineListModel(ListModel):
NameRole = Qt.ItemDataRole.UserRole + 1 NameRole = Qt.ItemDataRole.UserRole + 1
IdRole = Qt.ItemDataRole.UserRole + 2 IdRole = Qt.ItemDataRole.UserRole + 2
HasRemoteConnectionRole = Qt.ItemDataRole.UserRole + 3 HasRemoteConnectionRole = Qt.ItemDataRole.UserRole + 3
@ -24,6 +25,7 @@ class AbstractStacksModel(ListModel):
RemovalWarningRole = Qt.ItemDataRole.UserRole + 7 RemovalWarningRole = Qt.ItemDataRole.UserRole + 7
IsOnlineRole = Qt.ItemDataRole.UserRole + 8 IsOnlineRole = Qt.ItemDataRole.UserRole + 8
MachineTypeRole = Qt.ItemDataRole.UserRole + 9 MachineTypeRole = Qt.ItemDataRole.UserRole + 9
MachineCountRole = Qt.ItemDataRole.UserRole + 10
def __init__(self, parent=None) -> None: def __init__(self, parent=None) -> None:
super().__init__(parent) super().__init__(parent)
@ -37,6 +39,7 @@ class AbstractStacksModel(ListModel):
self.addRoleName(self.DiscoverySourceRole, "discoverySource") self.addRoleName(self.DiscoverySourceRole, "discoverySource")
self.addRoleName(self.IsOnlineRole, "isOnline") self.addRoleName(self.IsOnlineRole, "isOnline")
self.addRoleName(self.MachineTypeRole, "machineType") self.addRoleName(self.MachineTypeRole, "machineType")
self.addRoleName(self.MachineCountRole, "machineCount")
self._change_timer = QTimer() self._change_timer = QTimer()
self._change_timer.setInterval(200) self._change_timer.setInterval(200)
@ -71,7 +74,7 @@ class AbstractStacksModel(ListModel):
# Create item for abstract printer # Create item for abstract printer
items.append(self.createItem(abstract_machine)) items.append(self.createItem(abstract_machine, len(machine_stacks)))
# Create list of printers that are children of the abstract printer # Create list of printers that are children of the abstract printer
for stack in machine_stacks: for stack in machine_stacks:
@ -81,7 +84,7 @@ class AbstractStacksModel(ListModel):
self.setItems(items) self.setItems(items)
def createItem(self, container_stack: ContainerStack) -> Optional[Dict]: def createItem(self, container_stack: ContainerStack, machine_count: int = 0) -> Optional[Dict]:
if parseBool(container_stack.getMetaDataEntry("hidden", False)): if parseBool(container_stack.getMetaDataEntry("hidden", False)):
return return
@ -105,4 +108,5 @@ class AbstractStacksModel(ListModel):
"removalWarning": container_stack.getMetaDataEntry("removal_warning", default_removal_warning), "removalWarning": container_stack.getMetaDataEntry("removal_warning", default_removal_warning),
"isOnline": container_stack.getMetaDataEntry("is_online", False), "isOnline": container_stack.getMetaDataEntry("is_online", False),
"machineType": container_stack.getMetaDataEntry("type"), "machineType": container_stack.getMetaDataEntry("type"),
"machineCount": machine_count,
} }

View file

@ -0,0 +1,88 @@
// Copyright (c) 2018 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.10
import QtQuick.Controls 2.3
import UM 1.5 as UM
import Cura 1.0 as Cura
Button
{
id: machineListButton
width: parent.width
height: UM.Theme.getSize("large_button").height
leftPadding: UM.Theme.getSize("default_margin").width
rightPadding: UM.Theme.getSize("default_margin").width
checkable: true
hoverEnabled: true
contentItem: Item
{
width: machineListButton.width - machineListButton.leftPadding - machineListButton.rightPadding
height: UM.Theme.getSize("action_button").height
UM.ColorImage
{
id: printerIcon
height: UM.Theme.getSize("medium_button").height
width: UM.Theme.getSize("medium_button").width
color: UM.Theme.getColor("machine_selector_printer_icon")
visible: model.machineType == "abstract_machine"
source: model.machineType == "abstract_machine" ? UM.Theme.getIcon("PrinterTriple", "medium") : UM.Theme.getIcon("Printer", "medium")
anchors
{
left: parent.left
verticalCenter: parent.verticalCenter
}
}
UM.Label
{
id: buttonText
anchors
{
left: printerIcon.right
right: printerCount.left
verticalCenter: parent.verticalCenter
leftMargin: UM.Theme.getSize("default_margin").width
}
text: machineListButton.text
font: model.machineType == "abstract_machine" ? UM.Theme.getFont("medium_bold") : UM.Theme.getFont("medium")
visible: text != ""
elide: Text.ElideRight
}
Rectangle
{
id: printerCount
color: UM.Theme.getColor("background_2")
radius: height
width: height
anchors
{
right: parent.right
top: buttonText.top
bottom: buttonText.bottom
verticalCenter: parent.verticalCenter
}
visible: model.machineType == "abstract_machine"
UM.Label
{
text: model.machineCount
anchors.centerIn: parent
font: UM.Theme.getFont("default_bold")
}
}
}
background: Rectangle
{
id: backgroundRect
color: machineListButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
}
}

View file

@ -10,8 +10,8 @@ import Cura 1.0 as Cura
ListView ListView
{ {
id: listView id: listView
model: Cura.AbstractStacksModel {} model: Cura.MachineListModel {}
section.property: "hasRemoteConnection" section.property: "section"
property real contentHeight: childrenRect.height property real contentHeight: childrenRect.height
ScrollBar.vertical: UM.ScrollBar ScrollBar.vertical: UM.ScrollBar
@ -29,13 +29,10 @@ ListView
color: UM.Theme.getColor("text_medium") color: UM.Theme.getColor("text_medium")
} }
delegate: MachineSelectorButton delegate: MachineListButton
{ {
text: model.name ? model.name : "" text: model.name ? model.name : ""
width: listView.width - scrollBar.width width: listView.width - scrollBar.width
outputDevice: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null
checked: Cura.MachineManager.activeMachine ? Cura.MachineManager.activeMachine.id == model.id : false
onClicked: onClicked:
{ {

View file

@ -2,6 +2,7 @@ module Cura
MachineSelector 1.0 MachineSelector.qml MachineSelector 1.0 MachineSelector.qml
MachineSelectorButton 1.0 MachineSelectorButton.qml MachineSelectorButton 1.0 MachineSelectorButton.qml
MachineListButton 1.0 MachineListButton.qml
CustomConfigurationSelector 1.0 CustomConfigurationSelector.qml CustomConfigurationSelector 1.0 CustomConfigurationSelector.qml
PrintSetupSelector 1.0 PrintSetupSelector.qml PrintSetupSelector 1.0 PrintSetupSelector.qml
ProfileOverview 1.6 ProfileOverview.qml ProfileOverview 1.6 ProfileOverview.qml

View file

@ -564,6 +564,9 @@
"medium_button": [2.5, 2.5], "medium_button": [2.5, 2.5],
"medium_button_icon": [2, 2], "medium_button_icon": [2, 2],
"large_button": [3.5, 3.5],
"large_button_icon": [2.8, 2.8],
"context_menu": [20, 2], "context_menu": [20, 2],
"icon_indicator": [1, 1], "icon_indicator": [1, 1],