67 { |
67 { |
68 if (object->model() and object->model() != this) |
68 if (object->model() and object->model() != this) |
69 object->model()->withdraw(object); |
69 object->model()->withdraw(object); |
70 |
70 |
71 // TODO: check that the object isn't in the vector once there's a cheap way to do so! |
71 // TODO: check that the object isn't in the vector once there's a cheap way to do so! |
|
72 beginInsertRows({}, position, position); |
72 _objects.insert(position, object); |
73 _objects.insert(position, object); |
73 _needsTriangleRecount = true; |
74 _needsTriangleRecount = true; |
74 object->setDocument(this); |
75 object->setDocument(this); |
75 emit objectAdded(object); |
76 emit objectAdded(object); |
|
77 endInsertRows(); |
76 } |
78 } |
77 |
79 |
78 /* |
80 /* |
79 * Swaps one object with another, assuming they both are in this model. |
81 * Swaps one object with another, assuming they both are in this model. |
80 */ |
82 */ |
253 /* |
255 /* |
254 * Drops an object from the model at the provided position. The caller must immediately put the result value object into a new model. |
256 * Drops an object from the model at the provided position. The caller must immediately put the result value object into a new model. |
255 */ |
257 */ |
256 LDObject* Model::withdrawAt(int position) |
258 LDObject* Model::withdrawAt(int position) |
257 { |
259 { |
|
260 beginRemoveRows({}, position, position); |
258 LDObject* object = _objects[position]; |
261 LDObject* object = _objects[position]; |
259 emit aboutToRemoveObject(object); |
262 emit aboutToRemoveObject(object); |
260 _objects.removeAt(position); |
263 _objects.removeAt(position); |
261 _needsTriangleRecount = true; |
264 _needsTriangleRecount = true; |
|
265 endRemoveRows(); |
262 return object; |
266 return object; |
263 } |
267 } |
264 |
268 |
265 /* |
269 /* |
266 * Returns whether or not this model is empty. |
270 * Returns whether or not this model is empty. |
593 else |
597 else |
594 { |
598 { |
595 return {}; |
599 return {}; |
596 } |
600 } |
597 |
601 |
598 case ObjectRole: |
602 case ObjectIdRole: |
599 return {qMetaTypeId<LDObject*>(), object}; |
603 return object->id(); |
600 |
604 |
601 default: |
605 default: |
602 return {}; |
606 return {}; |
603 } |
607 } |
604 } |
608 } |
605 |
609 |
|
610 /* |
606 bool Model::removeRows(int row, int count, const QModelIndex& parent) |
611 bool Model::removeRows(int row, int count, const QModelIndex& parent) |
607 { |
612 { |
608 if (row >= 0 and row < size() and count <= size() - row) |
613 if (row >= 0 and row < size() and count <= size() - row) |
609 { |
614 { |
610 beginRemoveRows(parent, row, row + count - 1); |
615 beginRemoveRows(parent, row, row + count - 1); |