view DisplayModel.py @ 50:4b0d686493fb

better error handling while adding feeds: data is only saved if a feed could be created and entries could be retrieved. MainWindow displays feedback in the status bar if an exception occurred while adding a feed.
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 17 May 2010 04:30:55 +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()