# HG changeset patch # User Teemu Piippo # Date 1632306533 -10800 # Node ID 5d6a4ad46cc757b6b4d686036ba567506201edd7 # Parent fb9990772357be44b705215abb6b22c5f3417510 Document model.h diff -r fb9990772357 -r 5d6a4ad46cc7 src/model.h --- a/src/model.h Wed Sep 22 12:55:44 2021 +0300 +++ b/src/model.h Wed Sep 22 13:28:53 2021 +0300 @@ -60,8 +60,6 @@ template Get2Result get2(ldraw::Id id) const; template - void apply(Fn f); - template void apply(Fn f) const; Q_SIGNALS: void objectAdded(ldraw::id_t id, int position); @@ -77,15 +75,9 @@ ldraw::Object* objectAt(const QModelIndex& index); const ldraw::Object* objectAt(const QModelIndex& index) const; template - T* objectAt(ldraw::Id id) - { - return static_cast(this->objectAt(this->lookup(id))); - } + T* objectAt(ldraw::Id id); template - const T* objectAt(ldraw::Id id) const - { - return static_cast(this->objectAt(this->lookup(id))); - } + const T* objectAt(ldraw::Id id) const; void getObjectPolygons( const int index, std::vector& polygons_out, @@ -106,7 +98,9 @@ }; /** - * \brief Call @c f for all objects of type \c R + * @brief Calls the specified function to all matching objects in the model + * @tparam R Type of LDraw line type object to filter by + * @param fn Function to call. */ template void Model::apply(Fn f) const @@ -122,22 +116,6 @@ } /** - * \brief Call @c f for all objects of type \c R - */ -template -void Model::apply(Fn f) -{ - for (ModelObjectPointer& object : this->body) - { - R* subobject = dynamic_cast(object.get()); - if (subobject != nullptr) - { - f(subobject); - } - } -} - -/** * \brief Checks type of object behind id * Checks whether the specified id refers to an object of the specified type. * \returns id casted to subclass if appropriate, null id otherwise @@ -203,3 +181,20 @@ } 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->lookup(id))); +} + +template +const T* Model::objectAt(ldraw::Id id) const +{ + return static_cast(this->objectAt(this->lookup(id))); +} \ No newline at end of file