diff --git a/sdk/openbr_plugin.cpp b/sdk/openbr_plugin.cpp index f8a4ea0..b2ce0fd 100644 --- a/sdk/openbr_plugin.cpp +++ b/sdk/openbr_plugin.cpp @@ -121,6 +121,11 @@ float File::label() const return Globals->classes.value(variant.toString(), -1); } +void File::remove(const QString &key) +{ + m_metadata.remove(key); +} + void File::set(const QString &key, const QVariant &value) { if (key == "Label") { diff --git a/sdk/openbr_plugin.h b/sdk/openbr_plugin.h index 2ba1cd6..6035f99 100644 --- a/sdk/openbr_plugin.h +++ b/sdk/openbr_plugin.h @@ -186,6 +186,7 @@ struct BR_EXPORT File inline QString subject() const { return subject(label()); } /*!< \brief Looks up the subject from the file's label. */ inline bool failed() const { return getBool("FTE") || getBool("FTO"); } /*!< \brief Returns \c true if the file failed to open or enroll, \c false otherwise. */ + void remove(const QString &key); /*!< \brief Remove the metadata key. */ void set(const QString &key, const QVariant &value); /*!< \brief Insert or overwrite the metadata key with the specified value. */ QVariant get(const QString &key) const; /*!< \brief Returns a QVariant for the key, throwing an error if the key does not exist. */ QVariant get(const QString &key, const QVariant &value) const; /*!< \brief Returns a QVariant for the key, returning \em defaultValue if the key does not exist. */ diff --git a/sdk/plugins/misc.cpp b/sdk/plugins/misc.cpp index bf21933..c480680 100644 --- a/sdk/plugins/misc.cpp +++ b/sdk/plugins/misc.cpp @@ -208,4 +208,31 @@ class RemoveTransform : public UntrainableMetaTransform BR_REGISTER(Transform, RemoveTransform) //! [example_transform] +/*! + * \ingroup transforms + * \brief Rename metadata + * \author Josh Klontz \cite jklontz + */ +class RenameTransform : public UntrainableMetaTransform +{ + Q_OBJECT + Q_PROPERTY(QString find READ get_find WRITE set_find RESET reset_find STORED false) + Q_PROPERTY(QString replace READ get_replace WRITE set_replace RESET reset_replace STORED false) + BR_PROPERTY(QString, find, "") + BR_PROPERTY(QString, replace, "") + + void project(const Template &src, Template &dst) const + { + dst = src; + foreach (const QString &key, dst.file.localKeys()) + if (key.contains(find)) { + QString newKey = QString(key).replace(find, replace); + dst.file.insert(newKey, dst.file.get(key)); + dst.file.remove(key); + } + } +}; + +BR_REGISTER(Transform, RenameTransform) + #include "misc.moc"