Sun, 19 Jan 2020 02:54:48 +0200
commit work on GL rendering
#pragma once #include <QAbstractListModel> #include <memory> #include "main.h" #include "header.h" #include "linetypes/object.h" #include "gl/common.h" enum class HeaderProperty { Name }; class Model : public QAbstractListModel { Q_OBJECT public: class EditContext; Model(QObject* parent = nullptr); Model(const Model&) = delete; int size() const; EditContext edit(); int rowCount(const QModelIndex&) const override; QVariant data(const QModelIndex& index, int role) const override; QVariant getHeaderProperty(const HeaderProperty property); const QString& getName() const; QVariant getObjectProperty(const int index, const linetypes::Property property) const; std::vector<gl::Polygon> getPolygons(class DocumentManager* documents) const; void getObjectPolygons(const int index, std::vector<gl::Polygon>& polygons_out, linetypes::GetPolygonsContext* context) const; signals: void objectAdded(linetypes::Id id, int position); private: using ModelObjectPointer = std::unique_ptr<linetypes::Object>; template<typename T, typename... Args> T* append(Args&&... args); void append(ModelObjectPointer&& object); template<typename T, typename... Args> T* insert(int position, Args&&... args); bool modified = false; QString path; LDHeader header; std::vector<ModelObjectPointer> body; std::map<linetypes::Id, linetypes::Object*> objectsById; mutable std::vector<gl::Polygon> cachedPolygons; mutable bool needRecache = true; }; template<typename T, typename... Args> T* Model::append(Args&&... args) { emit layoutAboutToBeChanged(); this->body.push_back(std::make_unique<T>(args...)); T* pointer = static_cast<T*>(this->body.back().get()); this->objectsById[pointer->id] = pointer; emit objectAdded(pointer->id, this->body.size() - 1); emit layoutChanged(); return pointer; } template<typename T, typename... Args> T* Model::insert(int position, Args&&... args) { emit layoutAboutToBeChanged(); this->body.insert(position, std::make_unique<T>(args...)); T* pointer = static_cast<T*>(this->body[position]); this->objectsById[pointer->id] = pointer; emit objectAdded(pointer->id, position); emit layoutChanged(); return pointer; }