--- a/src/model.h Tue Sep 28 23:09:09 2021 +0300 +++ b/src/model.h Sun Oct 24 11:33:32 2021 +0300 @@ -46,6 +46,8 @@ QVariant getHeaderProperty(const HeaderProperty property); const QString& getName() const; QVariant getObjectProperty(const int index, const ldraw::Property property) const; + template<ldraw::Property Property> + ldraw::PropertyType<Property> getObjectProperty(const ldraw::id_t id) const; std::vector<gl::Polygon> getPolygons(class DocumentManager* documents) const; QModelIndex lookup(ldraw::id_t id) const; ldraw::id_t resolve(const QModelIndex& index) const; @@ -220,4 +222,22 @@ const T* Model::objectAt(ldraw::Id<T> id) const { return static_cast<const T*>(this->objectAt(this->lookup(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::Property Property> +ldraw::PropertyType<Property> Model::getObjectProperty(const ldraw::id_t id) const +{ + const ldraw::Object* const object = this->objectAt(id); + ldraw::PropertyType<Property> result; + if (object != nullptr) + { + result = object->getProperty<Property>() + } + return result; } \ No newline at end of file