46 } |
46 } |
47 ); |
47 ); |
48 |
48 |
49 beginInsertRows({}, row, row); |
49 beginInsertRows({}, row, row); |
50 _objects.insert(row, object); |
50 _objects.insert(row, object); |
|
51 _objectsById[object->id] = object; |
51 |
52 |
52 if (this->pickingColorCursor <= 0xffffff) |
53 if (this->pickingColorCursor <= 0xffffff) |
53 { |
54 { |
54 this->pickingColors[object] = this->pickingColorCursor; |
55 this->pickingColors[object] = this->pickingColorCursor; |
55 this->pickingColorCursor += 1; |
56 this->pickingColorCursor += 1; |
415 */ |
416 */ |
416 |
417 |
417 /* |
418 /* |
418 * Looks up an object by the given index. |
419 * Looks up an object by the given index. |
419 */ |
420 */ |
420 LDObject* Model::lookup(const QModelIndex &index) const |
421 LDObject* Model::lookup(const Uuid& id) const |
421 { |
422 { |
422 if (index.row() >= 0 and index.row() < size()) |
423 return _objectsById.value(id, nullptr); |
423 return this->objects()[index.row()]; |
424 } |
424 else |
425 |
425 return nullptr; |
426 QColor Model::pickingColorForObject(const Uuid& id) const |
426 } |
427 { |
427 |
428 return QColor::fromRgba(this->pickingColors.value(this->lookup(id)) | 0xff000000); |
428 QColor Model::pickingColorForObject(const QModelIndex& objectIndex) const |
|
429 { |
|
430 return QColor::fromRgba(this->pickingColors.value(this->lookup(objectIndex)) | 0xff000000); |
|
431 } |
429 } |
432 |
430 |
433 QModelIndex Model::objectByPickingColor(const QColor& color) const |
431 QModelIndex Model::objectByPickingColor(const QColor& color) const |
434 { |
432 { |
435 if (color != qRgb(0, 0, 0)) |
433 if (color != qRgb(0, 0, 0)) |