Make download model qtmodeltester compliant

This commit is contained in:
Florian Bruhin 2016-09-10 00:12:03 +02:00
parent 3bf841bdb4
commit cc4cd6913d

View File

@ -1263,7 +1263,7 @@ class DownloadManager(QAbstractListModel):
qtutils.ensure_valid(model_idx) qtutils.ensure_valid(model_idx)
self.dataChanged.emit(model_idx, self.last_index()) self.dataChanged.emit(model_idx, self.last_index())
def headerData(self, section, orientation, role): def headerData(self, section, orientation, role=Qt.DisplayRole):
"""Simple constant header.""" """Simple constant header."""
if (section == 0 and orientation == Qt.Horizontal and if (section == 0 and orientation == Qt.Horizontal and
role == Qt.DisplayRole): role == Qt.DisplayRole):
@ -1273,9 +1273,11 @@ class DownloadManager(QAbstractListModel):
def data(self, index, role): def data(self, index, role):
"""Download data from DownloadManager.""" """Download data from DownloadManager."""
qtutils.ensure_valid(index) if not index.isValid():
return None
if index.parent().isValid() or index.column() != 0: if index.parent().isValid() or index.column() != 0:
return QVariant() return None
item = self.downloads[index.row()] item = self.downloads[index.row()]
if role == Qt.DisplayRole: if role == Qt.DisplayRole:
@ -1288,18 +1290,20 @@ class DownloadManager(QAbstractListModel):
data = item data = item
elif role == Qt.ToolTipRole: elif role == Qt.ToolTipRole:
if item.error_msg is None: if item.error_msg is None:
data = QVariant() data = None
else: else:
return item.error_msg return item.error_msg
else: else:
data = QVariant() data = None
return data return data
def flags(self, _index): def flags(self, index):
"""Override flags so items aren't selectable. """Override flags so items aren't selectable.
The default would be Qt.ItemIsEnabled | Qt.ItemIsSelectable. The default would be Qt.ItemIsEnabled | Qt.ItemIsSelectable.
""" """
if not index.isValid():
return 0
return Qt.ItemIsEnabled | Qt.ItemNeverHasChildren return Qt.ItemIsEnabled | Qt.ItemNeverHasChildren
def rowCount(self, parent=QModelIndex()): def rowCount(self, parent=QModelIndex()):