-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventmodel.cpp
executable file
·65 lines (56 loc) · 1.38 KB
/
eventmodel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <QtGui>
#include "eventmodel.h"
#include "vcalparser.h"
#include "tevent.h"
EventModel::EventModel(QObject *parent)
: QAbstractTableModel(parent)
{
}
void EventModel::fetchData(VCalParser *parser)
{
modelData = parser->m_events;
reset();
qDebug() << "[info] there are" << modelData.size() << "events";
}
int EventModel::rowCount(const QModelIndex & /* parent */) const
{
return modelData.count();
}
int EventModel::columnCount(const QModelIndex & /* parent */) const
{
return 2;
}
QVariant EventModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid())
return QVariant();
TEvent event = modelData.at(index.row());
switch(role) {
case RoleSummary:
return event.getSummary();
case RoleDate:
return event.getStartString();
case RoleRemaining:
return event.getRemaining();
case RoleLocation:
return event.getLocation();
default:
return QVariant();
}
}
QVariant EventModel::headerData(int section, Qt::Orientation /* orientation */, int role) const
{
if (role == Qt::SizeHintRole) {
//qDebug() << "header data - size hint ";
switch(section) {
case 0: return QSize(100, 18);
case 1: return QSize(60, 18);
}
}
//qDebug() << "header data requested: \n\tsection: " << section << "\n\trole: " << role;
switch(section) {
case 0: return QString("Event");
case 1: return QString("Time");
default: return QVariant();
}
}