QmlDesigner: Remove "Unknown" from available datatypes

Task-number: QDS-12555
Change-Id: I9c3261ac23188bcd7db875bec49091d044231a9f
Reviewed-by: Ali Kianian <ali.kianian@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
(cherry picked from commit a1829f0317)
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Shrief Gabr
2024-04-24 11:30:08 +03:00
committed by Tim Jenssen
parent 52dacf9505
commit 6e3108b33e
4 changed files with 12 additions and 29 deletions

View File

@@ -23,7 +23,6 @@ const QList<CollectionDataTypeModel::Details> CollectionDataTypeModel::m_ordered
{DataType::Color, "Color", "HEX value"},
{DataType::Url, "Url", "Resource locator"},
{DataType::Boolean, "Boolean", "True/false"},
{DataType::Unknown, "Unknown", "Unknown data type"},
};
CollectionDataTypeModel::CollectionDataTypeModel(QObject *parent)
@@ -76,7 +75,7 @@ CollectionDetails::DataType CollectionDataTypeModel::dataTypeFromString(const QS
if (stringTypeHash.contains(dataType))
return stringTypeHash.value(dataType);
return DataType::Unknown;
return DataType::String;
}
void CollectionDataTypeModel::registerDeclarativeType()

View File

@@ -107,18 +107,15 @@ static bool getCustomUrl(const QString &value,
if (urlResult)
urlResult->clear();
if (subType)
subType->clear();
dataType = CollectionDetails::DataType::Unknown;
dataType = CollectionDetails::DataType::String;
return false;
}
/**
* @brief dataTypeFromString
* @param value The string value to be evaluated
* @return Unknown if the string is empty, But returns Bool, Color, Integer,
* Real, Url, Image if these types are detected within the non-empty string,
* @return Bool, Color, Integer, Real, Url,
* Image if these types are detected within the non-empty string,
* Otherwise it returns String.
* If the value is integer, but it's out of the int range, it will be
* considered as a Real.
@@ -144,7 +141,7 @@ static CollectionDetails::DataType dataTypeFromString(const QString &value)
}({boolIndex, colorIndex, integerIndex, realIndex});
if (value.isEmpty())
return DataType::Unknown;
return DataType::String;
const QString trimmedValue = value.trimmed();
QRegularExpressionMatch match = validator.match(trimmedValue);
@@ -176,7 +173,7 @@ static CollectionProperty::DataType dataTypeFromJsonValue(const QJsonValue &valu
switch (value.type()) {
case JsonType::Null:
case JsonType::Undefined:
return DataType::Unknown;
return DataType::String;
case JsonType::Bool:
return DataType::Boolean;
case JsonType::Double: {
@@ -187,7 +184,7 @@ static CollectionProperty::DataType dataTypeFromJsonValue(const QJsonValue &valu
case JsonType::String:
return dataTypeFromString(value.toString());
default:
return DataType::Unknown;
return DataType::String;
}
}
@@ -208,9 +205,7 @@ static QList<CollectionProperty> getColumnsFromImportedJsonArray(const QJsonArra
const QString propertyName = element.key();
if (resultSet.contains(propertyName)) {
CollectionProperty &property = result[resultSet.value(propertyName)];
if (property.type == DataType::Unknown) {
property.type = dataTypeFromJsonValue(element.value());
} else if (property.type == DataType::Integer) {
if (property.type == DataType::Integer) {
const DataType currentCellDataType = dataTypeFromJsonValue(element.value());
if (currentCellDataType == DataType::Real)
property.type = currentCellDataType;
@@ -258,21 +253,10 @@ static QVariant valueToVariant(const QJsonValue &value, CollectionDetails::DataT
}
static QJsonValue variantToJsonValue(
const QVariant &variant, CollectionDetails::DataType type = CollectionDetails::DataType::Unknown)
const QVariant &variant, CollectionDetails::DataType type = CollectionDetails::DataType::String)
{
using VariantType = QVariant::Type;
using DataType = CollectionDetails::DataType;
if (type == CollectionDetails::DataType::Unknown) {
static const QHash<VariantType, DataType> typeMap = {{VariantType::Bool, DataType::Boolean},
{VariantType::Double, DataType::Real},
{VariantType::Int, DataType::Integer},
{VariantType::String, DataType::String},
{VariantType::Color, DataType::Color},
{VariantType::Url, DataType::Url}};
type = typeMap.value(variant.type(), DataType::Unknown);
}
switch (type) {
case DataType::Boolean:
return variant.toBool();
@@ -606,7 +590,7 @@ DataTypeWarning::Warning CollectionDetails::cellWarningCheck(int row, int column
const DataType columnType = typeAt(column);
const DataType cellType = typeAt(row, column);
if (columnType == DataType::Unknown || isEmptyJsonValue(cellValue))
if (isEmptyJsonValue(cellValue))
return DataTypeWarning::Warning::None;
if (columnType == DataType::Real && cellType == DataType::Integer)

View File

@@ -90,7 +90,7 @@ public:
void insertColumn(const QString &propertyName,
int colIdx = -1,
const QVariant &defaultValue = {},
DataType type = DataType::Unknown);
DataType type = DataType::String);
bool removeColumns(int colIdx, int count = 1);
void insertEmptyRows(int row = 0, int count = 1);

View File

@@ -197,7 +197,7 @@ QVariant CollectionDetailsModel::headerData(int section, Qt::Orientation orienta
CollectionDetails::DataType CollectionDetailsModel::propertyDataType(int column) const
{
QTC_ASSERT(m_currentCollection.hasValidReference(), return CollectionDetails::DataType::Unknown);
QTC_ASSERT(m_currentCollection.hasValidReference(), return CollectionDetails::DataType::String);
return m_currentCollection.typeAt(column);
}