Skip to content

Commit

Permalink
[ui] GraphEditor: Move ChoiceParam control to its own file
Browse files Browse the repository at this point in the history
Start modularization of attribute controls for better readability
and maintenance.
Make Choice control independent from the MeshroomUI API.
  • Loading branch information
yann-lty committed Jan 30, 2025
1 parent 0d3a49d commit 3028090
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
34 changes: 34 additions & 0 deletions meshroom/ui/qml/GraphEditor/AttributeControls/Choice.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

import MaterialIcons
import Controls

/**
* A combobox-type control with a single current `value` and a list of possible `values`.
* Provides filtering capabilities and support for custom values (i.e: `value` not in `values`).
*/
RowLayout {
id: root

required property var value
required property var values

signal editingFinished(var value)

FilterComboBox {
id: comboBox

Layout.fillWidth: true
sourceModel: root.values
inputValue: root.value
onEditingFinished: value => root.editingFinished(value)
}

MaterialLabel {
visible: !comboBox.validValue
text: MaterialIcons.warning
ToolTip.text: "Custom value detected"
}
}
28 changes: 9 additions & 19 deletions meshroom/ui/qml/GraphEditor/AttributeItemDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import QtQuick.Dialogs
import MaterialIcons 2.2
import Utils 1.0
import Controls 1.0
import "AttributeControls" as AttributeControls

/**
* Instantiate a control to visualize and edit an Attribute based on its type.
Expand Down Expand Up @@ -208,7 +209,7 @@ RowLayout {
case "PushButtonParam":
return pushButtonComponent
case "ChoiceParam":
return attribute.desc.exclusive ? comboBoxComponent : multiChoiceComponent
return attribute.desc.exclusive ? choiceComponent : multiChoiceComponent
case "IntParam": return sliderComponent
case "FloatParam":
if (attribute.desc.semantic === 'color/hue')
Expand Down Expand Up @@ -469,26 +470,15 @@ RowLayout {
}

Component {
id: comboBoxComponent
id: choiceComponent

RowLayout {
FilterComboBox {
id: comboBox

Layout.fillWidth: true

enabled: root.editable
sourceModel: attribute.values
inputValue: attribute.value
AttributeControls.Choice {
value: root.attribute.value
values: root.attribute.values
enabled: root.editable

onEditingFinished: (value) => {
_reconstruction.setAttribute(attribute, value)
}
}
MaterialLabel {
visible: !comboBox.validValue
text: MaterialIcons.warning
ToolTip.text: "Custom value detected"
onEditingFinished: (value) => {
_reconstruction.setAttribute(root.attribute, value)
}
}
}
Expand Down

0 comments on commit 3028090

Please sign in to comment.