Commit a5e1455f0c30d7c1f99b2bb6d1dee26bb7c23530

Authored by Charles Otto
1 parent d177a459

Rework SubjectTransform

Filename is now accessible via the metadata interface, and Subject is now no
longer an important variable name.
Rework subject transform to apply an input regex to the value of an input key
name, and store the resulting value in the specified output key name.
Showing 1 changed file with 10 additions and 6 deletions
openbr/plugins/misc.cpp
... ... @@ -354,27 +354,31 @@ BR_REGISTER(Transform, AsTransform)
354 354  
355 355 /*!
356 356 * \ingroup transforms
357   - * \brief Change the template subject using a regular expresion matched to the file's base name.
  357 + * \brief Apply the input regular expression to the value of inputProperty, store the matched portion in outputProperty.
358 358 * \author Josh Klontz \cite jklontz
359 359 */
360   -class SubjectTransform : public UntrainableMetaTransform
  360 +class RegexPropertyTransform : public UntrainableMetaTransform
361 361 {
362 362 Q_OBJECT
363 363 Q_PROPERTY(QString regexp READ get_regexp WRITE set_regexp RESET reset_regexp STORED false)
  364 + Q_PROPERTY(QString inputProperty READ get_inputProperty WRITE set_inputProperty RESET reset_inputProperty STORED false)
  365 + Q_PROPERTY(QString outputProperty READ get_outputProperty WRITE set_outputProperty RESET reset_outputProperty STORED false)
364 366 BR_PROPERTY(QString, regexp, "(.*)")
  367 + BR_PROPERTY(QString, inputProperty, "name")
  368 + BR_PROPERTY(QString, outputProperty, "Label")
365 369  
366 370 void project(const Template &src, Template &dst) const
367 371 {
368 372 dst = src;
369 373 QRegularExpression re(regexp);
370   - QRegularExpressionMatch match = re.match(dst.file.baseName());
  374 + QRegularExpressionMatch match = re.match(dst.file.get<QString>(inputProprety));
371 375 if (!match.hasMatch())
372   - qFatal("Unable to match regular expression \"%s\" to base name \"%s\"!", qPrintable(regexp), qPrintable(dst.file.baseName()));
373   - dst.file.set("Subject", match.captured(match.lastCapturedIndex()));
  376 + qFatal("Unable to match regular expression \"%s\" to base name \"%s\"!", qPrintable(regexp), qPrintable(dst.file.get<QString>(inputProperty)));
  377 + dst.file.set(outputProperty, match.captured(match.lastCapturedIndex()));
374 378 }
375 379 };
376 380  
377   -BR_REGISTER(Transform, SubjectTransform)
  381 +BR_REGISTER(Transform, RegexPropertyTransform)
378 382  
379 383 /*!
380 384 * \ingroup transforms
... ...