diff FeedEntryTableModel.py @ 91:e5d5fc34ff2e

convert feed list to a table view. TODO: proper resizing for columns
author Dirk Olmes <dirk@xanthippe.ping.de>
date Sun, 26 Dec 2010 08:35:36 +0100
parents
children a16c4e2b2c55
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FeedEntryTableModel.py	Sun Dec 26 08:35:36 2010 +0100
@@ -0,0 +1,51 @@
+
+from PyQt4.QtCore import QAbstractTableModel, QVariant, Qt
+
+class TableModel(QAbstractTableModel):
+    '''
+    This is the abstract super class for table models in Python. It deals with the Qt specifics so
+    that subclasses only need to care about implementing the functionality
+    '''
+    def __init__(self, *args):
+        QAbstractTableModel.__init__(self, None, *args)
+
+    def headerData(self, col, orientation, role):
+        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
+            value = self.headerDataForColumn(col)
+            return QVariant(value)
+        else:
+            return QVariant()
+
+    def data(self, index, role):
+        if not index.isValid():
+            return QVariant()
+        elif role != Qt.DisplayRole:
+            return QVariant()
+        else:
+            value = self.dataForRowAndColumn(index.row(), index.column())
+            return QVariant(value)
+
+
+class FeedEntryTableModel(TableModel):
+    def __init__(self, feedEntries, *args):
+        TableModel.__init__(self, *args)
+        self.feedEntries = feedEntries
+
+    def rowCount(self, index):
+        return len(self.feedEntries)
+
+    def columnCount(self, index):
+        return 2
+
+    def dataForRowAndColumn(self, row, column):
+        feedEntry = self.feedEntries[row]
+        if column == 0:
+            return feedEntry.title
+        else:
+            return str(feedEntry.updated)
+
+    def headerDataForColumn(self, column):
+        if column == 0:
+            return "Title"
+        else:
+            return "Date"