QXRD  0.11.16
qxrdtodolist.cpp
Go to the documentation of this file.
1 #include "qxrdtodolist.h"
2 #include "qxrdtodolistitem.h"
3 #include "qcepmacros.h"
4 #include <QFont>
5 
6 #define TODO(d1,d2,s) m_Items.append(QxrdToDoListItemPtr(new QxrdToDoListItem(id++,true,d1,d2,s)));
7 #define DONE(d1,d2,s) m_Items.append(QxrdToDoListItemPtr(new QxrdToDoListItem(id++,false,d1,d2,s)));
8 
9 QxrdToDoList::QxrdToDoList(QObject *parent)
10  : QAbstractListModel(parent)
11 {
12  int id=0;
13 
14 #include "TODO.h"
15 }
16 
17 int QxrdToDoList::rowCount(const QModelIndex &parent) const
18 {
19  return m_Items.count();
20 }
21 
22 int QxrdToDoList::columnCount(const QModelIndex &parent) const
23 {
24  return 5;
25 }
26 
27 QVariant QxrdToDoList::data(const QModelIndex &index, int role) const
28 {
29  int row = index.row();
30  int col = index.column();
31 
32  QxrdToDoListItemPtr item = m_Items.value(row);
33 
34  if (role == Qt::DisplayRole && item) {
35  if (col == IdentifierColumn) {
36  return item->identifier();
37  } else if (col == ActiveColumn) {
38  return item->isActive();
39  } else if (col == InsertedDateColumn) {
40  return item->insertedDate().date();
41  } else if (col == CompletedDateColumn) {
42  return item->completedDate().date();
43  } else if (col == DescriptionColumn) {
44  return item->description();
45  }
46  } else if (role == Qt::TextAlignmentRole) {
47  if (col == IdentifierColumn || col == ActiveColumn || col == InsertedDateColumn || col == CompletedDateColumn) {
48  return QVariant(Qt::AlignHCenter | Qt::AlignTop);
49  } else if (col == DescriptionColumn) {
50  return QVariant(Qt::AlignLeft | Qt::AlignTop);
51  }
52 // } else if (role == Qt::FontRole) {
53 // QFont f;
54 // f.setPointSize(10);
55 
56 // return QVariant(f);
57  }
58 
59  return QVariant();
60 }
61 
62 QVariant QxrdToDoList::headerData(int section, Qt::Orientation orientation, int role) const
63 {
64  if (orientation == Qt::Horizontal) {
65  if (role == Qt::DisplayRole) {
66  if (section == IdentifierColumn) {
67  return "Id";
68  } else if (section == ActiveColumn) {
69  return "Active";
70  } else if (section == InsertedDateColumn) {
71  return "Started";
72  } else if (section == CompletedDateColumn) {
73  return "Completed";
74  } else if (section == DescriptionColumn) {
75  return "Description";
76  }
77  }
78  }
79 
80  return QVariant();
81 }
QVariant data(const QModelIndex &index, int role) const
QVector< QxrdToDoListItemPtr > m_Items
Definition: qxrdtodolist.h:33
QSharedPointer< QxrdToDoListItem > QxrdToDoListItemPtr
QxrdToDoList(QObject *parent=NULL)
Definition: qxrdtodolist.cpp:9
int rowCount(const QModelIndex &parent) const
QVariant headerData(int section, Qt::Orientation orientation, int role) const
int columnCount(const QModelIndex &parent) const