diff -r b6cbba6e29a1 -r e628fc2e0c72 src/model.h --- a/src/model.h Thu Mar 03 11:42:52 2022 +0200 +++ b/src/model.h Thu Mar 03 21:13:16 2022 +0200 @@ -43,10 +43,8 @@ EditContext edit(); int rowCount(const QModelIndex&) const override; QVariant data(const QModelIndex& index, int role) const override; - QVariant getHeaderProperty(const HeaderProperty property); - QVariant getObjectProperty(const int index, const ldraw::Property property) const; - template - ldraw::PropertyType getObjectProperty(const ldraw::id_t id) const; + ldraw::Object* findObjectById(const ldraw::id_t id); + const ldraw::Object* findObjectById(const ldraw::id_t id) const; QModelIndex find(ldraw::id_t id) const; ldraw::id_t idAt(const QModelIndex& index) const; template @@ -59,10 +57,8 @@ }; template Get2Result get2(ldraw::Id id) const; - template - void apply(Fn f) const; - void save(QIODevice *device) const; ldraw::Object* operator[](int index); + const ldraw::Object* operator[](int index) const; Q_SIGNALS: void objectAdded(int position); void objectModified(int position); @@ -75,16 +71,9 @@ template ldraw::Id insert(std::size_t position, Args&&... args); void remove(int position); - ldraw::Object* objectAt(const QModelIndex& index); - const ldraw::Object* objectAt(const QModelIndex& index) const; - template - T* objectAt(ldraw::Id id); - template - const T* objectAt(ldraw::Id id) const; void editFinished(); void objectModified(ldraw::id_t id); bool modified = false; - LDHeader header; std::vector body; std::map objectsById; /** @@ -94,6 +83,7 @@ }; void makeUnofficial(Model& model); +void save(const Model& model, QIODevice *device); /** * @brief Calls the specified function to all matching objects in the model @@ -101,11 +91,12 @@ * @param fn Function to call. */ template -void Model::apply(Fn f) const +void applyToModel(const Model& model, Fn&& f) { - for (const ModelObjectPointer& object : this->body) + for (int i = 0; i < model.size(); i += 1) { - const R* subobject = dynamic_cast(object.get()); + const ldraw::Object* object = model[i]; + const R* subobject = dynamic_cast(object); if (subobject != nullptr) { f(subobject); @@ -151,7 +142,7 @@ result.index = this->find(id); if (result.index.isValid()) { - result.object = static_cast(this->objectAt(result.index)); + result.object = static_cast((*this)[result.index.row()]); } else { @@ -159,38 +150,3 @@ } return result; } - -/** - * @brief Gets an object pointer by id. Used by the editing context to actually modify objects. - * @param id - * @return object pointer - */ -template -T* Model::objectAt(ldraw::Id id) -{ - return static_cast(this->objectAt(this->find(id))); -} - -template -const T* Model::objectAt(ldraw::Id id) const -{ - return static_cast(this->objectAt(this->find(id))); -} - -/** - * @brief Gets an object property by id - * @tparam Property Property to obtain - * @param id ID of object - * @returns property or default value - */ -template -ldraw::PropertyType Model::getObjectProperty(const ldraw::id_t id) const -{ - const ldraw::Object* const object = this->objectAt(id); - ldraw::PropertyType result; - if (object != nullptr) - { - result = object->getProperty(); - } - return result; -}