src/model.cpp

changeset 1244
68e126e8c629
parent 1240
cebb7ef54f41
child 1245
338d66111168
equal deleted inserted replaced
1243:0fb1d3d17b60 1244:68e126e8c629
523 } 523 }
524 else 524 else
525 return nullptr; 525 return nullptr;
526 } 526 }
527 527
528 IndexGenerator Model::indices() const
529 {
530 return {this};
531 }
532
528 int Model::rowCount(const QModelIndex&) const 533 int Model::rowCount(const QModelIndex&) const
529 { 534 {
530 return this->objects().size(); 535 return this->objects().size();
531 } 536 }
532 537
533 QVariant Model::data(const QModelIndex& index, int role) const 538 QVariant Model::data(const QModelIndex& index, int role) const
534 { 539 {
540 if (index.row() < 0 or index.row() >= size())
541 return {};
542
535 LDObject* object = this->objects()[index.row()]; 543 LDObject* object = this->objects()[index.row()];
536 544
537 switch (role) 545 switch (role)
538 { 546 {
539 case Qt::DisplayRole: 547 case Qt::DisplayRole:
564 object->isColored() 572 object->isColored()
565 and object->color().isValid() 573 and object->color().isValid()
566 and object->color() != MainColor 574 and object->color() != MainColor
567 and object->color() != EdgeColor 575 and object->color() != EdgeColor
568 ) { 576 ) {
569 // If the object isn't in the main or edge color, draw this list entry in that color. 577 // If the object isn't in the main or edge color, draw this list
578 // entry in that color.
570 return object->color().faceColor(); 579 return object->color().faceColor();
571 } 580 }
572 else 581 else
573 { 582 {
574 return {}; 583 return {};
584 else 593 else
585 { 594 {
586 return {}; 595 return {};
587 } 596 }
588 597
598 case ObjectRole:
599 return {qMetaTypeId<LDObject*>(), object};
600
589 default: 601 default:
590 return {}; 602 return {};
591 } 603 }
592 } 604 }
593 605
606 bool Model::removeRows(int row, int count, const QModelIndex& parent)
607 {
608 if (row >= 0 and row < size() and count <= size() - row)
609 {
610 beginRemoveRows(parent, row, row + count - 1);
611
612 for (signed int i = row + count - 1; i >= row; i -= 1)
613 this->removeAt(i);
614
615 endRemoveRows();
616 return true;
617 }
618 else
619 {
620 return false;
621 }
622 }
623
594 int countof(Model& model) 624 int countof(Model& model)
595 { 625 {
596 return model.size(); 626 return model.size();
597 } 627 }

mercurial