src/modeleditcontext.cpp

changeset 86
4bec0525ef1b
parent 77
028798a72591
child 87
93ec4d630346
equal deleted inserted replaced
85:40e2940605a3 86:4bec0525ef1b
21 Model::EditContext::EditContext(Model& model) : 21 Model::EditContext::EditContext(Model& model) :
22 storedModel{model} 22 storedModel{model}
23 { 23 {
24 } 24 }
25 25
26 Model::EditContext::~EditContext()
27 {
28 for (ldraw::id_t id : this->modifiedObjects)
29 {
30 const QModelIndex index = this->model().lookup(id);
31 emit this->model().dataChanged(index, index);
32 }
33 }
34
26 ldraw::id_t Model::EditContext::append(std::unique_ptr<ldraw::Object>&& object) 35 ldraw::id_t Model::EditContext::append(std::unique_ptr<ldraw::Object>&& object)
27 { 36 {
28 const ldraw::id_t id = object->id; 37 const ldraw::id_t id = object->id;
29 this->model().objectsById[id] = object.get(); 38 this->model().objectsById[id] = object.get();
30 this->model().append(std::move(object)); 39 this->model().append(std::move(object));
34 void Model::EditContext::remove(int position) 43 void Model::EditContext::remove(int position)
35 { 44 {
36 this->model().remove(position); 45 this->model().remove(position);
37 } 46 }
38 47
39 void Model::EditContext::setObjectProperty( 48 void Model::EditContext::setObjectPoint(ldraw::id_t id, int pointId, const glm::vec3& value)
40 ldraw::id_t id,
41 ldraw::Property property,
42 const QVariant& value)
43 { 49 {
44 ldraw::Object* object = this->model().objectAt(id); 50 ldraw::Object* object = this->model().objectAt(id);
45 if (object != nullptr) 51 if (object != nullptr)
46 { 52 {
47 object->setProperty(property, value); 53 object->setProperty(ldraw::PropertyKeyValue{ldraw::pointProperty(pointId), QVariant::fromValue(value)});
54 modifiedObjects.insert(id);
48 } 55 }
49 } 56 }
50 57
51 void Model::EditContext::invertObject(ldraw::id_t id) 58 void Model::EditContext::invertObject(ldraw::id_t id)
52 { 59 {

mercurial