changeset 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 a1066e5a8f88
children 7c6e500c1579
files FeedEntryTableModel.py MainWindow.py Ui_MainWindow.ui
diffstat 3 files changed, 62 insertions(+), 3 deletions(-) [+]
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"
--- a/MainWindow.py	Fri Dec 24 05:06:21 2010 +0100
+++ b/MainWindow.py	Sun Dec 26 08:35:36 2010 +0100
@@ -2,8 +2,8 @@
 from AddFeed import AddFeed
 from DisplayModel import DisplayModel
 from Feed import Feed
-from FeedEntry import FeedEntry
 from FeedEntryItemDelegate import FeedEntryItemDelegate
+from FeedEntryTableModel import FeedEntryTableModel
 from FeedSettings import FeedSettings
 from Preferences import Preferences
 from PreferencesDialog import PreferencesDialog
@@ -34,6 +34,13 @@
 
     def initFeedEntryList(self):
         self.ui.feedEntryList.setItemDelegate(FeedEntryItemDelegate())
+        self.ui.feedEntryList.setModel(FeedEntryTableModel([]))
+
+        width = self.ui.feedEntryList.width()
+        print("width: " + str(width))
+        firstColumnWidth = int(width * 0.8)
+        self.ui.feedEntryList.setColumnWidth(0, firstColumnWidth)
+        self.ui.feedEntryList.horizontalHeader().setStretchLastSection(True)
 
     def feedSelected(self, index):
         self.selectedFeed = self.allFeeds[index.row()]
@@ -50,10 +57,11 @@
         self.initFeedDisplayModel()
 
     def initFeedDisplayModel(self):
-        model = DisplayModel(self, self.feedEntries, FeedEntry.userPresentableString)
+        model = FeedEntryTableModel(self.feedEntries)
         self.ui.feedEntryList.setModel(model)
         self.ui.feedEntryList.itemDelegate().entries = self.feedEntries
         self.ui.feedEntryList.update()
+
         visibleIndex = model.createIndex(0, 0)
         self.ui.feedEntryList.scrollTo(visibleIndex)
 
--- a/Ui_MainWindow.ui	Fri Dec 24 05:06:21 2010 +0100
+++ b/Ui_MainWindow.ui	Sun Dec 26 08:35:36 2010 +0100
@@ -36,7 +36,7 @@
        <property name="orientation">
         <enum>Qt::Vertical</enum>
        </property>
-       <widget class="QListView" name="feedEntryList"/>
+       <widget class="QTableView" name="feedEntryList"/>
        <widget class="QWebView" name="webView">
         <property name="url">
          <url>