82 TestResultCategory.SKIP: QBrush(QColor("#c5c5c5")), |
82 TestResultCategory.SKIP: QBrush(QColor("#c5c5c5")), |
83 TestResultCategory.PENDING: QBrush(QColor("#6fbaff")), |
83 TestResultCategory.PENDING: QBrush(QColor("#6fbaff")), |
84 } |
84 } |
85 |
85 |
86 self.__testResults = [] |
86 self.__testResults = [] |
|
87 self.__testResultsById = {} |
87 |
88 |
88 def index(self, row, column, parent=QModelIndex()): |
89 def index(self, row, column, parent=QModelIndex()): |
89 """ |
90 """ |
90 Public method to generate an index for the given row and column to |
91 Public method to generate an index for the given row and column to |
91 identify the item. |
92 identify the item. |
248 """ |
249 """ |
249 Public method to clear the model data. |
250 Public method to clear the model data. |
250 """ |
251 """ |
251 self.beginResetModel() |
252 self.beginResetModel() |
252 self.__testResults.clear() |
253 self.__testResults.clear() |
|
254 self.__testResultsById.clear() |
253 self.endResetModel() |
255 self.endResetModel() |
254 |
256 |
255 self.summary.emit("") |
257 self.summary.emit("") |
256 |
258 |
257 def sort(self, column, order): |
259 def sort(self, column, order): |
305 @param testResults test results to be managed by the model |
307 @param testResults test results to be managed by the model |
306 @type list of TestResult |
308 @type list of TestResult |
307 """ |
309 """ |
308 self.beginResetModel() |
310 self.beginResetModel() |
309 self.__testResults = copy.deepcopy(testResults) |
311 self.__testResults = copy.deepcopy(testResults) |
|
312 self.__testResultsById.clear() |
|
313 for testResult in testResults: |
|
314 self.__testResultsById[testResult.id] = testResult |
310 self.endResetModel() |
315 self.endResetModel() |
311 |
316 |
312 self.summary.emit(self.__summary()) |
317 self.summary.emit(self.__summary()) |
313 |
318 |
314 def addTestResults(self, testResults): |
319 def addTestResults(self, testResults): |
321 """ |
326 """ |
322 firstRow = len(self.__testResults) |
327 firstRow = len(self.__testResults) |
323 lastRow = firstRow + len(testResults) - 1 |
328 lastRow = firstRow + len(testResults) - 1 |
324 self.beginInsertRows(QModelIndex(), firstRow, lastRow) |
329 self.beginInsertRows(QModelIndex(), firstRow, lastRow) |
325 self.__testResults.extend(testResults) |
330 self.__testResults.extend(testResults) |
|
331 for testResult in testResults: |
|
332 self.__testResultsById[testResult.id] = testResult |
326 self.endInsertRows() |
333 self.endInsertRows() |
327 |
334 |
328 self.summary.emit(self.__summary()) |
335 self.summary.emit(self.__summary()) |
329 |
336 |
330 def updateTestResults(self, testResults): |
337 def updateTestResults(self, testResults): |
338 maxIndex = None |
345 maxIndex = None |
339 |
346 |
340 testResultsToBeAdded = [] |
347 testResultsToBeAdded = [] |
341 |
348 |
342 for testResult in testResults: |
349 for testResult in testResults: |
343 for index, currentResult in enumerate(self.__testResults): |
350 if testResult.id in self.__testResultsById: |
344 if currentResult.id == testResult.id: |
351 result = self.__testResultsById[testResult.id] |
345 self.__testResults[index] = testResult |
352 index = self.__testResults.index(result) |
346 if minIndex is None: |
353 self.__testResults[index] = testResult |
347 minIndex = index |
354 self.__testResultsById[testResult.id] = testResult |
348 maxIndex = index |
355 if minIndex is None: |
349 else: |
356 minIndex = index |
350 minIndex = min(minIndex, index) |
357 maxIndex = index |
351 maxIndex = max(maxIndex, index) |
358 else: |
352 |
359 minIndex = min(minIndex, index) |
353 break |
360 maxIndex = max(maxIndex, index) |
|
361 |
354 else: |
362 else: |
355 # Test result with given id was not found. |
363 # Test result with given id was not found. |
356 # Just add it to the list (could be a sub test) |
364 # Just add it to the list (could be a sub test) |
357 testResultsToBeAdded.append(testResult) |
365 testResultsToBeAdded.append(testResult) |
358 |
366 |
447 self.doubleClicked.connect(self.__gotoTestDefinition) |
455 self.doubleClicked.connect(self.__gotoTestDefinition) |
448 self.customContextMenuRequested.connect(self.__showContextMenu) |
456 self.customContextMenuRequested.connect(self.__showContextMenu) |
449 |
457 |
450 self.header().sortIndicatorChanged.connect(self.sortByColumn) |
458 self.header().sortIndicatorChanged.connect(self.sortByColumn) |
451 self.header().sortIndicatorChanged.connect( |
459 self.header().sortIndicatorChanged.connect( |
452 lambda column, order: self.header().setSortIndicatorShown(True) |
460 lambda col, order: self.header().setSortIndicatorShown(True) # noqa: U100 |
453 ) |
461 ) |
454 |
462 |
455 def reset(self): |
463 def reset(self): |
456 """ |
464 """ |
457 Public method to reset the internal state of the view. |
465 Public method to reset the internal state of the view. |
472 @param endRow last row been inserted |
480 @param endRow last row been inserted |
473 @type int |
481 @type int |
474 """ |
482 """ |
475 super().rowsInserted(parent, startRow, endRow) |
483 super().rowsInserted(parent, startRow, endRow) |
476 |
484 |
477 self.resizeColumns() |
|
478 self.spanFirstColumn(startRow, endRow) |
485 self.spanFirstColumn(startRow, endRow) |
479 |
486 |
480 def dataChanged(self, topLeft, bottomRight, roles=[]): |
487 def dataChanged(self, topLeft, bottomRight, roles=[]): |
481 """ |
488 """ |
482 Public method called when the model data has changed. |
489 Public method called when the model data has changed. |
488 @param roles list of roles changed (defaults to []) |
495 @param roles list of roles changed (defaults to []) |
489 @type list of Qt.ItemDataRole (optional) |
496 @type list of Qt.ItemDataRole (optional) |
490 """ |
497 """ |
491 super().dataChanged(topLeft, bottomRight, roles) |
498 super().dataChanged(topLeft, bottomRight, roles) |
492 |
499 |
493 self.resizeColumns() |
|
494 while topLeft.parent().isValid(): |
500 while topLeft.parent().isValid(): |
495 topLeft = topLeft.parent() |
501 topLeft = topLeft.parent() |
496 while bottomRight.parent().isValid(): |
502 while bottomRight.parent().isValid(): |
497 bottomRight = bottomRight.parent() |
503 bottomRight = bottomRight.parent() |
498 self.spanFirstColumn(topLeft.row(), bottomRight.row()) |
504 self.spanFirstColumn(topLeft.row(), bottomRight.row()) |