Commit 7c5c787855b8eba3a0c3a4afedf388937563b81c

Authored by Josh Klontz
1 parent fe96e534

added Rename transform

sdk/openbr_plugin.cpp
... ... @@ -121,6 +121,11 @@ float File::label() const
121 121 return Globals->classes.value(variant.toString(), -1);
122 122 }
123 123  
  124 +void File::remove(const QString &key)
  125 +{
  126 + m_metadata.remove(key);
  127 +}
  128 +
124 129 void File::set(const QString &key, const QVariant &value)
125 130 {
126 131 if (key == "Label") {
... ...
sdk/openbr_plugin.h
... ... @@ -186,6 +186,7 @@ struct BR_EXPORT File
186 186 inline QString subject() const { return subject(label()); } /*!< \brief Looks up the subject from the file's label. */
187 187 inline bool failed() const { return getBool("FTE") || getBool("FTO"); } /*!< \brief Returns \c true if the file failed to open or enroll, \c false otherwise. */
188 188  
  189 + void remove(const QString &key); /*!< \brief Remove the metadata key. */
189 190 void set(const QString &key, const QVariant &value); /*!< \brief Insert or overwrite the metadata key with the specified value. */
190 191 QVariant get(const QString &key) const; /*!< \brief Returns a QVariant for the key, throwing an error if the key does not exist. */
191 192 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. */
... ...
sdk/plugins/misc.cpp
... ... @@ -208,4 +208,31 @@ class RemoveTransform : public UntrainableMetaTransform
208 208 BR_REGISTER(Transform, RemoveTransform)
209 209 //! [example_transform]
210 210  
  211 +/*!
  212 + * \ingroup transforms
  213 + * \brief Rename metadata
  214 + * \author Josh Klontz \cite jklontz
  215 + */
  216 +class RenameTransform : public UntrainableMetaTransform
  217 +{
  218 + Q_OBJECT
  219 + Q_PROPERTY(QString find READ get_find WRITE set_find RESET reset_find STORED false)
  220 + Q_PROPERTY(QString replace READ get_replace WRITE set_replace RESET reset_replace STORED false)
  221 + BR_PROPERTY(QString, find, "")
  222 + BR_PROPERTY(QString, replace, "")
  223 +
  224 + void project(const Template &src, Template &dst) const
  225 + {
  226 + dst = src;
  227 + foreach (const QString &key, dst.file.localKeys())
  228 + if (key.contains(find)) {
  229 + QString newKey = QString(key).replace(find, replace);
  230 + dst.file.insert(newKey, dst.file.get(key));
  231 + dst.file.remove(key);
  232 + }
  233 + }
  234 +};
  235 +
  236 +BR_REGISTER(Transform, RenameTransform)
  237 +
211 238 #include "misc.moc"
... ...