diff -r 5849ec046555 -r 26d6c2d13e47 tests/qt_repotreemodel_test.py
--- a/tests/qt_repotreemodel_test.py Tue Jul 13 19:50:10 2021 +0900
+++ b/tests/qt_repotreemodel_test.py Mon Apr 26 19:58:19 2021 +0200
@@ -3,8 +3,11 @@
from xml.dom import minidom
from tortoisehg.hgqt.qtcore import (
+ pyqtSignal,
QByteArray,
QBuffer,
+ QModelIndex,
+ QObject,
QIODevice,
)
@@ -124,3 +127,77 @@
repr(subroot.child(0))
assert type(subroot.child(1)) is repotreeitem.SubrepoItem, \
repr(subroot.child(1))
+
+filter_data = br'''<?xml version="1.0" encoding="UTF-8"?>
+<reporegistry>
+ <treeitem>
+ <allgroup name="default">
+ <repo root="/standalone" shortname="standalone" basenode="6c30f00cc82daff63b1260eec198256a9c8e5a56"/>
+ <repo root="/subroot" shortname="subroot" basenode="b986218ba1c9b0d6a259fac9b050b1724ed8e545">
+ <subrepo root="/subroot/svnsub" repotype="svn" shortname="svn"/>
+ <subrepo root="/subroot/sub" shortname="sub" basenode="2f425e331c8cdffa5103f3b181358092245bdc10"/>
+ </repo>
+ </allgroup>
+ <group name="fooGroup">
+ <group name="barGroup">
+ <repo root="/subsubroot" shortname="subsubroot2" basenode="b986218ba1c9b0d6a259fac9b050b1724ed8e545">
+ <subrepo root="/subsubroot/subroot2" shortname="subroot2" basenode="b986218ba1c9b0d6a259fac9b050b1724ed8e545">
+ <subrepo root="/subsubroot/subroot2/svnsub2" repotype="svn"/>
+ <subrepo root="/subsubroot/subroot2/sub2" shortname="sub2" basenode="2f425e331c8cdffa5103f3b181358092245bdc10"/>
+ </subrepo>
+ </repo>
+ </group>
+ </group>
+ </treeitem>
+</reporegistry>
+'''
+
+class DummyRepoManager(QObject):
+ configChanged = pyqtSignal(str)
+ repositoryChanged = pyqtSignal(str)
+ repositoryOpened = pyqtSignal(str)
+
+@with_qbuffer(filter_data)
+def test_repotreemodel(f):
+ """Test data used for the filtering tests"""
+ repomanager = DummyRepoManager()
+ model = repotreemodel.RepoTreeModel(f, repomanager)
+
+ rootIndex = QModelIndex()
+ assert model.rowCount(rootIndex) is 2
+
+ assert model.data(model.index(0, 1, rootIndex)) is ''
+ allGroupIndex = model.index(0, 0, rootIndex)
+ assert model.data(allGroupIndex) == 'default'
+ assert model.rowCount(allGroupIndex) is 2
+ assert model.data(model.index(0, 0, allGroupIndex)) == 'standalone'
+ assert model.data(model.index(0, 1, allGroupIndex)) == '/standalone'
+ assert model.data(model.index(1, 1, allGroupIndex)) == '/subroot'
+ subrootIndex = model.index(1, 0, allGroupIndex)
+ assert model.data(subrootIndex) == 'subroot'
+ assert model.rowCount(subrootIndex) is 2
+ assert model.data(model.index(0, 0, subrootIndex)) == 'svnsub'
+ assert model.data(model.index(0, 1, subrootIndex)) == '/subroot/svnsub'
+ assert model.data(model.index(1, 0, subrootIndex)) == 'sub'
+ assert model.data(model.index(1, 1, subrootIndex)) == '/subroot/sub'
+
+ assert model.data(model.index(1, 1, rootIndex)) is ''
+ fooGroupIndex = model.index(1, 0, rootIndex)
+ assert model.data(fooGroupIndex) == 'fooGroup'
+ assert model.rowCount(fooGroupIndex) is 1
+ assert model.data(model.index(0, 1, fooGroupIndex)) == ''
+ barGroupIndex = model.index(0, 0, fooGroupIndex)
+ assert model.data(barGroupIndex) == 'barGroup'
+ assert model.rowCount(barGroupIndex) is 1
+ assert model.data(model.index(0, 1, barGroupIndex)) == '/subsubroot'
+ subsubroot2Index = model.index(0, 0, barGroupIndex)
+ assert model.data(subsubroot2Index) == 'subsubroot2'
+ assert model.rowCount(subsubroot2Index) is 1
+ assert model.data(model.index(0, 1, subsubroot2Index)) == '/subsubroot/subroot2'
+ subroot2Index = model.index(0, 0, subsubroot2Index)
+ assert model.data(subroot2Index) == 'subroot2'
+ assert model.rowCount(subroot2Index) is 2
+ assert model.data(model.index(0, 0, subroot2Index)) == 'svnsub2'
+ assert model.data(model.index(0, 1, subroot2Index)) == '/subsubroot/subroot2/svnsub2'
+ assert model.data(model.index(1, 0, subroot2Index)) == 'sub2'
+ assert model.data(model.index(1, 1, subroot2Index)) == '/subsubroot/subroot2/sub2'
diff -r 5849ec046555 -r 26d6c2d13e47 tortoisehg/hgqt/reporegistry.py
--- a/tortoisehg/hgqt/reporegistry.py Tue Jul 13 19:50:10 2021 +0900
+++ b/tortoisehg/hgqt/reporegistry.py Mon Apr 26 19:58:19 2021 +0200
@@ -10,6 +10,7 @@
import os
from .qtcore import (
+ QFile,
QFileSystemWatcher,
QModelIndex,
QPoint,
@@ -263,7 +264,7 @@
self._updateSettingActions()
sfile = settingsfilename()
- model = repotreemodel.RepoTreeModel(sfile, repomanager, self,
+ model = repotreemodel.RepoTreeModel(QFile(sfile), repomanager, self,
showShortPaths=self._isSettingEnabled('showShortPaths'))
tv.setModel(model)
@@ -383,7 +384,7 @@
oldmodel = self.tview.model()
assert oldmodel is not None
activeroot = oldmodel.repoRoot(oldmodel.activeRepoIndex())
- newmodel = repotreemodel.RepoTreeModel(settingsfilename(),
+ newmodel = repotreemodel.RepoTreeModel(QFile(settingsfilename()),
self._repomanager, self,
self._isSettingEnabled('showShortPaths'))
self.tview.setModel(newmodel)
@@ -433,7 +434,7 @@
self._scanAddedRepo(index)
def setActiveTabRepo(self, root):
- """"The selected tab has changed on the workbench"""
+ """The selected tab has changed on the workbench"""
m = self.tview.model()
assert m is not None
index = m.indexFromRepoRoot(root)
diff -r 5849ec046555 -r 26d6c2d13e47 tortoisehg/hgqt/repotreemodel.py
--- a/tortoisehg/hgqt/repotreemodel.py Tue Jul 13 19:50:10 2021 +0900
+++ b/tortoisehg/hgqt/repotreemodel.py Mon Apr 26 19:58:19 2021 +0200
@@ -90,7 +90,7 @@
class RepoTreeModel(QAbstractItemModel):
- def __init__(self, filename, repomanager, parent=None,
+ def __init__(self, f, repomanager, parent=None,
showShortPaths=False):
QAbstractItemModel.__init__(self, parent)
@@ -103,8 +103,7 @@
self._activeRepoItem = None
root = None
- if filename:
- f = QFile(filename)
+ if f:
if f.open(QIODevice.ReadOnly):
root = readXml(f, reporegistryXmlElementName)
f.close()