|
1 #include "headerhistorymodel.h" |
|
2 #include "lddocument.h" |
|
3 |
|
4 HeaderHistoryModel::HeaderHistoryModel(LDHeader* header, QObject* parent) : |
|
5 QAbstractTableModel {parent}, |
|
6 header {header} {} |
|
7 |
|
8 int HeaderHistoryModel::rowCount(const QModelIndex&) const |
|
9 { |
|
10 if (this->header) |
|
11 return this->header->history.size(); |
|
12 } |
|
13 |
|
14 int HeaderHistoryModel::columnCount(const QModelIndex&) const |
|
15 { |
|
16 return 3; |
|
17 } |
|
18 |
|
19 QVariant HeaderHistoryModel::data(const QModelIndex& index, int role) const |
|
20 { |
|
21 if (this->header and role == Qt::DisplayRole) |
|
22 { |
|
23 const auto& entry = this->header->history[index.row()]; |
|
24 switch (static_cast<Column>(index.column())) |
|
25 { |
|
26 case DateColumn: |
|
27 return entry.date; |
|
28 |
|
29 case AuthorColumn: |
|
30 return entry.author; |
|
31 |
|
32 case DescriptionColumn: |
|
33 return entry.description; |
|
34 |
|
35 default: |
|
36 return {}; |
|
37 } |
|
38 } |
|
39 else |
|
40 { |
|
41 return {}; |
|
42 } |
|
43 } |
|
44 |
|
45 QVariant HeaderHistoryModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
46 { |
|
47 if (orientation == Qt::Horizontal and role == Qt::DisplayRole) |
|
48 { |
|
49 switch (static_cast<Column>(section)) |
|
50 { |
|
51 case DateColumn: |
|
52 return tr("Date"); |
|
53 |
|
54 case AuthorColumn: |
|
55 return tr("Author"); |
|
56 |
|
57 case DescriptionColumn: |
|
58 return tr("Description"); |
|
59 |
|
60 default: |
|
61 return {}; |
|
62 } |
|
63 } |
|
64 else |
|
65 { |
|
66 return {}; |
|
67 } |
|
68 } |
|
69 |
|
70 void HeaderHistoryModel::setHeader(LDHeader* header) |
|
71 { |
|
72 emit layoutAboutToBeChanged(); |
|
73 this->header = header; |
|
74 emit layoutChanged(); |
|
75 } |