fix errors when displaying empty table
This commit is contained in:
committed by
Thomas Peetz
parent
d98dc79cf8
commit
c6d1e4d7e7
@@ -35,10 +35,7 @@ class MediaFileTableModel(QAbstractTableModel):
|
|||||||
filter_rule += "WHERE "
|
filter_rule += "WHERE "
|
||||||
filter_rule += "review is true"
|
filter_rule += "review is true"
|
||||||
print(f"{filter_rule=}")
|
print(f"{filter_rule=}")
|
||||||
try:
|
|
||||||
cursor.execute(f"SELECT id, url, review, should_download, file_name, cloud_link FROM media_file {filter_rule}")
|
cursor.execute(f"SELECT id, url, review, should_download, file_name, cloud_link FROM media_file {filter_rule}")
|
||||||
except mariadb.Error as error:
|
|
||||||
print(error)
|
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
print(len(rows))
|
print(len(rows))
|
||||||
if len(rows) > 0:
|
if len(rows) > 0:
|
||||||
@@ -49,14 +46,13 @@ class MediaFileTableModel(QAbstractTableModel):
|
|||||||
self.endResetModel()
|
self.endResetModel()
|
||||||
else:
|
else:
|
||||||
self._data = None
|
self._data = None
|
||||||
try:
|
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
except:
|
|
||||||
|
|
||||||
self.main_window.statusBar.showMessage(f"{len(rows)} Einträge geladen", 3000)
|
self.main_window.statusBar.showMessage(f"{len(rows)} Einträge geladen", 3000)
|
||||||
|
|
||||||
def rowCount(self, parent=QModelIndex()):
|
def rowCount(self, parent=QModelIndex()):
|
||||||
# The length of the outer list.
|
# The length of the outer list.
|
||||||
|
if self._data is None:
|
||||||
|
return 0
|
||||||
return len(self._data)
|
return len(self._data)
|
||||||
|
|
||||||
def headerData(self, col, orientation, role=Qt.ItemDataRole.DisplayRole):
|
def headerData(self, col, orientation, role=Qt.ItemDataRole.DisplayRole):
|
||||||
@@ -78,6 +74,8 @@ class MediaFileTableModel(QAbstractTableModel):
|
|||||||
return str(col+1)
|
return str(col+1)
|
||||||
|
|
||||||
def data(self, index, role=Qt.ItemDataRole.DisplayRole):
|
def data(self, index, role=Qt.ItemDataRole.DisplayRole):
|
||||||
|
if self._data is None:
|
||||||
|
return None
|
||||||
value = self._data[index.row()][index.column()]
|
value = self._data[index.row()][index.column()]
|
||||||
if role == Qt.ItemDataRole.DisplayRole:
|
if role == Qt.ItemDataRole.DisplayRole:
|
||||||
if isinstance(value, datetime):
|
if isinstance(value, datetime):
|
||||||
@@ -101,6 +99,8 @@ class MediaFileTableModel(QAbstractTableModel):
|
|||||||
def columnCount(self, index=QModelIndex()):
|
def columnCount(self, index=QModelIndex()):
|
||||||
# The following takes the first sub-list, and returns
|
# The following takes the first sub-list, and returns
|
||||||
# the length (only works if all rows are an equal length)
|
# the length (only works if all rows are an equal length)
|
||||||
|
if self._data is None:
|
||||||
|
return 5
|
||||||
return len(self._data[0])
|
return len(self._data[0])
|
||||||
|
|
||||||
def setData(self, index, value, role=Qt.ItemDataRole.EditRole):
|
def setData(self, index, value, role=Qt.ItemDataRole.EditRole):
|
||||||
|
|||||||
Reference in New Issue
Block a user