-
Notifications
You must be signed in to change notification settings - Fork 49
Refactor avalon.tools to avoid cross-referencing imports between tools #440
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 20 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
72ba84f
Refactor tools cross-referencing each other, plus cleanup:
BigRoy e31d9d9
Refactor absolute import to relative import
BigRoy d07dcf6
Fix import consistency, order by most global to closest relative
BigRoy e2b59e7
Refactor `node` to `item` in variables for consistency/clarity
BigRoy c350d18
Refactor family and group config cache from `loader.lib` to `tools.lib`
BigRoy 93ed86f
Refactor model COLUMNS to columns
BigRoy 5ea6fb7
Fix refactored imports
BigRoy df4ec95
Fix refactored Qt
BigRoy 90e159e
Fix missing QtGui import
BigRoy 8bf7bc8
Fix some outdated/wrong docstrings
BigRoy 3904439
Use list literal
BigRoy dc1a3fc
Move utility function to top (ease debugging import error stack trace)
BigRoy 27449a5
Move RecursiveSortFilterProxyModel to tools.models + fix imports
BigRoy 4c6343a
Comment example code again as it requires database/qt app to pass tests
BigRoy bc3df32
Remove unused model
BigRoy db6f6e6
Fix missed refactoring of model.COLUMNS to model.columns
BigRoy a475623
Fix refactor of NodeRole to ItemRole
BigRoy 9bc098e
Remove "import as" for qtawesome imports
BigRoy ae70d90
Unify quote style from single quotes to double quotes (only in tools)
BigRoy 8f798ca
Refactor model columns to Columns to separate from variables and methods
BigRoy 5de72f3
Cleanup multiple lib imports + reduce importing of specific functions
BigRoy 3fa9636
Bump version to 5.4.0
BigRoy 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
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,71 @@ | ||
| from ..vendor.Qt import QtWidgets, QtCore | ||
| from .. import io | ||
|
|
||
| from .models import TreeModel | ||
|
|
||
|
|
||
| class VersionDelegate(QtWidgets.QStyledItemDelegate): | ||
| """A delegate that display version integer formatted as version string.""" | ||
|
|
||
| version_changed = QtCore.Signal() | ||
| first_run = False | ||
| lock = False | ||
|
|
||
| def _format_version(self, value): | ||
| """Formats integer to displayable version name""" | ||
| return "v{0:03d}".format(value) | ||
|
|
||
| def displayText(self, value, locale): | ||
| assert isinstance(value, int), "Version is not `int`" | ||
| return self._format_version(value) | ||
|
|
||
| def createEditor(self, parent, option, index): | ||
| item = index.data(TreeModel.ItemRole) | ||
| if item.get("isGroup"): | ||
| return | ||
|
|
||
| editor = QtWidgets.QComboBox(parent) | ||
|
|
||
| def commit_data(): | ||
| if not self.first_run: | ||
| self.commitData.emit(editor) # Update model data | ||
| self.version_changed.emit() # Display model data | ||
| editor.currentIndexChanged.connect(commit_data) | ||
|
|
||
| self.first_run = True | ||
| self.lock = False | ||
|
|
||
| return editor | ||
|
|
||
| def setEditorData(self, editor, index): | ||
| if self.lock: | ||
| # Only set editor data once per delegation | ||
| return | ||
|
|
||
| editor.clear() | ||
|
|
||
| # Current value of the index | ||
| value = index.data(QtCore.Qt.DisplayRole) | ||
BigRoy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert isinstance(value, int), "Version is not `int`" | ||
|
|
||
| # Add all available versions to the editor | ||
| item = index.data(TreeModel.ItemRole) | ||
| parent_id = item["version_document"]["parent"] | ||
| versions = io.find({"type": "version", "parent": parent_id}, | ||
| sort=[("name", 1)]) | ||
BigRoy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| index = 0 | ||
| for i, version in enumerate(versions): | ||
| label = self._format_version(version["name"]) | ||
| editor.addItem(label, userData=version) | ||
|
|
||
| if version["name"] == value: | ||
| index = i | ||
|
|
||
| editor.setCurrentIndex(index) # Will trigger index-change signal | ||
| self.first_run = False | ||
| self.lock = True | ||
|
|
||
| def setModelData(self, editor, model, index): | ||
| """Apply the integer version back in the model""" | ||
| version = editor.itemData(editor.currentIndex()) | ||
| model.setData(index, version["name"]) | ||
Oops, something went wrong.
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.