src/modeleditcontext.h

changeset 89
7abaf1d64719
parent 86
4bec0525ef1b
child 149
008989bc7d6e
child 151
e628fc2e0c72
equal deleted inserted replaced
88:14e51640c189 89:7abaf1d64719
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #pragma once 19 #pragma once
20 #include "model.h" 20 #include "model.h"
21 #include "linetypes/object.h"
22 #include "linetypes/quadrilateral.h"
23 #include "linetypes/triangle.h"
24 21
25 class Model::EditContext 22 class Model::EditContext
26 { 23 {
27 public: 24 public:
28 ~EditContext(); 25 ~EditContext();
31 ldraw::id_t append(std::unique_ptr<ldraw::Object>&& object); 28 ldraw::id_t append(std::unique_ptr<ldraw::Object>&& object);
32 template<typename T, typename... Args> 29 template<typename T, typename... Args>
33 ldraw::Id<T> insert(int position, Args&&... args); 30 ldraw::Id<T> insert(int position, Args&&... args);
34 void remove(int position); 31 void remove(int position);
35 template<ldraw::Property property> 32 template<ldraw::Property property>
36 void setObjectProperty(ldraw::id_t id, const ldraw::PropertyType_t<property>& value) 33 void setObjectProperty(ldraw::id_t id, const ldraw::PropertyType<property>& value);
37 { 34 auto setObjectProperty(ldraw::id_t id, ldraw::Property property, const QVariant& value)
38 ldraw::Object* object = this->model().objectAt(id); 35 -> ldraw::Object::SetPropertyResult;
39 if (object != nullptr)
40 {
41 object->setProperty<property>(value);
42 modifiedObjects.insert(id);
43 }
44 }
45 void setObjectPoint(ldraw::id_t id, int pointId, const glm::vec3& value); 36 void setObjectPoint(ldraw::id_t id, int pointId, const glm::vec3& value);
46 void invertObject(ldraw::id_t id); 37 void invertObject(ldraw::id_t id);
47 Model& model(); 38 Model& model();
48 private: 39 private:
49 EditContext(Model& model); 40 EditContext(Model& model);
50 friend class Model; 41 friend class Model;
51 QSet<ldraw::id_t> modifiedObjects; 42 QSet<ldraw::id_t> modifiedObjects;
52 Model& storedModel; 43 Model& storedModel;
53 }; 44 };
45
46 template<ldraw::Property Property>
47 void Model::EditContext::setObjectProperty(const ldraw::id_t id, const ldraw::PropertyType<Property>& value)
48 {
49 ldraw::Object* object = this->model().objectAt(id);
50 if (object != nullptr)
51 {
52 object->setProperty<Property>(value);
53 modifiedObjects.insert(id);
54 }
55 }
54 56
55 template<typename T, typename... Args> 57 template<typename T, typename... Args>
56 ldraw::Id<T> Model::EditContext::append(Args&&... args) 58 ldraw::Id<T> Model::EditContext::append(Args&&... args)
57 { 59 {
58 return this->storedModel.append<T>(args...); 60 return this->storedModel.append<T>(args...);

mercurial