src/mainwindow.cpp

changeset 1073
a0a0d581309b
parent 1072
9ce9496427f2
child 1075
711c5fff384d
equal deleted inserted replaced
1072:9ce9496427f2 1073:a0a0d581309b
356 int MainWindow::deleteSelection() 356 int MainWindow::deleteSelection()
357 { 357 {
358 if (selectedObjects().isEmpty()) 358 if (selectedObjects().isEmpty())
359 return 0; 359 return 0;
360 360
361 LDObjectList selCopy = selectedObjects(); 361 QSet<LDObject*> selectionCopy = selectedObjects();
362 362
363 // Delete the objects that were being selected 363 // Delete the objects that were being selected
364 for (LDObject* obj : selCopy) 364 for (LDObject* object : selectionCopy)
365 obj->destroy(); 365 m_currentDocument->remove(object);
366 366
367 refresh(); 367 refresh();
368 return countof(selCopy); 368 return countof(selectionCopy);
369 } 369 }
370 370
371 // --------------------------------------------------------------------------------------------------------------------- 371 // ---------------------------------------------------------------------------------------------------------------------
372 // 372 //
373 void MainWindow::buildObjectList() 373 void MainWindow::buildObjectList()
506 void MainWindow::scrollToSelection() 506 void MainWindow::scrollToSelection()
507 { 507 {
508 if (selectedObjects().isEmpty()) 508 if (selectedObjects().isEmpty())
509 return; 509 return;
510 510
511 LDObject* obj = selectedObjects().first(); 511 // TODO: Need a way to properly figure out the first selected object!
512 LDObject* obj = *selectedObjects().begin();
512 ui.objectList->scrollToItem (m_objectsInList[obj]); 513 ui.objectList->scrollToItem (m_objectsInList[obj]);
513 } 514 }
514 515
515 // --------------------------------------------------------------------------------------------------------------------- 516 // ---------------------------------------------------------------------------------------------------------------------
516 // 517 //
517 void MainWindow::selectionChanged() 518 void MainWindow::selectionChanged()
518 { 519 {
519 if (m_isSelectionLocked == true or m_currentDocument == nullptr) 520 if (m_isSelectionLocked == true or m_currentDocument == nullptr)
520 return; 521 return;
521 522
522 QSet<LDObject*> priorSelection = selectedObjects().toSet(); 523 QSet<LDObject*> priorSelection = selectedObjects();
523 524
524 // Get the objects from the object list selection 525 // Get the objects from the object list selection
525 m_currentDocument->clearSelection(); 526 m_currentDocument->clearSelection();
526 const QList<QListWidgetItem*> items = ui.objectList->selectedItems(); 527 const QList<QListWidgetItem*> items = ui.objectList->selectedItems();
527 528
529 { 530 {
530 for (QListWidgetItem* item : items) 531 for (QListWidgetItem* item : items)
531 { 532 {
532 if (item == m_objectsInList[obj]) 533 if (item == m_objectsInList[obj])
533 { 534 {
534 obj->select(); 535 m_currentDocument->addToSelection(obj);
535 break; 536 break;
536 } 537 }
537 } 538 }
538 } 539 }
539 540
540 // The select() method calls may have selected additional items (i.e. invertnexts) 541 // The select() method calls may have selected additional items (i.e. invertnexts)
541 // Update it all now. 542 // Update it all now.
542 updateSelection(); 543 updateSelection();
543 544
544 // Update the GL renderer 545 // Update the GL renderer
545 for (LDObject* obj : (priorSelection + selectedObjects().toSet())) 546 for (LDObject* obj : priorSelection + selectedObjects())
546 renderer()->compileObject (obj); 547 renderer()->compileObject (obj);
547 548
548 renderer()->update(); 549 renderer()->update();
549 } 550 }
550 551
593 // Returns the suggested position to place a new object at. 594 // Returns the suggested position to place a new object at.
594 // 595 //
595 int MainWindow::suggestInsertPoint() 596 int MainWindow::suggestInsertPoint()
596 { 597 {
597 // If we have a selection, put the item after it. 598 // If we have a selection, put the item after it.
599 // TODO: fix this properly!
598 if (not selectedObjects().isEmpty()) 600 if (not selectedObjects().isEmpty())
599 return selectedObjects().last()->lineNumber() + 1; 601 return (*(selectedObjects().end() - 1))->lineNumber() + 1;
600 602
601 // Otherwise place the object at the end. 603 // Otherwise place the object at the end.
602 return m_currentDocument->getObjectCount(); 604 return m_currentDocument->getObjectCount();
603 } 605 }
604 606
718 // --------------------------------------------------------------------------------------------------------------------- 720 // ---------------------------------------------------------------------------------------------------------------------
719 // 721 //
720 void MainWindow::spawnContextMenu (const QPoint& position) 722 void MainWindow::spawnContextMenu (const QPoint& position)
721 { 723 {
722 const bool single = (countof(selectedObjects()) == 1); 724 const bool single = (countof(selectedObjects()) == 1);
723 LDObject* singleObj = single ? selectedObjects().first() : nullptr; 725 LDObject* singleObj = single ? *selectedObjects().begin() : nullptr;
724 726
725 bool hasSubfiles = false; 727 bool hasSubfiles = false;
726 728
727 for (LDObject* obj : selectedObjects()) 729 for (LDObject* obj : selectedObjects())
728 { 730 {
783 785
784 // --------------------------------------------------------------------------------------------------------------------- 786 // ---------------------------------------------------------------------------------------------------------------------
785 // 787 //
786 void MainWindow::deleteByColor (LDColor color) 788 void MainWindow::deleteByColor (LDColor color)
787 { 789 {
788 LDObjectList objs; 790 LDObjectList unwanted;
789 791
790 for (LDObject* obj : m_currentDocument->objects()) 792 for (LDObject* object : m_currentDocument->objects())
791 { 793 {
792 if (not obj->isColored() or obj->color() != color) 794 if (not object->isColored() or object->color() != color)
793 continue; 795 continue;
794 796
795 objs << obj; 797 unwanted.append(object);
796 } 798 }
797 799
798 for (LDObject* obj : objs) 800 for (LDObject* obj : unwanted)
799 obj->destroy(); 801 m_currentDocument->remove(obj);
800 } 802 }
801 803
802 // --------------------------------------------------------------------------------------------------------------------- 804 // ---------------------------------------------------------------------------------------------------------------------
803 // 805 //
804 void MainWindow::updateEditModeActions() 806 void MainWindow::updateEditModeActions()
1287 */ 1289 */
1288 } 1290 }
1289 1291
1290 // --------------------------------------------------------------------------------------------------------------------- 1292 // ---------------------------------------------------------------------------------------------------------------------
1291 // 1293 //
1292 const LDObjectList& MainWindow::selectedObjects() 1294 const QSet<LDObject*>& MainWindow::selectedObjects()
1293 { 1295 {
1294 return m_currentDocument->getSelection(); 1296 return m_currentDocument->getSelection();
1295 } 1297 }
1296 1298
1297 // --------------------------------------------------------------------------------------------------------------------- 1299 // ---------------------------------------------------------------------------------------------------------------------

mercurial