Merge lp:~garyvdm/bzr-explorer/better_tree_filter into lp:bzr-explorer

Proposed by Gary van der Merwe
Status: Merged
Merged at revision: 481
Proposed branch: lp:~garyvdm/bzr-explorer/better_tree_filter
Merge into: lp:bzr-explorer
Diff against target: 146 lines (+36/-76)
2 files modified
lib/commands.py (+8/-0)
lib/wt_browser.py (+28/-76)
To merge this branch: bzr merge lp:~garyvdm/bzr-explorer/better_tree_filter
Reviewer Review Type Date Requested Status
Bazaar Explorer Developers Pending
Review via email: mp+20519@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Gary van der Merwe (garyvdm) wrote :

This makes the _QBrowseFilterProxyModel better use TreeFilterProxyModel. This makes the code simpler, and faster.

I've also make the auto expand more intelligent.

Unfortunately when I did this, I discovered that TreeFilterProxyModel is not as extendible as I thought. So I have made some improvements to TreeFilterProxyModel in qbzr. In order to be compatible with older versions of qbzr, I've duplicated some of the qbzr code into BE. Once we don't have to support qbzr 0.18, we can remove this.

457. By Gary van der Merwe <garyvdm@pinkies>

Update filter_id so that it is compatable with the latest version of qbzr.

Revision history for this message
Gary van der Merwe (garyvdm) wrote :

bialix: Sorry - I just missed you on irc.

bialix> GaryvdM: maybe I simply should dogfood your bzr-explorer patch? I'm not
bialix> really wise to easily review your changes

I would just like a second set of eyes on it. I don't contrubite a lot to
explorer, so there may be some things that I am un aware of. Any way, it makes
seens from the qbzr TreeWidget point of view.

bialix> about duplication: maybe it's worth to require in explorer trunk
bialix> compatibility with newer qbzr? and keep explorer 1.0.x as compatible
bialix> with qbzr 0.18?

I would be happy with that. I'll prepair a patch for this.

Revision history for this message
Gary van der Merwe (garyvdm) wrote :

P.s. If you want to look at the code with out the duplication, pull rev 456.1.1 (revid:garyvdm@pinkies-20100317191428-0ylldclj4cu9pdn)

I'm looking at checking for a minimum qbzr version.

458. By Gary van der Merwe

Require qbzr 0.19

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/commands.py'
--- lib/commands.py 2010-03-07 04:51:24 +0000
+++ lib/commands.py 2010-08-09 14:56:47 +0000
@@ -133,6 +133,14 @@
133133
134 def run(self, location=None, hat=None, dry_run=False,134 def run(self, location=None, hat=None, dry_run=False,
135 desktop=None, zzz=False, experimental=False, screenshots=False):135 desktop=None, zzz=False, experimental=False, screenshots=False):
136
137 required_qbzr_version = (0, 19)
138 from bzrlib.plugins import qbzr
139 if qbzr.version_info < required_qbzr_version:
140 from bzrlib.errors import IncompatibleAPI
141 raise IncompatibleAPI(qbzr, required_qbzr_version,
142 qbzr.version_info, qbzr.version_info)
143
136 from bzrlib.plugins.qbzr.lib import uifactory144 from bzrlib.plugins.qbzr.lib import uifactory
137 _init_explorer_command(zzz, experimental)145 _init_explorer_command(zzz, experimental)
138146
139147
=== modified file 'lib/wt_browser.py'
--- lib/wt_browser.py 2010-02-15 12:41:51 +0000
+++ lib/wt_browser.py 2010-08-09 14:56:47 +0000
@@ -591,85 +591,25 @@
591 def __init__(self, *args):591 def __init__(self, *args):
592 treewidget.TreeFilterProxyModel.__init__(self, *args)592 treewidget.TreeFilterProxyModel.__init__(self, *args)
593 self.text_to_match = None593 self.text_to_match = None
594 self._interesting = None
595 self._all_data_loaded = False
596 self._text_match_count = 0
597594
598 def setTextToMatch(self, text):595 def setTextToMatch(self, text):
599 self.text_to_match = text596 self.text_to_match = text
600 self._update_interesting()
601 self.invalidateFilter()597 self.invalidateFilter()
602598
603 def _update_interesting(self):599 def filter_id(self, id, item_data):
604 if not self.text_to_match:600 """Determines wether a item should be displayed.
605 self._interesting = None601 Returns :
606 return602 * True: Show the item
607 text = self.text_to_match603 * False: Donot show the item
608 interesting = set([''])604 * None: Show the item if there are any children that are visible.
609 directories = set()
610 for path in self._iter_paths():
611 if path.find(text) >= 0:
612 interesting.add(path)
613 directories.update(parent_directories(path))
614 self._text_match_count = len(interesting)
615 interesting.update(directories)
616 #print "\ninteresting for %s ...\n%s\n" % (text,
617 # "\n".join(sorted(interesting)))
618 self._interesting = interesting
619
620 def _iter_paths(self):
621 # The source model loads data lazily. We need everything loaded
622 # to find the complete set of paths though
623 self._ensure_all_data_loaded()
624 return iter(self.source_model.inventory_data_by_path.keys())
625
626 def _ensure_all_data_loaded(self):
627 if self._all_data_loaded:
628 return
629 model = self.source_model
630 for id in range(0, len(model.inventory_data)):
631 self._load_dirs(model, id)
632 self._all_data_loaded = True
633
634 def _load_dirs(self, model, id):
635 item_data = model.inventory_data[id]
636 if item_data.item.kind == "directory":
637 if item_data.children_ids is None:
638 # This locks and unlocks the tree each time.
639 # I wonder how that impacts performance?
640 model.load_dir(id)
641 for child_id in item_data.children_ids:
642 self._load_dirs(model, child_id)
643
644 def filterAcceptsRow(self, source_row, source_parent):
645 result = treewidget.TreeFilterProxyModel.filterAcceptsRow(
646 self, source_row, source_parent)
647 if result and self._interesting:
648 # Apply the text filter (matches found earlier)
649 path, kind = self._get_path_info(source_row, source_parent)
650 result = path in self._interesting
651 return result
652
653 def _get_path_info(self, source_row, source_parent):
654 """Return path, kind for a model item."""
655 model = self.source_model
656 parent_id = source_parent.internalId()
657 children_ids = model.inventory_data[parent_id].children_ids
658 # Why is this check required?
659 if len(children_ids) <= source_row:
660 return None, None
661 id = children_ids[source_row]
662 data = model.inventory_data[id]
663 return data.path, data.item.kind
664
665 def text_match_count(self):
666 """Number of items matching text or 0 if unknown.
667
668 Note: The number is across the WHOLE tree, not just those displayed
669 after applying the combined filtering.
670 """605 """
671 return self._text_match_count606 show = treewidget.TreeFilterProxyModel.filter_id(self, id, item_data)
672607 if self.text_to_match and show:
608 if item_data.path.find(self.text_to_match) >=1:
609 return True
610 else:
611 return None
612 return show
673613
674class _QBrowseTreeWidget(treewidget.TreeWidget):614class _QBrowseTreeWidget(treewidget.TreeWidget):
675 """Subclass the standard QBzr TreeWidget to patch in more features.615 """Subclass the standard QBzr TreeWidget to patch in more features.
@@ -781,9 +721,21 @@
781 # Automatically expand the tree if the match count is small.721 # Automatically expand the tree if the match count is small.
782 # The number could be configurable one day provided the doc722 # The number could be configurable one day provided the doc
783 # was very clear about potential vs actual match counts723 # was very clear about potential vs actual match counts
784 matches = self._tree_viewer.tree_filter_model.text_match_count()724 parents = [QtCore.QModelIndex()] # start at the root
785 if matches <= 10:725 next_parents = []
786 self._tree_viewer.expandAll()726 expanded = 0
727 while parents and expanded <= 15:
728 for parent in parents:
729 matches = self._tree_viewer.tree_filter_model.rowCount(parent)
730 if matches and matches <= 5:
731 self._tree_viewer.expand(parent)
732 if (self._tree_viewer.isExpanded(parent) or
733 parent == QtCore.QModelIndex()):
734 expanded += matches
735 for i in range(matches):
736 next_parents.append(
737 self._tree_viewer.tree_filter_model.index(i, 0, parent))
738 parents = next_parents
787 # Reset our memory wrt what's expanded. This is perhaps a little739 # Reset our memory wrt what's expanded. This is perhaps a little
788 # heavy handed wrt text matching as that isn't remembered across740 # heavy handed wrt text matching as that isn't remembered across
789 # tree switches. (Then again, perhaps it should be.)741 # tree switches. (Then again, perhaps it should be.)

Subscribers

People subscribed via source and target branches