diff -r 593a658cba8e -r 73e448b2943d src/model.h --- a/src/model.h Thu Oct 03 11:45:44 2019 +0300 +++ b/src/model.h Thu Oct 03 23:44:28 2019 +0300 @@ -13,6 +13,8 @@ Model(const Model&) = delete; int size() const; EditContext edit(); +signals: + void objectAdded(modelobjects::Id id, int position); private: template T* append(Args&&... args); @@ -23,18 +25,25 @@ using ModelObjectPointer = std::unique_ptr; LDHeader header; std::vector body; + std::map objectsById; }; template T* Model::append(Args&&... args) { this->body.push_back(std::make_unique(args...)); - return static_cast(this->body.back().get()); + T* pointer = static_cast(this->body.back().get()); + this->objectsById[pointer->id] = pointer; + emit objectAdded(pointer->id, this->body.size() - 1); + return pointer; } template T* Model::insert(int position, Args&&... args) { this->body.insert(position, std::make_unique(args...)); - return this->body[position]; + T* pointer = static_cast(this->body[position]); + this->objectsById[pointer->id] = pointer; + emit objectAdded(pointer->id, position); + return pointer; }