--- a/src/model.cpp Fri Dec 28 00:03:47 2018 +0200 +++ b/src/model.cpp Thu Jun 20 08:54:35 2019 +0300 @@ -48,6 +48,7 @@ beginInsertRows({}, row, row); _objects.insert(row, object); + _objectsById[object->id] = object; if (this->pickingColorCursor <= 0xffffff) { @@ -417,17 +418,14 @@ /* * Looks up an object by the given index. */ -LDObject* Model::lookup(const QModelIndex &index) const +LDObject* Model::lookup(const Uuid& id) const { - if (index.row() >= 0 and index.row() < size()) - return this->objects()[index.row()]; - else - return nullptr; + return _objectsById.value(id, nullptr); } -QColor Model::pickingColorForObject(const QModelIndex& objectIndex) const +QColor Model::pickingColorForObject(const Uuid& id) const { - return QColor::fromRgba(this->pickingColors.value(this->lookup(objectIndex)) | 0xff000000); + return QColor::fromRgba(this->pickingColors.value(this->lookup(id)) | 0xff000000); } QModelIndex Model::objectByPickingColor(const QColor& color) const