-
Notifications
You must be signed in to change notification settings - Fork 0
/
notesmodel.cpp
125 lines (110 loc) · 2.18 KB
/
notesmodel.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <QtCore>
#include <QtGui>
#include "qfont.h"
#include "notesmodel.h"
#include "account.h"
bool compareNotesGreaterThan(const Note *n1, const Note *n2)
{
return n1->date_modified > n2->date_modified;
}
NotesModel::NotesModel(QObject *parent) :
QAbstractTableModel(parent)
{
}
int NotesModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return notes->size();
}
int NotesModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return 4;
}
QVariant NotesModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Vertical) {
return QVariant();
}
switch(role) {
case 0:
switch(section) {
case 0:
return QString(tr("Name"));
case 1:
return QString(tr("Datum"));
case 2:
return QString(tr("Attachment"));
case 3:
return QString(tr("Beschreibung"));
}
case 13:
switch(section) {
case 0:
return QSize(150, 20);
case 1:
case 2:
return QSize(170, 20);
case 3:
return QSize(200, 20);
}
}
return QVariant();
}
QVariant NotesModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() ) {
return QVariant();
}
switch (role) {
case Qt::DisplayRole:
case Qt::ToolTipRole:
switch(index.column()) {
case 0:
return notes->at(index.row())->name;
case 1:
return notes->at(index.row())->date_modified.toString("d. MMM yyyy, HH:mm");
case 2:
return notes->at(index.row())->fileName;
case 3:
return notes->at(index.row())->description;
}
case Qt::FontRole:
QFont f;
f.setPixelSize(10);
switch(index.column()) {
case 0:
f.setBold(true);
return f;
case 1:
case 2:
f.setPixelSize(9);
return f;
case 3:
return f;
}
}
return QVariant();
}
void NotesModel::read(QList<Note *> *_notes)
{
notes = _notes;
processNewNote();
}
Note* NotesModel::newNote()
{
Note *_note = new Note();
notes->append(_note);
connect(_note, SIGNAL(saved()),
this, SLOT(processNewNote()));
return _note;
}
void NotesModel::processNewNote()
{
sortData();
reset();
}
void NotesModel::sortData()
{
qSort(notes->begin(), notes->end(), compareNotesGreaterThan);
}