Sun, 03 Nov 2019 13:18:55 +0200
added matrix conversions and datastream operators
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
1 | #include <QBrush> |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
2 | #include <QFont> |
3 | 3 | #include "model.h" |
4 | #include "modeleditcontext.h" | |
5 | ||
6 | Model::Model() | |
7 | { | |
8 | ||
9 | } | |
10 | ||
11 | int Model::size() const | |
12 | { | |
13 | return this->body.size(); | |
14 | } | |
15 | ||
16 | Model::EditContext Model::edit() | |
17 | { | |
18 | return {*this}; | |
19 | } | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
20 | |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
21 | int Model::rowCount(const QModelIndex&) const |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
22 | { |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
23 | return size(); |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
24 | } |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
25 | |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
26 | QVariant Model::data(const QModelIndex& index, int role) const |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
27 | { |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
28 | const int row = index.row(); |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
29 | modelobjects::BaseObject* object = this->body[row].get(); |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
30 | switch(role) |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
31 | { |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
32 | case Qt::DisplayRole: |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
33 | return object->textRepresentation(); |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
34 | case Qt::ForegroundRole: |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
35 | return object->textRepresentationForeground(); |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
36 | case Qt::BackgroundRole: |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
37 | return object->textRepresentationBackground(); |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
38 | case Qt::FontRole: |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
39 | return object->textRepresentationFont(); |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
40 | default: |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
41 | return {}; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
42 | } |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
43 | } |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
44 | |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
45 | QVariant Model::getHeaderProperty(const HeaderProperty property) |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
46 | { |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
47 | switch (property) |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
48 | { |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
49 | case HeaderProperty::Name: |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
50 | return header.name; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
51 | default: |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
52 | return {}; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
53 | } |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
54 | } |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
55 | |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
56 | void Model::append(ModelObjectPointer&& object) |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
57 | { |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
58 | this->body.push_back(std::move(object)); |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
3
diff
changeset
|
59 | } |