--- a/src/model.cpp Wed Mar 07 19:32:05 2018 +0200 +++ b/src/model.cpp Thu Mar 08 11:36:55 2018 +0200 @@ -43,6 +43,13 @@ connect(object, SIGNAL(codeChanged(LDObjectState, LDObjectState)), this, SLOT(recountTriangles())); beginInsertRows({}, row, row); _objects.insert(row, object); + + if (this->pickingColorCursor <= 0xffffff) + { + this->pickingColors[object] = this->pickingColorCursor; + this->pickingColorCursor += 1; + } + recountTriangles(); emit objectAdded(index(row)); endInsertRows(); @@ -628,15 +635,27 @@ return nullptr; } -QModelIndex Model::indexFromId(qint32 id) const +QColor Model::pickingColorForObject(const QModelIndex& objectIndex) const { - for (int row = 0; row < this->size(); ++row) + return QColor::fromRgba(this->pickingColors.value(this->lookup(objectIndex)) | 0xff000000); +} + +QModelIndex Model::objectByPickingColor(const QColor& color) const +{ + if (color != qRgb(0, 0, 0)) { - if (this->objects()[row]->id() == id) - return index(row); + for (int row = 0; row < this->size(); row += 1) + { + if (this->pickingColorForObject(this->index(row)) == color) + return this->index(row); + } + + return {}; } - - return {}; + else + { + return {}; + } } int countof(Model& model)