diff DisplayModel.py @ 130:1e6274cca035

merge with "backend" branch
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 22 Aug 2011 15:30:33 +0200
parents 04a730f9d07d
children c5a427d46703
line wrap: on
line diff
--- a/DisplayModel.py	Sun Aug 21 02:44:13 2011 +0200
+++ b/DisplayModel.py	Mon Aug 22 15:30:33 2011 +0200
@@ -2,19 +2,25 @@
 from PyQt4.QtCore import QAbstractListModel, QModelIndex, QVariant, Qt
 
 class DisplayModel(QAbstractListModel):
-    def __init__(self, parent=None, list=None, displayFunction=None, **args):
+    def __init__(self, parent=None, list=None, displayAttribute=None, **args):
         QAbstractListModel.__init__(self, parent, *args)
         self.list = list
-        self.displayFunction = displayFunction
-                
+        self.displayAttribute = displayAttribute
+
     def rowCount(self, parent=QModelIndex()):
         return len(self.list)
-    
-    def data(self, index, role): 
+
+    def data(self, index, role):
         if index.isValid() and role == Qt.DisplayRole:
             row = index.row()
             object = self.list[row]
-            displayString = self.displayFunction(object)
+            displayString = self._stringToDisplay(object)
             return QVariant(displayString)
-        else: 
+        else:
             return QVariant()
+
+    def _stringToDisplay(self, object):
+        if hasattr(object, self.displayAttribute):
+            return getattr(object, self.displayAttribute)
+        else:
+            return "invalid display attribute: " + self.displayAttribute