38 |
38 |
39 // If we move down, we need to iterate the array in reverse order. |
39 // If we move down, we need to iterate the array in reverse order. |
40 int start = up ? 0 : (countof(objs) - 1); |
40 int start = up ? 0 : (countof(objs) - 1); |
41 int end = up ? countof(objs) : -1; |
41 int end = up ? countof(objs) : -1; |
42 int increment = up ? 1 : -1; |
42 int increment = up ? 1 : -1; |
43 Model* model = (*objs.begin())->model(); |
|
44 |
43 |
45 for (int i = start; i != end; i += increment) |
44 for (int i = start; i != end; i += increment) |
46 { |
45 { |
47 LDObject* obj = objs[i]; |
46 LDObject* obj = objs[i]; |
48 |
47 |
49 int idx = model->indexOf(obj).row(); |
48 int idx = currentDocument()->indexOf(obj).row(); |
50 int target = idx + (up ? -1 : 1); |
49 int target = idx + (up ? -1 : 1); |
51 |
50 |
52 if ((up and idx == 0) or (not up and idx == countof(model->objects()) - 1)) |
51 if ((up and idx == 0) or (not up and idx == countof(currentDocument()->objects()) - 1)) |
53 { |
52 { |
54 // One of the objects hit the extrema. If this happens, this should be the first |
53 // One of the objects hit the extrema. If this happens, this should be the first |
55 // object to be iterated on. Thus, nothing has changed yet and it's safe to just |
54 // object to be iterated on. Thus, nothing has changed yet and it's safe to just |
56 // abort the entire operation. |
55 // abort the entire operation. |
57 return; |
56 return; |
58 } |
57 } |
59 |
58 |
60 model->swapObjects(obj, model->getObject(target)); |
59 currentDocument()->swapObjects(obj, currentDocument()->getObject(target)); |
61 } |
60 } |
62 } |
61 } |
63 |
62 |
64 void MoveToolset::moveUp() |
63 void MoveToolset::moveUp() |
65 { |
64 { |