annotate FeedEntryTableModel.py @ 92:7c6e500c1579

alternating row colors in feed entry list
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 27 Dec 2010 07:26:42 +0100
parents e5d5fc34ff2e
children a16c4e2b2c55
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
91
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
1
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
2 from PyQt4.QtCore import QAbstractTableModel, QVariant, Qt
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
3
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
4 class TableModel(QAbstractTableModel):
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
5 '''
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
6 This is the abstract super class for table models in Python. It deals with the Qt specifics so
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
7 that subclasses only need to care about implementing the functionality
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
8 '''
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
9 def __init__(self, *args):
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
10 QAbstractTableModel.__init__(self, None, *args)
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
11
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
12 def headerData(self, col, orientation, role):
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
13 if orientation == Qt.Horizontal and role == Qt.DisplayRole:
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
14 value = self.headerDataForColumn(col)
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
15 return QVariant(value)
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
16 else:
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
17 return QVariant()
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
18
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
19 def data(self, index, role):
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
20 if not index.isValid():
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
21 return QVariant()
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
22 elif role != Qt.DisplayRole:
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
23 return QVariant()
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
24 else:
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
25 value = self.dataForRowAndColumn(index.row(), index.column())
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
26 return QVariant(value)
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
27
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
28
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
29 class FeedEntryTableModel(TableModel):
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
30 def __init__(self, feedEntries, *args):
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
31 TableModel.__init__(self, *args)
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
32 self.feedEntries = feedEntries
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
33
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
34 def rowCount(self, index):
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
35 return len(self.feedEntries)
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
36
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
37 def columnCount(self, index):
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
38 return 2
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
39
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
40 def dataForRowAndColumn(self, row, column):
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
41 feedEntry = self.feedEntries[row]
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
42 if column == 0:
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
43 return feedEntry.title
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
44 else:
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
45 return str(feedEntry.updated)
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
46
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
47 def headerDataForColumn(self, column):
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
48 if column == 0:
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
49 return "Title"
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
50 else:
e5d5fc34ff2e convert feed list to a table view. TODO: proper resizing for columns
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
51 return "Date"