mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-14 23:06:13 +08:00
Reduce number of QML singletons
This commit is contained in:
parent
b415a36110
commit
392f729731
@ -2,6 +2,8 @@
|
|||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
#Type hinting.
|
#Type hinting.
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from PyQt5.QtCore import QObject
|
||||||
from PyQt5.QtNetwork import QLocalServer
|
from PyQt5.QtNetwork import QLocalServer
|
||||||
from PyQt5.QtNetwork import QLocalSocket
|
from PyQt5.QtNetwork import QLocalSocket
|
||||||
|
|
||||||
@ -859,11 +861,13 @@ class CuraApplication(QtApplication):
|
|||||||
self._object_manager = ObjectsModel.createObjectsModel()
|
self._object_manager = ObjectsModel.createObjectsModel()
|
||||||
return self._object_manager
|
return self._object_manager
|
||||||
|
|
||||||
|
@pyqtSlot(result = QObject)
|
||||||
def getMultiBuildPlateModel(self, *args):
|
def getMultiBuildPlateModel(self, *args):
|
||||||
if self._multi_build_plate_model is None:
|
if self._multi_build_plate_model is None:
|
||||||
self._multi_build_plate_model = MultiBuildPlateModel(self)
|
self._multi_build_plate_model = MultiBuildPlateModel(self)
|
||||||
return self._multi_build_plate_model
|
return self._multi_build_plate_model
|
||||||
|
|
||||||
|
@pyqtSlot(result = QObject)
|
||||||
def getBuildPlateModel(self, *args):
|
def getBuildPlateModel(self, *args):
|
||||||
if self._build_plate_model is None:
|
if self._build_plate_model is None:
|
||||||
self._build_plate_model = BuildPlateModel(self)
|
self._build_plate_model = BuildPlateModel(self)
|
||||||
@ -936,8 +940,8 @@ class CuraApplication(QtApplication):
|
|||||||
qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, "MachineActionManager", self.getMachineActionManager)
|
qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, "MachineActionManager", self.getMachineActionManager)
|
||||||
|
|
||||||
qmlRegisterSingletonType(ObjectsModel, "Cura", 1, 0, "ObjectsModel", self.getObjectsModel)
|
qmlRegisterSingletonType(ObjectsModel, "Cura", 1, 0, "ObjectsModel", self.getObjectsModel)
|
||||||
qmlRegisterSingletonType(BuildPlateModel, "Cura", 1, 0, "BuildPlateModel", self.getBuildPlateModel)
|
qmlRegisterType(BuildPlateModel, "Cura", 1, 0, "BuildPlateModel")
|
||||||
qmlRegisterSingletonType(MultiBuildPlateModel, "Cura", 1, 0, "MultiBuildPlateModel", self.getMultiBuildPlateModel)
|
qmlRegisterType(MultiBuildPlateModel, "Cura", 1, 0, "MultiBuildPlateModel")
|
||||||
qmlRegisterType(InstanceContainer, "Cura", 1, 0, "InstanceContainer")
|
qmlRegisterType(InstanceContainer, "Cura", 1, 0, "InstanceContainer")
|
||||||
qmlRegisterType(ExtrudersModel, "Cura", 1, 0, "ExtrudersModel")
|
qmlRegisterType(ExtrudersModel, "Cura", 1, 0, "ExtrudersModel")
|
||||||
|
|
||||||
|
@ -12,17 +12,19 @@ Menu
|
|||||||
id: menu
|
id: menu
|
||||||
title: "Build plate"
|
title: "Build plate"
|
||||||
|
|
||||||
|
property Cura.BuildPlateModel buildPlateModel: CuraApplication.getBuildPlateModel()
|
||||||
|
|
||||||
Instantiator
|
Instantiator
|
||||||
{
|
{
|
||||||
model: Cura.BuildPlateModel
|
model: menu.buildPlateModel
|
||||||
|
|
||||||
MenuItem {
|
MenuItem {
|
||||||
text: model.name
|
text: model.name
|
||||||
checkable: true
|
checkable: true
|
||||||
checked: model.name == Cura.MachineManager.globalVariantName // TODO
|
checked: model.name == Cura.MachineManager.globalVariantName
|
||||||
exclusiveGroup: group
|
exclusiveGroup: group
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
Cura.MachineManager.setGlobalVariant(model.container_node); // TODO
|
Cura.MachineManager.setGlobalVariant(model.container_node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@ Menu
|
|||||||
|
|
||||||
property bool shouldShowExtruders: machineExtruderCount.properties.value > 1;
|
property bool shouldShowExtruders: machineExtruderCount.properties.value > 1;
|
||||||
|
|
||||||
|
property Cura.MultiBuildPlateModel multiBuildPlateModel: CuraApplication.getMultiBuildPlateModel()
|
||||||
|
|
||||||
// Selection-related actions.
|
// Selection-related actions.
|
||||||
MenuItem { action: Cura.Actions.centerSelection; }
|
MenuItem { action: Cura.Actions.centerSelection; }
|
||||||
MenuItem { action: Cura.Actions.deleteSelection; }
|
MenuItem { action: Cura.Actions.deleteSelection; }
|
||||||
@ -45,13 +47,13 @@ Menu
|
|||||||
|
|
||||||
Instantiator
|
Instantiator
|
||||||
{
|
{
|
||||||
model: Cura.MultiBuildPlateModel
|
model: base.multiBuildPlateModel
|
||||||
MenuItem {
|
MenuItem {
|
||||||
enabled: UM.Selection.hasSelection
|
enabled: UM.Selection.hasSelection
|
||||||
text: Cura.MultiBuildPlateModel.getItem(index).name;
|
text: base.multiBuildPlateModel.getItem(index).name;
|
||||||
onTriggered: CuraActions.setBuildPlateForSelection(Cura.MultiBuildPlateModel.getItem(index).buildPlateNumber);
|
onTriggered: CuraActions.setBuildPlateForSelection(base.multiBuildPlateModel.getItem(index).buildPlateNumber);
|
||||||
checkable: true
|
checkable: true
|
||||||
checked: Cura.MultiBuildPlateModel.selectionBuildPlates.indexOf(Cura.MultiBuildPlateModel.getItem(index).buildPlateNumber) != -1;
|
checked: base.multiBuildPlateModel.selectionBuildPlates.indexOf(base.multiBuildPlateModel.getItem(index).buildPlateNumber) != -1;
|
||||||
visible: UM.Preferences.getValue("cura/use_multi_build_plate")
|
visible: UM.Preferences.getValue("cura/use_multi_build_plate")
|
||||||
}
|
}
|
||||||
onObjectAdded: base.insertItem(index, object);
|
onObjectAdded: base.insertItem(index, object);
|
||||||
@ -62,7 +64,7 @@ Menu
|
|||||||
enabled: UM.Selection.hasSelection
|
enabled: UM.Selection.hasSelection
|
||||||
text: "New build plate";
|
text: "New build plate";
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
CuraActions.setBuildPlateForSelection(Cura.MultiBuildPlateModel.maxBuildPlate + 1);
|
CuraActions.setBuildPlateForSelection(base.multiBuildPlateModel.maxBuildPlate + 1);
|
||||||
checked = false;
|
checked = false;
|
||||||
}
|
}
|
||||||
checkable: true
|
checkable: true
|
||||||
|
@ -13,6 +13,8 @@ Menu
|
|||||||
id: base
|
id: base
|
||||||
enabled: !PrintInformation.preSliced
|
enabled: !PrintInformation.preSliced
|
||||||
|
|
||||||
|
property Cura.MultiBuildPlateModel multiBuildPlateModel: CuraApplication.getMultiBuildPlateModel()
|
||||||
|
|
||||||
// main views
|
// main views
|
||||||
Instantiator
|
Instantiator
|
||||||
{
|
{
|
||||||
@ -53,12 +55,12 @@ Menu
|
|||||||
visible: UM.Preferences.getValue("cura/use_multi_build_plate")
|
visible: UM.Preferences.getValue("cura/use_multi_build_plate")
|
||||||
Instantiator
|
Instantiator
|
||||||
{
|
{
|
||||||
model: Cura.MultiBuildPlateModel
|
model: base.multiBuildPlateModel
|
||||||
MenuItem {
|
MenuItem {
|
||||||
text: Cura.MultiBuildPlateModel.getItem(index).name;
|
text: base.multiBuildPlateModel.getItem(index).name;
|
||||||
onTriggered: Cura.SceneController.setActiveBuildPlate(Cura.MultiBuildPlateModel.getItem(index).buildPlateNumber);
|
onTriggered: Cura.SceneController.setActiveBuildPlate(base.multiBuildPlateModel.getItem(index).buildPlateNumber);
|
||||||
checkable: true;
|
checkable: true;
|
||||||
checked: Cura.MultiBuildPlateModel.getItem(index).buildPlateNumber == Cura.MultiBuildPlateModel.activeBuildPlate;
|
checked: base.multiBuildPlateModel.getItem(index).buildPlateNumber == base.multiBuildPlateModel.activeBuildPlate;
|
||||||
exclusiveGroup: buildPlateGroup;
|
exclusiveGroup: buildPlateGroup;
|
||||||
visible: UM.Preferences.getValue("cura/use_multi_build_plate")
|
visible: UM.Preferences.getValue("cura/use_multi_build_plate")
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,8 @@ Rectangle
|
|||||||
|
|
||||||
property bool collapsed: true;
|
property bool collapsed: true;
|
||||||
|
|
||||||
|
property Cura.MultiBuildPlateModel multiBuildPlateModel: CuraApplication.getMultiBuildPlateModel()
|
||||||
|
|
||||||
SystemPalette { id: palette }
|
SystemPalette { id: palette }
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
@ -67,7 +69,7 @@ Rectangle
|
|||||||
Rectangle
|
Rectangle
|
||||||
{
|
{
|
||||||
height: childrenRect.height
|
height: childrenRect.height
|
||||||
color: Cura.MultiBuildPlateModel.getItem(index).buildPlateNumber == Cura.MultiBuildPlateModel.activeBuildPlate ? palette.highlight : index % 2 ? palette.base : palette.alternateBase
|
color: multiBuildPlateModel.getItem(index).buildPlateNumber == multiBuildPlateModel.activeBuildPlate ? palette.highlight : index % 2 ? palette.base : palette.alternateBase
|
||||||
width: parent.width
|
width: parent.width
|
||||||
Label
|
Label
|
||||||
{
|
{
|
||||||
@ -75,8 +77,8 @@ Rectangle
|
|||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.leftMargin: UM.Theme.getSize("default_margin").width
|
anchors.leftMargin: UM.Theme.getSize("default_margin").width
|
||||||
width: parent.width - 2 * UM.Theme.getSize("default_margin").width - 30
|
width: parent.width - 2 * UM.Theme.getSize("default_margin").width - 30
|
||||||
text: Cura.MultiBuildPlateModel.getItem(index) ? Cura.MultiBuildPlateModel.getItem(index).name : "";
|
text: multiBuildPlateModel.getItem(index) ? multiBuildPlateModel.getItem(index).name : "";
|
||||||
color: Cura.MultiBuildPlateModel.activeBuildPlate == index ? palette.highlightedText : palette.text
|
color: multiBuildPlateModel.activeBuildPlate == index ? palette.highlightedText : palette.text
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,13 +120,12 @@ Rectangle
|
|||||||
ListView
|
ListView
|
||||||
{
|
{
|
||||||
id: buildPlateListView
|
id: buildPlateListView
|
||||||
model: Cura.MultiBuildPlateModel
|
model: multiBuildPlateModel
|
||||||
width: parent.width
|
width: parent.width
|
||||||
delegate: buildPlateDelegate
|
delegate: buildPlateDelegate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
id: objectDelegate
|
id: objectDelegate
|
||||||
Rectangle
|
Rectangle
|
||||||
@ -200,7 +201,6 @@ Rectangle
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CheckBox
|
CheckBox
|
||||||
{
|
{
|
||||||
id: filterBuildPlateCheckbox
|
id: filterBuildPlateCheckbox
|
||||||
@ -260,6 +260,4 @@ Rectangle
|
|||||||
}
|
}
|
||||||
action: Cura.Actions.arrangeAll;
|
action: Cura.Actions.arrangeAll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user