src/headerhistorymodel.cpp

Mon, 04 Jun 2018 23:12:40 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 04 Jun 2018 23:12:40 +0300
changeset 1391
5fa4bf1fc781
parent 1326
69a90bd2dba2
permissions
-rw-r--r--

added work done on cylinders

1326
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
1 /*
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
2 * LDForge: LDraw parts authoring CAD
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
4 *
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
5 * This program is free software: you can redistribute it and/or modify
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
6 * it under the terms of the GNU General Public License as published by
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
8 * (at your option) any later version.
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
9 *
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
10 * This program is distributed in the hope that it will be useful,
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
13 * GNU General Public License for more details.
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
14 *
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
15 * You should have received a copy of the GNU General Public License
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
17 */
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
18
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 #include "headerhistorymodel.h"
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 #include "lddocument.h"
1292
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
21 #include "generics/migrate.h"
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 HeaderHistoryModel::HeaderHistoryModel(LDHeader* header, QObject* parent) :
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 QAbstractTableModel {parent},
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 header {header} {}
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 int HeaderHistoryModel::rowCount(const QModelIndex&) const
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 if (this->header)
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 return this->header->history.size();
1307
adb9d32a1426 fixed warning
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
31 else
adb9d32a1426 fixed warning
Teemu Piippo <teemu@hecknology.net>
parents: 1292
diff changeset
32 return 0;
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 int HeaderHistoryModel::columnCount(const QModelIndex&) const
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 return 3;
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 QVariant HeaderHistoryModel::data(const QModelIndex& index, int role) const
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 {
1292
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
42 if (this->header and (role == Qt::DisplayRole || role == Qt::EditRole))
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 const auto& entry = this->header->history[index.row()];
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 switch (static_cast<Column>(index.column()))
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 case DateColumn:
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 return entry.date;
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 case AuthorColumn:
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 return entry.author;
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 case DescriptionColumn:
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 return entry.description;
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 default:
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57 return {};
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
59 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
60 else
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
61 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62 return {};
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
64 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
66 QVariant HeaderHistoryModel::headerData(int section, Qt::Orientation orientation, int role) const
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
67 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
68 if (orientation == Qt::Horizontal and role == Qt::DisplayRole)
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
69 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
70 switch (static_cast<Column>(section))
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
71 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
72 case DateColumn:
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
73 return tr("Date");
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
74
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
75 case AuthorColumn:
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
76 return tr("Author");
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
77
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
78 case DescriptionColumn:
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
79 return tr("Description");
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
80
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
81 default:
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
82 return {};
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
83 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
84 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
85 else
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
86 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
87 return {};
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
88 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
89 }
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
90
1292
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
91 Qt::ItemFlags HeaderHistoryModel::flags(const QModelIndex& index) const
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
92 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
93 Qt::ItemFlags flags = QAbstractTableModel::flags(index);
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
94
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
95 if (index.isValid())
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
96 flags |= Qt::ItemIsEditable;
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
97
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
98 return flags;
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
99 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
100
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
101 bool HeaderHistoryModel::setData(const QModelIndex& index, const QVariant& value, int role)
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
102 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
103 if (role == Qt::EditRole)
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
104 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
105 LDHeader::HistoryEntry& entry = this->header->history[index.row()];
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
106
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
107 switch (static_cast<Column>(index.column()))
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
108 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
109 case DateColumn:
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
110 entry.date = value.toDate();
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
111 return true;
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
112
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
113 case AuthorColumn:
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
114 entry.author = value.toString();
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
115 return true;
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
116
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
117 case DescriptionColumn:
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
118 entry.description = value.toString();
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
119 return true;
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
120
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
121 default:
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
122 return false;
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
123 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
124 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
125 else
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
126 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
127 return false;
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
128 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
129 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
130
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
131 bool HeaderHistoryModel::moveRows(
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
132 const QModelIndex&,
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
133 int sourceRow,
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
134 int count,
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
135 const QModelIndex&,
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
136 int destinationRow
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
137 ) {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
138 int sourceRowLast = sourceRow + count - 1;
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
139 this->beginMoveRows({}, sourceRow, sourceRowLast, {}, destinationRow);
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
140 ::migrate(this->header->history, sourceRow, sourceRowLast, destinationRow);
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
141 this->endMoveRows();
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
142 return true;
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
143 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
144
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
145 bool HeaderHistoryModel::removeRows(int row, int count, const QModelIndex&)
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
146 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
147 if (row >= 0 and row + count - 1 < this->rowCount())
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
148 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
149 this->beginRemoveRows({}, row, row + count - 1);
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
150 this->header->history.remove(row, count);
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
151 this->endRemoveRows();
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
152 return true;
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
153 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
154 else
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
155 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
156 return false;
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
157 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
158 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
159
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
160 bool HeaderHistoryModel::insertRows(int startRow, int count, const QModelIndex&)
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
161 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
162 if (startRow >= 0 and startRow <= this->rowCount())
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
163 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
164 this->beginInsertRows({}, startRow, startRow + count - 1);
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
165
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
166 for (int row : range(startRow, startRow + 1, startRow + count - 1))
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
167 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
168 this->header->history.insert(row, {});
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
169 this->header->history[row].date = QDate::currentDate();
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1307
diff changeset
170 this->header->history[row].author = config::defaultUser();
1292
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
171 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
172
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
173 this->endInsertRows();
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
174 return true;
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
175 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
176 else
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
177 {
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
178 return false;
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
179 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
180 }
66d2050d3bd9 Part history can now be edited
Teemu Piippo <teemu@hecknology.net>
parents: 1291
diff changeset
181
1291
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
182 void HeaderHistoryModel::setHeader(LDHeader* header)
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
183 {
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
184 emit layoutAboutToBeChanged();
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
185 this->header = header;
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
186 emit layoutChanged();
9c570a30c98a Added basic header editing
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
187 }

mercurial