diff MainWindow.py @ 228:94a902de5266

use GenericTableModel instead of FeedEntryTableModel
author Dirk Olmes <dirk@xanthippe.ping.de>
date Sat, 31 May 2014 04:23:53 +0200
parents 016c89dfd488
children 9faa1f84e8c9
line wrap: on
line diff
--- a/MainWindow.py	Wed May 28 02:47:40 2014 +0200
+++ b/MainWindow.py	Sat May 31 04:23:53 2014 +0200
@@ -2,8 +2,8 @@
 import subprocess
 from AddFeed import AddFeed
 from PyQtLib.GenericListModel import GenericListModel
+from PyQtLib.GenericTableModel import GenericTableModel
 from FeedEntryItemDelegate import FeedEntryItemDelegate
-from FeedEntryTableModel import FeedEntryTableModel
 from FeedSettings import FeedSettings
 from PreferencesDialog import PreferencesDialog
 from PyQt4.QtCore import QUrl
@@ -20,7 +20,7 @@
         self.ui = Ui_MainWindow()
         self.ui.setupUi(self)
         self.updateFeedList()
-        self.initFeedEntryList()
+        self.initFeedEntryTable()
 
     def updateFeedList(self):
         allFeeds = self.backend.getFeeds()
@@ -28,13 +28,22 @@
         self.ui.feedList.setModel(feedModel)
         self.ui.feedList.update()
 
-    def initFeedEntryList(self):
+    def initFeedEntryTable(self):
         # setup the default row height. This must be called before a table model is set
-        self.ui.feedEntryList.verticalHeader().setDefaultSectionSize(20)
+        self.ui.feedEntryTable.verticalHeader().setDefaultSectionSize(20)
 
-        self.ui.feedEntryList.setItemDelegate(FeedEntryItemDelegate())
-        self.ui.feedEntryList.setModel(FeedEntryTableModel([]))
-        self.ui.feedEntryList.horizontalHeader().setStretchLastSection(True)
+        self.ui.feedEntryTable.setItemDelegate(FeedEntryItemDelegate())
+        model = self.__buildFeedEntryTableModel()
+        self.ui.feedEntryTable.setModel(model)
+        self.ui.feedEntryTable.horizontalHeader().setStretchLastSection(True)
+
+    def __buildFeedEntryTableModel(self):
+        model = GenericTableModel(self,  [])
+        titleDisplay = lambda feedEntry: feedEntry.title
+        model.defineColumn('Title',  titleDisplay)        
+        dateDisplay = lambda feedEntry: feedEntry.updated.strftime('%d.%m.%Y')
+        model.defineColumn('Date',  dateDisplay)
+        return model
 
     def feedSelected(self, index):
         self.backend.selectFeed(index.row())
@@ -49,24 +58,24 @@
 
     def setupFeedEntries(self):
         self.setupFeedEntriesTableModel()
-        self.ui.feedEntryList.update()
+        self.ui.feedEntryTable.update()
         self.setupFeedEntriesTableHeaderWidths()
         self.scrollFirstRowInFeedEntriesTableToVisible()
 
     def setupFeedEntriesTableModel(self):
         feedEntries = self.backend.entriesForSelectedFeed()
-        model = FeedEntryTableModel(feedEntries)
-        self.ui.feedEntryList.setModel(model)
+        model = self.ui.feedEntryTable.model()
+        model.setDisplayedObjects(feedEntries)
 
     def setupFeedEntriesTableHeaderWidths(self):
-        width = self.ui.feedEntryList.width()
+        width = self.ui.feedEntryTable.width()
         firstColumnWidth = int(width * 0.8)
-        self.ui.feedEntryList.setColumnWidth(0, firstColumnWidth)
+        self.ui.feedEntryTable.setColumnWidth(0, firstColumnWidth)
 
     def scrollFirstRowInFeedEntriesTableToVisible(self):
-        model = self.ui.feedEntryList.model()
+        model = self.ui.feedEntryTable.model()
         visibleIndex = model.createIndex(0, 0)
-        self.ui.feedEntryList.scrollTo(visibleIndex)
+        self.ui.feedEntryTable.scrollTo(visibleIndex)
 
     def feedEntrySelected(self, index):
         self.ui.webView.setZoomFactor(1.0)
@@ -115,15 +124,15 @@
 
     def toggleReadOnSelectedEntry(self):
         self.backend.toggleSelectedFeedEntryRead()
-        self.ui.feedEntryList.doItemsLayout()
+        self.ui.feedEntryTable.doItemsLayout()
 
     def markSelectedFeedRead(self):
         self.backend.markSelectedFeedAsRead()
-        self.ui.feedEntryList.doItemsLayout()
+        self.ui.feedEntryTable.doItemsLayout()
 
     def markSelectedEntriesRead(self):
         indexes = []
-        selectedIndexes = self.ui.feedEntryList.selectedIndexes()
+        selectedIndexes = self.ui.feedEntryTable.selectedIndexes()
         for index in selectedIndexes:
             # selectedIndexes returns one QModelIndex instance per row/column combo.
             # We are only interested in the rows here so just operate on the first
@@ -132,7 +141,7 @@
                 row = index.row()
                 indexes.append(row)
         self.backend.markFeedEntriesAsRead(indexes)
-        self.ui.feedEntryList.doItemsLayout()
+        self.ui.feedEntryTable.doItemsLayout()
 
     def addFeed(self):
         addFeed = AddFeed(self.backend)