annotate DisplayModel.py @ 113:04f8cf1558c1

Add a menu item to copy the selected article's link to the clipboard
author Dirk Olmes <dirk@xanthippe.ping.de>
date Fri, 29 Apr 2011 12:15:57 +0200
parents c8bb3cee7935
children 04a730f9d07d
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):
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()