mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
Per object settings can now be added & changed
CURA-1278
This commit is contained in:
parent
d5dbd0f77b
commit
89c1136d7f
5 changed files with 85 additions and 30 deletions
|
@ -14,10 +14,12 @@ from UM.Application import Application
|
||||||
class SettingOverrideDecorator(SceneNodeDecorator):
|
class SettingOverrideDecorator(SceneNodeDecorator):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._stack = ContainerStack(stack_id = "SettingOverrideStack")
|
self._stack = ContainerStack(stack_id = id(self))
|
||||||
self._instance = InstanceContainer(container_id = "SettingOverrideInstanceContainer")
|
self._instance = InstanceContainer(container_id = "SettingOverrideInstanceContainer")
|
||||||
self._stack.addContainer(self._instance)
|
self._stack.addContainer(self._instance)
|
||||||
|
|
||||||
|
ContainerRegistry.getInstance().addContainer(self._stack)
|
||||||
|
|
||||||
Application.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerStackChanged)
|
Application.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerStackChanged)
|
||||||
self._onGlobalContainerStackChanged()
|
self._onGlobalContainerStackChanged()
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,18 @@ UM.TooltipArea
|
||||||
width: childrenRect.width;
|
width: childrenRect.width;
|
||||||
height: childrenRect.height;
|
height: childrenRect.height;
|
||||||
|
|
||||||
CheckBox
|
Button
|
||||||
{
|
{
|
||||||
id: check
|
id: check
|
||||||
|
|
||||||
text: definition.label
|
text: definition.label
|
||||||
|
|
||||||
onClicked: addedSettingsModel.setVisible(model.key, checked);
|
onClicked:
|
||||||
|
{
|
||||||
|
addedSettingsModel.setVisible(model.key, true);
|
||||||
|
settingPickDialog.visible = false
|
||||||
|
UM.ActiveTool.forceUpdate()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,6 @@ class PerObjectSettingVisibilityHandler(QObject):
|
||||||
|
|
||||||
if visibility_changed:
|
if visibility_changed:
|
||||||
self.visibilityChanged.emit()
|
self.visibilityChanged.emit()
|
||||||
#settings.addInstance(SettingInstance())
|
|
||||||
|
|
||||||
def getVisible(self):
|
def getVisible(self):
|
||||||
visible_settings = set()
|
visible_settings = set()
|
||||||
|
|
|
@ -10,16 +10,20 @@ import UM 1.2 as UM
|
||||||
import Cura 1.0 as Cura
|
import Cura 1.0 as Cura
|
||||||
import ".."
|
import ".."
|
||||||
|
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: base;
|
id: base;
|
||||||
property int currentIndex: UM.ActiveTool.properties.getValue("SelectedIndex")
|
|
||||||
|
|
||||||
UM.I18nCatalog { id: catalog; name: "cura"; }
|
UM.I18nCatalog { id: catalog; name: "cura"; }
|
||||||
|
|
||||||
width: childrenRect.width;
|
width: childrenRect.width;
|
||||||
height: childrenRect.height;
|
height: childrenRect.height;
|
||||||
|
|
||||||
|
|
||||||
|
function updateContainerID()
|
||||||
|
{
|
||||||
|
console.log("containerid",UM.ActiveTool.properties.getValue("ContainerID"))
|
||||||
|
}
|
||||||
|
|
||||||
Column
|
Column
|
||||||
{
|
{
|
||||||
id: items
|
id: items
|
||||||
|
@ -27,33 +31,69 @@ Item {
|
||||||
anchors.left: parent.left;
|
anchors.left: parent.left;
|
||||||
|
|
||||||
spacing: UM.Theme.getSize("default_margin").height;
|
spacing: UM.Theme.getSize("default_margin").height;
|
||||||
height: childrenRect.height;
|
|
||||||
ListView
|
Repeater
|
||||||
{
|
{
|
||||||
id: contents
|
id: contents
|
||||||
spacing: UM.Theme.getSize("default_lining").height;
|
|
||||||
height: childrenRect.height;
|
height: childrenRect.height;
|
||||||
|
|
||||||
model: UM.SettingDefinitionsModel {
|
model: UM.SettingDefinitionsModel
|
||||||
|
{
|
||||||
id: addedSettingsModel;
|
id: addedSettingsModel;
|
||||||
containerId: Cura.MachineManager.activeDefinitionId
|
containerId: Cura.MachineManager.activeDefinitionId
|
||||||
visibilityHandler: Cura.PerObjectSettingVisibilityHandler {
|
visibilityHandler: Cura.PerObjectSettingVisibilityHandler
|
||||||
selectedObjectId: UM.ActiveTool.properties.getValue("Model").getItem(base.currentIndex).id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delegate:Button
|
|
||||||
{
|
{
|
||||||
anchors.left: parent.right;
|
selectedObjectId: UM.ActiveTool.properties.getValue("SelectedObjectId")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
width: 150
|
delegate: Loader
|
||||||
height:50
|
{
|
||||||
|
width: UM.Theme.getSize("setting").width;
|
||||||
|
height: UM.Theme.getSize("setting").height;
|
||||||
|
|
||||||
text: model.label
|
property var definition: model
|
||||||
|
property var settingDefinitionsModel: addedSettingsModel
|
||||||
|
property var propertyProvider: provider
|
||||||
|
|
||||||
|
//Qt5.4.2 and earlier has a bug where this causes a crash: https://bugreports.qt.io/browse/QTBUG-35989
|
||||||
|
//In addition, while it works for 5.5 and higher, the ordering of the actual combo box drop down changes,
|
||||||
|
//causing nasty issues when selecting differnt options. So disable asynchronous loading of enum type completely.
|
||||||
|
asynchronous: model.type != "enum"
|
||||||
|
|
||||||
|
source:
|
||||||
|
{
|
||||||
|
switch(model.type) // TODO: This needs to be fixed properly. Got frustrated with it not working, so this is the patch job!
|
||||||
|
{
|
||||||
|
case "int":
|
||||||
|
return "../../resources/qml/Settings/SettingTextField.qml"
|
||||||
|
case "float":
|
||||||
|
return "../../resources/qml/Settings/SettingTextField.qml"
|
||||||
|
case "enum":
|
||||||
|
return "../../resources/qml/Settings/SettingComboBox.qml"
|
||||||
|
case "bool":
|
||||||
|
return "../../resources/qml/Settings/SettingCheckBox.qml"
|
||||||
|
case "str":
|
||||||
|
return "../../resources/qml/Settings/SettingTextField.qml"
|
||||||
|
case "category":
|
||||||
|
return "../../resources/qml/Settings/SettingCategory.qml"
|
||||||
|
default:
|
||||||
|
return "../../resources/qml/Settings/SettingUnknown.qml"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UM.SettingPropertyProvider
|
||||||
|
{
|
||||||
|
id: provider
|
||||||
|
|
||||||
|
containerStackId: UM.ActiveTool.properties.getValue("ContainerID")
|
||||||
|
key: model.key
|
||||||
|
watchedProperties: [ "value", "enabled", "state", "validationState" ]
|
||||||
|
storeIndex: 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Button
|
Button
|
||||||
{
|
{
|
||||||
id: customise_settings_button;
|
id: customise_settings_button;
|
||||||
|
|
|
@ -13,23 +13,16 @@ class PerObjectSettingsTool(Tool):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._model = None
|
self._model = None
|
||||||
|
|
||||||
self.setExposedProperties("Model", "SelectedIndex")
|
self.setExposedProperties("SelectedObjectId","ContainerID")
|
||||||
|
|
||||||
Preferences.getInstance().preferenceChanged.connect(self._onPreferenceChanged)
|
Preferences.getInstance().preferenceChanged.connect(self._onPreferenceChanged)
|
||||||
|
Selection.selectionChanged.connect(self.propertyChanged)
|
||||||
self._onPreferenceChanged("cura/active_mode")
|
self._onPreferenceChanged("cura/active_mode")
|
||||||
|
|
||||||
def event(self, event):
|
def event(self, event):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def getModel(self):
|
def getSelectedObjectId(self):
|
||||||
if not self._model:
|
|
||||||
self._model = PerObjectSettingsModel.PerObjectSettingsModel()
|
|
||||||
|
|
||||||
#For some reason, casting this model to itself causes the model to properly be cast to a QVariant, even though it ultimately inherits from QVariant.
|
|
||||||
#Yeah, we have no idea either...
|
|
||||||
return PerObjectSettingsModel.PerObjectSettingsModel(self._model)
|
|
||||||
|
|
||||||
def getSelectedIndex(self):
|
|
||||||
try:
|
try:
|
||||||
selected_object = Selection.getSelectedObject(0)
|
selected_object = Selection.getSelectedObject(0)
|
||||||
if selected_object.getParent().callDecoration("isGroup"):
|
if selected_object.getParent().callDecoration("isGroup"):
|
||||||
|
@ -37,8 +30,24 @@ class PerObjectSettingsTool(Tool):
|
||||||
except:
|
except:
|
||||||
selected_object = None
|
selected_object = None
|
||||||
selected_object_id = id(selected_object)
|
selected_object_id = id(selected_object)
|
||||||
index = self.getModel().find("id", selected_object_id)
|
return selected_object_id
|
||||||
return index
|
|
||||||
|
def getContainerID(self):
|
||||||
|
try:
|
||||||
|
selected_object = Selection.getSelectedObject(0)
|
||||||
|
if selected_object.getParent().callDecoration("isGroup"):
|
||||||
|
selected_object = selected_object.getParent()
|
||||||
|
try:
|
||||||
|
return selected_object.callDecoration("getStack").getId()
|
||||||
|
except:
|
||||||
|
print(":(")
|
||||||
|
return
|
||||||
|
except:
|
||||||
|
print(":((")
|
||||||
|
return
|
||||||
|
|
||||||
|
def setContainerID(self, value):
|
||||||
|
pass
|
||||||
|
|
||||||
def _onPreferenceChanged(self, preference):
|
def _onPreferenceChanged(self, preference):
|
||||||
if preference == "cura/active_mode":
|
if preference == "cura/active_mode":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue