def data(self, index, role=Qt.DisplayRole):
        """ Returns the data stored under the given role for the item referred to by the index.

            Calls self.itemData for valid items. Descendants should typically override itemData
            instead of this function.
        """
        try:
            if index.isValid():
                item = self.getItem(index, altItem=self.invisibleRootItem)
                return self.itemData(item, index.column(), role=role)
            else:
                return None
        except Exception as ex:
            # This Qt slot is called directly from the event loop so uncaught exception make the
            # application crash (exceptions can come from plugins here). Instead of crashing we
            # show the error message in the table/tree and hope the users report the error.
            if not DEBUGGING and role in (Qt.DisplayRole, Qt.EditRole, Qt.ToolTipRole,
                                          Qt.StatusTipRole, Qt.WhatsThisRole):
                return repr(ex)
            else:
                raise