mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-10 07:15:03 -06:00
Add single setting update ComboBox
CURA-9793
This commit is contained in:
parent
0fc4773db3
commit
b53c8aac54
3 changed files with 72 additions and 5 deletions
|
@ -6,7 +6,7 @@ import QtQuick.Controls 2.3
|
|||
import QtQuick.Layouts 1.3
|
||||
|
||||
import UM 1.5 as UM
|
||||
import Cura 1.6 as Cura
|
||||
import Cura 1.7 as Cura
|
||||
|
||||
|
||||
RecommendedSettingSection
|
||||
|
@ -60,7 +60,7 @@ RecommendedSettingSection
|
|||
settingControl: Cura.ExtruderSelectorBar
|
||||
{
|
||||
model: extruderModel
|
||||
selectedIndex: (supportExtruderNr.properties.value !== undefined) ? supportExtruderNr.properties.value : 0
|
||||
selectedIndex: supportExtruderNr.properties.value !== undefined ? supportExtruderNr.properties.value : 0
|
||||
function onClickExtruder(index)
|
||||
{
|
||||
forceActiveFocus();
|
||||
|
@ -73,9 +73,13 @@ RecommendedSettingSection
|
|||
RecommendedSettingItem
|
||||
{
|
||||
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
|
||||
ExtruderSelectorBar 1.6 ExtruderSelectorBar.qml
|
||||
ExtruderButton 1.6 ExtruderButton.qml
|
||||
SingleSettingComboBox 1.7 SingleSettingComboBox.qml
|
||||
|
||||
|
||||
# Cura/MachineSettings
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue