Commit 04ae926e8d49e66571e966cd828e75ae97a01489
1 parent
c47e28a4
Add transform to filter templates based on a metadata ID
Showing
1 changed file
with
31 additions
and
0 deletions
openbr/plugins/template.cpp
| ... | ... | @@ -176,6 +176,37 @@ class SelectPointsTransform : public UntrainableMetadataTransform |
| 176 | 176 | |
| 177 | 177 | BR_REGISTER(Transform, SelectPointsTransform) |
| 178 | 178 | |
| 179 | +/*! | |
| 180 | + * \ingroup transforms | |
| 181 | + * \brief Removes duplicate templates based on a unique metadata key | |
| 182 | + * \author Austin Blanton \cite imaus10 | |
| 183 | + */ | |
| 184 | +class FilterDupeMetadataTransform : public TimeVaryingTransform | |
| 185 | +{ | |
| 186 | + Q_OBJECT | |
| 187 | + | |
| 188 | + Q_PROPERTY(QString key READ get_key WRITE set_key RESET reset_key STORED false) | |
| 189 | + BR_PROPERTY(QString, key, "TemplateID") | |
| 190 | + | |
| 191 | + QSet<QString> excluded; | |
| 192 | + | |
| 193 | + void projectUpdate(const TemplateList &src, TemplateList &dst) | |
| 194 | + { | |
| 195 | + foreach (const Template &t, src) { | |
| 196 | + QString id = t.file.get<QString>(key); | |
| 197 | + if (!excluded.contains(id)) { | |
| 198 | + dst.append(t); | |
| 199 | + excluded.insert(id); | |
| 200 | + } | |
| 201 | + } | |
| 202 | + } | |
| 203 | + | |
| 204 | +public: | |
| 205 | + FilterDupeMetadataTransform() : TimeVaryingTransform(false,false) {} | |
| 206 | +}; | |
| 207 | + | |
| 208 | +BR_REGISTER(Transform, FilterDupeMetadataTransform) | |
| 209 | + | |
| 179 | 210 | } // namespace br |
| 180 | 211 | |
| 181 | 212 | #include "template.moc" | ... | ... |