Mercurial > hg > Feedworm
comparison DisplayModel.py @ 225:f6dcc85cd8ca
use SIP API v2
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Thu, 22 May 2014 05:49:46 +0200 |
parents | 699d8f1cebd4 |
children |
comparison
equal
deleted
inserted
replaced
224:218c2b376169 | 225:f6dcc85cd8ca |
---|---|
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 from PyQt4.QtCore import QAbstractListModel, QModelIndex, QVariant, Qt | 2 from PyQt4.QtCore import QAbstractListModel, QModelIndex, Qt |
3 | 3 |
4 class DisplayModel(QAbstractListModel): | 4 class DisplayModel(QAbstractListModel): |
5 def __init__(self, parent=None, list=None, displayAttribute=None, **args): | 5 def __init__(self, parent=None, list=None, displayAttribute=None, **args): |
6 super(DisplayModel, self).__init__(parent, *args) | 6 super(DisplayModel, self).__init__(parent, *args) |
7 self.list = list | 7 self.list = list |
13 def data(self, index, role): | 13 def data(self, index, role): |
14 if index.isValid() and role == Qt.DisplayRole: | 14 if index.isValid() and role == Qt.DisplayRole: |
15 row = index.row() | 15 row = index.row() |
16 item = self.list[row] | 16 item = self.list[row] |
17 displayString = self._stringToDisplay(item) | 17 displayString = self._stringToDisplay(item) |
18 return QVariant(displayString) | 18 return displayString |
19 else: | 19 else: |
20 return QVariant() | 20 return None |
21 | 21 |
22 def _stringToDisplay(self, item): | 22 def _stringToDisplay(self, item): |
23 if hasattr(item, self.displayAttribute): | 23 if hasattr(item, self.displayAttribute): |
24 return getattr(item, self.displayAttribute) | 24 return getattr(item, self.displayAttribute) |
25 else: | 25 else: |