mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 15:37:27 -06:00
Make ExtruderManager a QML context item
There were two singletons of this manager: One created by QML and managed by QML, and one created by us and managed by our own singleton pattern. That won't work! So we now manage just our own singleton type, and make it a context item for QML so it can use the manager too. Contributes to issues CURA-340 and CURA-1278.
This commit is contained in:
parent
9fe5435963
commit
dff94b4559
4 changed files with 8 additions and 9 deletions
|
@ -353,8 +353,6 @@ class CuraApplication(QtApplication):
|
||||||
|
|
||||||
qmlRegisterSingletonType(MachineManagerModel.MachineManagerModel, "Cura", 1, 0, "MachineManager",
|
qmlRegisterSingletonType(MachineManagerModel.MachineManagerModel, "Cura", 1, 0, "MachineManager",
|
||||||
MachineManagerModel.createMachineManagerModel)
|
MachineManagerModel.createMachineManagerModel)
|
||||||
qmlRegisterSingletonType(ExtruderManager.ExtruderManager, "Cura", 1, 0, "ExtruderManager",
|
|
||||||
ExtruderManager.createExtruderManager)
|
|
||||||
|
|
||||||
self.setMainQml(Resources.getPath(self.ResourceTypes.QmlFiles, "Cura.qml"))
|
self.setMainQml(Resources.getPath(self.ResourceTypes.QmlFiles, "Cura.qml"))
|
||||||
self._qml_import_paths.append(Resources.getPath(self.ResourceTypes.QmlFiles))
|
self._qml_import_paths.append(Resources.getPath(self.ResourceTypes.QmlFiles))
|
||||||
|
@ -386,6 +384,9 @@ class CuraApplication(QtApplication):
|
||||||
def getPrintInformation(self):
|
def getPrintInformation(self):
|
||||||
return self._print_information
|
return self._print_information
|
||||||
|
|
||||||
|
## Registers objects for the QML engine to use.
|
||||||
|
#
|
||||||
|
# \param engine The QML engine.
|
||||||
def registerObjects(self, engine):
|
def registerObjects(self, engine):
|
||||||
engine.rootContext().setContextProperty("Printer", self)
|
engine.rootContext().setContextProperty("Printer", self)
|
||||||
self._print_information = PrintInformation.PrintInformation()
|
self._print_information = PrintInformation.PrintInformation()
|
||||||
|
@ -399,6 +400,8 @@ class CuraApplication(QtApplication):
|
||||||
|
|
||||||
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())
|
||||||
|
|
||||||
for path in Resources.getAllResourcesOfType(CuraApplication.ResourceTypes.QmlFiles):
|
for path in Resources.getAllResourcesOfType(CuraApplication.ResourceTypes.QmlFiles):
|
||||||
type_name = os.path.splitext(os.path.basename(path))[0]
|
type_name = os.path.splitext(os.path.basename(path))[0]
|
||||||
if type_name in ("Cura", "Actions"):
|
if type_name in ("Cura", "Actions"):
|
||||||
|
|
|
@ -76,7 +76,7 @@ class ExtruderManager(QObject):
|
||||||
|
|
||||||
#Add the extruder trains that don't exist yet.
|
#Add the extruder trains that don't exist yet.
|
||||||
for position, extruder_definition_id in machine_definition.getMetaDataEntry("machine_extruder_trains", default = {}).items():
|
for position, extruder_definition_id in machine_definition.getMetaDataEntry("machine_extruder_trains", default = {}).items():
|
||||||
extruder_definition = container_registry.findDefinitionContainers(id = extruder_definition_id)
|
extruder_definition = container_registry.findDefinitionContainers(machine = machine_definition.getId())
|
||||||
if extruder_definition:
|
if extruder_definition:
|
||||||
extruder_definition = extruder_definition[0]
|
extruder_definition = extruder_definition[0]
|
||||||
else:
|
else:
|
||||||
|
@ -194,7 +194,3 @@ class ExtruderManager(QObject):
|
||||||
i += 1 # Try next numbering.
|
i += 1 # Try next numbering.
|
||||||
unique_name = "%s #%d" % (name, i) # Fill name like this: "Extruder #2".
|
unique_name = "%s #%d" % (name, i) # Fill name like this: "Extruder #2".
|
||||||
return unique_name
|
return unique_name
|
||||||
|
|
||||||
|
|
||||||
def createExtruderManager(engine, script_engine):
|
|
||||||
return ExtruderManager()
|
|
|
@ -80,7 +80,7 @@ ScrollView
|
||||||
{
|
{
|
||||||
id: provider
|
id: provider
|
||||||
|
|
||||||
containerStackId: Cura.ExtruderManager.activeExtruderStackId ? Cura.ExtruderManager.activeExtruderStackId : Cura.MachineManager.activeMachineId
|
containerStackId: ExtruderManager.activeExtruderStackId ? ExtruderManager.activeExtruderStackId : Cura.MachineManager.activeMachineId
|
||||||
key: model.key
|
key: model.key
|
||||||
watchedProperties: [ "value", "enabled", "state", "validationState" ]
|
watchedProperties: [ "value", "enabled", "state", "validationState" ]
|
||||||
storeIndex: 0
|
storeIndex: 0
|
||||||
|
|
|
@ -111,7 +111,7 @@ Item
|
||||||
onClicked:
|
onClicked:
|
||||||
{
|
{
|
||||||
base.currentExtruderIndex = index
|
base.currentExtruderIndex = index
|
||||||
Cura.ExtruderManager.setActiveExtruderIndex(index)
|
ExtruderManager.setActiveExtruderIndex(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
style: ButtonStyle {
|
style: ButtonStyle {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue