Commit da83e1c63b67e4a4af4cc346ce8c7ef29b5897f0

Authored by Scott Klum
1 parent 2256f42b

Generalizing if a bit better

Showing 1 changed file with 7 additions and 7 deletions
openbr/plugins/imgproc/if.cpp
... ... @@ -22,12 +22,12 @@ class IfTransform : public MetaTransform
22 22 BR_PROPERTY(QString, comparison, "e")
23 23 BR_PROPERTY(bool, projectOnEmpty, false)
24 24  
25   - bool compare(const QString &metadata) const
  25 + bool compare(const QVariant &metadata) const
26 26 {
27 27 bool result, ok1 = true, ok2 = true;
28 28  
29   - if (comparison == "empty")
30   - result = metadata.isEmpty();
  29 + if (comparison == "empty")
  30 + result = metadata.isNull() || (metadata.canConvert<QString>() && metadata.toString().isEmpty());
31 31 else if (comparison == "e")
32 32 result = metadata == value;
33 33 else if (comparison == "ne")
... ... @@ -41,7 +41,7 @@ class IfTransform : public MetaTransform
41 41 else if (comparison == "ge")
42 42 result = metadata.toFloat(&ok1) >= value.toFloat(&ok2);
43 43 else if (comparison == "c") // contains
44   - result = metadata.contains(value);
  44 + result = metadata.toString().contains(value);
45 45 else
46 46 qFatal("Unrecognized comparison string.");
47 47  
... ... @@ -57,14 +57,14 @@ public:
57 57 if (transform->trainable) {
58 58 TemplateList passed;
59 59 for (int i=0; i<data.size(); i++)
60   - if ((data[i].file.contains(key) || projectOnEmpty) && compare(data[i].file.get<QString>(key, QString())))
  60 + if ((data[i].file.contains(key) || projectOnEmpty) && compare(data[i].file.value(key)))
61 61 passed.append(data[i]);
62 62 transform->train(passed);
63 63 }
64 64 }
65 65  
66 66 void project(const Template &src, Template &dst) const {
67   - if ((src.file.contains(key) || projectOnEmpty) && compare(src.file.get<QString>(key, QString())))
  67 + if ((src.file.contains(key) || projectOnEmpty) && compare(src.file.value(key)))
68 68 transform->project(src, dst);
69 69 else
70 70 dst = src;
... ... @@ -73,7 +73,7 @@ public:
73 73 void project(const TemplateList &src, TemplateList &dst) const {
74 74 TemplateList ifTrue, ifFalse;
75 75 foreach (const Template &t, src) {
76   - if ((t.file.contains(key) || projectOnEmpty) && compare(t.file.get<QString>(key, QString())))
  76 + if ((t.file.contains(key) || projectOnEmpty) && compare(t.file.value(key)))
77 77 ifTrue.append(t);
78 78 else
79 79 ifFalse.append(t);
... ...