Sun, 19 Jan 2020 02:54:48 +0200
commit work on GL rendering
3 | 1 | #pragma once |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
2 | #include <QAbstractListModel> |
3 | 3 | #include <memory> |
4 | #include "main.h" | |
5 | #include "header.h" | |
14 | 6 | #include "linetypes/object.h" |
21 | 7 | #include "gl/common.h" |
3 | 8 | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
9 | enum class HeaderProperty |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
10 | { |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
11 | Name |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
12 | }; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
13 | |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
14 | class Model : public QAbstractListModel |
3 | 15 | { |
16 | Q_OBJECT | |
17 | public: | |
18 | class EditContext; | |
21 | 19 | Model(QObject* parent = nullptr); |
5 | 20 | Model(const Model&) = delete; |
3 | 21 | int size() const; |
22 | EditContext edit(); | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
23 | int rowCount(const QModelIndex&) const override; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
24 | QVariant data(const QModelIndex& index, int role) const override; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
25 | QVariant getHeaderProperty(const HeaderProperty property); |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
26 | const QString& getName() const; |
13 | 27 | QVariant getObjectProperty(const int index, const linetypes::Property property) const; |
21 | 28 | std::vector<gl::Polygon> getPolygons(class DocumentManager* documents) const; |
29 | void getObjectPolygons(const int index, std::vector<gl::Polygon>& polygons_out, linetypes::GetPolygonsContext* context) const; | |
6 | 30 | signals: |
13 | 31 | void objectAdded(linetypes::Id id, int position); |
3 | 32 | private: |
13 | 33 | using ModelObjectPointer = std::unique_ptr<linetypes::Object>; |
3 | 34 | template<typename T, typename... Args> |
35 | T* append(Args&&... args); | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
36 | void append(ModelObjectPointer&& object); |
3 | 37 | template<typename T, typename... Args> |
38 | T* insert(int position, Args&&... args); | |
39 | bool modified = false; | |
40 | QString path; | |
41 | LDHeader header; | |
42 | std::vector<ModelObjectPointer> body; | |
13 | 43 | std::map<linetypes::Id, linetypes::Object*> objectsById; |
21 | 44 | mutable std::vector<gl::Polygon> cachedPolygons; |
45 | mutable bool needRecache = true; | |
3 | 46 | }; |
47 | ||
48 | template<typename T, typename... Args> | |
49 | T* Model::append(Args&&... args) | |
50 | { | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
51 | emit layoutAboutToBeChanged(); |
3 | 52 | this->body.push_back(std::make_unique<T>(args...)); |
6 | 53 | T* pointer = static_cast<T*>(this->body.back().get()); |
54 | this->objectsById[pointer->id] = pointer; | |
55 | emit objectAdded(pointer->id, this->body.size() - 1); | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
56 | emit layoutChanged(); |
6 | 57 | return pointer; |
3 | 58 | } |
59 | ||
60 | template<typename T, typename... Args> | |
61 | T* Model::insert(int position, Args&&... args) | |
62 | { | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
63 | emit layoutAboutToBeChanged(); |
3 | 64 | this->body.insert(position, std::make_unique<T>(args...)); |
6 | 65 | T* pointer = static_cast<T*>(this->body[position]); |
66 | this->objectsById[pointer->id] = pointer; | |
67 | emit objectAdded(pointer->id, position); | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
68 | emit layoutChanged(); |
6 | 69 | return pointer; |
3 | 70 | } |