461 return -1; |
461 return -1; |
462 } |
462 } |
463 |
463 |
464 // ============================================================================= |
464 // ============================================================================= |
465 // |
465 // |
466 void LDObject::moveObjects (LDObjectList objs, const bool up) |
|
467 { |
|
468 if (objs.isEmpty()) |
|
469 return; |
|
470 |
|
471 // If we move down, we need to iterate the array in reverse order. |
|
472 long const start = up ? 0 : (objs.size() - 1); |
|
473 long const end = up ? objs.size() : -1; |
|
474 long const incr = up ? 1 : -1; |
|
475 LDObjectList objsToCompile; |
|
476 LDDocument* file = objs[0]->document(); |
|
477 |
|
478 for (long i = start; i != end; i += incr) |
|
479 { |
|
480 LDObject* obj = objs[i]; |
|
481 |
|
482 long const idx = obj->lineNumber(); |
|
483 long const target = idx + (up ? -1 : 1); |
|
484 |
|
485 if ((up and idx == 0) or (not up and idx == (long) file->objects().size() - 1l)) |
|
486 { |
|
487 // One of the objects hit the extrema. If this happens, this should be the first |
|
488 // object to be iterated on. Thus, nothing has changed yet and it's safe to just |
|
489 // abort the entire operation. |
|
490 return; |
|
491 } |
|
492 |
|
493 objsToCompile << obj; |
|
494 objsToCompile << file->getObject (target); |
|
495 |
|
496 obj->swap (file->getObject (target)); |
|
497 } |
|
498 |
|
499 removeDuplicates (objsToCompile); |
|
500 |
|
501 // The objects need to be recompiled, otherwise their pick lists are left with |
|
502 // the wrong index colors which messes up selection. |
|
503 for (LDObject* obj : objsToCompile) |
|
504 g_win->renderer()->compileObject (obj); |
|
505 } |
|
506 |
|
507 // ============================================================================= |
|
508 // |
|
509 // Get type name by enumerator |
466 // Get type name by enumerator |
510 // |
467 // |
511 QString LDObject::typeName (LDObjectType type) |
468 QString LDObject::typeName (LDObjectType type) |
512 { |
469 { |
513 return LDObject::getDefault (type)->typeName(); |
470 return LDObject::getDefault (type)->typeName(); |