Skip to content

Commit

Permalink
Merge pull request #17954 from Ultimaker/CURA-7812-decrease-Qml-singl…
Browse files Browse the repository at this point in the history
…etons

CURA-7812-decrease-Qml-singletons
  • Loading branch information
wawanbreton authored Jan 12, 2024
2 parents 8f29e8d + db19f53 commit 0fe6824
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 40 deletions.
26 changes: 25 additions & 1 deletion cura/CuraActions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

from typing import List, cast

from PyQt6.QtCore import QObject, QUrl, QMimeData
from PyQt6.QtCore import QObject, QUrl, pyqtSignal, pyqtProperty
from PyQt6.QtGui import QDesktopServices
from PyQt6.QtWidgets import QApplication

from UM.Application import Application
from UM.Event import CallFunctionEvent
from UM.FlameProfiler import pyqtSlot
from UM.Math.Vector import Vector
Expand Down Expand Up @@ -37,6 +38,10 @@ class CuraActions(QObject):
def __init__(self, parent: QObject = None) -> None:
super().__init__(parent)

self._operation_stack = Application.getInstance().getOperationStack()
self._operation_stack.changed.connect(self._onUndoStackChanged)

undoStackChanged = pyqtSignal()
@pyqtSlot()
def openDocumentation(self) -> None:
# Starting a web browser from a signal handler connected to a menu will crash on windows.
Expand All @@ -45,6 +50,25 @@ def openDocumentation(self) -> None:
event = CallFunctionEvent(self._openUrl, [QUrl("https://ultimaker.com/en/resources/manuals/software?utm_source=cura&utm_medium=software&utm_campaign=dropdown-documentation")], {})
cura.CuraApplication.CuraApplication.getInstance().functionEvent(event)

@pyqtProperty(bool, notify=undoStackChanged)
def canUndo(self):
return self._operation_stack.canUndo()

@pyqtProperty(bool, notify=undoStackChanged)
def canRedo(self):
return self._operation_stack.canRedo()

@pyqtSlot()
def undo(self):
self._operation_stack.undo()

@pyqtSlot()
def redo(self):
self._operation_stack.redo()

def _onUndoStackChanged(self):
self.undoStackChanged.emit()

@pyqtSlot()
def openBugReportPage(self) -> None:
event = CallFunctionEvent(self._openUrl, [QUrl("https://github.com/Ultimaker/Cura/issues/new/choose")], {})
Expand Down
58 changes: 44 additions & 14 deletions cura/CuraApplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
from PyQt6.QtCore import QObject, QTimer, QUrl, QUrlQuery, pyqtSignal, pyqtProperty, QEvent, pyqtEnum, QCoreApplication, \
QByteArray
from PyQt6.QtGui import QColor, QIcon
from PyQt6.QtQml import qmlRegisterUncreatableType, qmlRegisterUncreatableMetaObject, qmlRegisterSingletonType, qmlRegisterType
from PyQt6.QtQml import qmlRegisterUncreatableMetaObject, qmlRegisterSingletonType, qmlRegisterType
from PyQt6.QtWidgets import QMessageBox

import UM.Util
import cura.Settings.cura_empty_instance_containers
from UM.Application import Application
from UM.Decorators import override
from UM.Decorators import override, deprecated
from UM.FlameProfiler import pyqtSlot
from UM.Logger import Logger
from UM.Math.AxisAlignedBox import AxisAlignedBox
Expand Down Expand Up @@ -191,7 +191,7 @@ def __init__(self, *args, **kwargs):
self.empty_container = None # type: EmptyInstanceContainer
self.empty_definition_changes_container = None # type: EmptyInstanceContainer
self.empty_variant_container = None # type: EmptyInstanceContainer
self.empty_intent_container = None # type: EmptyInstanceContainer
self.empty_intent_container = None # type: EmptyInstanceContainer
self.empty_material_container = None # type: EmptyInstanceContainer
self.empty_quality_container = None # type: EmptyInstanceContainer
self.empty_quality_changes_container = None # type: EmptyInstanceContainer
Expand Down Expand Up @@ -1138,6 +1138,10 @@ def getMachineActionManager(self, *args: Any) -> MachineActionManager.MachineAct

return cast(MachineActionManager.MachineActionManager, self._machine_action_manager)

@pyqtSlot(result = QObject)
def getMachineActionManagerQml(self)-> MachineActionManager.MachineActionManager:
return cast(QObject, self._machine_action_manager)

@pyqtSlot(result = QObject)
def getMaterialManagementModel(self) -> MaterialManagementModel:
if not self._material_management_model:
Expand All @@ -1150,7 +1154,8 @@ def getQualityManagementModel(self) -> QualityManagementModel:
self._quality_management_model = QualityManagementModel(parent = self)
return self._quality_management_model

def getSimpleModeSettingsManager(self, *args):
@pyqtSlot(result=QObject)
def getSimpleModeSettingsManager(self)-> SimpleModeSettingsManager:
if self._simple_mode_settings_manager is None:
self._simple_mode_settings_manager = SimpleModeSettingsManager()
return self._simple_mode_settings_manager
Expand Down Expand Up @@ -1193,16 +1198,43 @@ def getPrintInformation(self):

return self._print_information

def getQualityProfilesDropDownMenuModel(self, *args, **kwargs):
@pyqtSlot(result=QObject)
def getQualityProfilesDropDownMenuModel(self, *args, **kwargs)-> QualityProfilesDropDownMenuModel:
if self._quality_profile_drop_down_menu_model is None:
self._quality_profile_drop_down_menu_model = QualityProfilesDropDownMenuModel(self)
return self._quality_profile_drop_down_menu_model

def getCustomQualityProfilesDropDownMenuModel(self, *args, **kwargs):
@pyqtSlot(result=QObject)
def getCustomQualityProfilesDropDownMenuModel(self, *args, **kwargs)->CustomQualityProfilesDropDownMenuModel:
if self._custom_quality_profile_drop_down_menu_model is None:
self._custom_quality_profile_drop_down_menu_model = CustomQualityProfilesDropDownMenuModel(self)
return self._custom_quality_profile_drop_down_menu_model

@deprecated("SimpleModeSettingsManager is deprecated and will be removed in major SDK release, Use getSimpleModeSettingsManager() instead", since = "5.7.0")
def getSimpleModeSettingsManagerWrapper(self, *args, **kwargs):
return self.getSimpleModeSettingsManager()

@deprecated("MachineActionManager is deprecated and will be removed in major SDK release, Use getMachineActionManager() instead", since="5.7.0")
def getMachineActionManagerWrapper(self, *args, **kwargs):
return self.getMachineActionManager()

@deprecated("QualityManagementModel is deprecated and will be removed in major SDK release, Use getQualityManagementModel() instead", since="5.7.0")
def getQualityManagementModelWrapper(self, *args, **kwargs):
return self.getQualityManagementModel()

@deprecated("MaterialManagementModel is deprecated and will be removed in major SDK release, Use getMaterialManagementModel() instead", since = "5.7.0")
def getMaterialManagementModelWrapper(self, *args, **kwargs):
return self.getMaterialManagementModel()

@deprecated("QualityProfilesDropDownMenuModel is deprecated and will be removed in major SDK release, Use getQualityProfilesDropDownMenuModel() instead", since = "5.7.0")
def getQualityProfilesDropDownMenuModelWrapper(self, *args, **kwargs):
return self.getQualityProfilesDropDownMenuModel()

@deprecated("CustomQualityProfilesDropDownMenuModel is deprecated and will be removed in major SDK release, Use getCustomQualityProfilesDropDownMenuModel() instead", since = "5.7.0")
def getCustomQualityProfilesDropDownMenuModelWrapper(self, *args, **kwargs):
return self.getCustomQualityProfilesDropDownMenuModel()


def getCuraAPI(self, *args, **kwargs) -> "CuraAPI":
return self._cura_API

Expand Down Expand Up @@ -1231,8 +1263,8 @@ def registerObjects(self, engine):
qmlRegisterSingletonType(MachineManager, "Cura", 1, 0, self.getMachineManager, "MachineManager")
qmlRegisterSingletonType(IntentManager, "Cura", 1, 6, self.getIntentManager, "IntentManager")
qmlRegisterSingletonType(SettingInheritanceManager, "Cura", 1, 0, self.getSettingInheritanceManager, "SettingInheritanceManager")
qmlRegisterSingletonType(SimpleModeSettingsManager, "Cura", 1, 0, self.getSimpleModeSettingsManager, "SimpleModeSettingsManager")
qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, self.getMachineActionManager, "MachineActionManager")
qmlRegisterSingletonType(SimpleModeSettingsManager, "Cura", 1, 0, self.getSimpleModeSettingsManagerWrapper, "SimpleModeSettingsManager")
qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, self.getMachineActionManagerWrapper, "MachineActionManager")

self.processEvents()
qmlRegisterType(NetworkingUtil, "Cura", 1, 5, "NetworkingUtil")
Expand All @@ -1257,16 +1289,14 @@ def registerObjects(self, engine):
qmlRegisterType(FavoriteMaterialsModel, "Cura", 1, 0, "FavoriteMaterialsModel")
qmlRegisterType(GenericMaterialsModel, "Cura", 1, 0, "GenericMaterialsModel")
qmlRegisterType(MaterialBrandsModel, "Cura", 1, 0, "MaterialBrandsModel")
qmlRegisterSingletonType(QualityManagementModel, "Cura", 1, 0, self.getQualityManagementModel, "QualityManagementModel")
qmlRegisterSingletonType(MaterialManagementModel, "Cura", 1, 5, self.getMaterialManagementModel, "MaterialManagementModel")
qmlRegisterSingletonType(QualityManagementModel, "Cura", 1, 0, self.getQualityManagementModelWrapper,"QualityManagementModel")
qmlRegisterSingletonType(MaterialManagementModel, "Cura", 1, 5, self.getMaterialManagementModelWrapper,"MaterialManagementModel")

self.processEvents()
qmlRegisterType(DiscoveredPrintersModel, "Cura", 1, 0, "DiscoveredPrintersModel")
qmlRegisterType(DiscoveredCloudPrintersModel, "Cura", 1, 7, "DiscoveredCloudPrintersModel")
qmlRegisterSingletonType(QualityProfilesDropDownMenuModel, "Cura", 1, 0,
self.getQualityProfilesDropDownMenuModel, "QualityProfilesDropDownMenuModel")
qmlRegisterSingletonType(CustomQualityProfilesDropDownMenuModel, "Cura", 1, 0,
self.getCustomQualityProfilesDropDownMenuModel, "CustomQualityProfilesDropDownMenuModel")
qmlRegisterSingletonType(QualityProfilesDropDownMenuModel, "Cura", 1, 0, self.getQualityProfilesDropDownMenuModelWrapper, "QualityProfilesDropDownMenuModel")
qmlRegisterSingletonType(CustomQualityProfilesDropDownMenuModel, "Cura", 1, 0, self.getCustomQualityProfilesDropDownMenuModelWrapper, "CustomQualityProfilesDropDownMenuModel")
qmlRegisterType(NozzleModel, "Cura", 1, 0, "NozzleModel")
qmlRegisterType(IntentModel, "Cura", 1, 6, "IntentModel")
qmlRegisterType(IntentCategoryModel, "Cura", 1, 6, "IntentCategoryModel")
Expand Down
2 changes: 1 addition & 1 deletion plugins/PerObjectSettingsTool/PerObjectItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ UM.TooltipArea
onClicked:
{
addedSettingsModel.setVisible(model.key, checked);
UM.ActiveTool.forceUpdate();
UM.Controller.forceUpdate();
}
}

Expand Down
22 changes: 11 additions & 11 deletions plugins/PerObjectSettingsTool/PerObjectSettingsPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Item
readonly property string infillMeshType: "infill_mesh"
readonly property string antiOverhangMeshType: "anti_overhang_mesh"

property var currentMeshType: UM.ActiveTool.properties.getValue("MeshType")
property var currentMeshType: UM.Controller.properties.getValue("MeshType")

// Update the view every time the currentMeshType changes
onCurrentMeshTypeChanged:
Expand Down Expand Up @@ -56,7 +56,7 @@ Item

function setMeshType(type)
{
UM.ActiveTool.setProperty("MeshType", type)
UM.Controller.setProperty("MeshType", type)
updateMeshTypeCheckedState(type)
}

Expand Down Expand Up @@ -224,7 +224,7 @@ Item
visibilityHandler: Cura.PerObjectSettingVisibilityHandler
{
id: visibility_handler
selectedObjectId: UM.ActiveTool.properties.getValue("SelectedObjectId")
selectedObjectId: UM.Controller.properties.getValue("SelectedObjectId")
}

// For some reason the model object is updated after removing him from the memory and
Expand Down Expand Up @@ -320,7 +320,7 @@ Item
{
id: provider

containerStackId: UM.ActiveTool.properties.getValue("ContainerID")
containerStackId: UM.Controller.properties.getValue("ContainerID")
key: model.key
watchedProperties: [ "value", "enabled", "validationState" ]
storeIndex: 0
Expand All @@ -330,7 +330,7 @@ Item
UM.SettingPropertyProvider
{
id: inheritStackProvider
containerStackId: UM.ActiveTool.properties.getValue("ContainerID")
containerStackId: UM.Controller.properties.getValue("ContainerID")
key: model.key
watchedProperties: [ "limit_to_extruder" ]
}
Expand Down Expand Up @@ -381,22 +381,22 @@ Item

Connections
{
target: UM.ActiveTool
target: UM.Controller
function onPropertiesChanged()
{
// the values cannot be bound with UM.ActiveTool.properties.getValue() calls,
// the values cannot be bound with UM.Controller.properties.getValue() calls,
// so here we connect to the signal and update the those values.
if (typeof UM.ActiveTool.properties.getValue("SelectedObjectId") !== "undefined")
if (typeof UM.Controller.properties.getValue("SelectedObjectId") !== "undefined")
{
const selectedObjectId = UM.ActiveTool.properties.getValue("SelectedObjectId")
const selectedObjectId = UM.Controller.properties.getValue("SelectedObjectId")
if (addedSettingsModel.visibilityHandler.selectedObjectId != selectedObjectId)
{
addedSettingsModel.visibilityHandler.selectedObjectId = selectedObjectId
}
}
if (typeof UM.ActiveTool.properties.getValue("ContainerID") !== "undefined")
if (typeof UM.Controller.properties.getValue("ContainerID") !== "undefined")
{
const containerId = UM.ActiveTool.properties.getValue("ContainerID")
const containerId = UM.Controller.properties.getValue("ContainerID")
if (provider.containerStackId !== containerId)
{
provider.containerStackId = containerId
Expand Down
8 changes: 4 additions & 4 deletions resources/qml/Actions.qml
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ Item
text: catalog.i18nc("@action:inmenu menubar:edit", "&Undo")
icon.name: "edit-undo"
shortcut: StandardKey.Undo
onTriggered: UM.OperationStack.undo()
enabled: UM.OperationStack.canUndo
onTriggered: CuraActions.undo()
enabled: CuraActions.canUndo
}

Action
Expand All @@ -130,8 +130,8 @@ Item
text: catalog.i18nc("@action:inmenu menubar:edit", "&Redo")
icon.name: "edit-redo"
shortcut: StandardKey.Redo
onTriggered: UM.OperationStack.redo()
enabled: UM.OperationStack.canRedo
onTriggered: CuraActions.redo()
enabled: CuraActions.canRedo
}

Action
Expand Down
2 changes: 1 addition & 1 deletion resources/qml/Dialogs/AboutDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ UM.Dialog
UM.Label
{
id: version
text: catalog.i18nc("@label","version: %1").arg(UM.Application.version)
text: catalog.i18nc("@label","version: %1").arg(CuraApplication.version())
font: UM.Theme.getFont("large_bold")
color: UM.Theme.getColor("button_text")
anchors.right : logo.right
Expand Down
4 changes: 3 additions & 1 deletion resources/qml/Preferences/MachinesPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Cura 1.0 as Cura
UM.ManagementPage
{
id: base
property var machineActionManager: CuraApplication.getMachineActionManagerQml()
Item { enabled: false; UM.I18nCatalog { id: catalog; name: "cura"} }

title: catalog.i18nc("@title:tab", "Printers")
Expand Down Expand Up @@ -58,10 +59,11 @@ UM.ManagementPage
anchors.fill: parent
spacing: UM.Theme.getSize("default_margin").height


Repeater
{
id: machineActionRepeater
model: base.currentItem ? Cura.MachineActionManager.getSupportedActions(Cura.MachineManager.getDefinitionByMachineId(base.currentItem.id)) : null
model: base.currentItem ? machineActionManager.getSupportedActions(Cura.MachineManager.getDefinitionByMachineId(base.currentItem.id)) : null

Item
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Item
ProfileWarningReset
{
id: profileWarningReset
width: childrenRect.width
width: parent.width
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
fullWarning: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Popup
//Add all the custom profiles.
Repeater
{
model: Cura.CustomQualityProfilesDropDownMenuModel
model: CuraApplication.getCustomQualityProfilesDropDownMenuModel()
MenuButton
{
onClicked: Cura.MachineManager.setQualityChangesGroup(model.quality_changes_group)
Expand Down
4 changes: 2 additions & 2 deletions resources/qml/PrintSetupSelector/ProfileWarningReset.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import "../Dialogs"
Item
{
property bool fullWarning: true // <- Can you see the warning icon and the text, or is it just the buttons?

property var simpleModeSettingsManager :CuraApplication.getSimpleModeSettingsManager()
height: visible ? UM.Theme.getSize("action_button_icon").height : 0
width: visible ? childrenRect.width: 0
visible: Cura.MachineManager.hasUserSettings || (fullWarning && Cura.MachineManager.hasCustomQuality)
Expand Down Expand Up @@ -96,7 +96,7 @@ Item
State
{
name: "custom settings changed"
when: Cura.SimpleModeSettingsManager.isProfileCustomized
when: simpleModeSettingsManager.isProfileCustomized
PropertyChanges
{
target: warning
Expand Down
2 changes: 1 addition & 1 deletion resources/qml/Settings/SettingTextField.qml
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ SettingItem

cursorShape: Qt.IBeamCursor

onPressed: {
onPressed:(mouse)=> {
if (!input.activeFocus)
{
base.focusGainedByClick = true
Expand Down
4 changes: 2 additions & 2 deletions resources/qml/Toolbar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ Item
x: UM.Theme.getSize("default_margin").width
y: UM.Theme.getSize("default_margin").height

source: UM.ActiveTool.valid ? UM.ActiveTool.activeToolPanel : ""
source: UM.Controller.valid ? UM.Controller.activeToolPanel : ""
enabled: UM.Controller.toolsEnabled
}
}
Expand All @@ -222,7 +222,7 @@ Item
UM.Label
{
id: toolHint
text: UM.ActiveTool.properties.getValue("ToolHint") != undefined ? UM.ActiveTool.properties.getValue("ToolHint") : ""
text: UM.Controller.properties.getValue("ToolHint") != undefined ? UM.ActiveTool.properties.getValue("ToolHint") : ""
color: UM.Theme.getColor("tooltip_text")
anchors.horizontalCenter: parent.horizontalCenter
}
Expand Down

0 comments on commit 0fe6824

Please sign in to comment.