annotate DisplayModel.py @ 150:babe14449162

the entries for the selected feeds had to be set onto the item delegate so had access to the selected feed entry. Keep the list in one place only (the model) and access it from the item delegate.
author Dirk Olmes <dirk@xanthippe.ping.de>
date Sat, 27 Aug 2011 06:43:28 +0200
parents c5a427d46703
children bb3c851b18b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
1
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
2 from PyQt4.QtCore import QAbstractListModel, QModelIndex, QVariant, Qt
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
3
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
4 class DisplayModel(QAbstractListModel):
119
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 21
diff changeset
5 def __init__(self, parent=None, list=None, displayAttribute=None, **args):
21
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
6 QAbstractListModel.__init__(self, parent, *args)
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
7 self.list = list
119
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 21
diff changeset
8 self.displayAttribute = displayAttribute
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 21
diff changeset
9
21
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
10 def rowCount(self, parent=QModelIndex()):
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
11 return len(self.list)
119
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 21
diff changeset
12
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 21
diff changeset
13 def data(self, index, role):
21
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
14 if index.isValid() and role == Qt.DisplayRole:
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
15 row = index.row()
148
c5a427d46703 displaying entries for a feed works now with the couchdb backend
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 119
diff changeset
16 item = self.list[row]
c5a427d46703 displaying entries for a feed works now with the couchdb backend
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 119
diff changeset
17 displayString = self._stringToDisplay(item)
21
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
18 return QVariant(displayString)
119
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 21
diff changeset
19 else:
21
c8bb3cee7935 pull out DisplayModel into its own file, add the scaffolding for the add feed menu entry
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
20 return QVariant()
119
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 21
diff changeset
21
148
c5a427d46703 displaying entries for a feed works now with the couchdb backend
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 119
diff changeset
22 def _stringToDisplay(self, item):
c5a427d46703 displaying entries for a feed works now with the couchdb backend
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 119
diff changeset
23 if hasattr(item, self.displayAttribute):
c5a427d46703 displaying entries for a feed works now with the couchdb backend
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 119
diff changeset
24 return getattr(item, self.displayAttribute)
119
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 21
diff changeset
25 else:
04a730f9d07d move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 21
diff changeset
26 return "invalid display attribute: " + self.displayAttribute