aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2020-11-12 23:20:52 +0100
committerNao Pross <np@0hm.ch>2020-11-12 23:20:52 +0100
commit4696b5b4405f19ca653ce0098cbda297bd61f4d2 (patch)
treebd087e17080153dbc2315cb88cff478a1034d077
parentFix double-click to download and open file (diff)
downloadMuddle-4696b5b4405f19ca653ce0098cbda297bd61f4d2.tar.gz
Muddle-4696b5b4405f19ca653ce0098cbda297bd61f4d2.zip
Temporary fix for missing autotristate bug
Diffstat (limited to '')
-rw-r--r--gui.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/gui.py b/gui.py
index 2471a30..2439f72 100644
--- a/gui.py
+++ b/gui.py
@@ -20,6 +20,7 @@ from PyQt5.QtCore import (
Qt,
QDir,
QThread,
+ QSignalBlocker,
pyqtSlot,
pyqtSignal,
QObject,
@@ -100,6 +101,9 @@ class MoodleItem(QStandardItem):
self.setIcon(QIcon())
if self.metadata.type in [ MoodleItem.Type.FILE, MoodleItem.Type.FOLDER, MoodleItem.Type.RESOURCE ]:
+ # NOTE: because of a Qt Bug setAutoTristate does not work
+ # the tri-state behavior is implemented below in
+ # MuddleWindow.onMoodleTreeModelDataChanged()
self.setCheckable(True)
self.setCheckState(Qt.Unchecked)
@@ -280,13 +284,14 @@ class MuddleWindow(QMainWindow):
# set up proxymodel for moodle treeview
self.moodleTreeModel = MoodleTreeModel()
- self.filterModel = MoodleTreeFilterModel()
+ self.moodleTreeModel.dataChanged.connect(self.onMoodleTreeModelDataChanged)
+ self.filterModel = MoodleTreeFilterModel()
self.filterModel.setRecursiveFilteringEnabled(True)
self.filterModel.setDynamicSortFilter(True)
+ self.filterModel.setSourceModel(self.moodleTreeModel)
moodleTreeView = self.findChild(QTreeView, "moodleTree")
- self.filterModel.setSourceModel(self.moodleTreeModel)
moodleTreeView.setModel(self.filterModel)
moodleTreeView.setSortingEnabled(True)
moodleTreeView.sortByColumn(0, Qt.AscendingOrder)
@@ -392,6 +397,19 @@ class MuddleWindow(QMainWindow):
else: # linux variants
subprocess.Popen(('xdg-open', filepath))
+ # this is here to emulate the behavior of setAutoTristate which does not
+ # work because of a Qt Bug
+ @pyqtSlot(QModelIndex, QModelIndex)
+ def onMoodleTreeModelDataChanged(self, topLeft, bottomRight):
+ # TODO: this can probably be moved in Item.setData() by creating AutoTriStateRole
+ item = self.moodleTreeModel.itemFromIndex(topLeft)
+
+ if item.hasChildren():
+ for i in range(0, item.rowCount()):
+ # NOTE: this causes the child to emit a signal, which
+ # automatically causes to recursively set its children
+ item.child(i).setCheckState(item.checkState())
+
def start(instance_url, token):
app = QApplication(sys.argv)