Mercurial > hg > Feedworm
annotate DisplayModel.py @ 116:7f07ced80d6f
update README
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Sat, 20 Aug 2011 07:15:03 +0200 |
parents | c8bb3cee7935 |
children | 04a730f9d07d |
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): |
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
|
5 def __init__(self, parent=None, list=None, displayFunction=None, **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
|
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 |
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
|
8 self.displayFunction = displayFunction |
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
|
9 |
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) |
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
|
12 |
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
|
13 def data(self, index, role): |
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() |
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
|
16 object = self.list[row] |
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
|
17 displayString = self.displayFunction(object) |
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) |
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
|
19 else: |
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() |