00001 #include "historymodel.h"
00002 
00003 HistoryModel::HistoryModel(QObject *parent, DataProject *project): QAbstractTableModel(parent)
00004 {
00005     history = project->getChangeHistory();
00006     headers << "Name" << "Beschreibung" << "Besitzer" << "E-Mail";
00007 }
00008 
00009 int HistoryModel::rowCount(const QModelIndex &parent) const
00010 {
00011     Q_UNUSED(parent);
00012     return history.size();
00013 }
00014 
00015 int HistoryModel::columnCount(const QModelIndex &parent) const
00016 {
00017     Q_UNUSED(parent);
00018     return 4;
00019 }
00020 
00021 QStringList HistoryModel::data(const int row) const
00022 {
00023     QStringList rv;
00024     rv << history[row]->title() << history[row]->description() << history[row]->ownerName() << history[row]->ownerEmail();
00025     return rv;
00026 }
00027 
00028 QVariant HistoryModel::data(const QModelIndex &index, int role) const
00029 {
00030     if(!index.isValid() || index.row() >= history.size() || index.row() < 0)
00031     {
00032         return QVariant();
00033     }
00034 
00035     if(role == Qt::DisplayRole)
00036     {
00037         return data(index.row())[index.column()];
00038     }
00039     return QVariant();
00040 }
00041 
00042 QVariant HistoryModel::headerData(int section, Qt::Orientation orientation, int role) const
00043 {
00044     if(role != Qt::DisplayRole)
00045     {
00046         return QVariant();
00047     }
00048     if(orientation == Qt::Horizontal)
00049     {
00050         return headers[section];
00051     }
00052     return QVariant();
00053 }
00054 
00055 Qt::ItemFlags HistoryModel::flags(const QModelIndex &index) const
00056 {
00057     if(!index.isValid())
00058     {
00059         return 0;
00060     }
00061 
00062     return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
00063 }