-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[ui] Add new FilterComboBox for ChoiceParam attributes #2358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c439c5a
Add FilterComboBox.qml and update AttributeItemDelegate.qml
Just-Kiel 57a02fc
Filter text reset when attribute reset
Just-Kiel 9007dbd
[ui] Validate value even if not in values of ComboBox, Arrow Keys Nav…
Just-Kiel eaa021d
[ui] Placement of ComboBox according to space available
Just-Kiel 3f3f2e6
[GraphEditor] Use `attribute.values` for the model
cbentejac 27aceb3
[ui] fix : invalide value when reopening AttributeEditor
Just-Kiel da71470
[nodes] Texturing: Exclusively use lists for ChoiceParams values
cbentejac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| import QtQuick 2.15 | ||
| import QtQuick.Controls 2.15 | ||
| import Utils 1.0 | ||
|
|
||
| /** | ||
| * ComboBox with filter text area | ||
| * | ||
| * @param inputModel - model to filter | ||
| * @param editingFinished - signal emitted when editing is finished | ||
| * @alias filterText - text to filter the model | ||
| */ | ||
|
|
||
| ComboBox { | ||
| id: combo | ||
|
|
||
| property var inputModel | ||
| signal editingFinished(var value) | ||
|
|
||
| property alias filterText: filterTextArea | ||
| property bool validValue: true | ||
|
|
||
| enabled: root.editable | ||
| model: { | ||
| var filteredData = inputModel.filter(condition => { | ||
| if (filterTextArea.text.length > 0) return condition.toString().toLowerCase().includes(filterTextArea.text.toLowerCase()) | ||
| return true | ||
| }) | ||
| if (filteredData.length > 0) { | ||
| filterTextArea.background.color = Qt.lighter(palette.base, 2) | ||
| validValue = true | ||
|
|
||
| // order filtered data by relevance (results that start with the filter text come first) | ||
| filteredData.sort((a, b) => { | ||
| const nameA = a.toString().toLowerCase(); | ||
| const nameB = b.toString().toLowerCase(); | ||
| const filterText = filterTextArea.text.toLowerCase() | ||
| if (nameA.startsWith(filterText) && !nameB.startsWith(filterText)) | ||
| return -1 | ||
| if (!nameA.startsWith(filterText) && nameB.startsWith(filterText)) | ||
| return 1 | ||
| return 0 | ||
| }) | ||
| } else { | ||
| filterTextArea.background.color = Colors.red | ||
| validValue = false | ||
| } | ||
|
|
||
| if (filteredData.length == 0 || filterTextArea.length == 0) { | ||
| filteredData = inputModel | ||
| } | ||
|
|
||
| return filteredData | ||
| } | ||
|
|
||
| background: Rectangle { | ||
| implicitHeight: root.implicitHeight | ||
| color: { | ||
| if (validValue) { | ||
| return palette.mid | ||
| } else { | ||
| return Colors.red | ||
| } | ||
| } | ||
| border.color: palette.base | ||
| } | ||
|
|
||
| popup: Popup { | ||
| width: combo.width | ||
| implicitHeight: contentItem.implicitHeight | ||
|
|
||
| onAboutToShow: { | ||
| filterTextArea.forceActiveFocus() | ||
|
|
||
| if (mapToGlobal(popup.x, popup.y).y + root.implicitHeight * (model.length + 1) > _window.contentItem.height) { | ||
| y = -root.implicitHeight * (model.length + 1) | ||
| } else { | ||
| y = 0 | ||
| } | ||
| } | ||
|
|
||
| contentItem: Item { | ||
| anchors.fill: parent | ||
| TextArea { | ||
| id: filterTextArea | ||
| leftPadding: 12 | ||
| anchors.left: parent.left | ||
| anchors.right: parent.right | ||
| anchors.top: parent.top | ||
|
|
||
| selectByMouse: true | ||
| hoverEnabled: true | ||
| wrapMode: TextEdit.WrapAnywhere | ||
| placeholderText: "Filter" | ||
| background: Rectangle {} | ||
|
|
||
| onEditingFinished: { | ||
| combo.popup.close() | ||
| combo.editingFinished(displayText) | ||
| } | ||
|
|
||
| Keys.onEnterPressed: { | ||
| if (!validValue) { | ||
| displayText = filterTextArea.text | ||
| } else { | ||
| displayText = currentText | ||
| } | ||
| editingFinished() | ||
| } | ||
|
|
||
| Keys.onReturnPressed: { | ||
| if (!validValue) { | ||
| displayText = filterTextArea.text | ||
| } else { | ||
| displayText = currentText | ||
| } | ||
| editingFinished() | ||
| } | ||
|
|
||
| Keys.onUpPressed: { | ||
| // if the current index is 0, the user wants to go to the last item | ||
| if (combo.currentIndex == 0) { | ||
| combo.currentIndex = combo.model.length - 1 | ||
| } else { | ||
| combo.currentIndex-- | ||
| } | ||
| } | ||
|
|
||
| Keys.onDownPressed: { | ||
| // if the current index is the last one, the user wants to go to the first item | ||
| if (combo.currentIndex == combo.model.length - 1) { | ||
| combo.currentIndex = 0 | ||
| } else { | ||
| combo.currentIndex++ | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| ListView { | ||
| clip: true | ||
| anchors.left: parent.left | ||
| anchors.right: parent.right | ||
| anchors.top: filterTextArea.bottom | ||
|
|
||
| implicitHeight: contentHeight | ||
| model: combo.popup.visible ? combo.delegateModel : null | ||
|
|
||
| ScrollIndicator.vertical: ScrollIndicator {} | ||
| } | ||
| } | ||
|
|
||
| delegate: ItemDelegate { | ||
| width: combo.width | ||
| height: combo.height | ||
|
|
||
| contentItem: Text { | ||
| text: modelData | ||
| color: palette.text | ||
| } | ||
|
|
||
| highlighted: validValue ? combo.currentIndex === index : false | ||
|
|
||
| hoverEnabled: true | ||
| } | ||
|
|
||
| onHighlightedIndexChanged: { | ||
| if (highlightedIndex >= 0) { | ||
| combo.currentIndex = highlightedIndex | ||
| } | ||
| } | ||
|
|
||
| onCurrentTextChanged: { | ||
| displayText = currentText | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.