diff --git a/openbr/core/qtutils.cpp b/openbr/core/qtutils.cpp index 89a0da1..5941aae 100644 --- a/openbr/core/qtutils.cpp +++ b/openbr/core/qtutils.cpp @@ -172,12 +172,20 @@ QString find(const QString &file, const QString &alt) return ""; } -bool toBool(const QString &string) +bool toBool(const QString &string, bool *ok) { - bool ok; - bool result = (string.toFloat(&ok) != 0.f); - if (ok) return result; - else return (string != "FALSE") && (string != "false") && (string != "F") && (string != "f"); + bool floatOk; + bool result = (string.toFloat(&floatOk) != 0.f); + if (floatOk) { + if (ok) *ok = true; + return result; + } else { + if (ok) *ok = (string.compare("false", Qt::CaseInsensitive) == 0 || + string.compare("true", Qt::CaseInsensitive) == 0 || + string.compare("f", Qt::CaseInsensitive) == 0 || + string.compare("t", Qt::CaseInsensitive) == 0); + return (string.compare("false", Qt::CaseInsensitive) != 0 && string.compare("f", Qt::CaseInsensitive) != 0); + } } int toInt(const QString &string) @@ -533,6 +541,8 @@ QVariant fromString(const QString &value) if (ok) return i; const float f = value.toFloat(&ok); if (ok) return f; + const bool b = QtUtils::toBool(value, &ok); + if (ok) return b; return value; } diff --git a/openbr/core/qtutils.h b/openbr/core/qtutils.h index 83eacd5..c557888 100644 --- a/openbr/core/qtutils.h +++ b/openbr/core/qtutils.h @@ -56,7 +56,7 @@ namespace QtUtils QString getAbsolutePath(const QString &filename); /**** String Utilities ****/ - bool toBool(const QString &string); + bool toBool(const QString &string, bool *ok = NULL); int toInt(const QString &string); float toFloat(const QString &string); QList toFloats(const QStringList &strings); diff --git a/openbr/plugins/gallery/csv.cpp b/openbr/plugins/gallery/csv.cpp index d751227..efdfcac 100644 --- a/openbr/plugins/gallery/csv.cpp +++ b/openbr/plugins/gallery/csv.cpp @@ -172,14 +172,19 @@ class csvGallery : public FileGallery if (!value.canConvert() || !value.toString().isEmpty()) f.set(header.key, values[header.indices.first()]); } - } else if (header.indices.size() == 2) // QPointF - f.appendPoint(QPointF(values[header.indices[header.subKeys.indexOf("X")]].toFloat(), - values[header.indices[header.subKeys.indexOf("Y")]].toFloat())); - else if (header.indices.size() == 4) // QRectF - f.appendRect(QRectF(values[header.indices[header.subKeys.indexOf("X")]].toFloat(), - values[header.indices[header.subKeys.indexOf("Y")]].toFloat(), - values[header.indices[header.subKeys.indexOf("Width")]].toFloat(), - values[header.indices[header.subKeys.indexOf("Height")]].toFloat())); + } else if (header.indices.size() == 2) { // QPointF + const QPointF point(values[header.indices[header.subKeys.indexOf("X")]].toFloat(), + values[header.indices[header.subKeys.indexOf("Y")]].toFloat()); + f.set(header.key, point); + f.appendPoint(point); + } else if (header.indices.size() == 4) { // QRectF + const QRectF rect(values[header.indices[header.subKeys.indexOf("X")]].toFloat(), + values[header.indices[header.subKeys.indexOf("Y")]].toFloat(), + values[header.indices[header.subKeys.indexOf("Width")]].toFloat(), + values[header.indices[header.subKeys.indexOf("Height")]].toFloat()); + f.set(header.key, rect); + f.appendRect(rect); + } } }