src/eric7/Testing/TestResultsTree.py

branch
eric7-maintenance
changeset 10460
3b34efa2857c
parent 10079
0222a480e93d
parent 10439
21c28b0f9e41
child 10694
f46c1e224e8a
equal deleted inserted replaced
10366:411df92e881f 10460:3b34efa2857c
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 2
3 # Copyright (c) 2022 - 2023 Detlev Offenbach <detlev@die-offenbachs.de> 3 # Copyright (c) 2022 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>
4 # 4 #
5 5
6 """ 6 """
7 Module implementing a tree view and associated model to show the test result 7 Module implementing a tree view and associated model to show the test result
8 data. 8 data.
18 from PyQt6.QtCore import ( 18 from PyQt6.QtCore import (
19 QAbstractItemModel, 19 QAbstractItemModel,
20 QCoreApplication, 20 QCoreApplication,
21 QModelIndex, 21 QModelIndex,
22 QPoint, 22 QPoint,
23 QSortFilterProxyModel,
23 Qt, 24 Qt,
24 pyqtSignal, 25 pyqtSignal,
25 pyqtSlot, 26 pyqtSlot,
26 ) 27 )
27 from PyQt6.QtGui import QBrush, QColor 28 from PyQt6.QtGui import QBrush, QColor
420 counts[TestResultCategory.OK], 421 counts[TestResultCategory.OK],
421 counts[TestResultCategory.SKIP], 422 counts[TestResultCategory.SKIP],
422 counts[TestResultCategory.PENDING], 423 counts[TestResultCategory.PENDING],
423 ) 424 )
424 425
426 def getStatusFilterList(self):
427 """
428 Public method to get a list of the unique test result status.
429
430 @return test result status
431 @rtype set of str
432 """
433 return {t.status for t in self.__testResults}
434
435
436 class TestResultsFilterModel(QSortFilterProxyModel):
437 """
438 Class implementing a filter model to filter the test results by status.
439 """
440
441 def __init__(self, parent=None):
442 """
443 Constructor
444
445 @param parent reference to the parent object
446 @type QObject
447 """
448 super().__init__(parent)
449
450 self.__statusFilterString = ""
451
452 def filterAcceptsRow(self, sourceRow, sourceParent):
453 """
454 Public method to determine, if the row is acceptable.
455
456 @param sourceRow row number in the source model
457 @type int
458 @param sourceParent index of the source item
459 @type QModelIndex
460 @return flag indicating acceptance
461 @rtype bool
462 """
463 sm = self.sourceModel()
464 idx = sm.index(sourceRow, 0, sourceParent)
465 status = sm.data(idx, Qt.ItemDataRole.DisplayRole)
466 return (
467 sourceParent.isValid()
468 or self.__statusFilterString == ""
469 or status == self.__statusFilterString
470 )
471
472 def setStatusFilterString(self, filterString):
473 """
474 Public method to set the status filter string.
475
476 @param filterString status filter string
477 @type str
478 """
479 self.__statusFilterString = filterString
480 self.invalidateRowsFilter()
481
425 482
426 class TestResultsTreeView(QTreeView): 483 class TestResultsTreeView(QTreeView):
427 """ 484 """
428 Class implementing a tree view to show the test result data. 485 Class implementing a tree view to show the test result data.
429 486
450 self.header().setSortIndicatorShown(False) 507 self.header().setSortIndicatorShown(False)
451 508
452 self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) 509 self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
453 510
454 # connect signals and slots 511 # connect signals and slots
455 self.doubleClicked.connect(self.__gotoTestDefinition) 512 self.activated.connect(self.__gotoTestDefinition)
456 self.customContextMenuRequested.connect(self.__showContextMenu) 513 self.customContextMenuRequested.connect(self.__showContextMenu)
457 514
458 self.header().sortIndicatorChanged.connect(self.sortByColumn) 515 self.header().sortIndicatorChanged.connect(self.sortByColumn)
459 self.header().sortIndicatorChanged.connect( 516 self.header().sortIndicatorChanged.connect(
460 lambda col, order: self.header().setSortIndicatorShown(True) # noqa: U100 517 lambda col, order: self.header().setSortIndicatorShown(True) # noqa: U100
557 @param index index for the double-clicked item 614 @param index index for the double-clicked item
558 @type QModelIndex 615 @type QModelIndex
559 """ 616 """
560 cindex = self.__canonicalIndex(index) 617 cindex = self.__canonicalIndex(index)
561 filename, lineno = self.model().data(cindex, Qt.ItemDataRole.UserRole) 618 filename, lineno = self.model().data(cindex, Qt.ItemDataRole.UserRole)
562 if filename is not None: 619 if filename:
563 if lineno is None: 620 if lineno is None:
564 lineno = 1 621 lineno = 1
565 self.goto.emit(filename, lineno) 622 self.goto.emit(filename, lineno)
566 623
567 @pyqtSlot(QPoint) 624 @pyqtSlot(QPoint)
601 menu.addSeparator() 658 menu.addSeparator()
602 659
603 act = menu.addAction( 660 act = menu.addAction(
604 self.tr("Show Source"), lambda: self.__gotoTestDefinition(index) 661 self.tr("Show Source"), lambda: self.__gotoTestDefinition(index)
605 ) 662 )
606 act.setEnabled(self.model().data(index, Qt.ItemDataRole.UserRole) is not None) 663 act.setEnabled(
664 self.model().data(index, Qt.ItemDataRole.UserRole)[0] is not None
665 )
607 menu.addSeparator() 666 menu.addSeparator()
608 667
609 menu.addAction(self.tr("Collapse All"), self.collapseAll) 668 menu.addAction(self.tr("Collapse All"), self.collapseAll)
610 menu.addAction(self.tr("Expand All"), self.expandAll) 669 menu.addAction(self.tr("Expand All"), self.expandAll)
611 670

eric ide

mercurial