annotate FeedEntryTableModel.py @ 127:c923e4c57a81 backend

remove commented code
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 22 Aug 2011 14:26:54 +0200
parents a16c4e2b2c55
children bb3c851b18b1
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
94
a16c4e2b2c55 rename some parameters to be in line with the pyqt docs
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 91
diff changeset
12 def headerData(self, section, orientation, role):
91
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:
94
a16c4e2b2c55 rename some parameters to be in line with the pyqt docs
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 91
diff changeset
14 value = self.headerDataForColumn(section)
91
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
94
a16c4e2b2c55 rename some parameters to be in line with the pyqt docs
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 91
diff changeset
34 def rowCount(self, parent):
91
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
94
a16c4e2b2c55 rename some parameters to be in line with the pyqt docs
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 91
diff changeset
37 def columnCount(self, parent):
91
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"