CMake: Implement cmake true/false semantics

Implement proper support for cmakes true/false value semantics.

Change-Id: I127f73f62d1b7b21b2fee032f40c9cc448b876b8
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Tobias Hunger
2019-06-07 12:51:25 +02:00
parent 08d905ae3d
commit 1f6c0f63a7
3 changed files with 26 additions and 9 deletions

View File

@@ -36,13 +36,6 @@
namespace CMakeProjectManager {
static bool isTrue(const QString &value)
{
const QString lower = value.toLower();
return lower == QStringLiteral("true") || lower == QStringLiteral("on")
|| lower == QStringLiteral("1") || lower == QStringLiteral("yes");
}
ConfigModel::ConfigModel(QObject *parent) : Utils::TreeModel<>(parent)
{
setHeader({tr("Key"), tr("Value")});
@@ -431,15 +424,17 @@ QVariant ConfigModelTreeItem::data(int column, int role) const
}
case 1: {
const QString value = currentValue();
const auto boolValue = CMakeConfigItem::toBool(value.toUtf8());
const bool isTrue = boolValue.has_value() && boolValue.value();
switch (role) {
case Qt::CheckStateRole:
return (dataItem->type == ConfigModel::DataItem::BOOLEAN)
? QVariant(isTrue(value) ? Qt::Checked : Qt::Unchecked) : QVariant();
? QVariant(isTrue ? Qt::Checked : Qt::Unchecked) : QVariant();
case Qt::DisplayRole:
return value;
case Qt::EditRole:
return (dataItem->type == ConfigModel::DataItem::BOOLEAN) ? QVariant(isTrue(value)) : QVariant(value);
return (dataItem->type == ConfigModel::DataItem::BOOLEAN) ? QVariant(isTrue) : QVariant(value);
case Qt::FontRole: {
QFont font;
font.setBold((dataItem->isUserChanged || dataItem->isUserNew) && !dataItem->isUnset);