view DisplayModel.py @ 62:abc0516a1c0c

FeedEntry provides a static method for creating new entries: better modularization and support for working with the class in interactive mode. FeedUpdater's normalize method is a module function now, again for ease of use in interactive scenarios
author dirk@xanthippe.ping.de
date Wed, 28 Jul 2010 20:30:34 +0200
parents c8bb3cee7935
children 04a730f9d07d
line wrap: on
line source


from PyQt4.QtCore import QAbstractListModel, QModelIndex, QVariant, Qt

class DisplayModel(QAbstractListModel):
    def __init__(self, parent=None, list=None, displayFunction=None, **args):
        QAbstractListModel.__init__(self, parent, *args)
        self.list = list
        self.displayFunction = displayFunction
                
    def rowCount(self, parent=QModelIndex()):
        return len(self.list)
    
    def data(self, index, role): 
        if index.isValid() and role == Qt.DisplayRole:
            row = index.row()
            object = self.list[row]
            displayString = self.displayFunction(object)
            return QVariant(displayString)
        else: 
            return QVariant()