From 61704511f600d4761b1ee9d35d38473db31e4e8c Mon Sep 17 00:00:00 2001 From: Austin Blanton Date: Tue, 15 Oct 2013 16:05:23 -0400 Subject: [PATCH] Add File::setList to automatically convert QLists to QVariantLists --- openbr/openbr_plugin.h | 9 +++++++++ openbr/plugins/landmarks.cpp | 4 ++-- openbr/plugins/slidingwindow.cpp | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/openbr/openbr_plugin.h b/openbr/openbr_plugin.h index d382184..4235bf2 100644 --- a/openbr/openbr_plugin.h +++ b/openbr/openbr_plugin.h @@ -41,6 +41,7 @@ #include #include #include +#include /*! * \defgroup cpp_plugin_sdk C++ Plugin SDK @@ -215,6 +216,14 @@ struct BR_EXPORT File static QVariant parse(const QString &value); /*!< \brief Try to convert the QString to a QPointF or QRectF if possible. */ inline void set(const QString &key, const QVariant &value) { m_metadata.insert(key, value); } /*!< \brief Insert or overwrite the metadata key with the specified value. */ void set(const QString &key, const QString &value); /*!< \brief Insert or overwrite the metadata key with the specified value. */ + + /*!< \brief Specialization for list type. Insert or overwrite the metadata key with the specified value. */ + template + void setList(const QString &key, const QList &value) + { + set(key, QtUtils::toVariantList(value)); + } + inline void remove(const QString &key) { m_metadata.remove(key); } /*!< \brief Remove the metadata key. */ /*!< \brief Returns a value for the key, throwing an error if the key does not exist. */ diff --git a/openbr/plugins/landmarks.cpp b/openbr/plugins/landmarks.cpp index a19439a..0773541 100644 --- a/openbr/plugins/landmarks.cpp +++ b/openbr/plugins/landmarks.cpp @@ -113,7 +113,7 @@ class ProcrustesTransform : public Transform // R(0,0), R(1,0), R(1,1), R(0,1), mean_x, mean_y, norm QList procrustesStats; procrustesStats << R(0,0) << R(1,0) << R(1,1) << R(0,1) << mean[0] << mean[1] << norm; - dst.file.set("ProcrustesStats",QtUtils::toVariantList(procrustesStats)); + dst.file.setList("ProcrustesStats",procrustesStats); if (warp) { Eigen::MatrixXf dstMat = srcMat*R; @@ -273,7 +273,7 @@ class DelaunayTransform : public UntrainableTransform dst.file.setRects(QList() << OpenCVUtils::fromRect(boundingBox)); } else dst = src; - dst.file.set("DelaunayTriangles", QtUtils::toVariantList(validTriangles)); + dst.file.setList("DelaunayTriangles", validTriangles); } }; diff --git a/openbr/plugins/slidingwindow.cpp b/openbr/plugins/slidingwindow.cpp index 5763eb8..e3b5045 100644 --- a/openbr/plugins/slidingwindow.cpp +++ b/openbr/plugins/slidingwindow.cpp @@ -120,7 +120,7 @@ private: if (dst.file.contains("Confidences")) confidences = dst.file.getList("Confidences"); confidences.append(confidence); - dst.file.set("Confidences", QtUtils::toVariantList(confidences)); + dst.file.setList("Confidences", confidences); if (takeLargestScale) return; } } -- libgit2 0.21.4