mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-24 23:23:57 -06:00
Show quality profile and user profile settings side-by-side on Profiles manager
Introduces ContainerSettingsModel, which can combine the settings of instances from multiple containers into one model. Towards CURA-1668
This commit is contained in:
parent
8608468802
commit
485ae53660
3 changed files with 115 additions and 3 deletions
104
cura/ContainerSettingsModel.py
Normal file
104
cura/ContainerSettingsModel.py
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
from UM.Application import Application
|
||||||
|
from UM.Qt.ListModel import ListModel
|
||||||
|
|
||||||
|
from PyQt5.QtCore import pyqtProperty, Qt, pyqtSignal, pyqtSlot, QUrl
|
||||||
|
|
||||||
|
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
|
from UM.Settings.InstanceContainer import InstanceContainer
|
||||||
|
|
||||||
|
class ContainerSettingsModel(ListModel):
|
||||||
|
LabelRole = Qt.UserRole + 1
|
||||||
|
CategoryRole = Qt.UserRole + 2
|
||||||
|
UnitRole = Qt.UserRole + 3
|
||||||
|
ValuesRole = Qt.UserRole + 4
|
||||||
|
|
||||||
|
def __init__(self, parent = None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.addRoleName(self.LabelRole, "label")
|
||||||
|
self.addRoleName(self.CategoryRole, "category")
|
||||||
|
self.addRoleName(self.UnitRole, "unit")
|
||||||
|
self.addRoleName(self.ValuesRole, "values")
|
||||||
|
|
||||||
|
self._container_ids = []
|
||||||
|
self._container = None
|
||||||
|
|
||||||
|
self._global_container_stack = None
|
||||||
|
Application.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerChanged)
|
||||||
|
self._update()
|
||||||
|
|
||||||
|
def _onGlobalContainerChanged(self):
|
||||||
|
if self._global_container_stack:
|
||||||
|
self._global_container_stack.containersChanged.disconnect(self._onInstanceContainersChanged)
|
||||||
|
self._global_container_stack.propertyChanged.disconnect(self._onGlobalPropertyChanged)
|
||||||
|
|
||||||
|
self._global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||||
|
|
||||||
|
if self._global_container_stack:
|
||||||
|
Preferences.getInstance().setValue("cura/active_machine", self._global_container_stack.getId())
|
||||||
|
self._global_container_stack.containersChanged.connect(self._onInstanceContainersChanged)
|
||||||
|
self._global_container_stack.propertyChanged.connect(self._onGlobalPropertyChanged)
|
||||||
|
|
||||||
|
self._update()
|
||||||
|
|
||||||
|
def _onGlobalPropertyChanged(self, key, property_name):
|
||||||
|
if property_name == "value":
|
||||||
|
self._update()
|
||||||
|
|
||||||
|
def _onInstanceContainersChanged(self, container):
|
||||||
|
self._update()
|
||||||
|
|
||||||
|
def _update(self):
|
||||||
|
self.clear()
|
||||||
|
|
||||||
|
if len(self._container_ids) == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
keys = []
|
||||||
|
containers = []
|
||||||
|
for container_id in self._container_ids:
|
||||||
|
container = ContainerRegistry.getInstance().findContainers(id = container_id)
|
||||||
|
if not container:
|
||||||
|
return
|
||||||
|
|
||||||
|
keys = keys + list(container[0].getAllKeys())
|
||||||
|
containers.append(container[0])
|
||||||
|
|
||||||
|
keys = list(set(keys))
|
||||||
|
keys.sort()
|
||||||
|
|
||||||
|
for key in keys:
|
||||||
|
definition = None
|
||||||
|
category = None
|
||||||
|
values = []
|
||||||
|
for container in containers:
|
||||||
|
|
||||||
|
instance = container.getInstance(key)
|
||||||
|
if instance:
|
||||||
|
definition = instance.definition
|
||||||
|
|
||||||
|
# Traverse up to find the category
|
||||||
|
category = definition
|
||||||
|
while category.type != "category":
|
||||||
|
category = category.parent
|
||||||
|
|
||||||
|
values.append(container.getProperty(key, "value"))
|
||||||
|
else:
|
||||||
|
values.append("")
|
||||||
|
|
||||||
|
self.appendItem({
|
||||||
|
"key": key,
|
||||||
|
"values": values,
|
||||||
|
"label": definition.label,
|
||||||
|
"unit": definition.unit,
|
||||||
|
"category": category.label
|
||||||
|
})
|
||||||
|
|
||||||
|
## Set the id of the container which has the settings this model should list.
|
||||||
|
def setContainers(self, container_ids):
|
||||||
|
self._container_ids = container_ids
|
||||||
|
self._update()
|
||||||
|
|
||||||
|
containersChanged = pyqtSignal()
|
||||||
|
@pyqtProperty("QVariantList", fset = setContainers, notify = containersChanged)
|
||||||
|
def containers(self):
|
||||||
|
return self.container_ids
|
|
@ -42,6 +42,7 @@ from . import MultiMaterialDecorator
|
||||||
from . import ZOffsetDecorator
|
from . import ZOffsetDecorator
|
||||||
from . import CuraSplashScreen
|
from . import CuraSplashScreen
|
||||||
from . import MachineManagerModel
|
from . import MachineManagerModel
|
||||||
|
from . import ContainerSettingsModel
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty, QEvent, Q_ENUMS
|
from PyQt5.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty, QEvent, Q_ENUMS
|
||||||
from PyQt5.QtGui import QColor, QIcon
|
from PyQt5.QtGui import QColor, QIcon
|
||||||
|
@ -400,6 +401,8 @@ class CuraApplication(QtApplication):
|
||||||
|
|
||||||
qmlRegisterType(ExtrudersModel.ExtrudersModel, "Cura", 1, 0, "ExtrudersModel")
|
qmlRegisterType(ExtrudersModel.ExtrudersModel, "Cura", 1, 0, "ExtrudersModel")
|
||||||
|
|
||||||
|
qmlRegisterType(ContainerSettingsModel.ContainerSettingsModel, "Cura", 1, 0, "ContainerSettingsModel")
|
||||||
|
|
||||||
qmlRegisterSingletonType(QUrl.fromLocalFile(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "Actions.qml")), "Cura", 1, 0, "Actions")
|
qmlRegisterSingletonType(QUrl.fromLocalFile(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "Actions.qml")), "Cura", 1, 0, "Actions")
|
||||||
|
|
||||||
engine.rootContext().setContextProperty("ExtruderManager", ExtruderManager.ExtruderManager.getInstance())
|
engine.rootContext().setContextProperty("ExtruderManager", ExtruderManager.ExtruderManager.getInstance())
|
||||||
|
|
|
@ -128,16 +128,21 @@ UM.ManagementPage
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
model: base.currentItem ? base.currentItem.settings: null
|
model: Cura.ContainerSettingsModel{ containers: [base.currentItem.id, Cura.MachineManager.activeUserProfileId] }
|
||||||
delegate: Row {
|
delegate: Row {
|
||||||
|
property variant setting: model
|
||||||
spacing: UM.Theme.getSize("default_margin").width
|
spacing: UM.Theme.getSize("default_margin").width
|
||||||
Label {
|
Label {
|
||||||
text: model.label
|
text: model.label
|
||||||
elide: Text.ElideMiddle
|
elide: Text.ElideMiddle
|
||||||
width: scrollView.width / 100 * 40
|
width: scrollView.width / 100 * 40
|
||||||
}
|
}
|
||||||
|
Repeater {
|
||||||
|
model: setting.values.length
|
||||||
Label {
|
Label {
|
||||||
text: model.value.toString()
|
text: setting.values[index].toString()
|
||||||
|
width: scrollView.width / 100 * 10
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Label {
|
Label {
|
||||||
text: model.unit
|
text: model.unit
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue