Mercurial > hg > Feedworm
comparison 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 |
comparison
equal
deleted
inserted
replaced
90:a1066e5a8f88 | 91:e5d5fc34ff2e |
---|---|
1 | |
2 from PyQt4.QtCore import QAbstractTableModel, QVariant, Qt | |
3 | |
4 class TableModel(QAbstractTableModel): | |
5 ''' | |
6 This is the abstract super class for table models in Python. It deals with the Qt specifics so | |
7 that subclasses only need to care about implementing the functionality | |
8 ''' | |
9 def __init__(self, *args): | |
10 QAbstractTableModel.__init__(self, None, *args) | |
11 | |
12 def headerData(self, col, orientation, role): | |
13 if orientation == Qt.Horizontal and role == Qt.DisplayRole: | |
14 value = self.headerDataForColumn(col) | |
15 return QVariant(value) | |
16 else: | |
17 return QVariant() | |
18 | |
19 def data(self, index, role): | |
20 if not index.isValid(): | |
21 return QVariant() | |
22 elif role != Qt.DisplayRole: | |
23 return QVariant() | |
24 else: | |
25 value = self.dataForRowAndColumn(index.row(), index.column()) | |
26 return QVariant(value) | |
27 | |
28 | |
29 class FeedEntryTableModel(TableModel): | |
30 def __init__(self, feedEntries, *args): | |
31 TableModel.__init__(self, *args) | |
32 self.feedEntries = feedEntries | |
33 | |
34 def rowCount(self, index): | |
35 return len(self.feedEntries) | |
36 | |
37 def columnCount(self, index): | |
38 return 2 | |
39 | |
40 def dataForRowAndColumn(self, row, column): | |
41 feedEntry = self.feedEntries[row] | |
42 if column == 0: | |
43 return feedEntry.title | |
44 else: | |
45 return str(feedEntry.updated) | |
46 | |
47 def headerDataForColumn(self, column): | |
48 if column == 0: | |
49 return "Title" | |
50 else: | |
51 return "Date" |