Document model.h

Wed, 22 Sep 2021 13:28:53 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 22 Sep 2021 13:28:53 +0300
changeset 138
5d6a4ad46cc7
parent 137
fb9990772357
child 139
72098474d362

Document model.h

src/model.h file | annotate | diff | comparison | revisions
--- 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<typename R>
 	Get2Result<R> get2(ldraw::Id<R> id) const;
 	template<typename R, typename Fn>
-	void apply(Fn f);
-	template<typename R, typename Fn>
 	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<typename T>
-	T* objectAt(ldraw::Id<T> id)
-	{
-		return static_cast<T*>(this->objectAt(this->lookup(id)));
-	}
+	T* objectAt(ldraw::Id<T> id);
 	template<typename T>
-	const T* objectAt(ldraw::Id<T> id) const
-	{
-		return static_cast<const T*>(this->objectAt(this->lookup(id)));
-	}
+	const T* objectAt(ldraw::Id<T> id) const;
 	void getObjectPolygons(
 		const int index,
 		std::vector<gl::Polygon>& 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<typename R, typename Fn>
 void Model::apply(Fn f) const
@@ -122,22 +116,6 @@
 }
 
 /**
- * \brief Call @c f for all objects of type \c R
- */
-template<typename R, typename Fn>
-void Model::apply(Fn f)
-{
-	for (ModelObjectPointer& object : this->body)
-	{
-		R* subobject = dynamic_cast<R*>(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<typename T>
+T* Model::objectAt(ldraw::Id<T> id)
+{
+	return static_cast<T*>(this->objectAt(this->lookup(id)));
+}
+
+template<typename T>
+const T* Model::objectAt(ldraw::Id<T> id) const
+{
+	return static_cast<const T*>(this->objectAt(this->lookup(id)));
+}
\ No newline at end of file

mercurial