Commit 49d069afbc18b022dfc5823b8c6e5329f16a0ded

Authored by Scott Klum
1 parent 0f9ce2b1

More enhancements

openbr/core/qtutils.cpp
... ... @@ -172,12 +172,20 @@ QString find(const QString &file, const QString &alt)
172 172 return "";
173 173 }
174 174  
175   -bool toBool(const QString &string)
  175 +bool toBool(const QString &string, bool *ok)
176 176 {
177   - bool ok;
178   - bool result = (string.toFloat(&ok) != 0.f);
179   - if (ok) return result;
180   - else return (string != "FALSE") && (string != "false") && (string != "F") && (string != "f");
  177 + bool floatOk;
  178 + bool result = (string.toFloat(&floatOk) != 0.f);
  179 + if (floatOk) {
  180 + if (ok) *ok = true;
  181 + return result;
  182 + } else {
  183 + if (ok) *ok = (string.compare("false", Qt::CaseInsensitive) == 0 ||
  184 + string.compare("true", Qt::CaseInsensitive) == 0 ||
  185 + string.compare("f", Qt::CaseInsensitive) == 0 ||
  186 + string.compare("t", Qt::CaseInsensitive) == 0);
  187 + return (string.compare("false", Qt::CaseInsensitive) != 0 && string.compare("f", Qt::CaseInsensitive) != 0);
  188 + }
181 189 }
182 190  
183 191 int toInt(const QString &string)
... ... @@ -533,6 +541,8 @@ QVariant fromString(const QString &value)
533 541 if (ok) return i;
534 542 const float f = value.toFloat(&ok);
535 543 if (ok) return f;
  544 + const bool b = QtUtils::toBool(value, &ok);
  545 + if (ok) return b;
536 546 return value;
537 547 }
538 548  
... ...
openbr/core/qtutils.h
... ... @@ -56,7 +56,7 @@ namespace QtUtils
56 56 QString getAbsolutePath(const QString &filename);
57 57  
58 58 /**** String Utilities ****/
59   - bool toBool(const QString &string);
  59 + bool toBool(const QString &string, bool *ok = NULL);
60 60 int toInt(const QString &string);
61 61 float toFloat(const QString &string);
62 62 QList<float> toFloats(const QStringList &strings);
... ...
openbr/plugins/gallery/csv.cpp
... ... @@ -172,14 +172,19 @@ class csvGallery : public FileGallery
172 172 if (!value.canConvert<QString>() || !value.toString().isEmpty())
173 173 f.set(header.key, values[header.indices.first()]);
174 174 }
175   - } else if (header.indices.size() == 2) // QPointF
176   - f.appendPoint(QPointF(values[header.indices[header.subKeys.indexOf("X")]].toFloat(),
177   - values[header.indices[header.subKeys.indexOf("Y")]].toFloat()));
178   - else if (header.indices.size() == 4) // QRectF
179   - f.appendRect(QRectF(values[header.indices[header.subKeys.indexOf("X")]].toFloat(),
180   - values[header.indices[header.subKeys.indexOf("Y")]].toFloat(),
181   - values[header.indices[header.subKeys.indexOf("Width")]].toFloat(),
182   - values[header.indices[header.subKeys.indexOf("Height")]].toFloat()));
  175 + } else if (header.indices.size() == 2) { // QPointF
  176 + const QPointF point(values[header.indices[header.subKeys.indexOf("X")]].toFloat(),
  177 + values[header.indices[header.subKeys.indexOf("Y")]].toFloat());
  178 + f.set(header.key, point);
  179 + f.appendPoint(point);
  180 + } else if (header.indices.size() == 4) { // QRectF
  181 + const QRectF rect(values[header.indices[header.subKeys.indexOf("X")]].toFloat(),
  182 + values[header.indices[header.subKeys.indexOf("Y")]].toFloat(),
  183 + values[header.indices[header.subKeys.indexOf("Width")]].toFloat(),
  184 + values[header.indices[header.subKeys.indexOf("Height")]].toFloat());
  185 + f.set(header.key, rect);
  186 + f.appendRect(rect);
  187 + }
183 188 }
184 189 }
185 190  
... ...