diff -r 204dc77e5654 -r 7c4a63a02632 src/model.h --- a/src/model.h Sat Mar 07 01:25:37 2020 +0200 +++ b/src/model.h Mon Mar 09 22:12:50 2020 +0200 @@ -49,7 +49,7 @@ template ldraw::Id checkType(ldraw::id_t id) const; template - const R* get(ldraw::Id id) const; + const R* get(ldraw::Id id, QModelIndex* index_out = nullptr) const; signals: void objectAdded(ldraw::id_t id, int position); private: @@ -58,7 +58,8 @@ ldraw::Id append(Args&&... args); void append(ModelObjectPointer&& object); template - ldraw::Id insert(int position, Args&&... args); + ldraw::Id insert(std::size_t position, Args&&... args); + void remove(int position); ldraw::Object* objectAt(const QModelIndex& index); const ldraw::Object* objectAt(const QModelIndex& index) const; template @@ -109,25 +110,30 @@ this->body.push_back(std::make_unique(args...)); ldraw::Object* pointer = this->body.back().get(); this->objectsById[pointer->id] = pointer; - emit objectAdded(pointer->id, this->body.size() - 1); + emit objectAdded(pointer->id, static_cast(this->body.size() - 1)); emit layoutChanged(); - return ldraw::Id{pointer->id}; + return ldraw::Id{pointer->id.value}; } template -ldraw::Id Model::insert(int position, Args&&... args) +ldraw::Id Model::insert(std::size_t position, Args&&... args) { emit layoutAboutToBeChanged(); - this->body.insert(position, std::make_unique(args...)); + this->body.insert(std::begin(this->body) + position, std::make_unique(args...)); ldraw::Object* pointer = this->body[position].get(); this->objectsById[pointer->id] = pointer; - emit objectAdded(pointer->id, position); + emit objectAdded(pointer->id, static_cast(position)); emit layoutChanged(); - return ldraw::Id{pointer->id}; + return ldraw::Id{pointer->id.value}; } template -const R* Model::get(ldraw::Id id) const +const R* Model::get(ldraw::Id id, QModelIndex* index_out) const { - return this->objectAt(id); + QModelIndex index = this->lookup(id); + if (index_out != nullptr) + { + *index_out = index; + } + return static_cast(this->objectAt(index)); }