diff DisplayModel.py @ 119:04a730f9d07d backend

move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
author Dirk Olmes <dirk@xanthippe.ping.de>
date Sun, 21 Aug 2011 03:55:16 +0200
parents c8bb3cee7935
children c5a427d46703
line wrap: on
line diff
--- a/DisplayModel.py	Sun Aug 21 02:47:25 2011 +0200
+++ b/DisplayModel.py	Sun Aug 21 03:55:16 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