mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-10-04 11:46:40 +08:00
Add single setting update ComboBox
CURA-9793
This commit is contained in:
parent
0fc4773db3
commit
b53c8aac54
@ -6,7 +6,7 @@ import QtQuick.Controls 2.3
|
|||||||
import QtQuick.Layouts 1.3
|
import QtQuick.Layouts 1.3
|
||||||
|
|
||||||
import UM 1.5 as UM
|
import UM 1.5 as UM
|
||||||
import Cura 1.6 as Cura
|
import Cura 1.7 as Cura
|
||||||
|
|
||||||
|
|
||||||
RecommendedSettingSection
|
RecommendedSettingSection
|
||||||
@ -60,7 +60,7 @@ RecommendedSettingSection
|
|||||||
settingControl: Cura.ExtruderSelectorBar
|
settingControl: Cura.ExtruderSelectorBar
|
||||||
{
|
{
|
||||||
model: extruderModel
|
model: extruderModel
|
||||||
selectedIndex: (supportExtruderNr.properties.value !== undefined) ? supportExtruderNr.properties.value : 0
|
selectedIndex: supportExtruderNr.properties.value !== undefined ? supportExtruderNr.properties.value : 0
|
||||||
function onClickExtruder(index)
|
function onClickExtruder(index)
|
||||||
{
|
{
|
||||||
forceActiveFocus();
|
forceActiveFocus();
|
||||||
@ -73,9 +73,13 @@ RecommendedSettingSection
|
|||||||
RecommendedSettingItem
|
RecommendedSettingItem
|
||||||
{
|
{
|
||||||
settingName: catalog.i18nc("@action:label", "Placement")
|
settingName: catalog.i18nc("@action:label", "Placement")
|
||||||
settingControl: Rectangle { color: "green"; width: 50; height:50 }
|
|
||||||
|
settingControl: Cura.SingleSettingComboBox
|
||||||
|
{
|
||||||
|
width: parent.width
|
||||||
|
height: UM.Theme.getSize("combobox").height
|
||||||
|
settingName: "support_type"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
62
resources/qml/Widgets/SingleSettingComboBox.qml
Normal file
62
resources/qml/Widgets/SingleSettingComboBox.qml
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
// Copyright (c) 2022 UltiMaker B.V.
|
||||||
|
// Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
|
import QtQuick 2.10
|
||||||
|
import QtQuick.Controls 2.3
|
||||||
|
import QtQuick.Layouts 1.3
|
||||||
|
|
||||||
|
import UM 1.5 as UM
|
||||||
|
import Cura 1.7 as Cura
|
||||||
|
|
||||||
|
// This ComboBox allows changing of a single setting. Only the setting name has to be passed in to "settingName".
|
||||||
|
// All of the setting updating logic is handled by this component.
|
||||||
|
// This uses the "options" value of a setting to populate the drop down. This will only work for settings with "options"
|
||||||
|
Cura.ComboBox {
|
||||||
|
textRole: "text"
|
||||||
|
property alias settingName: propertyProvider.key
|
||||||
|
|
||||||
|
model: ListModel {
|
||||||
|
id: comboboxModel
|
||||||
|
|
||||||
|
// The propertyProvider has not loaded the setting when this components onComplete triggers. Populating the model
|
||||||
|
// is defered until propertyProvider signals "onIsValueUsedChanged".
|
||||||
|
function updateModel()
|
||||||
|
{
|
||||||
|
clear()
|
||||||
|
|
||||||
|
if(!propertyProvider.properties.options) // No options have been loaded yet to populate combobox
|
||||||
|
{
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < propertyProvider.properties["options"].keys().length; i++)
|
||||||
|
{
|
||||||
|
var key = propertyProvider.properties["options"].keys()[i]
|
||||||
|
var value = propertyProvider.properties["options"][key]
|
||||||
|
comboboxModel.append({ text: value, code: key})
|
||||||
|
|
||||||
|
if (propertyProvider.properties.value == key)
|
||||||
|
{
|
||||||
|
// The combobox is cleared after each value change so the currentIndex must be set each time.
|
||||||
|
currentIndex = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
property UM.SettingPropertyProvider propertyProvider: UM.SettingPropertyProvider
|
||||||
|
{
|
||||||
|
id: propertyProvider
|
||||||
|
containerStack: Cura.MachineManager.activeMachine
|
||||||
|
watchedProperties: [ "value" , "options"]
|
||||||
|
}
|
||||||
|
|
||||||
|
Connections
|
||||||
|
{
|
||||||
|
target: propertyProvider
|
||||||
|
function onContainerStackChanged() { comboboxModel.updateModel() }
|
||||||
|
function onIsValueUsedChanged() { comboboxModel.updateModel() }
|
||||||
|
}
|
||||||
|
|
||||||
|
onCurrentIndexChanged: propertyProvider.setPropertyValue("value", comboboxModel.get(currentIndex).code)
|
||||||
|
}
|
@ -40,6 +40,7 @@ MenuItem 1.0 MenuItem.qml
|
|||||||
MenuSeparator 1.0 MenuSeparator.qml
|
MenuSeparator 1.0 MenuSeparator.qml
|
||||||
ExtruderSelectorBar 1.6 ExtruderSelectorBar.qml
|
ExtruderSelectorBar 1.6 ExtruderSelectorBar.qml
|
||||||
ExtruderButton 1.6 ExtruderButton.qml
|
ExtruderButton 1.6 ExtruderButton.qml
|
||||||
|
SingleSettingComboBox 1.7 SingleSettingComboBox.qml
|
||||||
|
|
||||||
|
|
||||||
# Cura/MachineSettings
|
# Cura/MachineSettings
|
||||||
|
Loading…
x
Reference in New Issue
Block a user