src/model.cpp

changeset 1278
6e1ea24e5a5e
parent 1277
821c30615069
child 1279
0f6a4a7cafec
equal deleted inserted replaced
1277:821c30615069 1278:6e1ea24e5a5e
41 void Model::installObject(int row, LDObject* object) 41 void Model::installObject(int row, LDObject* object)
42 { 42 {
43 connect(object, SIGNAL(codeChanged(LDObjectState, LDObjectState)), this, SLOT(recountTriangles())); 43 connect(object, SIGNAL(codeChanged(LDObjectState, LDObjectState)), this, SLOT(recountTriangles()));
44 beginInsertRows({}, row, row); 44 beginInsertRows({}, row, row);
45 _objects.insert(row, object); 45 _objects.insert(row, object);
46
47 if (this->pickingColorCursor <= 0xffffff)
48 {
49 this->pickingColors[object] = this->pickingColorCursor;
50 this->pickingColorCursor += 1;
51 }
52
46 recountTriangles(); 53 recountTriangles();
47 emit objectAdded(index(row)); 54 emit objectAdded(index(row));
48 endInsertRows(); 55 endInsertRows();
49 } 56 }
50 57
626 return this->objects()[index.row()]; 633 return this->objects()[index.row()];
627 else 634 else
628 return nullptr; 635 return nullptr;
629 } 636 }
630 637
631 QModelIndex Model::indexFromId(qint32 id) const 638 QColor Model::pickingColorForObject(const QModelIndex& objectIndex) const
632 { 639 {
633 for (int row = 0; row < this->size(); ++row) 640 return QColor::fromRgba(this->pickingColors.value(this->lookup(objectIndex)) | 0xff000000);
634 { 641 }
635 if (this->objects()[row]->id() == id) 642
636 return index(row); 643 QModelIndex Model::objectByPickingColor(const QColor& color) const
637 } 644 {
638 645 if (color != qRgb(0, 0, 0))
639 return {}; 646 {
647 for (int row = 0; row < this->size(); row += 1)
648 {
649 if (this->pickingColorForObject(this->index(row)) == color)
650 return this->index(row);
651 }
652
653 return {};
654 }
655 else
656 {
657 return {};
658 }
640 } 659 }
641 660
642 int countof(Model& model) 661 int countof(Model& model)
643 { 662 {
644 return model.size(); 663 return model.size();

mercurial